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
|
|
|
|
|
|
|
problemsCheckInterval: '1 minute ago',
|
|
|
|
|
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-02-23 04:41:12 +08:00
|
|
|
renderTemplate: function() {
|
|
|
|
this.render({into: 'admin/templates/admin'});
|
|
|
|
},
|
2013-02-26 05:21:52 +08:00
|
|
|
|
2013-03-15 06:26:12 +08:00
|
|
|
fetchDashboardData: function(c) {
|
|
|
|
if( !c.get('dashboardFetchedAt') || Date.create('1 hour ago', 'en') > c.get('dashboardFetchedAt') ) {
|
|
|
|
c.set('dashboardFetchedAt', new Date());
|
2013-03-30 03:48:26 +08:00
|
|
|
c.set('problemsFetchedAt', new Date());
|
2013-03-15 06:26:12 +08:00
|
|
|
Discourse.AdminDashboard.find().then(function(d) {
|
|
|
|
if( Discourse.SiteSettings.version_checks ){
|
|
|
|
c.set('versionCheck', Discourse.VersionCheck.create(d.version_check));
|
|
|
|
}
|
|
|
|
d.reports.each(function(report){
|
|
|
|
c.set(report.type, Discourse.Report.create(report));
|
|
|
|
});
|
2013-03-23 05:50:22 +08:00
|
|
|
c.set('admins', d.admins);
|
|
|
|
c.set('moderators', d.moderators);
|
2013-03-20 11:18:00 +08:00
|
|
|
c.set('problems', d.problems);
|
2013-02-23 04:41:12 +08:00
|
|
|
c.set('loading', false);
|
|
|
|
});
|
2013-03-30 04:05:29 +08:00
|
|
|
} else if( !c.get('problemsFetchedAt') || Date.create(this.problemsCheckInterval, 'en') > c.get('problemsFetchedAt') ) {
|
2013-03-30 03:48:26 +08:00
|
|
|
c.set('problemsFetchedAt', new Date());
|
2013-03-30 04:05:29 +08:00
|
|
|
var _this = this;
|
2013-03-30 03:48:26 +08:00
|
|
|
Discourse.AdminDashboard.fetchProblems().then(function(d) {
|
|
|
|
c.set('problems', d.problems);
|
|
|
|
c.set('loading', false);
|
2013-03-30 04:05:29 +08:00
|
|
|
if( d.problems && d.problems.length > 0 ) {
|
|
|
|
_this.problemsCheckInterval = '1 minute ago';
|
|
|
|
} else {
|
|
|
|
_this.problemsCheckInterval = '10 minutes ago';
|
|
|
|
}
|
2013-03-30 03:48:26 +08:00
|
|
|
});
|
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-03-13 20:04:10 +08:00
|
|
|
if( !c.get('commitsCheckedAt') || Date.create('1 hour ago', 'en') > 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
|
|
|
|