2015-06-25 14:53:03 -07:00
|
|
|
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
|
|
|
|
2015-06-25 14:53:03 -07:00
|
|
|
createProperties() {
|
2015-06-30 12:52:17 -07:00
|
|
|
if (this.get('sql')) {
|
|
|
|
// Importing
|
|
|
|
return this.updateProperties();
|
|
|
|
}
|
2015-06-26 09:16:09 -07:00
|
|
|
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;
|
2015-06-25 14:53:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
run() {
|
|
|
|
console.log("Called query#run");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-30 10:20:22 -07:00
|
|
|
Query.reopenClass({
|
|
|
|
updatePropertyNames: ["name", "description", "sql", "defaults"]
|
|
|
|
});
|
|
|
|
|
2015-06-25 14:53:03 -07:00
|
|
|
export default Query;
|