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:
Isaac Janzen 2023-02-07 12:44:38 -06:00 committed by GitHub
parent 29cfa6383c
commit 04b2177749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 52 deletions

View File

@ -1,27 +1,36 @@
import discourseComputed, {
observes,
on,
} from "discourse-common/utils/decorators";
import getURL from "discourse-common/lib/get-url";
import RestModel from "discourse/models/rest";
import { reads } from "@ember/object/computed";
const Query = RestModel.extend({
params: {},
results: null,
hasParams: reads("param_info.length"),
export default class Query extends RestModel {
static updatePropertyNames = [
"name",
"description",
"sql",
"user_id",
"created_at",
"group_ids",
"last_run_at",
];
@on("init")
@observes("param_info")
_initParams() {
this.resetParams();
},
params = {};
constructor() {
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() {
const newParams = {};
const oldParams = this.params;
const paramInfo = this.param_info || [];
paramInfo.forEach((pinfo) => {
this.param_info.forEach((pinfo) => {
const name = pinfo.identifier;
if (oldParams[pinfo.identifier]) {
newParams[name] = oldParams[name];
@ -37,22 +46,8 @@ const Query = RestModel.extend({
newParams[name] = "";
}
});
this.set("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");
},
this.params = newParams;
}
updateProperties() {
const props = this.getProperties(Query.updatePropertyNames);
@ -60,19 +55,5 @@ const Query = RestModel.extend({
props.id = this.id;
}
return props;
},
});
Query.reopenClass({
updatePropertyNames: [
"name",
"description",
"sql",
"user_id",
"created_at",
"group_ids",
"last_run_at",
],
});
export default Query;
}
}

View File

@ -275,10 +275,10 @@
{{#unless this.selectedItem.fake}}
<QueryResultsWrapper
@results={{results}}
@showResults={{showResults}}
@query={{selectedItem}}
@content={{results}}
@results={{this.results}}
@showResults={{this.showResults}}
@query={{this.selectedItem}}
@content={{this.results}}
/>
{{/unless}}