mirror of
https://github.com/discourse/discourse-data-explorer.git
synced 2025-03-06 17:39:08 +00:00
Added clickable rows, default query sorting by id and clickable usernames
This commit is contained in:
parent
e341d5a6fa
commit
6e806cc1df
@ -21,6 +21,8 @@ export default Ember.Controller.extend({
|
|||||||
editing: false,
|
editing: false,
|
||||||
everEditing: false,
|
everEditing: false,
|
||||||
showRecentQueries: true,
|
showRecentQueries: true,
|
||||||
|
sortBy: ['id:desc'],
|
||||||
|
sortedQueries: Em.computed.sort('model', 'sortBy'),
|
||||||
|
|
||||||
createDisabled: function() {
|
createDisabled: function() {
|
||||||
return (this.get('newQueryName') || "").trim().length === 0;
|
return (this.get('newQueryName') || "").trim().length === 0;
|
||||||
@ -29,9 +31,7 @@ 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)) {
|
!isNaN(id) ? this.set('showRecentQueries', false) : this.set('showRecentQueries', true);
|
||||||
this.set('showRecentQueries', false);
|
|
||||||
}
|
|
||||||
return item || NoQuery;
|
return item || NoQuery;
|
||||||
}.property('selectedQueryId'),
|
}.property('selectedQueryId'),
|
||||||
|
|
||||||
@ -80,11 +80,6 @@ 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() {
|
||||||
|
@ -134,7 +134,7 @@
|
|||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
{{#if showRecentQueries}}
|
{{#if showRecentQueries}}
|
||||||
{{#if model.length}}
|
{{#if sortedQueries.length}}
|
||||||
<table class="recent-queries">
|
<table class="recent-queries">
|
||||||
<thead class="heading-container">
|
<thead class="heading-container">
|
||||||
<th class="col heading name">{{i18n 'explorer.query_name'}}</th>
|
<th class="col heading name">{{i18n 'explorer.query_name'}}</th>
|
||||||
@ -142,18 +142,22 @@
|
|||||||
<th class="col heading time">{{i18n 'explorer.query_time'}}</th>
|
<th class="col heading time">{{i18n 'explorer.query_time'}}</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tr></tr>
|
<tr></tr>
|
||||||
{{#each model as |query|}}
|
{{#each sortedQueries as |query|}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a>
|
<a href="/admin/plugins/explorer/?id={{query.id}}">
|
||||||
<b class="query-name">{{query.name}}</b>
|
<b class="query-name">{{query.name}}</b>
|
||||||
<br>
|
<br>
|
||||||
<medium class="query-desc">{{query.description}}</medium>
|
<medium class="query-desc">{{query.description}}</medium>
|
||||||
<br>
|
<br>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td><medium class="query-user">{{query.user}}</medium></td>
|
<td>
|
||||||
<td><medium class="query-time">{{query.time}}</medium></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>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</table>
|
</table>
|
||||||
|
@ -217,20 +217,18 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
th {
|
|
||||||
.time {
|
.time {
|
||||||
width: 15%;
|
width: 15%;
|
||||||
}
|
}
|
||||||
.user {
|
.user {
|
||||||
width: 15%;
|
width: 20%;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
td{
|
td{
|
||||||
.query-time {
|
.query-created-at {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: dark-light-diff($primary, $secondary, 40%, -20%);
|
color: dark-light-diff($primary, $secondary, 40%, -20%);
|
||||||
}
|
}
|
||||||
.query-user {
|
.query-created-by {
|
||||||
color: dark-light-diff($primary, $secondary, 25%, -20%);
|
color: dark-light-diff($primary, $secondary, 25%, -20%);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
plugin.rb
15
plugin.rb
@ -567,15 +567,12 @@ 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, :user, :time
|
attr_accessor :id, :name, :description, :sql, :created_by, :created_at, :username
|
||||||
|
|
||||||
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
|
||||||
@ -612,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, :username].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]
|
||||||
@ -626,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,
|
||||||
|
username: @username
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -943,6 +941,9 @@ SQL
|
|||||||
# 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_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.id = nil # json import will assign an id, which is wrong
|
||||||
query.save
|
query.save
|
||||||
|
|
||||||
@ -1078,7 +1079,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
|
attributes :id, :sql, :name, :description, :param_info, :created_by, :created_at, :username
|
||||||
|
|
||||||
def param_info
|
def param_info
|
||||||
object.params.map(&:to_hash) rescue nil
|
object.params.map(&:to_hash) rescue nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user