-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
255 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,15 @@ const moment = require('moment'); | |
const LogEntry = require('../models/LogEntry'); | ||
const lookups = require('../public/js/lookups.js'); | ||
|
||
|
||
/** | ||
* Return activityDefinitions object | ||
*/ | ||
exports.getActivityDefinitions = (req, res) => { | ||
res.send(lookups.activityDefinitions); | ||
}; | ||
|
||
|
||
/** | ||
* GET /log | ||
* Render logEntry log template | ||
|
@@ -21,35 +23,41 @@ exports.getLog = (req, res) => { | |
}); | ||
}; | ||
|
||
|
||
/** | ||
* REST API endpoint | ||
* GET all log entries. Can filter with query string, e.g.: | ||
* /api/[email protected]&from=2017-05-01&to=2017-06-01 | ||
*/ | ||
exports.getLogEntries = (req, res) => { | ||
const user = req.query.user; // user's email address | ||
let user = req.query.user; // user's email address | ||
let from = req.query.from; | ||
let to = req.query.to; | ||
let filter = {}; | ||
|
||
if (user !== undefined) { | ||
filter.user = user; | ||
user = user.replace('%40', '@'); // '@' symbol gets escaped sometimes | ||
filter["user"] = user; | ||
} | ||
if (from !== undefined) { | ||
from = moment(from, 'YYYY-MM-DD').toArray(); | ||
filter.from = { $gte: new Date(from[0], from[1], from[2]) }; | ||
} | ||
if (to !== undefined) { | ||
to = moment(to, 'YYYY-MM-DD').toArray(); | ||
filter.to = { $lte: new Date(to[0], to[1], to[2]) }; | ||
|
||
if (from !== undefined || to !== undefined) { | ||
filter["date"] = {}; | ||
if (from !== undefined) { | ||
filter["date"]["$gte"] = from; | ||
} | ||
if (to !== undefined) { | ||
filter["date"]["$lte"] = to; | ||
} | ||
} | ||
console.log(JSON.stringify(filter)); | ||
|
||
console.log('filter: ' + JSON.stringify(filter)); | ||
|
||
LogEntry.find(filter, function(err, activities) { | ||
res.send({ data: activities }); | ||
}); | ||
}; | ||
|
||
|
||
/** | ||
* REST API endpoint | ||
* GET one log entry by ID | ||
|
@@ -62,6 +70,7 @@ exports.getLogEntry = (req, res) => { | |
}); | ||
}; | ||
|
||
|
||
/** | ||
* REST API endpoint | ||
* Update log entry by ID | ||
|
@@ -76,6 +85,7 @@ exports.updateLogEntry = (req, res) => { | |
}); | ||
}; | ||
|
||
|
||
/** | ||
* REST API endpoint | ||
* Create new log entry | ||
|
@@ -89,6 +99,7 @@ exports.createLogEntry = (req, res) => { | |
}); | ||
}; | ||
|
||
|
||
/** | ||
* REST API endpoint | ||
* Delete log entry by id | ||
|
@@ -102,6 +113,7 @@ exports.deleteLogEntry = (req, res) => { | |
}); | ||
}; | ||
|
||
|
||
/** | ||
* Calculate points based on activity and duration | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,103 @@ | ||
|
||
// TODO: get log data | ||
// TODO: map log data to DOM calendar | ||
// TODO: view existing log entry | ||
// TODO: create/edit log entry (in modal?) | ||
// TODO: save log entry | ||
|
||
|
||
/** | ||
* Get log data from REST API | ||
* E.g. queryParams = {'user': 'me@domain.com', 'from': '2017-08-01', 'to': '2017-09-01'}; | ||
* Get log data from REST API, then draw them to calendar | ||
*/ | ||
getLogEntries = (queryParams) => { | ||
let url = '/api/log?' + jQuery.param(queryParams); | ||
console.log(url); | ||
fillLogEntries = () => { | ||
const dayElems = $('.fc-day'); | ||
const email = window.location.href.split("/").slice(-1)[0]; | ||
const startDate = dayElems[0].dataset.date; | ||
const endDate = dayElems[dayElems.length - 1].dataset.date; | ||
const ignoreDataKeys = {'_id': 1, 'user': 1} | ||
let entryTitle = undefined; | ||
let entryElem = undefined; | ||
|
||
// Build query parameters for GET request | ||
const url = '/api/log?' + jQuery.param({ | ||
"email": email, | ||
"from": startDate, | ||
"to": endDate | ||
}); | ||
|
||
// Map data to calendar days | ||
// Could probably do this more efficiently... | ||
$.get(url, function(data) { | ||
return data; | ||
for (entry of data.data) { | ||
for (dayElem of dayElems) { | ||
if (entry.date.slice(0, 10) === dayElem.dataset.date) { | ||
entryTitle = entry.title || (entry.activity + " (" + entry.durationValue + " " + entry.durationUnit + "s)"); | ||
entryElem = document.createElement("div"); | ||
entryElem.className = "log-entry-title"; | ||
entryElem.textContent = entryTitle; | ||
|
||
// Add data as data-foo attributes to the event element (probably a better way...) | ||
for (let [key, value] of Object.entries(entry)) { | ||
if ( !(key in ignoreDataKeys) ) { | ||
entryElem.dataset[key] = value; | ||
} | ||
} | ||
|
||
dayElem.appendChild(entryElem); | ||
break; | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
|
||
/** | ||
* Render and display modal to reflect data (date, user, existing activities) | ||
*/ | ||
drawLogEntryModal = (email, date) => { | ||
const modal = $('#log-entry-modal'); | ||
const modalTitle = modal.find('.modal-title'); | ||
const modalBody = modal.find('.modal-body'); | ||
|
||
const testQueryParams = { | ||
'user': '[email protected]', | ||
'from': '2017-08-01', | ||
'to': '2017-09-01' | ||
}; | ||
const testData = getLogEntries(testQueryParams); | ||
console.log(testData); | ||
|
||
modalTitle.html('Log: ' + data.date); | ||
drawLogEntryModal = (clickedDayElem) => { | ||
const entryElem = clickedDayElem.find('.log-entry-title')[0]; | ||
let modal = $('#log-entry-modal'); | ||
let modalDate = modal.find('.entry-date'); | ||
let modalTitle = modal.find('.entry-title-input'); | ||
let modalActivity = modal.find('.entry-activity-input'); | ||
let modalDurationValue = modal.find('.entry-duration-value-input'); | ||
let modalDescription = modal.find('.entry-description-input'); | ||
|
||
modalDate.html( entryElem.dataset.date.slice(0, 10) ); | ||
modalTitle.val(entryElem.dataset.title); | ||
modalActivity.html(entryElem.dataset.activity); // TODO: this is wrong | ||
modalDurationValue.val(entryElem.dataset.durationValue); | ||
modalDescription.val(entryElem.dataset.description); | ||
|
||
modal.modal('show'); | ||
}; | ||
|
||
|
||
|
||
|
||
/** | ||
* Do stuff when page loads | ||
*/ | ||
$(document).ready(function() { | ||
let visibleDates = undefined; | ||
|
||
// Hide modal | ||
$('#log-entry-modal').modal('hide'); | ||
|
||
// Draw calendar | ||
// Draw calendar | ||
$('#calendar').fullCalendar({ | ||
// put options and callbacks here | ||
}); | ||
|
||
// Retrieve and insert log entries for visible date range | ||
// TODO: this should also get called when month arrows are clicked | ||
fillLogEntries(); | ||
|
||
$('.fc-day').on('click touch', function () { | ||
const clickedDate = $(this).attr('data-date'); | ||
const clickedDayElem = $(this); | ||
|
||
// Mark active day | ||
$('.fc-day').removeClass('active'); | ||
$(this).addClass('active'); | ||
clickedDayElem.addClass('active'); | ||
|
||
drawLogEntryModal(clickedDate); | ||
drawLogEntryModal(clickedDayElem); | ||
// $('#log-entry-modal').modal('show'); | ||
}); | ||
}); |
Oops, something went wrong.