diff --git a/app/dictionary.js b/app/dictionary.js new file mode 100644 index 0000000..9650a87 --- /dev/null +++ b/app/dictionary.js @@ -0,0 +1,13 @@ +module.exports = function(req, res) { + searchword = function(word, callback) { + connection.query("SELECT * FROM dictionary WHERE word = ?", [word], function(err, rows) { + if (err) throw err; + return callback(null, rows); + }); + } +}; +var mysql = require('mysql'); +var dbconfig = require('../config/database'); +var bcrypt = require('bcrypt-nodejs'); +var connection = mysql.createConnection(dbconfig.connection); +connection.query('USE ' + dbconfig.database); diff --git a/app/routes.js b/app/routes.js index 1e809bc..65fcd33 100644 --- a/app/routes.js +++ b/app/routes.js @@ -98,12 +98,12 @@ module.exports = function(app, passport) { }); app.post('/addword', function(req, res) { - addWord(req.user.id, req.body.word, req.body.phonetic, req.body.meaning); + addWord(req.user.id, req.body.word, req.body.pos, req.body.meaning); res.redirect('back'); }); app.post('/editword', function(req, res) { - editWord(req.user.id, req.body.id, req.body.word, req.body.phonetic, req.body.meaning); + editWord(req.user.id, req.body.id, req.body.word, req.body.pos, req.body.meaning); res.redirect('back'); }); @@ -134,6 +134,12 @@ module.exports = function(app, passport) { }); }); + app.post('/searchword', function(req, res) { + searchword(req.body.word, function(err, data){ + res.send(data); + }); + }); + app.get('/logout', function(req, res) { req.logout(); res.redirect('/'); @@ -148,6 +154,7 @@ connection.query('USE ' + dbconfig.database); require('./profile.js')(); require('./word-list.js')(); require('./review.js')(); +require('./dictionary.js')(); function isLoggedIn(req, res, next) { if (req.isAuthenticated()) diff --git a/app/word-list.js b/app/word-list.js index 0f81a2d..dd3a8f2 100644 --- a/app/word-list.js +++ b/app/word-list.js @@ -1,5 +1,5 @@ module.exports = function(req, res) { - addWord = function(userid, word, phonetic, meaning) { + addWord = function(userid, word, pos, meaning) { var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; @@ -12,8 +12,8 @@ module.exports = function(req, res) { yyyy = tomorrow.getFullYear(); tomorrow = yyyy + '-' + mm + '-' + dd; // review date is set to today for testing purpose - connection.query("INSERT INTO ?? ( word, phonetic, meaning, progress, dateadded, daterev, datecomp ) values (?,?,?,?,?,?,?)", - [userid, word, phonetic, meaning, 0, today, today, "1000-1-1"], function(err, rows) { + connection.query("INSERT INTO ?? ( word, pos, meaning, progress, dateadded, daterev, datecomp ) values (?,?,?,?,?,?,?)", + [userid, word, pos, meaning, 0, today, today, "1000-1-1"], function(err, rows) { if (err) throw err; }); } @@ -27,9 +27,9 @@ module.exports = function(req, res) { }); } - editWord = function(userid, wordid, word, phonetic, meaning) { - connection.query("UPDATE ?? SET word = ?, phonetic = ?, meaning = ? WHERE id = ?", - [userid, word, phonetic, meaning, wordid], function(err, rows){ + editWord = function(userid, wordid, word, pos, meaning) { + connection.query("UPDATE ?? SET word = ?, pos = ?, meaning = ? WHERE id = ?", + [userid, word, pos, meaning, wordid], function(err, rows){ if (err) throw err; }); } diff --git a/config/passport.js b/config/passport.js index 08ea435..d6bafd8 100644 --- a/config/passport.js +++ b/config/passport.js @@ -47,7 +47,7 @@ module.exports = function(passport) { console.log(rows.insertId); var tablename = rows.insertId; connection.query('CREATE TABLE ?? (id INT AUTO_INCREMENT PRIMARY KEY, \ - word VARCHAR(30), phonetic VARCHAR(10), meaning VARCHAR(255), \ + word VARCHAR(30), pos VARCHAR(10), meaning VARCHAR(255), \ progress TINYINT, dateadded DATE, daterev DATE, datecomp DATE, \ UNIQUE INDEX `id_UNIQUE` (`id` ASC))', [tablename], function(err, rows) { if (err) throw err; diff --git a/views/dictionary.ejs b/views/dictionary.ejs index 3d90616..2ccc45f 100644 --- a/views/dictionary.ejs +++ b/views/dictionary.ejs @@ -3,6 +3,59 @@ <% include partials/head %> + + + @@ -10,21 +63,26 @@
-
-
- - - +
+ + + -
- - +
-
-
+
+
+ + + + + + + + +
WordPart of SpeechMeaning
diff --git a/views/modals/word-list.ejs b/views/modals/word-list.ejs index 75ae5bb..eba6471 100644 --- a/views/modals/word-list.ejs +++ b/views/modals/word-list.ejs @@ -16,9 +16,9 @@
- +
- +
@@ -73,9 +73,9 @@
- +
- +
diff --git a/views/review.ejs b/views/review.ejs index 89e7b0c..d3dbda7 100644 --- a/views/review.ejs +++ b/views/review.ejs @@ -38,7 +38,6 @@ numDontRem: wordlist[0].numDontRem } }); - console.log(wordlist[0].numDontRem); wordlist.shift(); this.disabled = true; dontRem.disabled = true; @@ -55,7 +54,6 @@ }); $('#dontRem').on('click', function() { wordlist[0].numDontRem++; - console.log(wordlist[0].numDontRem); wordlist.push(wordlist.shift()); this.disabled = true; rem.disabled = true; diff --git a/views/word-list.ejs b/views/word-list.ejs index 7bed09b..4cdafc7 100644 --- a/views/word-list.ejs +++ b/views/word-list.ejs @@ -38,7 +38,7 @@ var data = table.rows('.selected').data(); $(this).find('#id').val(data[0][0]); $(this).find('#word').val(data[0][1]); - $(this).find('#phonetic').val(data[0][2]); + $(this).find('#pos').val(data[0][2]); $(this).find('#meaning').val(data[0][3]); }); @@ -84,7 +84,7 @@ ID Word - Phonetic
Symbol + Part of Speech Meaning Progress Date added @@ -100,7 +100,7 @@ <%= wordlist[i].word %> - <%= wordlist[i].phonetic %> + <%= wordlist[i].pos %> <%= wordlist[i].meaning %>