2023-03-15 17:42:12 +08:00
|
|
|
import { computed } from "@ember/object";
|
2021-05-26 00:37:32 +08:00
|
|
|
import Controller, { inject as controller } from "@ember/controller";
|
2019-04-01 18:39:49 +08:00
|
|
|
import AdminDashboard from "admin/models/admin-dashboard";
|
2018-07-20 02:33:11 +08:00
|
|
|
import I18n from "I18n";
|
|
|
|
import PeriodComputationMixin from "admin/mixins/period-computation";
|
2019-04-01 18:39:49 +08:00
|
|
|
import Report from "admin/models/report";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2020-06-04 00:45:26 +08:00
|
|
|
import getURL from "discourse-common/lib/get-url";
|
2019-11-02 01:06:50 +08:00
|
|
|
import { makeArray } from "discourse-common/lib/helpers";
|
2018-07-20 02:33:11 +08:00
|
|
|
import { setting } from "discourse/lib/computed";
|
|
|
|
|
2018-07-20 07:30:13 +08:00
|
|
|
function staticReport(reportType) {
|
2019-11-09 02:28:11 +08:00
|
|
|
return computed("reports.[]", function () {
|
2019-11-02 01:57:22 +08:00
|
|
|
return makeArray(this.reports).find((report) => report.type === reportType);
|
2019-07-19 01:28:23 +08:00
|
|
|
});
|
2018-07-20 07:30:13 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
export default class AdminDashboardGeneralController extends Controller.extend(
|
|
|
|
PeriodComputationMixin
|
|
|
|
) {
|
|
|
|
@controller("exception") exceptionController;
|
|
|
|
|
|
|
|
isLoading = false;
|
|
|
|
dashboardFetchedAt = null;
|
|
|
|
|
|
|
|
@setting("log_search_queries") logSearchQueriesEnabled;
|
|
|
|
|
|
|
|
@staticReport("users_by_type") usersByTypeReport;
|
|
|
|
@staticReport("users_by_trust_level") usersByTrustLevelReport;
|
|
|
|
@staticReport("storage_report") storageReport;
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("siteSettings.dashboard_general_tab_activity_metrics")
|
2018-12-26 17:29:07 +08:00
|
|
|
activityMetrics(metrics) {
|
2020-04-30 23:31:04 +08:00
|
|
|
return (metrics || "").split("|").filter(Boolean);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-08-07 04:57:40 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@computed("siteSettings.dashboard_hidden_reports")
|
|
|
|
get hiddenReports() {
|
2020-04-30 23:31:04 +08:00
|
|
|
return (this.siteSettings.dashboard_hidden_reports || "")
|
|
|
|
.split("|")
|
|
|
|
.filter(Boolean);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed("activityMetrics", "hiddenReports")
|
|
|
|
get isActivityMetricsVisible() {
|
|
|
|
return (
|
|
|
|
this.activityMetrics.length &&
|
|
|
|
this.activityMetrics.some((x) => !this.hiddenReports.includes(x))
|
|
|
|
);
|
|
|
|
}
|
2020-04-30 23:31:04 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@computed("hiddenReports")
|
|
|
|
get isSearchReportsVisible() {
|
2020-04-30 23:31:04 +08:00
|
|
|
return ["top_referred_topics", "trending_search"].some(
|
|
|
|
(x) => !this.hiddenReports.includes(x)
|
|
|
|
);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2020-04-30 23:31:04 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@computed("hiddenReports")
|
|
|
|
get isCommunityHealthVisible() {
|
2020-04-30 23:31:04 +08:00
|
|
|
return [
|
|
|
|
"consolidated_page_views",
|
|
|
|
"signups",
|
|
|
|
"topics",
|
|
|
|
"posts",
|
|
|
|
"dau_by_mau",
|
|
|
|
"daily_engaged_users",
|
|
|
|
"new_contributors",
|
|
|
|
].some((x) => !this.hiddenReports.includes(x));
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2020-04-30 23:31:04 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2018-08-22 18:37:05 +08:00
|
|
|
activityMetricsFilters() {
|
|
|
|
return {
|
2019-05-27 16:15:39 +08:00
|
|
|
startDate: this.lastMonth,
|
|
|
|
endDate: this.today,
|
2018-08-22 18:37:05 +08:00
|
|
|
};
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-08-22 18:37:05 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2018-09-07 22:49:44 +08:00
|
|
|
topReferredTopicsOptions() {
|
|
|
|
return {
|
|
|
|
table: { total: false, limit: 8 },
|
|
|
|
};
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-09-07 22:49:44 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2018-09-07 22:49:44 +08:00
|
|
|
topReferredTopicsFilters() {
|
|
|
|
return {
|
2018-09-10 16:40:19 +08:00
|
|
|
startDate: moment().subtract(6, "days").startOf("day"),
|
2019-05-27 16:15:39 +08:00
|
|
|
endDate: this.today,
|
2018-09-07 22:49:44 +08:00
|
|
|
};
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-09-07 22:49:44 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2018-09-07 22:49:44 +08:00
|
|
|
trendingSearchFilters() {
|
|
|
|
return {
|
2018-12-18 05:30:30 +08:00
|
|
|
startDate: moment().subtract(1, "month").startOf("day"),
|
2019-05-27 16:15:39 +08:00
|
|
|
endDate: this.today,
|
2018-09-07 22:49:44 +08:00
|
|
|
};
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-09-07 22:49:44 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2018-07-20 02:33:11 +08:00
|
|
|
trendingSearchOptions() {
|
2018-09-07 22:49:44 +08:00
|
|
|
return {
|
|
|
|
table: { total: false, limit: 8 },
|
|
|
|
};
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2018-11-08 00:59:42 +08:00
|
|
|
trendingSearchDisabledLabel() {
|
|
|
|
return I18n.t("admin.dashboard.reports.trending_search.disabled", {
|
2020-08-25 17:42:50 +08:00
|
|
|
basePath: getURL(""),
|
2018-11-08 00:59:42 +08:00
|
|
|
});
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-07-20 02:33:11 +08:00
|
|
|
|
|
|
|
fetchDashboard() {
|
2020-09-22 22:28:28 +08:00
|
|
|
if (this.isLoading) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-20 02:33:11 +08:00
|
|
|
|
|
|
|
if (
|
2019-05-27 16:15:39 +08:00
|
|
|
!this.dashboardFetchedAt ||
|
|
|
|
moment().subtract(30, "minutes").toDate() > this.dashboardFetchedAt
|
2018-07-20 02:33:11 +08:00
|
|
|
) {
|
|
|
|
this.set("isLoading", true);
|
|
|
|
|
2019-04-01 18:39:49 +08:00
|
|
|
AdminDashboard.fetchGeneral()
|
|
|
|
.then((adminDashboardModel) => {
|
2018-07-20 02:33:11 +08:00
|
|
|
this.setProperties({
|
|
|
|
dashboardFetchedAt: new Date(),
|
2019-04-01 18:39:49 +08:00
|
|
|
model: adminDashboardModel,
|
2019-11-01 01:55:01 +08:00
|
|
|
reports: makeArray(adminDashboardModel.reports).map((x) =>
|
2018-08-01 09:23:28 +08:00
|
|
|
Report.create(x)
|
|
|
|
),
|
2018-07-20 02:33:11 +08:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.exceptionController.set("thrown", e.jqXHR);
|
2018-07-20 02:33:11 +08:00
|
|
|
this.replaceRoute("exception");
|
|
|
|
})
|
|
|
|
.finally(() => this.set("isLoading", false));
|
|
|
|
}
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("startDate", "endDate")
|
2018-07-27 13:22:00 +08:00
|
|
|
filters(startDate, endDate) {
|
|
|
|
return { startDate, endDate };
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2018-07-27 13:22:00 +08:00
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
_reportsForPeriodURL(period) {
|
2020-06-04 00:45:26 +08:00
|
|
|
return getURL(`/admin?period=${period}`);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
}
|