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