Merge pull request #13 from discourse/list_queries_homepage
[WIP] FEATURE: List previous queries on Data Explorer homepage
This commit is contained in:
@@ -20,6 +20,9 @@ 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;
|
||||
@@ -28,6 +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);
|
||||
!isNaN(id) ? this.set('showRecentQueries', false) : this.set('showRecentQueries', true);
|
||||
return item || NoQuery;
|
||||
}.property('selectedQueryId'),
|
||||
|
||||
@@ -86,6 +90,10 @@ export default Ember.Controller.extend({
|
||||
window.open(this.get('selectedItem.downloadUrl'), "_blank");
|
||||
},
|
||||
|
||||
scrollTop() {
|
||||
window.scrollTo(0,0);
|
||||
},
|
||||
|
||||
resetParams() {
|
||||
this.get('selectedItem').resetParams();
|
||||
},
|
||||
@@ -106,6 +114,7 @@ export default Ember.Controller.extend({
|
||||
const name = this.get("newQueryName").trim();
|
||||
this.set('loading', true);
|
||||
this.set('showCreate', false);
|
||||
this.set('showRecentQueries', false);
|
||||
this.store
|
||||
.createRecord('query', { name })
|
||||
.save()
|
||||
|
||||
@@ -133,6 +133,37 @@
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
|
||||
{{#if showRecentQueries}}
|
||||
{{#if sortedQueries.length}}
|
||||
<table class="recent-queries">
|
||||
<thead class="heading-container">
|
||||
<th class="col heading name">{{i18n 'explorer.query_name'}}</th>
|
||||
<th class="col heading user">{{i18n 'explorer.query_user'}}</th>
|
||||
<th class="col heading time">{{i18n 'explorer.query_time'}}</th>
|
||||
</thead>
|
||||
<tr></tr>
|
||||
{{#each sortedQueries as |query|}}
|
||||
<tr>
|
||||
<td>
|
||||
<a {{action "scrollTop"}} href="/admin/plugins/explorer/?id={{query.id}}">
|
||||
<b class="query-name">{{query.name}}</b>
|
||||
<br>
|
||||
<medium class="query-desc">{{query.description}}</medium>
|
||||
<br>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/users/{{query.username}}/activity">
|
||||
<medium class="query-created-by">{{query.username}}</medium>
|
||||
</a>
|
||||
</td>
|
||||
<td><medium class="query-created-at">{{query.created_at}}</medium></td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
<div class="explorer-pad-bottom"></div>
|
||||
|
||||
{{else}}
|
||||
|
||||
@@ -210,6 +210,45 @@
|
||||
}
|
||||
}
|
||||
|
||||
.recent-queries {
|
||||
tr a {
|
||||
display:block;
|
||||
width:100%;
|
||||
height: 100%;
|
||||
color: inherit;
|
||||
}
|
||||
.time {
|
||||
width: 15%;
|
||||
}
|
||||
.user {
|
||||
width: 20%;
|
||||
}
|
||||
td{
|
||||
.query-created-at {
|
||||
font-weight: bold;
|
||||
color: dark-light-diff($primary, $secondary, 40%, -20%);
|
||||
}
|
||||
.query-created-by {
|
||||
color: dark-light-diff($primary, $secondary, 25%, -20%);
|
||||
}
|
||||
}
|
||||
hr {
|
||||
height: 2px;
|
||||
width: 100%;
|
||||
color: dark-light-diff($primary, $secondary, 35%, -20%);
|
||||
}
|
||||
.heading {
|
||||
padding-top: 30px;
|
||||
color: dark-light-diff($primary, $secondary, 30%, -20%);
|
||||
}
|
||||
.query-name {
|
||||
color: dark-light-diff($primary, $secondary, 15%, -20%);
|
||||
}
|
||||
.query-desc {
|
||||
color: dark-light-diff($primary, $secondary, 25%, -20%);
|
||||
}
|
||||
}
|
||||
|
||||
.explorer-pad-bottom {
|
||||
margin-bottom: 200px;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ en:
|
||||
download_csv: "CSV"
|
||||
others_dirty: "A query has unsaved changes that will be lost if you navigate away."
|
||||
run_time: "Query completed in {{value}} ms."
|
||||
query_name: "Query"
|
||||
query_description: "Description"
|
||||
query_time: "Date created"
|
||||
query_user: "Created by"
|
||||
column: "Column {{number}}"
|
||||
explain_label: "Include query plan?"
|
||||
save_params: "Set Defaults"
|
||||
|
||||
@@ -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
|
||||
attr_accessor :id, :name, :description, :sql, :created_by, :created_at
|
||||
|
||||
def initialize
|
||||
@name = 'Unnamed Query'
|
||||
@@ -609,7 +609,7 @@ SQL
|
||||
|
||||
def self.from_hash(h)
|
||||
query = DataExplorer::Query.new
|
||||
[:name, :description, :sql].each do |sym|
|
||||
[:name, :description, :sql, :created_by, :created_at].each do |sym|
|
||||
query.send("#{sym}=", h[sym].strip) if h[sym]
|
||||
end
|
||||
query.id = h[:id].to_i if h[:id]
|
||||
@@ -622,6 +622,8 @@ SQL
|
||||
name: @name,
|
||||
description: @description,
|
||||
sql: @sql,
|
||||
created_by: @created_by,
|
||||
created_at: @created_at
|
||||
}
|
||||
end
|
||||
|
||||
@@ -938,6 +940,8 @@ SQL
|
||||
# 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_by = current_user.id.to_s
|
||||
query.id = nil # json import will assign an id, which is wrong
|
||||
query.save
|
||||
|
||||
@@ -1073,11 +1077,15 @@ SQL
|
||||
end
|
||||
|
||||
class DataExplorer::QuerySerializer < ActiveModel::Serializer
|
||||
attributes :id, :sql, :name, :description, :param_info
|
||||
attributes :id, :sql, :name, :description, :param_info, :created_by, :created_at, :username
|
||||
|
||||
def param_info
|
||||
object.params.map(&:to_hash) rescue nil
|
||||
end
|
||||
|
||||
def username
|
||||
User.find(created_by).username rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
DataExplorer::Engine.routes.draw do
|
||||
|
||||
Reference in New Issue
Block a user