2018-07-20 02:33:11 +08:00
|
|
|
import { setting } from "discourse/lib/computed";
|
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
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";
|
|
|
|
|
2018-07-20 07:30:13 +08:00
|
|
|
function staticReport(reportType) {
|
|
|
|
return function() {
|
2019-05-27 16:15:39 +08:00
|
|
|
return Ember.makeArray(this.reports).find(
|
2018-08-07 04:57:40 +08:00
|
|
|
report => report.type === reportType
|
|
|
|
);
|
2018-07-20 07:30:13 +08:00
|
|
|
}.property("reports.[]");
|
|
|
|
}
|
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
export default Ember.Controller.extend(PeriodComputationMixin, {
|
|
|
|
isLoading: false,
|
|
|
|
dashboardFetchedAt: null,
|
|
|
|
exceptionController: Ember.inject.controller("exception"),
|
|
|
|
logSearchQueriesEnabled: setting("log_search_queries"),
|
2018-11-08 00:59:42 +08:00
|
|
|
basePath: Discourse.BaseUri,
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2018-12-26 17:29:07 +08:00
|
|
|
@computed("siteSettings.dashboard_general_tab_activity_metrics")
|
|
|
|
activityMetrics(metrics) {
|
|
|
|
return (metrics || "").split("|").filter(m => m);
|
2018-08-07 04:57:40 +08:00
|
|
|
},
|
|
|
|
|
2018-08-22 18:37:05 +08:00
|
|
|
@computed
|
|
|
|
activityMetricsFilters() {
|
|
|
|
return {
|
2019-05-27 16:15:39 +08:00
|
|
|
startDate: this.lastMonth,
|
|
|
|
endDate: this.today
|
2018-08-22 18:37:05 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-09-07 22:49:44 +08:00
|
|
|
@computed
|
|
|
|
topReferredTopicsOptions() {
|
|
|
|
return {
|
|
|
|
table: { total: false, limit: 8 }
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed
|
|
|
|
topReferredTopicsFilters() {
|
|
|
|
return {
|
|
|
|
startDate: moment()
|
2018-09-10 16:40:19 +08:00
|
|
|
.subtract(6, "days")
|
2018-09-07 22:49:44 +08:00
|
|
|
.startOf("day"),
|
2019-05-27 16:15:39 +08:00
|
|
|
endDate: this.today
|
2018-09-07 22:49:44 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed
|
|
|
|
trendingSearchFilters() {
|
|
|
|
return {
|
|
|
|
startDate: moment()
|
2018-12-18 05:30:30 +08:00
|
|
|
.subtract(1, "month")
|
2018-09-07 22:49:44 +08:00
|
|
|
.startOf("day"),
|
2019-05-27 16:15:39 +08:00
|
|
|
endDate: this.today
|
2018-09-07 22:49:44 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
@computed
|
|
|
|
trendingSearchOptions() {
|
2018-09-07 22:49:44 +08:00
|
|
|
return {
|
|
|
|
table: { total: false, limit: 8 }
|
|
|
|
};
|
2018-07-20 02:33:11 +08:00
|
|
|
},
|
|
|
|
|
2018-11-08 00:59:42 +08:00
|
|
|
@computed
|
|
|
|
trendingSearchDisabledLabel() {
|
|
|
|
return I18n.t("admin.dashboard.reports.trending_search.disabled", {
|
|
|
|
basePath: Discourse.BaseUri
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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 ||
|
2018-07-20 02:33:11 +08:00
|
|
|
moment()
|
|
|
|
.subtract(30, "minutes")
|
2019-05-27 16:15:39 +08:00
|
|
|
.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,
|
|
|
|
reports: Ember.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));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-07-27 13:22:00 +08:00
|
|
|
@computed("startDate", "endDate")
|
|
|
|
filters(startDate, endDate) {
|
|
|
|
return { startDate, endDate };
|
|
|
|
},
|
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
_reportsForPeriodURL(period) {
|
2018-07-27 13:22:00 +08:00
|
|
|
return Discourse.getURL(`/admin?period=${period}`);
|
2018-07-20 02:33:11 +08:00
|
|
|
}
|
|
|
|
});
|