2018-10-10 07:56:23 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2015-06-25 17:53:03 -04:00
|
|
|
|
2015-06-25 16:26:31 -04:00
|
|
|
export default Discourse.Route.extend({
|
2018-10-10 07:56:23 -04:00
|
|
|
controllerName: "admin-plugins-explorer",
|
2015-06-25 16:26:31 -04:00
|
|
|
|
|
|
|
model() {
|
2019-09-11 10:09:41 -04:00
|
|
|
const groupPromise = this.store.findAll("group");
|
|
|
|
const schemaPromise = ajax("/admin/plugins/explorer/schema.json", { cache: true });
|
|
|
|
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",
|
|
|
|
query.group_ids
|
|
|
|
.map(id => groupNames[id])
|
|
|
|
.filter(n => n)
|
|
|
|
.join(", ")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
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
|
|
|
});
|