57 lines
1.2 KiB
Plaintext
Raw Normal View History

import RestModel from 'discourse/models/rest';
2015-06-30 10:20:22 -07:00
let Query;
Query = RestModel.extend({
dirty: false,
markDirty: function() {
this.set('dirty', true);
}.observes('name', 'description', 'sql', 'defaults'),
markNotDirty() {
this.set('dirty', false);
},
2015-06-30 12:52:17 -07:00
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");
}.property('id'),
2015-06-30 10:20:22 -07:00
listName: function() {
2015-06-30 12:52:17 -07:00
let name = this.get('name');
2015-06-30 10:20:22 -07:00
if (this.get('dirty')) {
2015-06-30 12:52:17 -07:00
name += " (*)";
}
if (this.get('destroyed')) {
name += " (deleted)";
2015-06-30 10:20:22 -07:00
}
2015-06-30 12:52:17 -07:00
return name;
}.property('name', 'dirty', 'destroyed'),
2015-06-30 10:20:22 -07:00
createProperties() {
2015-06-30 12:52:17 -07:00
if (this.get('sql')) {
// Importing
return this.updateProperties();
}
return this.getProperties("name");
},
updateProperties() {
2015-06-30 12:52:17 -07:00
let props = this.getProperties(Query.updatePropertyNames);
if (this.get('destroyed')) {
props.id = this.get('id');
}
return props;
},
run() {
console.log("Called query#run");
}
});
2015-06-30 10:20:22 -07:00
Query.reopenClass({
updatePropertyNames: ["name", "description", "sql", "defaults"]
});
export default Query;