2018-10-10 07:56:23 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2020-05-12 14:41:26 -04:00
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
2015-06-25 17:53:03 -04:00
|
|
|
|
2020-05-12 14:41:26 -04:00
|
|
|
export default DiscourseRoute.extend({
|
2018-10-10 07:56:23 -04:00
|
|
|
controllerName: "admin-plugins-explorer",
|
2015-06-25 16:26:31 -04:00
|
|
|
|
|
|
|
model() {
|
2019-11-14 13:39:55 -05:00
|
|
|
const groupPromise = ajax("/admin/plugins/explorer/groups.json");
|
2019-09-11 11:30:39 -04:00
|
|
|
const schemaPromise = ajax("/admin/plugins/explorer/schema.json", {
|
|
|
|
cache: true
|
|
|
|
});
|
2019-09-11 10:09:41 -04:00
|
|
|
const queryPromise = this.store.findAll("query");
|
2015-09-21 14:19:31 -04:00
|
|
|
|
2019-09-11 10:09:41 -04:00
|
|
|
return groupPromise
|
|
|
|
.then(groups => {
|
|
|
|
let groupNames = {};
|
|
|
|
groups.forEach(g => {
|
|
|
|
groupNames[g.id] = g.name;
|
|
|
|
});
|
|
|
|
return schemaPromise.then(schema => {
|
|
|
|
return queryPromise.then(model => {
|
|
|
|
model.forEach(query => {
|
|
|
|
query.markNotDirty();
|
|
|
|
query.set(
|
|
|
|
"group_names",
|
2019-10-28 21:34:08 -04:00
|
|
|
(query.group_ids || []).map(id => groupNames[id])
|
2019-09-11 10:09:41 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
return { model, schema, groups };
|
|
|
|
});
|
2018-10-10 07:56:23 -04:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2019-09-11 10:09:41 -04:00
|
|
|
schemaPromise.catch(() => {});
|
|
|
|
queryPromise.catch(() => {});
|
|
|
|
return { model: null, schema: null, disallow: true, groups: null };
|
2018-10-10 07:56:23 -04:00
|
|
|
});
|
2015-07-08 16:45:13 -04:00
|
|
|
},
|
|
|
|
|
2019-07-16 06:46:32 -04:00
|
|
|
setupController(controller, model) {
|
2015-09-21 14:19:31 -04:00
|
|
|
controller.setProperties(model);
|
2018-08-30 04:43:40 -04:00
|
|
|
},
|
2018-09-04 12:22:44 -04:00
|
|
|
|
2018-08-30 04:43:40 -04:00
|
|
|
actions: {
|
2019-07-16 06:46:32 -04:00
|
|
|
refreshModel() {
|
2018-10-10 07:56:23 -04:00
|
|
|
this.refresh();
|
2018-12-16 09:22:23 -05:00
|
|
|
return false;
|
2018-10-10 07:56:23 -04:00
|
|
|
}
|
2015-06-25 16:26:31 -04:00
|
|
|
}
|
2018-10-10 07:56:23 -04:00
|
|
|
});
|