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 @@+ | Word | +Part of Speech | +Meaning | +
---|