2015-11-20 20:27:06 -05:00
|
|
|
import AdminDashboard from 'admin/models/admin-dashboard';
|
2016-08-03 15:36:41 -04:00
|
|
|
import Report from 'admin/models/report';
|
|
|
|
import AdminUser from 'admin/models/admin-user';
|
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
|
|
|
|
|
|
|
|
2017-11-10 12:18:08 -05:00
|
|
|
const ATTRIBUTES = [ 'disk_space','admins', 'moderators', 'silenced', 'suspended', 'top_traffic_sources',
|
2016-08-03 15:36:41 -04:00
|
|
|
'top_referred_topics', 'updated_at'];
|
|
|
|
|
|
|
|
const REPORTS = [ 'global_reports', 'page_view_reports', 'private_message_reports', 'http_reports',
|
|
|
|
'user_reports', 'mobile_reports'];
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2015-08-07 15:08:27 -04:00
|
|
|
// This controller supports the default interface when you enter the admin section.
|
2014-07-22 23:20:45 -04:00
|
|
|
export default Ember.Controller.extend({
|
2016-08-03 15:36:41 -04:00
|
|
|
loading: null,
|
2013-03-19 23:18:00 -04:00
|
|
|
versionCheck: null,
|
2016-08-03 15:36:41 -04:00
|
|
|
dashboardFetchedAt: null,
|
2018-03-29 14:12:29 -04:00
|
|
|
exceptionController: Ember.inject.controller('exception'),
|
2014-09-11 16:30:47 -04:00
|
|
|
|
2016-08-03 15:36:41 -04:00
|
|
|
fetchDashboard() {
|
|
|
|
if (!this.get('dashboardFetchedAt') || moment().subtract(30, 'minutes').toDate() > this.get('dashboardFetchedAt')) {
|
|
|
|
this.set('loading', true);
|
|
|
|
AdminDashboard.find().then(d => {
|
2018-03-29 14:12:29 -04:00
|
|
|
this.set('dashboardFetchedAt', new Date());
|
2016-08-03 15:36:41 -04:00
|
|
|
|
|
|
|
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]));
|
2018-03-29 14:12:29 -04:00
|
|
|
}).catch(e => {
|
|
|
|
this.get('exceptionController').set('thrown', e.jqXHR);
|
|
|
|
this.replaceRoute('exception');
|
|
|
|
}).finally(() => {
|
2016-08-03 15:36:41 -04:00
|
|
|
this.set('loading', false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-08-02 18:31:25 -04:00
|
|
|
|
2016-08-03 15:36:41 -04:00
|
|
|
@computed('updated_at')
|
|
|
|
updatedTimestamp(updatedAt) {
|
|
|
|
return moment(updatedAt).format('LLL');
|
|
|
|
},
|
2013-09-16 14:08:55 -04:00
|
|
|
|
|
|
|
actions: {
|
2016-08-03 15:36:41 -04:00
|
|
|
showTrafficReport() {
|
2015-02-05 22:39:04 -05:00
|
|
|
this.set("showTrafficReport", true);
|
2013-09-16 14:08:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|