diff --git a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 index 0ea1153..bf007a9 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 @@ -21,7 +21,7 @@ export default Ember.Controller.extend({ editing: false, everEditing: false, showRecentQueries: true, - sortBy: ['id:desc'], + sortBy: ['last_run_at:desc'], sortedQueries: Em.computed.sort('model', 'sortBy'), createDisabled: function() { diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index 6a922ea..06289c1 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -160,12 +160,12 @@
- + - {{query.username}} + {{query.username}} - {{query.created_at}} + {{bound-date query.last_run_at}} {{/each}} diff --git a/assets/stylesheets/explorer.scss b/assets/stylesheets/explorer.scss index aa11e32..8bb4ed3 100644 --- a/assets/stylesheets/explorer.scss +++ b/assets/stylesheets/explorer.scss @@ -226,19 +226,21 @@ } .time { width: 15%; + text-align: center; } .user { width: 20%; + padding-left: 1em; } - td{ - .query-created-at { - font-weight: bold; - color: $secondary-medium; - } - .query-created-by { - color: $primary-high; - } - } + .query-created-at { + color: $secondary-medium; + font-weight: bold; + text-align: center; + vertical-align: middle; + } + .query-created-by { + color: $primary-high; + } tr { height: 2px; } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 1c24ae3..1b54981 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -55,7 +55,7 @@ en: run_time: "Query completed in {{value}} ms." query_name: "Query" query_description: "Description" - query_time: "Date created" + query_time: "Last run" query_user: "Created by" column: "Column {{number}}" explain_label: "Include query plan?" diff --git a/plugin.rb b/plugin.rb index 4b03fe7..51f9244 100644 --- a/plugin.rb +++ b/plugin.rb @@ -567,7 +567,7 @@ SQL # Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead class DataExplorer::Query - attr_accessor :id, :name, :description, :sql, :created_by, :created_at + attr_accessor :id, :name, :description, :sql, :created_by, :created_at, :last_run_at def initialize @name = 'Unnamed Query' @@ -609,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, :last_run_at].each do |sym| query.send("#{sym}=", h[sym].strip) if h[sym] end query.id = h[:id].to_i if h[:id] @@ -623,7 +623,8 @@ SQL description: @description, sql: @sql, created_by: @created_by, - created_at: @created_at + created_at: @created_at, + last_run_at: @last_run_at } end @@ -938,10 +939,11 @@ SQL def create # guardian.ensure_can_create_explorer_query! - + query = DataExplorer::Query.from_hash params.require(:query) - query.created_at = Time.now.strftime("%b %e, %Y") + query.created_at = Time.now query.created_by = current_user.id.to_s + query.last_run_at = Time.now query.id = nil # json import will assign an id, which is wrong query.save @@ -999,6 +1001,9 @@ SQL def run check_xhr unless params[:download] query = DataExplorer::Query.find(params[:id].to_i) + query.last_run_at = Time.now + query.save + if params[:download] response.sending_file = true end @@ -1077,7 +1082,7 @@ SQL end class DataExplorer::QuerySerializer < ActiveModel::Serializer - attributes :id, :sql, :name, :description, :param_info, :created_by, :created_at, :username + attributes :id, :sql, :name, :description, :param_info, :created_by, :created_at, :username, :last_run_at def param_info object.params.map(&:to_hash) rescue nil