2018-07-19 14:33:11 -04:00
|
|
|
import { setting } from "discourse/lib/computed";
|
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
import AdminDashboardNext from "admin/models/admin-dashboard-next";
|
|
|
|
import Report from "admin/models/report";
|
|
|
|
import PeriodComputationMixin from "admin/mixins/period-computation";
|
|
|
|
|
2018-07-19 19:30:13 -04:00
|
|
|
function staticReport(reportType) {
|
|
|
|
return function() {
|
2018-08-06 16:57:40 -04:00
|
|
|
return Ember.makeArray(this.get("reports")).find(
|
|
|
|
report => report.type === reportType
|
|
|
|
);
|
2018-07-19 19:30:13 -04:00
|
|
|
}.property("reports.[]");
|
|
|
|
}
|
|
|
|
|
2018-07-19 14:33:11 -04:00
|
|
|
export default Ember.Controller.extend(PeriodComputationMixin, {
|
|
|
|
isLoading: false,
|
|
|
|
dashboardFetchedAt: null,
|
|
|
|
exceptionController: Ember.inject.controller("exception"),
|
|
|
|
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 {
|
|
|
|
startDate: this.get("lastMonth"),
|
|
|
|
endDate: this.get("today")
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
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"),
|
|
|
|
endDate: this.get("today")
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
@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"),
|
|
|
|
endDate: this.get("today")
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
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() {
|
|
|
|
if (this.get("isLoading")) return;
|
|
|
|
|
|
|
|
if (
|
|
|
|
!this.get("dashboardFetchedAt") ||
|
|
|
|
moment()
|
|
|
|
.subtract(30, "minutes")
|
|
|
|
.toDate() > this.get("dashboardFetchedAt")
|
|
|
|
) {
|
|
|
|
this.set("isLoading", true);
|
|
|
|
|
|
|
|
AdminDashboardNext.fetchGeneral()
|
|
|
|
.then(adminDashboardNextModel => {
|
|
|
|
this.setProperties({
|
|
|
|
dashboardFetchedAt: new Date(),
|
|
|
|
model: adminDashboardNextModel,
|
2018-07-31 21:23:28 -04:00
|
|
|
reports: Ember.makeArray(adminDashboardNextModel.reports).map(x =>
|
|
|
|
Report.create(x)
|
|
|
|
)
|
2018-07-19 14:33:11 -04:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.get("exceptionController").set("thrown", e.jqXHR);
|
|
|
|
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
|
|
|
@computed("model.attributes.updated_at")
|
|
|
|
updatedTimestamp(updatedAt) {
|
2018-08-07 08:19:52 -04:00
|
|
|
return moment(updatedAt)
|
|
|
|
.tz(moment.tz.guess())
|
|
|
|
.format("LLL");
|
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
|
|
|
}
|
|
|
|
});
|