2013-02-23 04:41:12 +08:00
|
|
|
/**
|
|
|
|
Handles the default admin route
|
2013-02-21 02:15:50 +08:00
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
@class AdminDashboardRoute
|
|
|
|
@extends Discourse.Route
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
|
|
|
**/
|
|
|
|
Discourse.AdminDashboardRoute = 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-03-12 03:26:14 +08:00
|
|
|
this.fetchGithubCommits(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) {
|
2013-08-03 06:31:25 +08:00
|
|
|
if( !c.get('dashboardFetchedAt') || moment().subtract('minutes', 30).toDate() > c.get('dashboardFetchedAt') ) {
|
2013-03-15 06:26:12 +08:00
|
|
|
c.set('dashboardFetchedAt', new Date());
|
|
|
|
Discourse.AdminDashboard.find().then(function(d) {
|
|
|
|
if( Discourse.SiteSettings.version_checks ){
|
|
|
|
c.set('versionCheck', Discourse.VersionCheck.create(d.version_check));
|
|
|
|
}
|
2013-06-11 04:48:50 +08:00
|
|
|
_.each(d.reports,function(report){
|
2013-03-15 06:26:12 +08:00
|
|
|
c.set(report.type, Discourse.Report.create(report));
|
|
|
|
});
|
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) {
|
|
|
|
return Discourse.AdminUser.create(user);
|
|
|
|
});
|
|
|
|
c.set('top_referrers', topReferrers);
|
|
|
|
}
|
|
|
|
|
2013-11-08 02:53:32 +08:00
|
|
|
['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
|
|
|
}
|
|
|
|
|
2013-06-11 23:46:14 +08:00
|
|
|
if( !c.get('problemsFetchedAt') || moment().subtract('minute',c.problemsCheckMinutes).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-03-08 00:07:59 +08:00
|
|
|
},
|
|
|
|
|
2013-03-12 03:26:14 +08:00
|
|
|
fetchGithubCommits: function(c) {
|
2013-06-11 04:48:50 +08:00
|
|
|
if( !c.get('commitsCheckedAt') || moment().subtract('hour',1).toDate() > c.get('commitsCheckedAt') ) {
|
2013-03-12 03:26:14 +08:00
|
|
|
c.set('commitsCheckedAt', new Date());
|
|
|
|
c.set('githubCommits', Discourse.GithubCommit.findAll());
|
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
}
|
|
|
|
});
|
2013-02-21 02:15:50 +08:00
|
|
|
|