Work on new parameter model

This commit is contained in:
Kane York
2015-07-14 16:01:38 -07:00
parent 9d41222dc7
commit 0672e99da2
11 changed files with 210 additions and 60 deletions
@@ -7,37 +7,35 @@ const Query = RestModel.extend({
_init: function() {
this._super();
if (!this.get('options')) {
this.set('options', {defaults:{}});
}
this.set('dirty', false);
}.on('init'),
_initParams: function() {
this.resetParams();
}.on('init').observes('param_names'),
// the server uses 'qopts' and the client uses 'options' due to ActiveRecord
// freaking out if a serialized value is named 'options'
options: Em.computed.alias('qopts'),
}.on('init').observes('param_info'),
markDirty: function() {
this.set('dirty', true);
}.observes('name', 'description', 'sql', 'options', 'options.defaults'),
}.observes('name', 'description', 'sql'),
markNotDirty() {
this.set('dirty', false);
},
hasParams: function() {
return this.get('param_info.length') > 0;
}.property('param_info'),
resetParams() {
const newParams = {};
const oldParams = this.get('params');
const defaults = this.get('options.defaults') || {};
(this.get('param_names') || []).forEach(function(name) {
if (defaults[name]) {
newParams[name] = defaults[name];
} else if (oldParams[name]) {
const paramInfo = this.get('param_info') || [];
paramInfo.forEach(function(pinfo) {
const name = pinfo.identifier;
if (oldParams[pinfo.identifier]) {
newParams[name] = oldParams[name];
} else if (pinfo['default'] !== null) {
newParams[name] = pinfo['default'];
} else {
newParams[name] = '';
}
@@ -45,19 +43,6 @@ const Query = RestModel.extend({
this.set('params', newParams);
},
saveDefaults() {
const currentParams = this.get('params');
let defaults = {};
(this.get('param_names') || []).forEach(function(name) {
if (currentParams[name]) {
defaults[name] = currentParams[name];
} else {
delete defaults[name];
}
});
this.set('options.defaults', defaults);
},
downloadUrl: function() {
// TODO - can we change this to use the store/adapter?
return Discourse.getURL("/admin/plugins/explorer/queries/" + this.get('id') + ".json?export=1");
@@ -88,15 +73,11 @@ const Query = RestModel.extend({
props.id = this.get('id');
}
return props;
},
run() {
console.log("Called query#run");
}
});
Query.reopenClass({
updatePropertyNames: ["name", "description", "sql", "qopts"]
updatePropertyNames: ["name", "description", "sql"]
});
export default Query;