From bb4a2ab896ce12672203e38c3a1527c336ee1678 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 20 Sep 2014 18:31:39 +0900 Subject: [PATCH] Adding preset table to prevent core keywords from being deleted --- client/application.js | 1 + scrape/db.js | 12 ++++++++++++ scrape/hscd.sql | 25 ++++++++++++++++++++++++- server/search.js | 4 ++-- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/client/application.js b/client/application.js index b698809..224bd97 100644 --- a/client/application.js +++ b/client/application.js @@ -152,6 +152,7 @@ $('#forgetKeyword').click(onForget); $('#forgetDialog').on('show.bs.modal', function() { + $('#forgetError').hide(); $.getJSON('/node/getKeywords', function(keywords) { $('#forgetKeyword').prop('disabled', keywords.length === 0); $('#keywordToForget').empty(); diff --git a/scrape/db.js b/scrape/db.js index 4185029..e62e65d 100755 --- a/scrape/db.js +++ b/scrape/db.js @@ -49,4 +49,16 @@ for (var keyword in keywords) { conn.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', [keyword].concat(record)); } + +// +// Presets +// + +conn.query('DROP TABLE IF EXISTS presets'); +conn.query('CREATE TABLE presets(name VARCHAR(50) NOT NULL, PRIMARY KEY(name))'); + +for (var keyword in keywords) { + conn.query('INSERT INTO presets VALUES(?)', [keyword]); +} + conn.end(); diff --git a/scrape/hscd.sql b/scrape/hscd.sql index 4e312ed..782943b 100644 --- a/scrape/hscd.sql +++ b/scrape/hscd.sql @@ -42,6 +42,29 @@ INSERT INTO `keywords` VALUES ('atmosphere',0,0,0,1),('food',1,0,0,0),('service' /*!40000 ALTER TABLE `keywords` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Table structure for table `presets` +-- + +DROP TABLE IF EXISTS `presets`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `presets` ( + `name` varchar(50) NOT NULL, + PRIMARY KEY (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `presets` +-- + +LOCK TABLES `presets` WRITE; +/*!40000 ALTER TABLE `presets` DISABLE KEYS */; +INSERT INTO `presets` VALUES ('atmosphere'),('food'),('service'),('value'); +/*!40000 ALTER TABLE `presets` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `reviews` -- @@ -78,4 +101,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2014-09-19 10:22:03 +-- Dump completed on 2014-09-20 18:31:08 diff --git a/server/search.js b/server/search.js index 51858df..6abba66 100644 --- a/server/search.js +++ b/server/search.js @@ -168,10 +168,10 @@ function addKeyword(query, callback) { } function removeKeyword(query, callback) { - connection.query('DELETE FROM keywords WHERE name=?', [query.keyword], function(err) { + connection.query('DELETE FROM keywords WHERE name=? AND name NOT IN (SELECT name FROM presets)', [query.keyword], function(err, fields) { callback({ keyword: query.keyword, - success: err === null + success: err === null && fields.affectedRows > 0 }); }); }