Skip to content

Commit

Permalink
Adding public rules page; rounding points
Browse files Browse the repository at this point in the history
  • Loading branch information
etousley committed Aug 31, 2017
1 parent c5cfec4 commit 315ae2a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 12 deletions.
4 changes: 3 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ dotenv.load({ path: '.env' });
const homeController = require('./controllers/home');
const userController = require('./controllers/user');
const logEntryController = require('./controllers/logEntry');
const contestController = require('./controllers/contest')
const contestController = require('./controllers/contest');
const rulesController = require('./controllers/rules');

/**
* API keys and Passport configuration.
Expand Down Expand Up @@ -118,6 +119,7 @@ app.use(express.static(path.join(__dirname, 'public'), { maxAge: 31557600000 }))
* Primary app routes.
*/
app.get('/', homeController.index);
app.get('/rules', rulesController.index);
app.get('/login', userController.getLogin);
app.post('/login', userController.postLogin);
app.get('/logout', userController.logout);
Expand Down
3 changes: 0 additions & 3 deletions controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ exports.index = (req, res) => {
const tomorrow = moment(today).add(1, 'days').format(dateMask);
const entriesTodayQuery = {"date": { "$gte": today, "$lt": tomorrow } };

console.log(entriesTodayQuery);

LogEntry.find(entriesTodayQuery, function(err, result) {
if (err) {
res.status(500).send({"error": err})
} else {
console.log(result);
res.render('home', {
title: 'Home',
user: req.user,
Expand Down
8 changes: 4 additions & 4 deletions controllers/logEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ exports.getActivityDefinitions = (req, res) => {
*/
calculateActivityPoints = (logEntry) => {
const activityDefinition = lookups.activitiesSortedAlpha[logEntry.activity];
// console.log(JSON.stringify(logEntry));
console.log(JSON.stringify(logEntry));

// Is it the right time unit?
if (logEntry.durationUnit !== activityDefinition.durationUnit) {
throw Error('500 error: Invalid activity.durationUnit: ' + logEntry.durationUnit + '. Expected: ' + activityDefinition.durationUnit);
}

const completedTimeChunks = Math.floor(logEntry.durationValue / activityDefinition.durationValue);
const points = completedTimeChunks * activityDefinition.points;
// console.log("calculated points: " + points);
const completedTimeChunks = logEntry.durationValue / activityDefinition.durationValue;
const points = Math.round(completedTimeChunks * activityDefinition.points);
console.log("calculated points: " + points);

return points;
};
Expand Down
11 changes: 11 additions & 0 deletions controllers/rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

/**
* GET /
* Rules page.
*/
exports.index = (req, res) => {
res.render('rules', {
title: 'Rules',
user: req.user
});
};
8 changes: 8 additions & 0 deletions public/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ textarea {
margin-left: 1em;
}

.paper {
margin: 20px;
width: 100%;
box-shadow: 0px 0px 30px 3px grey;
}



// .entry-duration-value-input {
// max-width: 100px;
// }
8 changes: 4 additions & 4 deletions public/js/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fillLogEntries = () => {
const startDate = dayElems[0].dataset.date;
const endDate = dayElems[dayElems.length - 1].dataset.date;
const getLogEntriesUrl = '/api/log?' + jQuery.param({
"userEmail": ownerEmail,
"user": ownerEmail,
"from": startDate,
"to": endDate
});
Expand Down Expand Up @@ -115,7 +115,7 @@ drawLogEntryModal = (clickedDayElem) => {
let entryData = {
"date": entryDateField.text(),
"title": entryTitleField.val(),
"userEmail": ownerEmail,
"user": ownerEmail,
"activity": entryActivityField.html(),
"description": entryDescriptionField.val(),
"durationValue": entryDurationValueField.val(),
Expand Down Expand Up @@ -335,8 +335,8 @@ selectActivity = (activityElem) => {
$(document).ready(function() {
setCSRFToken($('meta[name="csrf-token"]').attr('content'));

console.log('ownerEmail: ' + ownerEmail);
console.log('userEmail: ' + userEmail);
// console.log('ownerEmail: ' + ownerEmail);
// console.log('userEmail: ' + userEmail);

modal.modal('hide');

Expand Down
Empty file added public/js/rules.js
Empty file.
Binary file added public/rules.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions views/partials/header.pug
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
ul.nav.navbar-nav
li(class=(title == 'Home') ? 'active' : undefined)
a(href='/') Home
li(class=(title == 'Rules') ? 'active' : undefined)
a(href='/rules') Rules
if user
li(class=(title == 'My Log') ? 'active' : undefined)
a(href='/log/' + user.email) My Log
Expand Down
8 changes: 8 additions & 0 deletions views/rules/index.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends ../layout

block content
h1 Rules

.row
.col-md-10.col-md-offset-1
img.paper(src='/rules.jpg' title="Rules")

0 comments on commit 315ae2a

Please sign in to comment.