Display errors, convert integers
This commit is contained in:
parent
497f71896d
commit
1ea74847ae
|
@ -4,5 +4,5 @@ export default Ember.TextField.extend({
|
||||||
this.get('params')[this.get('pname')] = value;
|
this.get('params')[this.get('pname')] = value;
|
||||||
}
|
}
|
||||||
return this.get('params')[this.get('pname')];
|
return this.get('params')[this.get('pname')];
|
||||||
}.property()
|
}.property('params', 'pname')
|
||||||
});
|
});
|
||||||
|
|
|
@ -137,14 +137,17 @@ export default Ember.ArrayController.extend({
|
||||||
explain: this.get('explain')
|
explain: this.get('explain')
|
||||||
}
|
}
|
||||||
}).then(function(result) {
|
}).then(function(result) {
|
||||||
|
self.set('results', result);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return popupAjaxError(result);
|
self.set('showResults', false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(result);
|
|
||||||
self.set('showResults', true);
|
self.set('showResults', true);
|
||||||
|
}).catch(function(result) {
|
||||||
|
self.set('showResults', false);
|
||||||
self.set('results', result);
|
self.set('results', result);
|
||||||
}).catch(popupAjaxError).finally(function() {
|
}).finally(function() {
|
||||||
self.set('loading', false);
|
self.set('loading', false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,20 @@ Query = RestModel.extend({
|
||||||
dirty: false,
|
dirty: false,
|
||||||
params: {},
|
params: {},
|
||||||
|
|
||||||
|
_init: function() {
|
||||||
|
this._super();
|
||||||
|
if (!this.get('options')) {
|
||||||
|
this.set('options', {defaults:{}});
|
||||||
|
}
|
||||||
|
this.set('dirty', false);
|
||||||
|
}.on('init'),
|
||||||
|
|
||||||
_initParams: function() {
|
_initParams: function() {
|
||||||
this.resetParams();
|
this.resetParams();
|
||||||
}.on('init').observes('param_names'),
|
}.on('init').observes('param_names'),
|
||||||
|
|
||||||
|
options: Em.computed.alias('qopts'),
|
||||||
|
|
||||||
markDirty: function() {
|
markDirty: function() {
|
||||||
this.set('dirty', true);
|
this.set('dirty', true);
|
||||||
}.observes('name', 'description', 'sql', 'options', 'options.defaults'),
|
}.observes('name', 'description', 'sql', 'options', 'options.defaults'),
|
||||||
|
@ -37,7 +47,11 @@ Query = RestModel.extend({
|
||||||
const currentParams = this.get('params');
|
const currentParams = this.get('params');
|
||||||
let defaults = {};
|
let defaults = {};
|
||||||
(this.get('param_names') || []).forEach(function(name) {
|
(this.get('param_names') || []).forEach(function(name) {
|
||||||
|
if (currentParams[name]) {
|
||||||
defaults[name] = currentParams[name];
|
defaults[name] = currentParams[name];
|
||||||
|
} else {
|
||||||
|
delete defaults[name];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.set('options.defaults', defaults);
|
this.set('options.defaults', defaults);
|
||||||
},
|
},
|
||||||
|
@ -80,7 +94,7 @@ Query = RestModel.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
Query.reopenClass({
|
Query.reopenClass({
|
||||||
updatePropertyNames: ["name", "description", "sql", "options"]
|
updatePropertyNames: ["name", "description", "sql", "qopts"]
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Query;
|
export default Query;
|
||||||
|
|
|
@ -1,24 +1,38 @@
|
||||||
<h3>Queries</h3>
|
<h2>Queries</h2>
|
||||||
|
|
||||||
<div class="query-list">
|
<div class="query-list">
|
||||||
{{combo-box valueAttribute="id" value=selectedQueryId nameProperty="listName" content=content castInteger="true" nameChanges="true"}}
|
{{combo-box valueAttribute="id" value=selectedQueryId nameProperty="listName" content=content castInteger="true" nameChanges="true"}}
|
||||||
{{d-button action="showCreate" icon="plus" class="no-text"}}
|
{{d-button action="showCreate" icon="plus" class="no-text"}}
|
||||||
{{d-button action="importQuery" label="explorer.import.label" icon="upload"}}
|
{{d-button action="importQuery" label="explorer.import.label" icon="upload"}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#if showCreate}}
|
{{#if showCreate}}
|
||||||
<div class="query-create">
|
<div class="query-create">
|
||||||
{{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}}
|
{{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}}
|
||||||
{{d-button action="create" label="explorer.create" icon="plus" class="btn-primary"}}
|
{{d-button action="create" label="explorer.create" icon="plus" class="btn-primary"}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<div class="query-edit">
|
<div class="query-edit">
|
||||||
{{partial "admin/plugins-explorer-show" model=selectedItem}}
|
{{partial "admin/plugins-explorer-show" model=selectedItem}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{conditional-loading-spinner condition=loading}}
|
||||||
|
|
||||||
<div class="query-run">
|
<div class="query-run">
|
||||||
{{#if selectedItem.param_names}}
|
{{#if selectedItem.param_names}}
|
||||||
<div class="query-params">
|
<div class="query-params">
|
||||||
|
<div class="param-save">
|
||||||
|
{{d-button action="saveDefaults" label="explorer.save_params"}}
|
||||||
|
{{d-button action="resetParams" label="explorer.reset_params"}}
|
||||||
|
</div>
|
||||||
{{#each selectedItem.param_names as |pname|}}
|
{{#each selectedItem.param_names as |pname|}}
|
||||||
{{param-field params=selectedItem.params pname=pname}} {{pname}}
|
<div class="param">
|
||||||
|
{{param-field params=selectedItem.params pname=pname}}
|
||||||
|
<span class="param-name">{{pname}}</span>
|
||||||
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -27,10 +41,17 @@
|
||||||
</div>
|
</div>
|
||||||
{{d-button action="run" label="explorer.run" disabled=runDisabled}}
|
{{d-button action="run" label="explorer.run" disabled=runDisabled}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
{{conditional-loading-spinner condition=loading}}
|
|
||||||
{{#if results}}
|
{{#if results}}
|
||||||
<div class="query-results">
|
<div class="query-results">
|
||||||
|
{{#if showResults}}
|
||||||
{{query-result query=selectedItem content=results}}
|
{{query-result query=selectedItem content=results}}
|
||||||
|
{{else}}
|
||||||
|
{{#each results.errors as |err|}}
|
||||||
|
<pre class="query-error"><code>{{~err}}</code></pre>
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -33,6 +33,18 @@
|
||||||
input {
|
input {
|
||||||
margin: 9px;
|
margin: 9px;
|
||||||
}
|
}
|
||||||
|
.param {
|
||||||
|
display: inline-block;
|
||||||
|
overflow-x: visible;
|
||||||
|
}
|
||||||
|
.param-save {
|
||||||
|
float: right;
|
||||||
|
margin: 9px;
|
||||||
|
}
|
||||||
|
.param-name {
|
||||||
|
display: inline-block;
|
||||||
|
width: 70px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.query-list, .query-edit, .query-results, .query-params {
|
.query-list, .query-edit, .query-results, .query-params {
|
||||||
|
|
|
@ -38,3 +38,5 @@ en:
|
||||||
run_time: "Query completed in {{value}} ms."
|
run_time: "Query completed in {{value}} ms."
|
||||||
column: "Column {{number}}"
|
column: "Column {{number}}"
|
||||||
explain_label: "Include query plan?"
|
explain_label: "Include query plan?"
|
||||||
|
save_params: "Set Defaults"
|
||||||
|
reset_params: "Reset"
|
||||||
|
|
21
plugin.rb
21
plugin.rb
|
@ -79,6 +79,15 @@ after_initialize do
|
||||||
|
|
||||||
query_args = (query.qopts[:defaults] || {}).with_indifferent_access.merge(params)
|
query_args = (query.qopts[:defaults] || {}).with_indifferent_access.merge(params)
|
||||||
|
|
||||||
|
# Rudimentary types
|
||||||
|
query_args.map! do |arg|
|
||||||
|
if arg =~ /\A\d+\z/
|
||||||
|
arg.to_i
|
||||||
|
else
|
||||||
|
arg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
time_start, time_end, explain, err, result = nil
|
time_start, time_end, explain, err, result = nil
|
||||||
begin
|
begin
|
||||||
ActiveRecord::Base.connection.transaction do
|
ActiveRecord::Base.connection.transaction do
|
||||||
|
@ -89,7 +98,7 @@ after_initialize do
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DataExplorer Query
|
* DataExplorer Query
|
||||||
* Query: /admin/plugins/explorer/#{query.id}
|
* Query: /admin/plugins/explorer?id=#{query.id}
|
||||||
* Started by: #{opts[:current_user]}
|
* Started by: #{opts[:current_user]}
|
||||||
*/
|
*/
|
||||||
WITH query AS (
|
WITH query AS (
|
||||||
|
@ -290,11 +299,20 @@ SQL
|
||||||
render json: {success: true, errors: []}
|
render json: {success: true, errors: []}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return value:
|
||||||
|
# success - true/false. if false, inspect the errors value.
|
||||||
|
# errors - array of strings.
|
||||||
|
# params - hash. Echo of the query parameters as executed.
|
||||||
|
# duration - float. Time to execute the query, in milliseconds, to 1 decimal place.
|
||||||
|
# columns - array of strings. Titles of the returned columns, in order.
|
||||||
|
# explain - string. (Optional - pass explain=true in the request) Postgres query plan, UNIX newlines.
|
||||||
|
# rows - array of array of strings. Results of the query. In the same order as 'columns'.
|
||||||
def run
|
def run
|
||||||
query = DataExplorer::Query.find(params[:id].to_i)
|
query = DataExplorer::Query.find(params[:id].to_i)
|
||||||
query_params = MultiJson.load(params[:params])
|
query_params = MultiJson.load(params[:params])
|
||||||
opts = {current_user: current_user.username}
|
opts = {current_user: current_user.username}
|
||||||
opts[:explain] = true if params[:explain] == "true"
|
opts[:explain] = true if params[:explain] == "true"
|
||||||
|
opts[:limit] = params[:limit].to_i if params[:limit]
|
||||||
result = DataExplorer.run_query(query, query_params, opts)
|
result = DataExplorer.run_query(query, query_params, opts)
|
||||||
|
|
||||||
if result[:error]
|
if result[:error]
|
||||||
|
@ -320,7 +338,6 @@ SQL
|
||||||
json = {
|
json = {
|
||||||
success: true,
|
success: true,
|
||||||
errors: [],
|
errors: [],
|
||||||
params: query_params,
|
|
||||||
duration: (result[:duration_nanos].to_f / 1_000_000).round(1),
|
duration: (result[:duration_nanos].to_f / 1_000_000).round(1),
|
||||||
columns: cols,
|
columns: cols,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue