2018-07-20 02:33:11 +08: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-20 07:30:13 +08:00
|
|
|
function staticReport(reportType) {
|
|
|
|
return function() {
|
2018-08-07 04:57:40 +08:00
|
|
|
return Ember.makeArray(this.get("reports")).find(
|
|
|
|
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"),
|
|
|
|
diskSpace: Ember.computed.alias("model.attributes.disk_space"),
|
|
|
|
logSearchQueriesEnabled: setting("log_search_queries"),
|
|
|
|
lastBackupTakenAt: Ember.computed.alias(
|
|
|
|
"model.attributes.last_backup_taken_at"
|
|
|
|
),
|
2018-07-27 06:38:55 +08:00
|
|
|
shouldDisplayDurability: Ember.computed.and("diskSpace"),
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2018-08-07 04:57:40 +08:00
|
|
|
@computed
|
|
|
|
activityMetrics() {
|
|
|
|
return [
|
|
|
|
"page_view_total_reqs",
|
|
|
|
"visits",
|
|
|
|
"time_to_first_response",
|
|
|
|
"likes",
|
|
|
|
"flags",
|
|
|
|
"user_to_user_private_messages_with_replies"
|
|
|
|
];
|
|
|
|
},
|
|
|
|
|
2018-08-22 18:37:05 +08:00
|
|
|
@computed
|
|
|
|
activityMetricsFilters() {
|
|
|
|
return {
|
|
|
|
startDate: this.get("lastMonth"),
|
|
|
|
endDate: this.get("today")
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
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"),
|
|
|
|
endDate: this.get("today")
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed
|
|
|
|
trendingSearchFilters() {
|
|
|
|
return {
|
|
|
|
startDate: moment()
|
2018-09-10 16:40:19 +08:00
|
|
|
.subtract(6, "days")
|
2018-09-07 22:49:44 +08:00
|
|
|
.startOf("day"),
|
|
|
|
endDate: this.get("today")
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
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-07-20 07:30:13 +08:00
|
|
|
usersByTypeReport: staticReport("users_by_type"),
|
|
|
|
usersByTrustLevelReport: staticReport("users_by_trust_level"),
|
2018-07-20 02:33:11 +08: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-08-01 09:23:28 +08:00
|
|
|
reports: Ember.makeArray(adminDashboardNextModel.reports).map(x =>
|
|
|
|
Report.create(x)
|
|
|
|
)
|
2018-07-20 02:33:11 +08:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.get("exceptionController").set("thrown", e.jqXHR);
|
|
|
|
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
|
|
|
@computed("model.attributes.updated_at")
|
|
|
|
updatedTimestamp(updatedAt) {
|
2018-08-07 20:19:52 +08:00
|
|
|
return moment(updatedAt)
|
|
|
|
.tz(moment.tz.guess())
|
|
|
|
.format("LLL");
|
2018-07-20 02:33:11 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
@computed("lastBackupTakenAt")
|
|
|
|
backupTimestamp(lastBackupTakenAt) {
|
2018-08-07 20:19:52 +08:00
|
|
|
return moment(lastBackupTakenAt)
|
|
|
|
.tz(moment.tz.guess())
|
|
|
|
.format("LLL");
|
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
|
|
|
}
|
|
|
|
});
|