From c52ac59eee2cdca83e3116cfc7c1c0630fd83465 Mon Sep 17 00:00:00 2001 From: Kane York Date: Fri, 26 Jun 2015 09:16:09 -0700 Subject: [PATCH] Missed description sections, try to get model to work --- assets/javascripts/discourse/adapters/query.js.es6 | 6 ------ .../discourse/controllers/admin-plugins-explorer.js.es6 | 4 +++- assets/javascripts/discourse/models/query.js.es6 | 7 ++++++- .../discourse/templates/admin/plugins-explorer.hbs | 4 +++- plugin.rb | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/assets/javascripts/discourse/adapters/query.js.es6 b/assets/javascripts/discourse/adapters/query.js.es6 index 1a5eebc..2a09e09 100644 --- a/assets/javascripts/discourse/adapters/query.js.es6 +++ b/assets/javascripts/discourse/adapters/query.js.es6 @@ -2,10 +2,4 @@ import buildPluginAdapter from 'discourse/adapters/build-plugin'; 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 index de0210d..22fbed3 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 @@ -1,4 +1,5 @@ import showModal from 'discourse/lib/show-modal'; +import Query from 'discourse/plugins/discourse-data-explorer/discourse/models/query'; export default Ember.Controller.extend({ selectedItem: null, @@ -11,7 +12,8 @@ export default Ember.Controller.extend({ dummy() {}, create() { - var newQuery = this.store.createRecord('query', {name: this.get('newQueryName')}); + var newQuery = Query.create({name: this.get('newQueryName')}); + //var newQuery = this.store.createRecord('query', {name: this.get('newQueryName')}); newQuery.save(); }, diff --git a/assets/javascripts/discourse/models/query.js.es6 b/assets/javascripts/discourse/models/query.js.es6 index 399967a..1f71f82 100644 --- a/assets/javascripts/discourse/models/query.js.es6 +++ b/assets/javascripts/discourse/models/query.js.es6 @@ -2,7 +2,11 @@ import RestModel from 'discourse/models/rest'; const Query = RestModel.extend({ createProperties() { - return this.getProperties("name", "description"); + return this.getProperties("name"); + }, + + updateProperties() { + return this.getProperties("name", "description", "sql", "defaults"); }, run() { @@ -12,4 +16,5 @@ const Query = RestModel.extend({ console.log('query model loaded'); +Discourse.Query = Query; export default Query; diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index e17604a..23ab322 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -5,11 +5,13 @@

Queries

+ + - {{#each query in content}} + {{#each content as |query|}} diff --git a/plugin.rb b/plugin.rb index 87d2411..d4b9112 100644 --- a/plugin.rb +++ b/plugin.rb @@ -240,7 +240,7 @@ SQL def create # guardian.ensure_can_create_explorer_query! - query = DataExplorer::Query.from_hash params.permit(:name, :sql, :defaults) + query = DataExplorer::Query.from_hash params.permit(:name, :sql, :defaults, :description) # Set the ID _only_ if undeleting if params[:recover] query.id = params[:id].to_i @@ -252,7 +252,7 @@ SQL def update query = DataExplorer::Query.find(params[:id].to_i) - [:name, :sql, :defaults].each do |sym| + [:name, :sql, :defaults, :description].each do |sym| query.send("#{sym}=", params[sym]) if params[sym] end query.save
Name Description
{{query.name}} {{query.description}}