diff --git a/assets/javascripts/discourse/adapters/query.js.es6 b/assets/javascripts/discourse/adapters/query.js.es6 index 7875d61..1a5eebc 100644 --- a/assets/javascripts/discourse/adapters/query.js.es6 +++ b/assets/javascripts/discourse/adapters/query.js.es6 @@ -1,3 +1,11 @@ import buildPluginAdapter from 'discourse/adapters/build-plugin'; -export default buildPluginAdapter('explorer'); +export default buildPluginAdapter('explorer').extend({ + + createRecord(store, type, args) { + const typeField = Ember.String.underscore(type); + return Discourse.ajax(this.pathFor(store, type), {method: 'POST', data: args}).then(function (json) { + return new Result(json[typeField], json); + }); + } +}); diff --git a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 new file mode 100644 index 0000000..de0210d --- /dev/null +++ b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 @@ -0,0 +1,39 @@ +import showModal from 'discourse/lib/show-modal'; + +export default Ember.Controller.extend({ + selectedItem: null, + + actions: { + selectItem(item) { + this.set('selectedItem', item); + }, + + dummy() {}, + + create() { + var newQuery = this.store.createRecord('query', {name: this.get('newQueryName')}); + newQuery.save(); + }, + + importQuery() { + showModal('import-query'); + }, + + run() { + const self = this; + this.set('loading', true); + Discourse.ajax("/admin/plugins/explorer/query/" + this.get('selectedItem.id') + "/run", { + type: "POST", + data: { + params: JSON.stringify({foo: 34}), + explain: true + } + }).then(function(result) { + console.log(result); + self.set('results', result); + }).finally(function() { + self.set('loading', false); + }); + } + } +}); diff --git a/assets/javascripts/discourse/controllers/admin/plugins/explorer.js b/assets/javascripts/discourse/controllers/admin/plugins/explorer.js deleted file mode 100644 index bbce391..0000000 --- a/assets/javascripts/discourse/controllers/admin/plugins/explorer.js +++ /dev/null @@ -1,5 +0,0 @@ - - -export default Ember.ArrayController.extend({ - -}); diff --git a/assets/javascripts/discourse/controllers/import-query.js.es6 b/assets/javascripts/discourse/controllers/import-query.js.es6 index 1159197..f409bed 100644 --- a/assets/javascripts/discourse/controllers/import-query.js.es6 +++ b/assets/javascripts/discourse/controllers/import-query.js.es6 @@ -22,7 +22,7 @@ export default Ember.Controller.extend(ModalFunctionality, { const object = JSON.parse(this.get('queryFile')).query; // Slight fixup before creating object - delete object.id; + object.id = 0; // 0 means no Id yet this.set('loading', true); this.store.createRecord('query', object).save().then(function(query) { diff --git a/assets/javascripts/discourse/models/query.js.es6 b/assets/javascripts/discourse/models/query.js.es6 new file mode 100644 index 0000000..399967a --- /dev/null +++ b/assets/javascripts/discourse/models/query.js.es6 @@ -0,0 +1,15 @@ +import RestModel from 'discourse/models/rest'; + +const Query = RestModel.extend({ + createProperties() { + return this.getProperties("name", "description"); + }, + + run() { + console.log("Called query#run"); + } +}); + +console.log('query model loaded'); + +export default Query; diff --git a/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 index a057375..ed58205 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 @@ -1,22 +1,9 @@ -import showModal from 'discourse/lib/show-modal'; + export default Discourse.Route.extend({ controllerName: 'admin-plugins-explorer', model() { return this.store.findAll('query'); - }, - - setupController(controller, model) { - - }, - - actions: { - create() { - - }, - importQuery() { - showModal('import-query'); - } } }); diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer-show.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer-show.hbs new file mode 100644 index 0000000..a8180ba --- /dev/null +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer-show.hbs @@ -0,0 +1,6 @@ +{{#if model}} +
Name | +Description | + + + {{#each query in content}} +
---|---|
{{query.name}} | +{{query.description}} | +