2018-04-26 20:49:41 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
2018-12-15 06:14:46 +08:00
|
|
|
const GENERAL_ATTRIBUTES = ["updated_at"];
|
2018-04-19 03:30:41 +08:00
|
|
|
|
|
|
|
const AdminDashboardNext = Discourse.Model.extend({});
|
|
|
|
|
|
|
|
AdminDashboardNext.reopenClass({
|
2018-07-20 02:33:11 +08:00
|
|
|
fetch() {
|
2018-07-27 02:59:28 +08:00
|
|
|
return ajax("/admin/dashboard.json").then(json => {
|
2018-07-20 02:33:11 +08:00
|
|
|
const model = AdminDashboardNext.create();
|
|
|
|
model.set("version_check", json.version_check);
|
|
|
|
return model;
|
|
|
|
});
|
|
|
|
},
|
2018-04-19 03:30:41 +08:00
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
fetchGeneral() {
|
|
|
|
return ajax("/admin/dashboard/general.json").then(json => {
|
|
|
|
const model = AdminDashboardNext.create();
|
2018-04-26 20:49:41 +08:00
|
|
|
|
|
|
|
const attributes = {};
|
2018-07-20 02:33:11 +08:00
|
|
|
GENERAL_ATTRIBUTES.forEach(a => (attributes[a] = json[a]));
|
2018-04-26 20:49:41 +08:00
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
model.setProperties({
|
|
|
|
reports: json.reports,
|
|
|
|
attributes,
|
|
|
|
loaded: true
|
|
|
|
});
|
2018-04-26 20:49:41 +08:00
|
|
|
|
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", {
|
2018-06-15 23:03:24 +08:00
|
|
|
type: "GET",
|
|
|
|
dataType: "json"
|
2018-05-14 11:07:59 +08:00
|
|
|
}).then(function(json) {
|
|
|
|
var model = AdminDashboardNext.create(json);
|
2018-06-15 23:03:24 +08:00
|
|
|
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;
|