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"),
|
|
|
|
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-26 18:38:55 -04:00
|
|
|
shouldDisplayDurability: Ember.computed.and("diskSpace"),
|
2018-11-07 11:59:42 -05:00
|
|
|
basePath: Discourse.BaseUri,
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2018-08-06 16:57:40 -04: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 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-09-10 04:40:19 -04:00
|
|
|
.subtract(6, "days")
|
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-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
|
|
|
},
|
|
|
|
|
|
|
|
@computed("lastBackupTakenAt")
|
|
|
|
backupTimestamp(lastBackupTakenAt) {
|
2018-08-07 08:19:52 -04:00
|
|
|
return moment(lastBackupTakenAt)
|
|
|
|
.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
|
|
|
}
|
|
|
|
});
|