DEV: Upgrade `query` model to Octane (#221)
- Upgrade `query` model to Octane - Update `assets/javascripts/discourse/templates/admin/plugins-explorer.hbs` to access values via `this.`
This commit is contained in:
parent
29cfa6383c
commit
04b2177749
|
@ -1,27 +1,36 @@
|
||||||
import discourseComputed, {
|
|
||||||
observes,
|
|
||||||
on,
|
|
||||||
} from "discourse-common/utils/decorators";
|
|
||||||
import getURL from "discourse-common/lib/get-url";
|
import getURL from "discourse-common/lib/get-url";
|
||||||
import RestModel from "discourse/models/rest";
|
import RestModel from "discourse/models/rest";
|
||||||
import { reads } from "@ember/object/computed";
|
|
||||||
|
|
||||||
const Query = RestModel.extend({
|
export default class Query extends RestModel {
|
||||||
params: {},
|
static updatePropertyNames = [
|
||||||
results: null,
|
"name",
|
||||||
hasParams: reads("param_info.length"),
|
"description",
|
||||||
|
"sql",
|
||||||
|
"user_id",
|
||||||
|
"created_at",
|
||||||
|
"group_ids",
|
||||||
|
"last_run_at",
|
||||||
|
];
|
||||||
|
|
||||||
@on("init")
|
params = {};
|
||||||
@observes("param_info")
|
|
||||||
_initParams() {
|
constructor() {
|
||||||
this.resetParams();
|
super(...arguments);
|
||||||
},
|
this.param_info?.resetParams();
|
||||||
|
}
|
||||||
|
|
||||||
|
get downloadUrl() {
|
||||||
|
return getURL(`/admin/plugins/explorer/queries/${this.id}.json?export=1`);
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasParams() {
|
||||||
|
return this.param_info.length;
|
||||||
|
}
|
||||||
|
|
||||||
resetParams() {
|
resetParams() {
|
||||||
const newParams = {};
|
const newParams = {};
|
||||||
const oldParams = this.params;
|
const oldParams = this.params;
|
||||||
const paramInfo = this.param_info || [];
|
this.param_info.forEach((pinfo) => {
|
||||||
paramInfo.forEach((pinfo) => {
|
|
||||||
const name = pinfo.identifier;
|
const name = pinfo.identifier;
|
||||||
if (oldParams[pinfo.identifier]) {
|
if (oldParams[pinfo.identifier]) {
|
||||||
newParams[name] = oldParams[name];
|
newParams[name] = oldParams[name];
|
||||||
|
@ -37,22 +46,8 @@ const Query = RestModel.extend({
|
||||||
newParams[name] = "";
|
newParams[name] = "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.set("params", newParams);
|
this.params = newParams;
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("id")
|
|
||||||
downloadUrl(id) {
|
|
||||||
// TODO - can we change this to use the store/adapter?
|
|
||||||
return getURL(`/admin/plugins/explorer/queries/${id}.json?export=1`);
|
|
||||||
},
|
|
||||||
|
|
||||||
createProperties() {
|
|
||||||
if (this.sql) {
|
|
||||||
// Importing
|
|
||||||
return this.updateProperties();
|
|
||||||
}
|
|
||||||
return this.getProperties("name");
|
|
||||||
},
|
|
||||||
|
|
||||||
updateProperties() {
|
updateProperties() {
|
||||||
const props = this.getProperties(Query.updatePropertyNames);
|
const props = this.getProperties(Query.updatePropertyNames);
|
||||||
|
@ -60,19 +55,5 @@ const Query = RestModel.extend({
|
||||||
props.id = this.id;
|
props.id = this.id;
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
Query.reopenClass({
|
|
||||||
updatePropertyNames: [
|
|
||||||
"name",
|
|
||||||
"description",
|
|
||||||
"sql",
|
|
||||||
"user_id",
|
|
||||||
"created_at",
|
|
||||||
"group_ids",
|
|
||||||
"last_run_at",
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Query;
|
|
||||||
|
|
|
@ -275,10 +275,10 @@
|
||||||
|
|
||||||
{{#unless this.selectedItem.fake}}
|
{{#unless this.selectedItem.fake}}
|
||||||
<QueryResultsWrapper
|
<QueryResultsWrapper
|
||||||
@results={{results}}
|
@results={{this.results}}
|
||||||
@showResults={{showResults}}
|
@showResults={{this.showResults}}
|
||||||
@query={{selectedItem}}
|
@query={{this.selectedItem}}
|
||||||
@content={{results}}
|
@content={{this.results}}
|
||||||
/>
|
/>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue