зеркало из https://github.com/mozilla/CSOL-site.git
Basic dashboard setup
This commit is contained in:
Родитель
00637a8208
Коммит
328be700cc
1
app.js
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);
|
||||
|
|
|
@ -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
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
}
|
|
@ -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 %}
|
Загрузка…
Ссылка в новой задаче