szurubooru/client/js/controllers/home_controller.js
Shyam Sunder 3972b902d8 client: fetch configurations from server at runtime
Permissions, regex filters, app title, email info,
and safety now fetched using server's Info API
2018-06-27 21:20:03 +02:00

50 lines
1.4 KiB
JavaScript

'use strict';
const api = require('../api.js');
const config = require('../config.js');
const Info = require('../models/info.js');
const topNavigation = require('../models/top_navigation.js');
const HomeView = require('../views/home_view.js');
class HomeController {
constructor() {
topNavigation.activate('home');
topNavigation.setTitle('Home');
this._homeView = new HomeView({
name: api.getName(),
version: config.meta.version,
buildDate: config.meta.buildDate,
canListSnapshots: api.hasPrivilege('snapshots:list'),
canListPosts: api.hasPrivilege('posts:list'),
});
Info.get()
.then(info => {
this._homeView.setStats({
diskUsage: info.diskUsage,
postCount: info.postCount,
});
this._homeView.setFeaturedPost({
featuredPost: info.featuredPost,
featuringUser: info.featuringUser,
featuringTime: info.featuringTime,
});
},
error => this._homeView.showError(error.message));
}
showSuccess(message) {
this._homeView.showSuccess(message);
}
showError(message) {
this._homeView.showError(message);
}
};
module.exports = router => {
router.enter([], (ctx, next) => {
ctx.controller = new HomeController();
});
};