2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-11-02 01:06:50 +08:00
|
|
|
import { makeArray } from "discourse-common/lib/helpers";
|
2019-10-30 01:31:44 +08:00
|
|
|
import { inject } from "@ember/controller";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2018-07-20 02:33:11 +08:00
|
|
|
import { setting } from "discourse/lib/computed";
|
2019-04-01 18:39:49 +08:00
|
|
|
import AdminDashboard from "admin/models/admin-dashboard";
|
2018-07-20 02:33:11 +08:00
|
|
|
import Report from "admin/models/report";
|
|
|
|
import PeriodComputationMixin from "admin/mixins/period-computation";
|
2019-11-14 00:57:42 +08:00
|
|
|
import { computed } from "@ember/object";
|
2020-06-04 00:45:26 +08:00
|
|
|
import getURL from "discourse-common/lib/get-url";
|
2018-07-20 02:33:11 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend(PeriodComputationMixin, {
|
2018-07-20 02:33:11 +08:00
|
|
|
isLoading: false,
|
|
|
|
dashboardFetchedAt: null,
|
2019-10-30 01:13:31 +08:00
|
|
|
exceptionController: inject("exception"),
|
2018-07-20 02:33:11 +08:00
|
|
|
logSearchQueriesEnabled: setting("log_search_queries"),
|
|
|
|
|
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);
|
2018-08-07 04:57:40 +08:00
|
|
|
},
|
|
|
|
|
2020-04-30 23:31:04 +08:00
|
|
|
hiddenReports: computed("siteSettings.dashboard_hidden_reports", function () {
|
|
|
|
return (this.siteSettings.dashboard_hidden_reports || "")
|
|
|
|
.split("|")
|
|
|
|
.filter(Boolean);
|
|
|
|
}),
|
|
|
|
|
|
|
|
isActivityMetricsVisible: computed(
|
|
|
|
"activityMetrics",
|
|
|
|
"hiddenReports",
|
|
|
|
function () {
|
|
|
|
return (
|
|
|
|
this.activityMetrics.length &&
|
|
|
|
this.activityMetrics.some((x) => !this.hiddenReports.includes(x))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
isSearchReportsVisible: computed("hiddenReports", function () {
|
|
|
|
return ["top_referred_topics", "trending_search"].some(
|
|
|
|
(x) => !this.hiddenReports.includes(x)
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
|
|
|
|
isCommunityHealthVisible: computed("hiddenReports", function () {
|
|
|
|
return [
|
|
|
|
"consolidated_page_views",
|
|
|
|
"signups",
|
|
|
|
"topics",
|
|
|
|
"posts",
|
|
|
|
"dau_by_mau",
|
|
|
|
"daily_engaged_users",
|
|
|
|
"new_contributors",
|
|
|
|
].some((x) => !this.hiddenReports.includes(x));
|
|
|
|
}),
|
|
|
|
|
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
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2018-09-07 22:49:44 +08:00
|
|
|
topReferredTopicsOptions() {
|
|
|
|
return {
|
|
|
|
table: { total: false, limit: 8 },
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
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
|
|
|
};
|
|
|
|
},
|
|
|
|
|
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
|
|
|
};
|
|
|
|
},
|
|
|
|
|
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 },
|
|
|
|
};
|
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
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-07-20 07:30:13 +08:00
|
|
|
usersByTypeReport: staticReport("users_by_type"),
|
|
|
|
usersByTrustLevelReport: staticReport("users_by_trust_level"),
|
2018-12-15 06:14:46 +08:00
|
|
|
storageReport: staticReport("storage_report"),
|
2018-07-20 02:33:11 +08:00
|
|
|
|
|
|
|
fetchDashboard() {
|
2019-05-27 16:15:39 +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));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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 };
|
|
|
|
},
|
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
_reportsForPeriodURL(period) {
|
2020-06-04 00:45:26 +08:00
|
|
|
return getURL(`/admin?period=${period}`);
|
2018-07-20 02:33:11 +08:00
|
|
|
},
|
|
|
|
});
|