diff --git a/assets/javascripts/discourse/models/query.js b/assets/javascripts/discourse/models/query.js index d167ba2..0d95084 100644 --- a/assets/javascripts/discourse/models/query.js +++ b/assets/javascripts/discourse/models/query.js @@ -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; + } +} diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index af7681a..9822b6b 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -275,10 +275,10 @@ {{#unless this.selectedItem.fake}} {{/unless}}