Fetch the list of problems more frequently on the admin dashboard

This commit is contained in:
Neil Lalonde
2013-03-29 15:48:26 -04:00
parent df85201298
commit 25073e873f
6 changed files with 96 additions and 4 deletions

View File

@@ -1,6 +1,23 @@
/**
A model that stores all or some data that is displayed on the dashboard.
@class AdminDashboard
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.AdminDashboard = Discourse.Model.extend({});
Discourse.AdminDashboard.reopenClass({
/**
Fetch all dashboard data. This can be an expensive request when the cached data
has expired and the server must collect the data again.
@method find
@return {jqXHR} a jQuery Promise object
**/
find: function() {
var model = Discourse.AdminDashboard.create();
return $.ajax(Discourse.getURL("/admin/dashboard"), {
@@ -11,5 +28,24 @@ Discourse.AdminDashboard.reopenClass({
model.set('loaded', true);
}
});
},
/**
Only fetch the list of problems that should be rendered on the dashboard.
The model will only have its "problems" attribute set.
@method fetchProblems
@return {jqXHR} a jQuery Promise object
**/
fetchProblems: function() {
var model = Discourse.AdminDashboard.create();
return $.ajax(Discourse.getURL("/admin/dashboard/problems"), {
type: 'GET',
dataType: 'json',
success: function(json) {
model.mergeAttributes(json);
model.set('loaded', true);
}
});
}
});

View File

@@ -19,6 +19,7 @@ Discourse.AdminDashboardRoute = Discourse.Route.extend({
fetchDashboardData: function(c) {
if( !c.get('dashboardFetchedAt') || Date.create('1 hour ago', 'en') > c.get('dashboardFetchedAt') ) {
c.set('dashboardFetchedAt', new Date());
c.set('problemsFetchedAt', new Date());
Discourse.AdminDashboard.find().then(function(d) {
if( Discourse.SiteSettings.version_checks ){
c.set('versionCheck', Discourse.VersionCheck.create(d.version_check));
@@ -31,6 +32,12 @@ Discourse.AdminDashboardRoute = Discourse.Route.extend({
c.set('problems', d.problems);
c.set('loading', false);
});
} else if( !c.get('problemsFetchedAt') || Date.create('1 minute ago', 'en') > c.get('problemsFetchedAt') ) {
c.set('problemsFetchedAt', new Date());
Discourse.AdminDashboard.fetchProblems().then(function(d) {
c.set('problems', d.problems);
c.set('loading', false);
});
}
},