2016-03-19 21:37:04 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-22 22:39:31 +02:00
|
|
|
const api = require('../api.js');
|
2016-06-14 10:31:48 +02:00
|
|
|
const config = require('../config.js');
|
2016-06-19 19:16:40 +02:00
|
|
|
const Info = require('../models/info.js');
|
2016-06-14 10:31:48 +02:00
|
|
|
const topNavigation = require('../models/top_navigation.js');
|
2016-04-01 00:20:34 +02:00
|
|
|
const HomeView = require('../views/home_view.js');
|
|
|
|
|
2016-03-19 21:37:04 +01:00
|
|
|
class HomeController {
|
2016-04-01 00:20:34 +02:00
|
|
|
constructor() {
|
2016-06-14 10:31:48 +02:00
|
|
|
topNavigation.activate('home');
|
2016-07-13 21:50:07 +02:00
|
|
|
topNavigation.setTitle('Home');
|
2016-04-06 21:49:26 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
this._homeView = new HomeView({
|
|
|
|
name: config.name,
|
|
|
|
version: config.meta.version,
|
|
|
|
buildDate: config.meta.buildDate,
|
|
|
|
canListPosts: api.hasPrivilege('posts:list'),
|
|
|
|
});
|
2016-05-22 22:39:31 +02:00
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
Info.get()
|
|
|
|
.then(info => {
|
2016-06-14 10:31:48 +02:00
|
|
|
this._homeView.setStats({
|
2016-06-19 19:16:40 +02:00
|
|
|
diskUsage: info.diskUsage,
|
|
|
|
postCount: info.postCount,
|
2016-06-14 10:31:48 +02:00
|
|
|
});
|
|
|
|
this._homeView.setFeaturedPost({
|
2016-06-19 19:16:40 +02:00
|
|
|
featuredPost: info.featuredPost,
|
|
|
|
featuringUser: info.featuringUser,
|
|
|
|
featuringTime: info.featuringTime,
|
2016-05-22 22:39:31 +02:00
|
|
|
});
|
|
|
|
},
|
2016-06-19 19:16:40 +02:00
|
|
|
errorMessage => {
|
|
|
|
this._homeView.showError(errorMessage);
|
2016-05-22 22:39:31 +02:00
|
|
|
});
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
showSuccess(message) {
|
|
|
|
this._homeView.showSuccess(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
showError(message) {
|
|
|
|
this._homeView.showError(message);
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
2016-06-14 10:31:48 +02:00
|
|
|
};
|
2016-03-19 21:37:04 +01:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
module.exports = router => {
|
|
|
|
router.enter('/', (ctx, next) => {
|
|
|
|
ctx.controller = new HomeController();
|
|
|
|
});
|
|
|
|
};
|