diff --git a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 index a281235..236de82 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 @@ -21,6 +21,8 @@ export default Ember.Controller.extend({ editing: false, everEditing: false, showRecentQueries: true, + sortBy: ['id:desc'], + sortedQueries: Em.computed.sort('model', 'sortBy'), createDisabled: function() { return (this.get('newQueryName') || "").trim().length === 0; @@ -29,9 +31,7 @@ export default Ember.Controller.extend({ selectedItem: function() { const id = parseInt(this.get('selectedQueryId')); const item = this.get('content').find(q => q.get('id') === id); - if (!isNaN(id)) { - this.set('showRecentQueries', false); - } + !isNaN(id) ? this.set('showRecentQueries', false) : this.set('showRecentQueries', true); return item || NoQuery; }.property('selectedQueryId'), @@ -80,11 +80,6 @@ export default Ember.Controller.extend({ showCreate() { this.set('showCreate', true); - this.set('showRecentQueries', false); - }, - - showRecentQueries() { - this.set('showRecentQueries', true); }, editName() { diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index 24d229c..f04f685 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -134,7 +134,7 @@ {{/unless}} {{#if showRecentQueries}} - {{#if model.length}} + {{#if sortedQueries.length}} @@ -142,18 +142,22 @@ - {{#each model as |query|}} + {{#each sortedQueries as |query|}} - - + + {{/each}}
{{i18n 'explorer.query_name'}}{{i18n 'explorer.query_time'}}
- + {{query.name}}
{{query.description}}
{{query.user}}{{query.time}} + + {{query.username}} + + {{query.created_at}}
diff --git a/assets/stylesheets/explorer.scss b/assets/stylesheets/explorer.scss index 7bef968..08f2c67 100644 --- a/assets/stylesheets/explorer.scss +++ b/assets/stylesheets/explorer.scss @@ -217,20 +217,18 @@ height: 100%; color: inherit; } - th { - .time{ - width: 15%; - } - .user { + .time { width: 15%; } + .user { + width: 20%; } td{ - .query-time { + .query-created-at { font-weight: bold; color: dark-light-diff($primary, $secondary, 40%, -20%); } - .query-user { + .query-created-by { color: dark-light-diff($primary, $secondary, 25%, -20%); } } diff --git a/plugin.rb b/plugin.rb index bd446ba..2c73607 100644 --- a/plugin.rb +++ b/plugin.rb @@ -567,15 +567,12 @@ SQL # Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead class DataExplorer::Query - attr_accessor :id, :name, :description, :sql, :user, :time + attr_accessor :id, :name, :description, :sql, :created_by, :created_at, :username def initialize @name = 'Unnamed Query' @description = 'Enter a description here' @sql = 'SELECT 1' - #TODO: Figure out where to assign current user for storage - @created_by = 'Admin' - @created_at = Time.now.strftime("%b %e, %Y") end def slug @@ -612,7 +609,7 @@ SQL def self.from_hash(h) query = DataExplorer::Query.new - [:name, :description, :sql, :created_by, :created_at].each do |sym| + [:name, :description, :sql, :created_by, :created_at, :username].each do |sym| query.send("#{sym}=", h[sym].strip) if h[sym] end query.id = h[:id].to_i if h[:id] @@ -626,7 +623,8 @@ SQL description: @description, sql: @sql, created_by: @created_by, - created_at: @created_at + created_at: @created_at, + username: @username } end @@ -943,6 +941,9 @@ SQL # guardian.ensure_can_create_explorer_query! query = DataExplorer::Query.from_hash params.require(:query) + query.created_by = current_user.id.to_s + query.created_at = Time.now.strftime("%b %e, %Y") + query.username = current_user.username query.id = nil # json import will assign an id, which is wrong query.save @@ -1078,7 +1079,7 @@ SQL end class DataExplorer::QuerySerializer < ActiveModel::Serializer - attributes :id, :sql, :name, :description, :param_info, :created_by, :created_at + attributes :id, :sql, :name, :description, :param_info, :created_by, :created_at, :username def param_info object.params.map(&:to_hash) rescue nil