2016-03-19 21:37:04 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-06 21:49:26 +02:00
|
|
|
const page = require('page');
|
2016-05-22 22:39:31 +02:00
|
|
|
const api = require('../api.js');
|
|
|
|
const events = require('../events.js');
|
2016-04-01 00:20:34 +02:00
|
|
|
const topNavController = require('../controllers/top_nav_controller.js');
|
|
|
|
const HomeView = require('../views/home_view.js');
|
2016-05-21 11:48:23 +02:00
|
|
|
const NotFoundView = require('../views/not_found_view.js');
|
2016-04-01 00:20:34 +02:00
|
|
|
|
2016-03-19 21:37:04 +01:00
|
|
|
class HomeController {
|
2016-04-01 00:20:34 +02:00
|
|
|
constructor() {
|
2016-05-20 21:35:12 +02:00
|
|
|
this._homeView = new HomeView();
|
2016-05-21 11:48:23 +02:00
|
|
|
this._notFoundView = new NotFoundView();
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 21:49:26 +02:00
|
|
|
registerRoutes() {
|
2016-05-20 21:35:12 +02:00
|
|
|
page('/', (ctx, next) => { this._indexRoute(); });
|
2016-05-21 12:03:31 +02:00
|
|
|
page('*', (ctx, next) => { this._notFoundRoute(ctx); });
|
2016-04-06 21:49:26 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:35:12 +02:00
|
|
|
_indexRoute() {
|
2016-04-01 00:20:34 +02:00
|
|
|
topNavController.activate('home');
|
2016-05-22 22:39:31 +02:00
|
|
|
|
|
|
|
api.get('/info')
|
|
|
|
.then(response => {
|
|
|
|
this._homeView.render({
|
2016-05-29 12:28:52 +02:00
|
|
|
canListPosts: api.hasPrivilege('posts:list'),
|
|
|
|
canListComments: api.hasPrivilege('comments:list'),
|
|
|
|
canListTags: api.hasPrivilege('tags:list'),
|
|
|
|
canListUsers: api.hasPrivilege('users:list'),
|
2016-05-22 22:39:31 +02:00
|
|
|
diskUsage: response.diskUsage,
|
|
|
|
postCount: response.postCount,
|
|
|
|
featuredPost: response.featuredPost,
|
2016-05-29 12:48:51 +02:00
|
|
|
featuringUser: response.featuringUser,
|
|
|
|
featuringTime: response.featuringTime,
|
2016-05-22 22:39:31 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
response => {
|
2016-05-29 12:28:52 +02:00
|
|
|
this._homeView.render({
|
|
|
|
canListPosts: api.hasPrivilege('posts:list'),
|
|
|
|
canListComments: api.hasPrivilege('comments:list'),
|
|
|
|
canListTags: api.hasPrivilege('tags:list'),
|
|
|
|
canListUsers: api.hasPrivilege('users:list'),
|
|
|
|
});
|
2016-05-22 22:39:31 +02:00
|
|
|
events.notify(events.Error, response.description);
|
|
|
|
});
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
2016-05-21 12:03:31 +02:00
|
|
|
_notFoundRoute(ctx) {
|
2016-04-01 00:20:34 +02:00
|
|
|
topNavController.activate('');
|
2016-05-21 12:03:31 +02:00
|
|
|
this._notFoundView.render({path: ctx.canonicalPath});
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 00:20:34 +02:00
|
|
|
module.exports = new HomeController();
|