diff --git a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6
index 2e1d9a1..4118918 100644
--- a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6
+++ b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6
@@ -1,5 +1,6 @@
import showModal from 'discourse/lib/show-modal';
import Query from 'discourse/plugins/discourse-data-explorer/discourse/models/query';
+import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.ArrayController.extend({
selectedQueryId: null,
@@ -20,24 +21,16 @@ export default Ember.ArrayController.extend({
});
}.property('selectedQueryId'),
+ addCreatedRecord(record) {
+ this.pushObject(record);
+ this.set('selectedQueryId', Ember.get(record, 'id'));
+ this.get('selectedItem').set('dirty', false);
+ this.set('results', null);
+ },
+
actions: {
dummy() {},
- create() {
- const self = this;
- this.set('loading', true);
- this.set('showCreate', false);
- var newQuery = this.store.createRecord('query', {name: this.get('newQueryName')});
- newQuery.save().then(function(result) {
- self.pushObject(result.target);
- self.set('selectedQueryId', result.target.id);
- self.set('selectedItem.dirty', false);
- self.set('results', null);
- }).finally(function() {
- self.set('loading', false);
- });
- },
-
importQuery() {
showModal('import-query');
this.set('showCreate', false);
@@ -51,6 +44,22 @@ export default Ember.ArrayController.extend({
this.set('editName', true);
},
+ download() {
+ window.open(this.get('selectedItem.downloadUrl'), "_blank");
+ },
+
+ create() {
+ const self = this;
+ this.set('loading', true);
+ this.set('showCreate', false);
+ var newQuery = this.store.createRecord('query', {name: this.get('newQueryName')});
+ newQuery.save().then(function(result) {
+ self.addCreatedRecord(result.target);
+ }).catch(popupAjaxError).finally(function() {
+ self.set('loading', false);
+ });
+ },
+
save() {
const self = this;
this.set('loading', true);
@@ -58,7 +67,7 @@ export default Ember.ArrayController.extend({
const query = self.get('selectedItem');
query.markNotDirty();
self.set('editName', false);
- }).finally(function() {
+ }).catch(popupAjaxError).finally(function() {
self.set('loading', false);
});
},
@@ -72,7 +81,29 @@ export default Ember.ArrayController.extend({
query.markNotDirty();
self.set('editName', false);
self.set('results', null);
- }).finally(function() {
+ }).catch(popupAjaxError).finally(function() {
+ self.set('loading', false);
+ });
+ },
+
+ destroy() {
+ const self = this;
+ const query = this.get('selectedItem');
+ this.set('loading', true);
+ this.store.destroyRecord('query', query).then(function() {
+ query.set('destroyed', true);
+ }).catch(popupAjaxError).finally(function() {
+ self.set('loading', false);
+ });
+ },
+
+ recover() {
+ const self = this;
+ const query = this.get('selectedItem');
+ this.set('loading', true);
+ query.save().then(function() {
+ query.set('destroyed', false);
+ }).catch(popupAjaxError).finally(function() {
self.set('loading', false);
});
},
@@ -93,7 +124,7 @@ export default Ember.ArrayController.extend({
}).then(function(result) {
console.log(result);
self.set('results', result);
- }).finally(function() {
+ }).catch(popupAjaxError).finally(function() {
self.set('loading', false);
});
}
diff --git a/assets/javascripts/discourse/controllers/import-query.js.es6 b/assets/javascripts/discourse/controllers/import-query.js.es6
index f409bed..e072413 100644
--- a/assets/javascripts/discourse/controllers/import-query.js.es6
+++ b/assets/javascripts/discourse/controllers/import-query.js.es6
@@ -1,4 +1,5 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
+import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend(ModalFunctionality, {
notReady: Em.computed.not('ready'),
@@ -30,16 +31,8 @@ export default Ember.Controller.extend(ModalFunctionality, {
self.set('loading', false);
const parentController = self.get('controllers.admin-plugins-explorer');
- parentController.pushObject(query);
- parentController.set('selectedItem', query);
- }).catch(function(xhr) {
- self.set('loading', false);
- if (xhr.responseJSON) {
- bootbox.alert(xhr.responseJSON.errors.join("
"));
- } else {
- bootbox.alert(I18n.t('generic_error'));
- }
- });
+ parentController.addCreatedRecord(query.target);
+ }).catch(popupAjaxError);
}
}
diff --git a/assets/javascripts/discourse/models/query.js.es6 b/assets/javascripts/discourse/models/query.js.es6
index 63d95c2..ddb878c 100644
--- a/assets/javascripts/discourse/models/query.js.es6
+++ b/assets/javascripts/discourse/models/query.js.es6
@@ -12,19 +12,36 @@ Query = RestModel.extend({
this.set('dirty', false);
},
+ 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'),
+
listName: function() {
+ let name = this.get('name');
if (this.get('dirty')) {
- return this.get('name') + " (*)";
+ name += " (*)";
}
- return this.get('name');
- }.property('name', 'dirty'),
+ if (this.get('destroyed')) {
+ name += " (deleted)";
+ }
+ return name;
+ }.property('name', 'dirty', 'destroyed'),
createProperties() {
+ if (this.get('sql')) {
+ // Importing
+ return this.updateProperties();
+ }
return this.getProperties("name");
},
updateProperties() {
- return this.getProperties(Query.updatePropertyNames);
+ let props = this.getProperties(Query.updatePropertyNames);
+ if (this.get('destroyed')) {
+ props.id = this.get('id');
+ }
+ return props;
},
run() {
diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer-show.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer-show.hbs
index 317d31a..535941c 100644
--- a/assets/javascripts/discourse/templates/admin/plugins-explorer-show.hbs
+++ b/assets/javascripts/discourse/templates/admin/plugins-explorer-show.hbs
@@ -17,7 +17,18 @@