2021-05-25 18:37:32 +02:00
|
|
|
import Controller, { inject as controller } from "@ember/controller";
|
2023-10-10 19:38:59 +01:00
|
|
|
import { action, computed } from "@ember/object";
|
2024-03-06 18:05:11 +01:00
|
|
|
import { service } from "@ember/service";
|
2023-10-10 19:38:59 +01:00
|
|
|
import { setting } from "discourse/lib/computed";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-04-01 12:39:49 +02:00
|
|
|
import AdminDashboard from "admin/models/admin-dashboard";
|
|
|
|
import VersionCheck from "admin/models/version-check";
|
2016-08-03 15:36:41 -04:00
|
|
|
|
2019-04-01 12:39:49 +02:00
|
|
|
const PROBLEMS_CHECK_MINUTES = 1;
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2023-03-15 09:42:12 +00:00
|
|
|
export default class AdminDashboardController extends Controller {
|
2023-07-18 15:16:41 -05:00
|
|
|
@service router;
|
|
|
|
@service siteSettings;
|
2023-03-15 09:42:12 +00:00
|
|
|
@controller("exception") exceptionController;
|
|
|
|
|
|
|
|
isLoading = false;
|
|
|
|
dashboardFetchedAt = null;
|
|
|
|
|
|
|
|
@setting("version_checks") showVersionChecks;
|
2019-04-01 12:39:49 +02:00
|
|
|
|
2023-03-15 09:42:12 +00:00
|
|
|
@computed("siteSettings.dashboard_visible_tabs")
|
|
|
|
get visibleTabs() {
|
2020-04-30 17:31:04 +02:00
|
|
|
return (this.siteSettings.dashboard_visible_tabs || "")
|
|
|
|
.split("|")
|
|
|
|
.filter(Boolean);
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2020-04-30 17:31:04 +02:00
|
|
|
|
2023-03-15 09:42:12 +00:00
|
|
|
@computed("visibleTabs")
|
|
|
|
get isModerationTabVisible() {
|
2020-04-30 17:31:04 +02:00
|
|
|
return this.visibleTabs.includes("moderation");
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2020-04-30 17:31:04 +02:00
|
|
|
|
2023-03-15 09:42:12 +00:00
|
|
|
@computed("visibleTabs")
|
|
|
|
get isSecurityTabVisible() {
|
2020-04-30 17:31:04 +02:00
|
|
|
return this.visibleTabs.includes("security");
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2020-04-30 17:31:04 +02:00
|
|
|
|
2023-03-15 09:42:12 +00:00
|
|
|
@computed("visibleTabs")
|
|
|
|
get isReportsTabVisible() {
|
2020-04-30 17:31:04 +02:00
|
|
|
return this.visibleTabs.includes("reports");
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2020-04-30 17:31:04 +02:00
|
|
|
|
2019-04-01 12:39:49 +02:00
|
|
|
fetchProblems() {
|
2020-09-22 16:28:28 +02:00
|
|
|
if (this.isLoadingProblems) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-01 12:39:49 +02:00
|
|
|
|
|
|
|
if (
|
2019-05-27 10:15:39 +02:00
|
|
|
!this.problemsFetchedAt ||
|
2019-04-01 12:39:49 +02:00
|
|
|
moment().subtract(PROBLEMS_CHECK_MINUTES, "minutes").toDate() >
|
2019-05-27 10:15:39 +02:00
|
|
|
this.problemsFetchedAt
|
2019-04-01 12:39:49 +02:00
|
|
|
) {
|
|
|
|
this._loadProblems();
|
|
|
|
}
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2014-09-11 16:30:47 -04:00
|
|
|
|
2016-08-03 15:36:41 -04:00
|
|
|
fetchDashboard() {
|
2019-04-01 12:39:49 +02:00
|
|
|
const versionChecks = this.siteSettings.version_checks;
|
|
|
|
|
2020-09-22 16:28:28 +02:00
|
|
|
if (this.isLoading || !versionChecks) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-01 12:39:49 +02:00
|
|
|
|
2016-08-03 15:36:41 -04:00
|
|
|
if (
|
2019-05-27 10:15:39 +02:00
|
|
|
!this.dashboardFetchedAt ||
|
|
|
|
moment().subtract(30, "minutes").toDate() > this.dashboardFetchedAt
|
2016-08-03 15:36:41 -04:00
|
|
|
) {
|
2019-04-01 12:39:49 +02:00
|
|
|
this.set("isLoading", true);
|
2018-06-15 17:03:24 +02:00
|
|
|
|
2019-04-01 12:39:49 +02:00
|
|
|
AdminDashboard.fetch()
|
|
|
|
.then((model) => {
|
|
|
|
let properties = {
|
|
|
|
dashboardFetchedAt: new Date(),
|
|
|
|
};
|
2018-06-15 17:03:24 +02:00
|
|
|
|
2019-04-01 12:39:49 +02:00
|
|
|
if (versionChecks) {
|
|
|
|
properties.versionCheck = VersionCheck.create(model.version_check);
|
2016-08-03 15:36:41 -04:00
|
|
|
}
|
2018-06-15 17:03:24 +02:00
|
|
|
|
2019-04-01 12:39:49 +02:00
|
|
|
this.setProperties(properties);
|
2018-03-29 14:12:29 -04:00
|
|
|
})
|
|
|
|
.catch((e) => {
|
2019-05-27 10:15:39 +02:00
|
|
|
this.exceptionController.set("thrown", e.jqXHR);
|
2023-07-24 12:32:17 +01:00
|
|
|
this.router.replaceWith("exception");
|
2018-03-29 14:12:29 -04:00
|
|
|
})
|
|
|
|
.finally(() => {
|
2019-04-01 12:39:49 +02:00
|
|
|
this.set("isLoading", false);
|
2016-08-03 15:36:41 -04:00
|
|
|
});
|
|
|
|
}
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2016-08-03 15:36:41 -04:00
|
|
|
|
2019-04-01 12:39:49 +02:00
|
|
|
_loadProblems() {
|
|
|
|
this.setProperties({
|
|
|
|
loadingProblems: true,
|
|
|
|
problemsFetchedAt: new Date(),
|
|
|
|
});
|
|
|
|
|
|
|
|
AdminDashboard.fetchProblems()
|
2024-09-17 14:43:34 +08:00
|
|
|
.then((model) => this.set("problems", model.problems))
|
2019-04-01 12:39:49 +02:00
|
|
|
.finally(() => this.set("loadingProblems", false));
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2019-04-01 12:39:49 +02:00
|
|
|
|
2019-11-07 15:38:28 -06:00
|
|
|
@discourseComputed("problemsFetchedAt")
|
2019-04-01 12:39:49 +02:00
|
|
|
problemsTimestamp(problemsFetchedAt) {
|
2025-01-06 14:59:21 +10:00
|
|
|
return moment(problemsFetchedAt).format("LLL");
|
2023-03-15 09:42:12 +00:00
|
|
|
}
|
2013-09-16 14:08:55 -04:00
|
|
|
|
2023-03-15 09:42:12 +00:00
|
|
|
@action
|
|
|
|
refreshProblems() {
|
|
|
|
this._loadProblems();
|
|
|
|
}
|
|
|
|
}
|