2020-06-05 22:03:37 +00:00
|
|
|
"use strict";
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
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");
|
2016-03-31 22:20:34 +00:00
|
|
|
|
2016-03-19 20:37:04 +00:00
|
|
|
class HomeController {
|
2016-03-31 22:20:34 +00:00
|
|
|
constructor() {
|
2020-06-05 22:03:37 +00:00
|
|
|
topNavigation.activate("home");
|
|
|
|
topNavigation.setTitle("Home");
|
2016-04-06 19:49:26 +00:00
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
this._homeView = new HomeView({
|
2018-06-25 14:47:20 +00:00
|
|
|
name: api.getName(),
|
2016-06-14 08:31:48 +00:00
|
|
|
version: config.meta.version,
|
|
|
|
buildDate: config.meta.buildDate,
|
2020-06-05 22:03:37 +00:00
|
|
|
canListSnapshots: api.hasPrivilege("snapshots:list"),
|
|
|
|
canListPosts: api.hasPrivilege("posts:list"),
|
2021-05-14 14:39:40 +00:00
|
|
|
isDevelopmentMode: config.environment == "development"
|
2016-06-14 08:31:48 +00:00
|
|
|
});
|
2016-05-22 20:39:31 +00:00
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
Info.get().then(
|
|
|
|
(info) => {
|
2016-06-14 08:31:48 +00:00
|
|
|
this._homeView.setStats({
|
2016-06-19 17:16:40 +00:00
|
|
|
diskUsage: info.diskUsage,
|
|
|
|
postCount: info.postCount,
|
2016-06-14 08:31:48 +00:00
|
|
|
});
|
|
|
|
this._homeView.setFeaturedPost({
|
2016-06-19 17:16:40 +00:00
|
|
|
featuredPost: info.featuredPost,
|
|
|
|
featuringUser: info.featuringUser,
|
|
|
|
featuringTime: info.featuringTime,
|
2016-05-22 20:39:31 +00:00
|
|
|
});
|
|
|
|
},
|
2020-06-05 22:03:37 +00:00
|
|
|
(error) => this._homeView.showError(error.message)
|
|
|
|
);
|
2016-03-19 20:37:04 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
showSuccess(message) {
|
|
|
|
this._homeView.showSuccess(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
showError(message) {
|
|
|
|
this._homeView.showError(message);
|
2016-03-19 20:37:04 +00:00
|
|
|
}
|
2020-06-04 18:09:35 +00:00
|
|
|
}
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
module.exports = (router) => {
|
2017-01-20 20:51:04 +00:00
|
|
|
router.enter([], (ctx, next) => {
|
2016-06-14 08:31:48 +00:00
|
|
|
ctx.controller = new HomeController();
|
|
|
|
});
|
2020-06-05 22:03:37 +00:00
|
|
|
};
|