mirror of
https://github.com/discourse/discourse.git
synced 2024-12-03 10:33:41 +08:00
9554d9c56a
- tooltips - revert chart title UI - reduce period chooser font-size - localize dates of data points - fix a bug where multiple reports were loaded at the same time - fix a bug where % was not showing anymore - remove spacing at the top - remove loadingTitle feature (Loading...%report name%) incompatible with new hijack design
140 lines
3.9 KiB
JavaScript
140 lines
3.9 KiB
JavaScript
import { setting } from "discourse/lib/computed";
|
|
import DiscourseURL from "discourse/lib/url";
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
import AdminDashboardNext from "admin/models/admin-dashboard-next";
|
|
import Report from "admin/models/report";
|
|
import VersionCheck from "admin/models/version-check";
|
|
|
|
const PROBLEMS_CHECK_MINUTES = 1;
|
|
|
|
export default Ember.Controller.extend({
|
|
queryParams: ["period"],
|
|
period: "monthly",
|
|
isLoading: false,
|
|
dashboardFetchedAt: null,
|
|
exceptionController: Ember.inject.controller("exception"),
|
|
showVersionChecks: setting("version_checks"),
|
|
diskSpace: Ember.computed.alias("model.attributes.disk_space"),
|
|
logSearchQueriesEnabled: setting("log_search_queries"),
|
|
availablePeriods: ["yearly", "quarterly", "monthly", "weekly"],
|
|
|
|
@computed("problems.length")
|
|
foundProblems(problemsLength) {
|
|
return this.currentUser.get("admin") && (problemsLength || 0) > 0;
|
|
},
|
|
|
|
@computed("foundProblems")
|
|
thereWereProblems(foundProblems) {
|
|
if (!this.currentUser.get("admin")) { return false; }
|
|
|
|
if (foundProblems) {
|
|
this.set("hadProblems", true);
|
|
return true;
|
|
} else {
|
|
return this.get("hadProblems") || false;
|
|
}
|
|
},
|
|
|
|
fetchDashboard() {
|
|
if (this.get("isLoading")) return;
|
|
|
|
if (!this.get("dashboardFetchedAt") || moment().subtract(30, "minutes").toDate() > this.get("dashboardFetchedAt")) {
|
|
this.set("isLoading", true);
|
|
|
|
const versionChecks = this.siteSettings.version_checks;
|
|
|
|
AdminDashboardNext.find().then(adminDashboardNextModel => {
|
|
|
|
if (versionChecks) {
|
|
this.set("versionCheck", VersionCheck.create(adminDashboardNextModel.version_check));
|
|
}
|
|
|
|
this.setProperties({
|
|
dashboardFetchedAt: new Date(),
|
|
model: adminDashboardNextModel,
|
|
reports: adminDashboardNextModel.reports.map(x => Report.create(x))
|
|
});
|
|
}).catch(e => {
|
|
this.get("exceptionController").set("thrown", e.jqXHR);
|
|
this.replaceRoute("exception");
|
|
}).finally(() => {
|
|
this.set("isLoading", false);
|
|
});
|
|
}
|
|
|
|
if (!this.get("problemsFetchedAt") || moment().subtract(PROBLEMS_CHECK_MINUTES, "minutes").toDate() > this.get("problemsFetchedAt")) {
|
|
this.loadProblems();
|
|
}
|
|
},
|
|
|
|
loadProblems() {
|
|
this.set("loadingProblems", true);
|
|
this.set("problemsFetchedAt", new Date());
|
|
AdminDashboardNext.fetchProblems().then(d => {
|
|
this.set("problems", d.problems);
|
|
}).finally(() => {
|
|
this.set("loadingProblems", false);
|
|
});
|
|
},
|
|
|
|
@computed("problemsFetchedAt")
|
|
problemsTimestamp(problemsFetchedAt) {
|
|
return moment(problemsFetchedAt).locale("en").format("LLL");
|
|
},
|
|
|
|
@computed("period")
|
|
startDate(period) {
|
|
let fullDay = moment().locale("en").utc().subtract(1, "day");
|
|
|
|
switch (period) {
|
|
case "yearly":
|
|
return fullDay.subtract(1, "year").startOf("day");
|
|
break;
|
|
case "quarterly":
|
|
return fullDay.subtract(3, "month").startOf("day");
|
|
break;
|
|
case "weekly":
|
|
return fullDay.subtract(1, "week").startOf("day");
|
|
break;
|
|
case "monthly":
|
|
return fullDay.subtract(1, "month").startOf("day");
|
|
break;
|
|
default:
|
|
return fullDay.subtract(1, "month").startOf("day");
|
|
}
|
|
},
|
|
|
|
@computed()
|
|
lastWeek() {
|
|
return moment().locale("en").utc().endOf("day").subtract(1, "week");
|
|
},
|
|
|
|
@computed()
|
|
endDate() {
|
|
return moment().locale("en").utc().subtract(1, "day").endOf("day");
|
|
},
|
|
|
|
@computed("updated_at")
|
|
updatedTimestamp(updatedAt) {
|
|
return moment(updatedAt).format("LLL");
|
|
},
|
|
|
|
@computed("last_backup_taken_at")
|
|
backupTimestamp(lastBackupTakenAt) {
|
|
return moment(lastBackupTakenAt).format("LLL");
|
|
},
|
|
|
|
actions: {
|
|
changePeriod(period) {
|
|
DiscourseURL.routeTo(this._reportsForPeriodURL(period));
|
|
},
|
|
refreshProblems() {
|
|
this.loadProblems();
|
|
},
|
|
},
|
|
|
|
_reportsForPeriodURL(period) {
|
|
return Discourse.getURL(`/admin?period=${period}`);
|
|
}
|
|
});
|