2018-04-26 20:49:41 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
2018-05-03 21:41:41 +08:00
|
|
|
const ATTRIBUTES = [ "disk_space", "updated_at", "last_backup_taken_at" ];
|
2018-04-19 03:30:41 +08: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 20:49:41 +08:00
|
|
|
find() {
|
2018-05-14 11:07:59 +08:00
|
|
|
|
2018-04-19 03:30:41 +08:00
|
|
|
return ajax("/admin/dashboard-next.json").then(function(json) {
|
2018-05-14 11:07:59 +08:00
|
|
|
|
2018-04-26 20:49:41 +08:00
|
|
|
var model = AdminDashboardNext.create();
|
|
|
|
|
2018-05-03 21:41:41 +08:00
|
|
|
model.set("reports", json.reports);
|
2018-05-14 11:07:59 +08:00
|
|
|
model.set("version_check", json.version_check);
|
2018-04-26 20:49:41 +08:00
|
|
|
|
|
|
|
const attributes = {};
|
|
|
|
ATTRIBUTES.forEach(a => attributes[a] = json[a]);
|
|
|
|
model.set("attributes", attributes);
|
|
|
|
|
|
|
|
model.set("loaded", true);
|
|
|
|
|
2018-05-14 11:07:59 +08: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-19 03:30:41 +08:00
|
|
|
return model;
|
|
|
|
});
|
2018-04-26 20:49:41 +08:00
|
|
|
}
|
2018-04-19 03:30:41 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export default AdminDashboardNext;
|