2015-11-20 20:27:06 -05:00
|
|
|
import AdminDashboard from 'admin/models/admin-dashboard';
|
|
|
|
import VersionCheck from 'admin/models/version-check';
|
|
|
|
import Report from 'admin/models/report';
|
|
|
|
import AdminUser from 'admin/models/admin-user';
|
|
|
|
|
2014-07-22 23:20:45 -04:00
|
|
|
export default Discourse.Route.extend({
|
2013-03-29 16:05:29 -04:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
setupController: function(c) {
|
2013-03-14 18:26:12 -04:00
|
|
|
this.fetchDashboardData(c);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
2013-02-25 16:21:52 -05:00
|
|
|
|
2013-03-14 18:26:12 -04:00
|
|
|
fetchDashboardData: function(c) {
|
2014-08-20 16:22:58 -04:00
|
|
|
if( !c.get('dashboardFetchedAt') || moment().subtract(30, 'minutes').toDate() > c.get('dashboardFetchedAt') ) {
|
2013-03-14 18:26:12 -04:00
|
|
|
c.set('dashboardFetchedAt', new Date());
|
2014-12-15 14:41:08 -05:00
|
|
|
var versionChecks = this.siteSettings.version_checks;
|
2015-11-20 20:27:06 -05:00
|
|
|
AdminDashboard.find().then(function(d) {
|
2014-12-15 14:41:08 -05:00
|
|
|
if (versionChecks) {
|
2015-11-20 20:27:06 -05:00
|
|
|
c.set('versionCheck', VersionCheck.create(d.version_check));
|
2013-03-14 18:26:12 -04:00
|
|
|
}
|
2015-06-24 20:42:08 -04:00
|
|
|
|
2015-07-07 12:31:07 -04:00
|
|
|
['global_reports', 'page_view_reports', 'private_message_reports', 'http_reports', 'user_reports', 'mobile_reports'].forEach(name => {
|
2015-11-20 20:27:06 -05:00
|
|
|
c.set(name, d[name].map(r => Report.create(r)));
|
2013-03-14 18:26:12 -04:00
|
|
|
});
|
2013-07-23 13:35:32 -04:00
|
|
|
|
|
|
|
var topReferrers = d.top_referrers;
|
|
|
|
if (topReferrers && topReferrers.data) {
|
|
|
|
d.top_referrers.data = topReferrers.data.map(function (user) {
|
2015-11-20 20:27:06 -05:00
|
|
|
return AdminUser.create(user);
|
2013-07-23 13:35:32 -04:00
|
|
|
});
|
|
|
|
c.set('top_referrers', topReferrers);
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:08:52 -05:00
|
|
|
[ 'disk_space','admins', 'moderators', 'blocked', 'suspended',
|
|
|
|
'top_traffic_sources', 'top_referred_topics', 'updated_at'].forEach(function(x) {
|
2013-07-08 12:21:08 -04:00
|
|
|
c.set(x, d[x]);
|
|
|
|
});
|
2013-07-23 13:35:32 -04:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
c.set('loading', false);
|
|
|
|
});
|
2013-05-15 11:09:12 -04:00
|
|
|
}
|
|
|
|
|
2014-08-20 16:22:58 -04:00
|
|
|
if( !c.get('problemsFetchedAt') || moment().subtract(c.problemsCheckMinutes, 'minutes').toDate() > c.get('problemsFetchedAt') ) {
|
2013-03-29 15:48:26 -04:00
|
|
|
c.set('problemsFetchedAt', new Date());
|
2013-04-16 12:09:37 -04:00
|
|
|
c.loadProblems();
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
});
|
2013-02-20 13:15:50 -05:00
|
|
|
|