2019-11-01 13:06:50 -04:00
|
|
|
import { makeArray } from "discourse-common/lib/helpers";
|
2019-10-29 13:31:44 -04:00
|
|
|
import { inject } from "@ember/controller";
|
2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2018-07-19 14:33:11 -04:00
|
|
|
import { setting } from "discourse/lib/computed";
|
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2019-04-01 06:39:49 -04:00
|
|
|
import AdminDashboard from "admin/models/admin-dashboard";
|
2018-07-19 14:33:11 -04:00
|
|
|
import Report from "admin/models/report";
|
|
|
|
import PeriodComputationMixin from "admin/mixins/period-computation";
|
|
|
|
|
2018-07-19 19:30:13 -04:00
|
|
|
function staticReport(reportType) {
|
2019-07-18 13:28:23 -04:00
|
|
|
return Ember.computed("reports.[]", function() {
|
2019-11-01 13:57:22 -04:00
|
|
|
return makeArray(this.reports).find(report => report.type === reportType);
|
2019-07-18 13:28:23 -04:00
|
|
|
});
|
2018-07-19 19:30:13 -04:00
|
|
|
}
|
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend(PeriodComputationMixin, {
|
2018-07-19 14:33:11 -04:00
|
|
|
isLoading: false,
|
|
|
|
dashboardFetchedAt: null,
|
2019-10-29 13:13:31 -04:00
|
|
|
exceptionController: inject("exception"),
|
2018-07-19 14:33:11 -04:00
|
|
|
logSearchQueriesEnabled: setting("log_search_queries"),
|
2018-11-07 11:59:42 -05:00
|
|
|
basePath: Discourse.BaseUri,
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2018-12-26 04:29:07 -05:00
|
|
|
@computed("siteSettings.dashboard_general_tab_activity_metrics")
|
|
|
|
activityMetrics(metrics) {
|
|
|
|
return (metrics || "").split("|").filter(m => m);
|
2018-08-06 16:57:40 -04:00
|
|
|
},
|
|
|
|
|
2018-08-22 06:37:05 -04:00
|
|
|
@computed
|
|
|
|
activityMetricsFilters() {
|
|
|
|
return {
|
2019-05-27 04:15:39 -04:00
|
|
|
startDate: this.lastMonth,
|
|
|
|
endDate: this.today
|
2018-08-22 06:37:05 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-09-07 10:49:44 -04:00
|
|
|
@computed
|
|
|
|
topReferredTopicsOptions() {
|
|
|
|
return {
|
|
|
|
table: { total: false, limit: 8 }
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed
|
|
|
|
topReferredTopicsFilters() {
|
|
|
|
return {
|
|
|
|
startDate: moment()
|
2018-09-10 04:40:19 -04:00
|
|
|
.subtract(6, "days")
|
2018-09-07 10:49:44 -04:00
|
|
|
.startOf("day"),
|
2019-05-27 04:15:39 -04:00
|
|
|
endDate: this.today
|
2018-09-07 10:49:44 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed
|
|
|
|
trendingSearchFilters() {
|
|
|
|
return {
|
|
|
|
startDate: moment()
|
2018-12-17 16:30:30 -05:00
|
|
|
.subtract(1, "month")
|
2018-09-07 10:49:44 -04:00
|
|
|
.startOf("day"),
|
2019-05-27 04:15:39 -04:00
|
|
|
endDate: this.today
|
2018-09-07 10:49:44 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-07-19 14:33:11 -04:00
|
|
|
@computed
|
|
|
|
trendingSearchOptions() {
|
2018-09-07 10:49:44 -04:00
|
|
|
return {
|
|
|
|
table: { total: false, limit: 8 }
|
|
|
|
};
|
2018-07-19 14:33:11 -04:00
|
|
|
},
|
|
|
|
|
2018-11-07 11:59:42 -05:00
|
|
|
@computed
|
|
|
|
trendingSearchDisabledLabel() {
|
|
|
|
return I18n.t("admin.dashboard.reports.trending_search.disabled", {
|
|
|
|
basePath: Discourse.BaseUri
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-07-19 19:30:13 -04:00
|
|
|
usersByTypeReport: staticReport("users_by_type"),
|
|
|
|
usersByTrustLevelReport: staticReport("users_by_trust_level"),
|
2018-12-14 17:14:46 -05:00
|
|
|
storageReport: staticReport("storage_report"),
|
2018-07-19 14:33:11 -04:00
|
|
|
|
|
|
|
fetchDashboard() {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.isLoading) return;
|
2018-07-19 14:33:11 -04:00
|
|
|
|
|
|
|
if (
|
2019-05-27 04:15:39 -04:00
|
|
|
!this.dashboardFetchedAt ||
|
2018-07-19 14:33:11 -04:00
|
|
|
moment()
|
|
|
|
.subtract(30, "minutes")
|
2019-05-27 04:15:39 -04:00
|
|
|
.toDate() > this.dashboardFetchedAt
|
2018-07-19 14:33:11 -04:00
|
|
|
) {
|
|
|
|
this.set("isLoading", true);
|
|
|
|
|
2019-04-01 06:39:49 -04:00
|
|
|
AdminDashboard.fetchGeneral()
|
|
|
|
.then(adminDashboardModel => {
|
2018-07-19 14:33:11 -04:00
|
|
|
this.setProperties({
|
|
|
|
dashboardFetchedAt: new Date(),
|
2019-04-01 06:39:49 -04:00
|
|
|
model: adminDashboardModel,
|
2019-10-31 13:55:01 -04:00
|
|
|
reports: makeArray(adminDashboardModel.reports).map(x =>
|
2018-07-31 21:23:28 -04:00
|
|
|
Report.create(x)
|
|
|
|
)
|
2018-07-19 14:33:11 -04:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(e => {
|
2019-05-27 04:15:39 -04:00
|
|
|
this.exceptionController.set("thrown", e.jqXHR);
|
2018-07-19 14:33:11 -04:00
|
|
|
this.replaceRoute("exception");
|
|
|
|
})
|
|
|
|
.finally(() => this.set("isLoading", false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-07-27 01:22:00 -04:00
|
|
|
@computed("startDate", "endDate")
|
|
|
|
filters(startDate, endDate) {
|
|
|
|
return { startDate, endDate };
|
|
|
|
},
|
|
|
|
|
2018-07-19 14:33:11 -04:00
|
|
|
_reportsForPeriodURL(period) {
|
2018-07-27 01:22:00 -04:00
|
|
|
return Discourse.getURL(`/admin?period=${period}`);
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
|
|
|
});
|