2018-04-26 08:49:41 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
2018-05-03 09:41:41 -04:00
|
|
|
const ATTRIBUTES = [ "disk_space", "updated_at", "last_backup_taken_at" ];
|
2018-04-18 15:30:41 -04:00
|
|
|
|
|
|
|
const AdminDashboardNext = Discourse.Model.extend({});
|
|
|
|
|
|
|
|
AdminDashboardNext.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
|
|
|
|
**/
|
2018-04-26 08:49:41 -04:00
|
|
|
find() {
|
2018-05-13 23:07:59 -04:00
|
|
|
|
2018-04-18 15:30:41 -04:00
|
|
|
return ajax("/admin/dashboard-next.json").then(function(json) {
|
2018-05-13 23:07:59 -04:00
|
|
|
|
2018-04-26 08:49:41 -04:00
|
|
|
var model = AdminDashboardNext.create();
|
|
|
|
|
2018-05-03 09:41:41 -04:00
|
|
|
model.set("reports", json.reports);
|
2018-05-13 23:07:59 -04:00
|
|
|
model.set("version_check", json.version_check);
|
2018-04-26 08:49:41 -04:00
|
|
|
|
|
|
|
const attributes = {};
|
|
|
|
ATTRIBUTES.forEach(a => attributes[a] = json[a]);
|
|
|
|
model.set("attributes", attributes);
|
|
|
|
|
|
|
|
model.set("loaded", true);
|
|
|
|
|
2018-05-13 23:07:59 -04:00
|
|
|
return model;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
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() {
|
|
|
|
return ajax("/admin/dashboard/problems.json", {
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json'
|
|
|
|
}).then(function(json) {
|
|
|
|
var model = AdminDashboardNext.create(json);
|
|
|
|
model.set('loaded', true);
|
2018-04-18 15:30:41 -04:00
|
|
|
return model;
|
|
|
|
});
|
2018-04-26 08:49:41 -04:00
|
|
|
}
|
2018-04-18 15:30:41 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default AdminDashboardNext;
|