List all previous queries on Data Explorer homepage
This commit is contained in:
parent
cb16f9106b
commit
e341d5a6fa
|
@ -20,6 +20,7 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
editing: false,
|
editing: false,
|
||||||
everEditing: false,
|
everEditing: false,
|
||||||
|
showRecentQueries: true,
|
||||||
|
|
||||||
createDisabled: function() {
|
createDisabled: function() {
|
||||||
return (this.get('newQueryName') || "").trim().length === 0;
|
return (this.get('newQueryName') || "").trim().length === 0;
|
||||||
|
@ -28,6 +29,9 @@ export default Ember.Controller.extend({
|
||||||
selectedItem: function() {
|
selectedItem: function() {
|
||||||
const id = parseInt(this.get('selectedQueryId'));
|
const id = parseInt(this.get('selectedQueryId'));
|
||||||
const item = this.get('content').find(q => q.get('id') === id);
|
const item = this.get('content').find(q => q.get('id') === id);
|
||||||
|
if (!isNaN(id)) {
|
||||||
|
this.set('showRecentQueries', false);
|
||||||
|
}
|
||||||
return item || NoQuery;
|
return item || NoQuery;
|
||||||
}.property('selectedQueryId'),
|
}.property('selectedQueryId'),
|
||||||
|
|
||||||
|
@ -76,6 +80,11 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
showCreate() {
|
showCreate() {
|
||||||
this.set('showCreate', true);
|
this.set('showCreate', true);
|
||||||
|
this.set('showRecentQueries', false);
|
||||||
|
},
|
||||||
|
|
||||||
|
showRecentQueries() {
|
||||||
|
this.set('showRecentQueries', true);
|
||||||
},
|
},
|
||||||
|
|
||||||
editName() {
|
editName() {
|
||||||
|
@ -106,6 +115,7 @@ export default Ember.Controller.extend({
|
||||||
const name = this.get("newQueryName").trim();
|
const name = this.get("newQueryName").trim();
|
||||||
this.set('loading', true);
|
this.set('loading', true);
|
||||||
this.set('showCreate', false);
|
this.set('showCreate', false);
|
||||||
|
this.set('showRecentQueries', false);
|
||||||
this.store
|
this.store
|
||||||
.createRecord('query', { name })
|
.createRecord('query', { name })
|
||||||
.save()
|
.save()
|
||||||
|
|
|
@ -133,6 +133,33 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
|
{{#if showRecentQueries}}
|
||||||
|
{{#if model.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 model as |query|}}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a>
|
||||||
|
<b class="query-name">{{query.name}}</b>
|
||||||
|
<br>
|
||||||
|
<medium class="query-desc">{{query.description}}</medium>
|
||||||
|
<br>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td><medium class="query-user">{{query.user}}</medium></td>
|
||||||
|
<td><medium class="query-time">{{query.time}}</medium></td>
|
||||||
|
</tr>
|
||||||
|
{{/each}}
|
||||||
|
</table>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<div class="explorer-pad-bottom"></div>
|
<div class="explorer-pad-bottom"></div>
|
||||||
|
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
|
@ -210,6 +210,47 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.recent-queries {
|
||||||
|
tr a {
|
||||||
|
display:block;
|
||||||
|
width:100%;
|
||||||
|
height: 100%;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
.time{
|
||||||
|
width: 15%;
|
||||||
|
}
|
||||||
|
.user {
|
||||||
|
width: 15%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
td{
|
||||||
|
.query-time {
|
||||||
|
font-weight: bold;
|
||||||
|
color: dark-light-diff($primary, $secondary, 40%, -20%);
|
||||||
|
}
|
||||||
|
.query-user {
|
||||||
|
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 {
|
.explorer-pad-bottom {
|
||||||
margin-bottom: 200px;
|
margin-bottom: 200px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,10 @@ en:
|
||||||
download_csv: "CSV"
|
download_csv: "CSV"
|
||||||
others_dirty: "A query has unsaved changes that will be lost if you navigate away."
|
others_dirty: "A query has unsaved changes that will be lost if you navigate away."
|
||||||
run_time: "Query completed in {{value}} ms."
|
run_time: "Query completed in {{value}} ms."
|
||||||
|
query_name: "Query"
|
||||||
|
query_description: "Description"
|
||||||
|
query_time: "Date created"
|
||||||
|
query_user: "Created by"
|
||||||
column: "Column {{number}}"
|
column: "Column {{number}}"
|
||||||
explain_label: "Include query plan?"
|
explain_label: "Include query plan?"
|
||||||
save_params: "Set Defaults"
|
save_params: "Set Defaults"
|
||||||
|
|
11
plugin.rb
11
plugin.rb
|
@ -567,12 +567,15 @@ 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
|
attr_accessor :id, :name, :description, :sql, :user, :time
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@name = 'Unnamed Query'
|
@name = 'Unnamed Query'
|
||||||
@description = 'Enter a description here'
|
@description = 'Enter a description here'
|
||||||
@sql = 'SELECT 1'
|
@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
|
end
|
||||||
|
|
||||||
def slug
|
def slug
|
||||||
|
@ -609,7 +612,7 @@ SQL
|
||||||
|
|
||||||
def self.from_hash(h)
|
def self.from_hash(h)
|
||||||
query = DataExplorer::Query.new
|
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]
|
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]
|
||||||
|
@ -622,6 +625,8 @@ SQL
|
||||||
name: @name,
|
name: @name,
|
||||||
description: @description,
|
description: @description,
|
||||||
sql: @sql,
|
sql: @sql,
|
||||||
|
created_by: @created_by,
|
||||||
|
created_at: @created_at
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1073,7 +1078,7 @@ SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
class DataExplorer::QuerySerializer < ActiveModel::Serializer
|
class DataExplorer::QuerySerializer < ActiveModel::Serializer
|
||||||
attributes :id, :sql, :name, :description, :param_info
|
attributes :id, :sql, :name, :description, :param_info, :created_by, :created_at
|
||||||
|
|
||||||
def param_info
|
def param_info
|
||||||
object.params.map(&:to_hash) rescue nil
|
object.params.map(&:to_hash) rescue nil
|
||||||
|
|
Loading…
Reference in New Issue