diff options
author | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-24 22:49:33 +0200 |
---|---|---|
committer | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-24 22:49:33 +0200 |
commit | a8f97f0c4fe2bea23be66965c250b257ace04971 (patch) | |
tree | fc253f0ff63ce2da0dcf90711e8776b1b6eea268 | |
parent | added overview and example of dividing. (diff) | |
download | Divid-a8f97f0c4fe2bea23be66965c250b257ace04971.tar.gz |
fixed settlement in projects on dashboard. improves on #9 and closes #29
-rw-r--r-- | controllers/system.js | 32 | ||||
-rw-r--r-- | views/dashboard.ejs | 23 |
2 files changed, 29 insertions, 26 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 }); }); }); diff --git a/views/dashboard.ejs b/views/dashboard.ejs index 21aef0d..c759add 100644 --- a/views/dashboard.ejs +++ b/views/dashboard.ejs @@ -32,7 +32,8 @@ </small> </div> <div class="span4"> - <small>Oppgjør: <span class="text-error">-200 kr</span></small> + <% s = (pro.project[projects.project._id].user - (pro.project[projects.project._id].total / pro.project[projects.project._id].users)).toFixed(2); %> + <small>Oppgjør: <%- s >= 0 ? '<span class="text-success">' + s : '<span class="text-error">' + s %></span> <%= projects.project.currency %></small> </div> </div> </div> @@ -55,25 +56,7 @@ <div class="smallfullwidth span7"> <section class="status"> - <div class="row-fluid"> - <div class="span6 smallfullwidth"> - <h1>Status total</h1> - </div> - <div class="span6 smallfullwidth"> - <div class="row-fluid"> - <table class="table table-bordered table-condensed"> - <tr> - <td class="success">3000</td> - <td class="error">4000</td> - <td>1000</td> - </tr> - </table><a href="#table-info" class="accordion-toggle" data-toggle="collapse"><i class="icon-info-sign"></i></a> - </div> - <div class="row-fluid accordion collapse" id="table-info"> - <p class="text-info"><small>Her vises hvor mye andre skylder deg totalt, hvor mye du skylder andre totalt, og differansen mellom disse to tallene</small></p> - </div> - </div> - </div> + <h1>Status total</h1> <canvas id="myChart" width="530" height="200"></canvas> </section> <section class="overview"> |