1

Adding preset table to prevent core keywords from being deleted

This commit is contained in:
Alex Yatskov 2014-09-20 18:31:39 +09:00
parent 764643da03
commit bb4a2ab896
4 changed files with 39 additions and 3 deletions

View File

@ -152,6 +152,7 @@
$('#forgetKeyword').click(onForget); $('#forgetKeyword').click(onForget);
$('#forgetDialog').on('show.bs.modal', function() { $('#forgetDialog').on('show.bs.modal', function() {
$('#forgetError').hide();
$.getJSON('/node/getKeywords', function(keywords) { $.getJSON('/node/getKeywords', function(keywords) {
$('#forgetKeyword').prop('disabled', keywords.length === 0); $('#forgetKeyword').prop('disabled', keywords.length === 0);
$('#keywordToForget').empty(); $('#keywordToForget').empty();

View File

@ -49,4 +49,16 @@ for (var keyword in keywords) {
conn.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', [keyword].concat(record)); 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(); conn.end();

View File

@ -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 */; /*!40000 ALTER TABLE `keywords` ENABLE KEYS */;
UNLOCK TABLES; 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` -- Table structure for table `reviews`
-- --
@ -78,4 +101,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!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

View File

@ -168,10 +168,10 @@ function addKeyword(query, callback) {
} }
function removeKeyword(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({ callback({
keyword: query.keyword, keyword: query.keyword,
success: err === null success: err === null && fields.affectedRows > 0
}); });
}); });
} }