* [WIP] group ids saving on new reports * Add groups to default queries, and added tab connector * group_ids set to empty array for default queries * group reports route (in & and) action * [WIP] created group reports show route/controller * Find correct query in show route * Removed empty array for group_ids in query file * Add report show view, where users can run queries * Removed unneeded commas from queries.rb * Allow non-admin group members to access reports * query-result component dynamic download url based on location * Removed accidental changes, and corrected tab size * Group members can add params to queries * Specs for new QueryController actions * remove "Inlude query plan" from group reports * Run prettier * return and return -> return render Co-Authored-By: Robin Ward <[email protected]> * [WIP] changes from review * Remove weird [-1] group_ids logic, for a simply check for [] in query update action * Added integration tests for group report access * Using guardian for securing endpoints, and much improved specs * Update assets/javascripts/discourse/components/group-reports-nav-item.js.es6 Co-Authored-By: Robin Ward <[email protected]>
94 lines
1.8 KiB
JavaScript
94 lines
1.8 KiB
JavaScript
import {
|
|
default as computed,
|
|
on,
|
|
observes
|
|
} from "ember-addons/ember-computed-decorators";
|
|
import RestModel from "discourse/models/rest";
|
|
|
|
const Query = RestModel.extend({
|
|
dirty: false,
|
|
params: {},
|
|
results: null,
|
|
|
|
@on("init")
|
|
_init() {
|
|
this._super(...arguments);
|
|
|
|
this.set("dirty", false);
|
|
},
|
|
|
|
@on("init")
|
|
@observes("param_info")
|
|
_initParams() {
|
|
this.resetParams();
|
|
},
|
|
|
|
@observes("name", "description", "sql", "group_ids")
|
|
markDirty() {
|
|
this.set("dirty", true);
|
|
},
|
|
|
|
markNotDirty() {
|
|
this.set("dirty", false);
|
|
},
|
|
|
|
hasParams: Ember.computed.reads("param_info.length"),
|
|
|
|
resetParams() {
|
|
const newParams = {};
|
|
const oldParams = this.params;
|
|
const paramInfo = this.param_info || [];
|
|
paramInfo.forEach(pinfo => {
|
|
const name = pinfo.identifier;
|
|
if (oldParams[pinfo.identifier]) {
|
|
newParams[name] = oldParams[name];
|
|
} else if (pinfo["default"] !== null) {
|
|
newParams[name] = pinfo["default"];
|
|
} else if (pinfo["type"] === "boolean") {
|
|
newParams[name] = "false";
|
|
} else {
|
|
newParams[name] = "";
|
|
}
|
|
});
|
|
this.set("params", newParams);
|
|
},
|
|
|
|
@computed("id")
|
|
downloadUrl(id) {
|
|
// TODO - can we change this to use the store/adapter?
|
|
return Discourse.getURL(
|
|
`/admin/plugins/explorer/queries/${id}.json?export=1`
|
|
);
|
|
},
|
|
|
|
createProperties() {
|
|
if (this.sql) {
|
|
// Importing
|
|
return this.updateProperties();
|
|
}
|
|
return this.getProperties("name");
|
|
},
|
|
|
|
updateProperties() {
|
|
const props = this.getProperties(Query.updatePropertyNames);
|
|
if (this.destroyed) {
|
|
props.id = this.id;
|
|
}
|
|
return props;
|
|
}
|
|
});
|
|
|
|
Query.reopenClass({
|
|
updatePropertyNames: [
|
|
"name",
|
|
"description",
|
|
"sql",
|
|
"created_by",
|
|
"created_at",
|
|
"group_ids",
|
|
"last_run_at"
|
|
]
|
|
});
|
|
|
|
export default Query;
|