/
admin-dashboard.js.es6
78 lines (69 loc) · 1.92 KB
/
admin-dashboard.js.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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";
const ATTRIBUTES = [
"admins",
"moderators",
"silenced",
"suspended",
"top_traffic_sources",
"top_referred_topics",
"updated_at"
];
const REPORTS = [
"global_reports",
"page_view_reports",
"private_message_reports",
"http_reports",
"user_reports",
"mobile_reports"
];
// This controller supports the default interface when you enter the admin section.
export default Ember.Controller.extend({
loading: null,
versionCheck: null,
dashboardFetchedAt: null,
exceptionController: Ember.inject.controller("exception"),
fetchDashboard() {
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);
});
}
},
@computed("updated_at")
updatedTimestamp(updatedAt) {
return moment(updatedAt).format("LLL");
},
actions: {
showTrafficReport() {
this.set("showTrafficReport", true);
}
}
});