discourse/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6

93 lines
2.2 KiB
Plaintext
Raw Normal View History

2019-10-29 13:31:44 -04:00
import { inject } from "@ember/controller";
import Controller from "@ember/controller";
2019-04-01 06:39:49 -04:00
import { setting } from "discourse/lib/computed";
2018-06-15 11:03:24 -04:00
import computed from "ember-addons/ember-computed-decorators";
2019-04-01 06:39:49 -04:00
import AdminDashboard from "admin/models/admin-dashboard";
import VersionCheck from "admin/models/version-check";
2019-04-01 06:39:49 -04:00
const PROBLEMS_CHECK_MINUTES = 1;
export default Controller.extend({
2019-04-01 06:39:49 -04:00
isLoading: false,
dashboardFetchedAt: null,
exceptionController: inject("exception"),
2019-04-01 06:39:49 -04:00
showVersionChecks: setting("version_checks"),
@computed("problems.length")
foundProblems(problemsLength) {
return this.currentUser.get("admin") && (problemsLength || 0) > 0;
},
fetchProblems() {
if (this.isLoadingProblems) return;
2019-04-01 06:39:49 -04:00
if (
!this.problemsFetchedAt ||
2019-04-01 06:39:49 -04:00
moment()
.subtract(PROBLEMS_CHECK_MINUTES, "minutes")
.toDate() > this.problemsFetchedAt
2019-04-01 06:39:49 -04:00
) {
this._loadProblems();
}
},
fetchDashboard() {
2019-04-01 06:39:49 -04:00
const versionChecks = this.siteSettings.version_checks;
if (this.isLoading || !versionChecks) return;
2019-04-01 06:39:49 -04:00
2018-06-15 11:03:24 -04:00
if (
!this.dashboardFetchedAt ||
2018-06-15 11:03:24 -04:00
moment()
.subtract(30, "minutes")
.toDate() > this.dashboardFetchedAt
2018-06-15 11:03:24 -04:00
) {
2019-04-01 06:39:49 -04:00
this.set("isLoading", true);
2018-06-15 11:03:24 -04:00
2019-04-01 06:39:49 -04:00
AdminDashboard.fetch()
.then(model => {
let properties = {
dashboardFetchedAt: new Date()
};
2018-06-15 11:03:24 -04:00
2019-04-01 06:39:49 -04:00
if (versionChecks) {
properties.versionCheck = VersionCheck.create(model.version_check);
2018-06-15 11:03:24 -04:00
}
2019-04-01 06:39:49 -04:00
this.setProperties(properties);
2018-06-15 11:03:24 -04:00
})
.catch(e => {
this.exceptionController.set("thrown", e.jqXHR);
2018-06-15 11:03:24 -04:00
this.replaceRoute("exception");
})
.finally(() => {
2019-04-01 06:39:49 -04:00
this.set("isLoading", false);
2018-06-15 11:03:24 -04:00
});
}
},
2019-04-01 06:39:49 -04:00
_loadProblems() {
this.setProperties({
loadingProblems: true,
problemsFetchedAt: new Date()
});
AdminDashboard.fetchProblems()
.then(model => this.set("problems", model.problems))
.finally(() => this.set("loadingProblems", false));
},
@computed("problemsFetchedAt")
problemsTimestamp(problemsFetchedAt) {
return moment(problemsFetchedAt)
.locale("en")
.format("LLL");
},
2013-09-16 14:08:55 -04:00
actions: {
2019-04-01 06:39:49 -04:00
refreshProblems() {
this._loadProblems();
2013-09-16 14:08:55 -04:00
}
}
});