aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/controllers
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-05-24 22:49:33 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-05-24 22:49:33 +0200
commita8f97f0c4fe2bea23be66965c250b257ace04971 (patch)
treefc253f0ff63ce2da0dcf90711e8776b1b6eea268 /controllers
parentadded overview and example of dividing. (diff)
downloadDivid-a8f97f0c4fe2bea23be66965c250b257ace04971.tar.gz
fixed settlement in projects on dashboard. improves on #9 and closes #29
Diffstat (limited to 'controllers')
-rw-r--r--controllers/system.js32
1 files changed, 26 insertions, 6 deletions
diff --git a/controllers/system.js b/controllers/system.js
index c083835..c29e06f 100644
--- a/controllers/system.js
+++ b/controllers/system.js
@@ -99,19 +99,39 @@ exports.dashboard = function(req, res) {
Access.loadUser(req.user._id, function(err, projects) {
if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
var projectIDs = [];
- projects.forEach(function(project) { projectIDs.push(project.project._id); });
+ var pro = { project: [] };
+ projects.forEach(function(project) {
+ projectIDs.push(project.project._id);
+ pro.project[project.project._id] = {
+ total: 0 // total for project
+ , user: 0 // what req-user has spent on project
+ , users: 0 // number of users on project
+ };
+ });
Access.loadProjects(projectIDs, function(err, participants) {
if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
+ participants.forEach(function(p) {
+ pro.project[p.project].users++;
+ });
pPost.loadByProjects(projectIDs, function(err, posts) {
if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
Access.loadProjects(projectIDs, function(err, participants) {
if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
+
+ // FUN FUN FUN CALCULATIONS
+
+ posts.forEach(function(p) {
+ if (String(p.user._id) === String(req.user._id)) pro.project[p.project._id].user += p.value;
+ pro.project[p.project._id].total += p.value;
+ });
+
res.render('dashboard', {
- title: 'Dashboard',
- user: req.user,
- projects: projects,
- posts: posts,
- participants: participants
+ title: 'Dashboard'
+ , user: req.user
+ , projects: projects
+ , posts: posts
+ , participants: participants
+ , pro: pro
});
});
});