FEATURE: Sort queries by last_run_at as default

This commit is contained in:
Rishabh Nambiar 2018-08-24 17:28:51 +05:30
parent feb8a1ce0f
commit 1b68847d21
5 changed files with 27 additions and 20 deletions

View File

@ -21,7 +21,7 @@ export default Ember.Controller.extend({
editing: false, editing: false,
everEditing: false, everEditing: false,
showRecentQueries: true, showRecentQueries: true,
sortBy: ['id:desc'], sortBy: ['last_run_at:desc'],
sortedQueries: Em.computed.sort('model', 'sortBy'), sortedQueries: Em.computed.sort('model', 'sortBy'),
createDisabled: function() { createDisabled: function() {

View File

@ -160,12 +160,12 @@
<br> <br>
</a> </a>
</td> </td>
<td> <td class="query-created-by">
<a href="/users/{{query.username}}/activity"> <a href="/users/{{query.username}}/activity">
<medium class="query-created-by">{{query.username}}</medium> <medium>{{query.username}}</medium>
</a> </a>
</td> </td>
<td><medium class="query-created-at">{{query.created_at}}</medium></td> <td class="query-created-at"><medium>{{bound-date query.last_run_at}}</medium></td>
</tr> </tr>
{{/each}} {{/each}}
</table> </table>

View File

@ -226,19 +226,21 @@
} }
.time { .time {
width: 15%; width: 15%;
text-align: center;
} }
.user { .user {
width: 20%; width: 20%;
padding-left: 1em;
} }
td{ .query-created-at {
.query-created-at { color: $secondary-medium;
font-weight: bold; font-weight: bold;
color: $secondary-medium; text-align: center;
} vertical-align: middle;
.query-created-by { }
color: $primary-high; .query-created-by {
} color: $primary-high;
} }
tr { tr {
height: 2px; height: 2px;
} }

View File

@ -55,7 +55,7 @@ en:
run_time: "Query completed in {{value}} ms." run_time: "Query completed in {{value}} ms."
query_name: "Query" query_name: "Query"
query_description: "Description" query_description: "Description"
query_time: "Date created" query_time: "Last run"
query_user: "Created by" query_user: "Created by"
column: "Column {{number}}" column: "Column {{number}}"
explain_label: "Include query plan?" explain_label: "Include query plan?"

View File

@ -567,7 +567,7 @@ SQL
# Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead # Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead
class DataExplorer::Query 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 def initialize
@name = 'Unnamed Query' @name = 'Unnamed Query'
@ -609,7 +609,7 @@ SQL
def self.from_hash(h) def self.from_hash(h)
query = DataExplorer::Query.new 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] query.send("#{sym}=", h[sym].strip) if h[sym]
end end
query.id = h[:id].to_i if h[:id] query.id = h[:id].to_i if h[:id]
@ -623,7 +623,8 @@ SQL
description: @description, description: @description,
sql: @sql, sql: @sql,
created_by: @created_by, created_by: @created_by,
created_at: @created_at created_at: @created_at,
last_run_at: @last_run_at
} }
end end
@ -938,10 +939,11 @@ SQL
def create def create
# guardian.ensure_can_create_explorer_query! # guardian.ensure_can_create_explorer_query!
query = DataExplorer::Query.from_hash params.require(: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.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.id = nil # json import will assign an id, which is wrong
query.save query.save
@ -999,6 +1001,9 @@ SQL
def run def run
check_xhr unless params[:download] check_xhr unless params[:download]
query = DataExplorer::Query.find(params[:id].to_i) query = DataExplorer::Query.find(params[:id].to_i)
query.last_run_at = Time.now
query.save
if params[:download] if params[:download]
response.sending_file = true response.sending_file = true
end end
@ -1077,7 +1082,7 @@ SQL
end end
class DataExplorer::QuerySerializer < ActiveModel::Serializer 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 def param_info
object.params.map(&:to_hash) rescue nil object.params.map(&:to_hash) rescue nil