2018-06-15 23:03:24 +08:00
|
|
|
import AdminDashboard from "admin/models/admin-dashboard";
|
|
|
|
import Report from "admin/models/report";
|
|
|
|
import AdminUser from "admin/models/admin-user";
|
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2016-08-04 03:36:41 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
const ATTRIBUTES = [
|
|
|
|
"admins",
|
|
|
|
"moderators",
|
|
|
|
"silenced",
|
|
|
|
"suspended",
|
|
|
|
"top_traffic_sources",
|
|
|
|
"top_referred_topics",
|
|
|
|
"updated_at"
|
|
|
|
];
|
2016-08-04 03:36:41 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
const REPORTS = [
|
|
|
|
"global_reports",
|
|
|
|
"page_view_reports",
|
|
|
|
"private_message_reports",
|
|
|
|
"http_reports",
|
|
|
|
"user_reports",
|
|
|
|
"mobile_reports"
|
|
|
|
];
|
2013-02-21 02:15:50 +08:00
|
|
|
|
2015-08-08 03:08:27 +08:00
|
|
|
// This controller supports the default interface when you enter the admin section.
|
2014-07-23 11:20:45 +08:00
|
|
|
export default Ember.Controller.extend({
|
2016-08-04 03:36:41 +08:00
|
|
|
loading: null,
|
2013-03-20 11:18:00 +08:00
|
|
|
versionCheck: null,
|
2016-08-04 03:36:41 +08:00
|
|
|
dashboardFetchedAt: null,
|
2018-06-15 23:03:24 +08:00
|
|
|
exceptionController: Ember.inject.controller("exception"),
|
2014-09-12 04:30:47 +08:00
|
|
|
|
2016-08-04 03:36:41 +08:00
|
|
|
fetchDashboard() {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
!this.get("dashboardFetchedAt") ||
|
|
|
|
moment()
|
|
|
|
.subtract(30, "minutes")
|
|
|
|
.toDate() > this.get("dashboardFetchedAt")
|
|
|
|
) {
|
|
|
|
this.set("loading", true);
|
|
|
|
AdminDashboard.find()
|
|
|
|
.then(d => {
|
|
|
|
this.set("dashboardFetchedAt", new Date());
|
|
|
|
|
|
|
|
REPORTS.forEach(name =>
|
|
|
|
this.set(name, d[name].map(r => Report.create(r)))
|
|
|
|
);
|
|
|
|
|
|
|
|
const topReferrers = d.top_referrers;
|
|
|
|
if (topReferrers && topReferrers.data) {
|
|
|
|
d.top_referrers.data = topReferrers.data.map(user =>
|
|
|
|
AdminUser.create(user)
|
|
|
|
);
|
|
|
|
this.set("top_referrers", topReferrers);
|
|
|
|
}
|
|
|
|
|
|
|
|
ATTRIBUTES.forEach(a => this.set(a, d[a]));
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.get("exceptionController").set("thrown", e.jqXHR);
|
|
|
|
this.replaceRoute("exception");
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.set("loading", false);
|
|
|
|
});
|
2016-08-04 03:36:41 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("updated_at")
|
2016-08-04 03:36:41 +08:00
|
|
|
updatedTimestamp(updatedAt) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return moment(updatedAt).format("LLL");
|
2016-08-04 03:36:41 +08:00
|
|
|
},
|
2013-09-17 02:08:55 +08:00
|
|
|
|
|
|
|
actions: {
|
2016-08-04 03:36:41 +08:00
|
|
|
showTrafficReport() {
|
2015-02-06 11:39:04 +08:00
|
|
|
this.set("showTrafficReport", true);
|
2013-09-17 02:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|