This commit is contained in:
Andrew Hayward 2013-06-01 00:18:42 +01:00
Родитель 00637a8208
Коммит 328be700cc
3 изменённых файлов: 61 добавлений и 0 удалений

1
app.js
Просмотреть файл

@ -35,6 +35,7 @@ app.use(helpers.addMessages);
require('./controllers/auth')(app);
require('./controllers/info')(app);
require('./controllers/backpack')(app);
require('./controllers/dashboard')(app);
require('./controllers/program')(app);
require('./controllers/learn')(app);
require('./controllers/challenges')(app);

32
controllers/dashboard.js Normal file
Просмотреть файл

@ -0,0 +1,32 @@
const db = require('../db');
const isGuardian = require('../middleware').isGuardian;
const _ = require('underscore');
const learners = db.model('Learner');
module.exports = function (app) {
app.get('/dashboard/:learnerName?', [isGuardian], function (req, res, next) {
var learnerName = req.params.learnerName;
req.session.user.getDependants()
.complete(function (err, dependants) {
if (err)
return next(err);
if (learnerName) {
var usernames = _.pluck(dependants, 'username');
if (usernames.indexOf(learnerName) === -1)
return res.redirect('/dashboard');
} else if (dependants.length === 1) {
return res.redirect('/dashboard/' + dependants[0].username);
}
res.render('/user/dashboard.html', {
dependants: dependants,
currentDependant: learnerName
});
})
});
}

28
views/user/dashboard.html Normal file
Просмотреть файл

@ -0,0 +1,28 @@
{% extends 'layout.html' %}
{% block content %}
<div class="row">
<div class="span3">
<ul>
{% if dependants.length > 1 %}
<li>
{%- if currentDependant -%}
<a href="/dashboard">All</a>
{%- else -%}
<strong>All</strong>
{%- endif -%}
</li>
{% endif %}
{% for dependant in dependants %}
<li>
{%- if dependant.username == currentDependant -%}
<strong>{{ dependant.getDisplayName() }}</strong>
{%- else -%}
<a href="/dashboard/{{ dependant.username }}">{{ dependant.getDisplayName() }}</a>
{%- endif -%}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endblock %}