Skip to content

Commit

Permalink
Review works
Browse files Browse the repository at this point in the history
For testing purpose, when user remembers a word, the rev date is unchanged. Also when user adds a new word, user can review the word right after (before it was one day later)
  • Loading branch information
githubalexliu committed Mar 22, 2018
1 parent 1b25af6 commit 1bb2652
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 48 deletions.
20 changes: 10 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var express = require('express');
var session = require('express-session');
var express = require('express');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var app = express();
var port = process.env.PORT || 3000;
var app = express();
var port = process.env.PORT || 3000;

var passport = require('passport');
var flash = require('connect-flash');
var flash = require('connect-flash');

require('./config/passport')(passport);
app.use('/public', express.static('public'));
Expand All @@ -17,17 +17,17 @@ app.use('/node_modules', express.static('node_modules'));
app.use(morgan('dev'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({
extended: true
extended: true
}));
app.use(bodyParser.json());

app.set('view engine', 'ejs');

app.use(session({
secret: 'vocabuilder',
resave: true,
saveUninitialized: true
} ));
secret: 'vocabuilder',
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
Expand Down
20 changes: 16 additions & 4 deletions app/review.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
module.exports = function(req, res) {
remword = function(userid, wordid) {
connection.query("UPDATE ?? SET progress = progress + 1, daterev = ADDDATE(daterev, 2*progress) WHERE id = ?",
[userid, wordid], function(err, rows) {
if (err) throw err;
});
if (word.numDontRem < 2) {
connection.query("UPDATE ?? SET progress = progress + 1, daterev = ADDDATE(daterev, 2*progress) WHERE id = ?",
[userid, wordid], function(err, rows) {
if (err) throw err;
});
}
}

// a function that does not set a new revision date, for testing purposes
remword2 = function(userid, word) {
if (word.numDontRem < 2) {
connection.query("UPDATE ?? SET progress = progress + 1 WHERE id = ?",
[userid, word.id], function(err, rows) {
if (err) throw err;
});
}
}
};
var mysql = require('mysql');
Expand Down
2 changes: 1 addition & 1 deletion app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module.exports = function(app, passport) {
});

app.post('/remword', function(req, res) {
remword(req.user.id, req.body.id);
remword2(req.user.id, req.body);
});

app.get('/logout', function(req, res) {
Expand Down
6 changes: 4 additions & 2 deletions app/word-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ module.exports = function(req, res) {
mm = tomorrow.getMonth()+1;
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, tomorrow, "1000-1-1"], function(err, rows) {
[userid, word, phonetic, meaning, 0, today, today, "1000-1-1"], function(err, rows) {
if (err) throw err;
});
}
Expand Down Expand Up @@ -40,7 +41,8 @@ module.exports = function(req, res) {
}

getRevWordList = function(userid, callback) {
connection.query("SELECT * FROM ?? WHERE DATE_FORMAT(daterev, '%Y-%m-%d') <= CURDATE()",
connection.query("SELECT * FROM ?? WHERE DATE_FORMAT(daterev, '%Y-%m-%d') <= CURDATE() \
and progress < 10",
[userid], function(err, rows){
if (err) throw err;
return callback(null, rows);
Expand Down
16 changes: 8 additions & 8 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// config/database.js
module.exports = {
'connection': {
'host': 'localhost',
'user': 'root',
'password': 'root'
},
'database': 'vocabuilder',
'users_table': 'users'
};
'connection': {
'host': 'localhost',
'user': 'root',
'password': 'root'
},
'database': 'vocabuilder',
'users_table': 'users'
};
9 changes: 4 additions & 5 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@ module.exports = function(passport) {
password: bcrypt.hashSync(password, null, null),
};
var insertQuery = "INSERT INTO users ( username, password, firstname, lastname, email ) values (?,?,?,?,?)";
connection.query(insertQuery, [newUserMysql.username, newUserMysql.password
, req.body.firstname, req.body.lastname, req.body.email], function(err, rows) {
connection.query(insertQuery, [newUserMysql.username, newUserMysql.password, req.body.firstname, req.body.lastname, req.body.email], function(err, rows) {
newUserMysql.id = rows.insertId;
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), \
progress TINYINT, dateadded DATE, daterev DATE, datecomp DATE, \
UNIQUE INDEX `id_UNIQUE` (`id` ASC))', [tablename], function(err, rows) {
if (err) throw err;
});
if (err) throw err;
});
return done(null, newUserMysql);
});
}
Expand Down Expand Up @@ -86,4 +85,4 @@ module.exports = function(passport) {
});
})
);
};
};
41 changes: 27 additions & 14 deletions public/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
.btn-primary {
background-color: #5B9BD5 !important;
}

.top-buffer-20 {
margin-top:20px;
margin-top: 20px;
}

.top-buffer-50 {
margin-top:50px;
margin-top: 50px;
}

.table-borderless td, .table-borderless th {
border: none;
border: none;
}

.form-inline input {
margin-left: 10px;
margin-left: 10px;
}

.form-inline * {
margin-bottom: 10px;
}

.navbar-custom {
background-color: #5B9BD5;
background-color: #5B9BD5;
}

/* change the brand and text color */
.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
color: rgba(255,255,255,.8);

.navbar-custom .navbar-brand, .navbar-custom .navbar-text {
color: rgba(255, 255, 255, .8);
}

/* change the link color */

.navbar-custom .navbar-nav .nav-link {
color: rgba(255,255,255,.5);
color: rgba(255, 255, 255, .5);
}

/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:hover .nav-link {
color: #ffffff;

.navbar-custom .nav-item.active .nav-link, .navbar-custom .nav-item:hover .nav-link {
color: #ffffff;
}

.form-control {
width: 100%;
}
.form-control { width: 100%; }

.modal-error {
background-color: #F2DEDE !important;
Expand All @@ -56,4 +69,4 @@
width: 50%;
float: left;
padding: 1%;
}
}
2 changes: 1 addition & 1 deletion views/modals/profile.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@
</div>
</div>
</div>
</div>
</div>
4 changes: 3 additions & 1 deletion views/partials/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<link rel="stylesheet" href="public/css/styles.css">
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<title>Vocabuilder | <%= title %></title>
<title>Vocabuilder |
<%= title %>
</title>
7 changes: 6 additions & 1 deletion views/review.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
numRemain.innerHTML = wordlist.length;
if (wordlist.length > 0) {
word.innerHTML = wordlist[0].word;
wordlist[0].numDontRem = 0;
} else {
word.style.color = "red";
word.innerHTML = "There are no words to review";
Expand All @@ -33,9 +34,11 @@
url: "/remword",
type: "post",
data: {
id: wordlist[0].id
id: wordlist[0].id,
numDontRem: wordlist[0].numDontRem
}
});
console.log(wordlist[0].numDontRem);
wordlist.shift();
this.disabled = true;
dontRem.disabled = true;
Expand All @@ -51,6 +54,8 @@
}
});
$('#dontRem').on('click', function() {
wordlist[0].numDontRem++;
console.log(wordlist[0].numDontRem);
wordlist.push(wordlist.shift());
this.disabled = true;
rem.disabled = true;
Expand Down
5 changes: 4 additions & 1 deletion views/word-list.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@
<%= wordlist[i].meaning %>
</td>
<td>
<%= wordlist[i].progress %>
<!-- <%= wordlist[i].progress %> -->
<div class="progress">
<div class="progress-bar bg-success" role="progressbar" style="width: <%- wordlist[i].progress %>0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="10"></div>
</div>
</td>
<td>
<%= wordlist[i].dateadded.toLocaleDateString("en-US") %>
Expand Down

0 comments on commit 1bb2652

Please sign in to comment.