Add text for no queries, keep results in query object
This commit is contained in:
parent
052fb97396
commit
d9dbfc8408
|
@ -2,10 +2,11 @@ import showModal from 'discourse/lib/show-modal';
|
|||
import Query from 'discourse/plugins/discourse-data-explorer/discourse/models/query';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
const NoQuery = Query.create({name: "No queries", fake: true});
|
||||
|
||||
export default Ember.ArrayController.extend({
|
||||
queryParams: { selectedQueryId: "id" },
|
||||
selectedQueryId: null,
|
||||
results: null,
|
||||
showResults: false,
|
||||
loading: false,
|
||||
|
||||
|
@ -17,15 +18,13 @@ export default Ember.ArrayController.extend({
|
|||
selectedItem: function() {
|
||||
const _id = this.get('selectedQueryId');
|
||||
const id = parseInt(_id);
|
||||
return this.get('content').find(function(q) {
|
||||
const item = this.get('content').find(function(q) {
|
||||
return q.get('id') === id;
|
||||
});
|
||||
return item || NoQuery;
|
||||
}.property('selectedQueryId'),
|
||||
|
||||
clearResults: function() {
|
||||
this.set('showResults', false);
|
||||
this.set('results', null);
|
||||
}.observes('selectedQueryId'),
|
||||
results: Em.computed.alias('selectedItem.results'),
|
||||
|
||||
addCreatedRecord(record) {
|
||||
this.pushObject(record);
|
||||
|
@ -103,7 +102,6 @@ export default Ember.ArrayController.extend({
|
|||
query.setProperties(result.getProperties(Query.updatePropertyNames));
|
||||
query.markNotDirty();
|
||||
self.set('editName', false);
|
||||
self.set('results', null);
|
||||
}).catch(popupAjaxError).finally(function() {
|
||||
self.set('loading', false);
|
||||
});
|
||||
|
@ -138,6 +136,7 @@ export default Ember.ArrayController.extend({
|
|||
}
|
||||
|
||||
this.set('loading', true);
|
||||
this.set('showResults', false);
|
||||
Discourse.ajax("/admin/plugins/explorer/queries/" + this.get('selectedItem.id') + "/run", {
|
||||
type: "POST",
|
||||
data: {
|
||||
|
|
|
@ -4,6 +4,7 @@ let Query;
|
|||
Query = RestModel.extend({
|
||||
dirty: false,
|
||||
params: {},
|
||||
results: null,
|
||||
|
||||
_init: function() {
|
||||
this._super();
|
||||
|
|
|
@ -22,43 +22,47 @@
|
|||
|
||||
<hr>
|
||||
|
||||
<div class="query-edit {{if editName "editing"}}">
|
||||
{{partial "admin/plugins-explorer-show" model=selectedItem}}
|
||||
</div>
|
||||
{{#if selectedItem.fake}}
|
||||
{{i18n "explorer.no_queries"}} <a {{action "showCreate"}}>{{i18n "explorer.no_queries_hook"}}</a>
|
||||
{{else}}
|
||||
<div class="query-edit {{if editName "editing"}}">
|
||||
{{partial "admin/plugins-explorer-show" model=selectedItem}}
|
||||
</div>
|
||||
|
||||
<div class="query-run">
|
||||
{{#if selectedItem.param_names}}
|
||||
<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|}}
|
||||
<div class="param">
|
||||
{{param-field params=selectedItem.params pname=pname}}
|
||||
<span class="param-name">{{pname}}</span>
|
||||
<div class="query-run">
|
||||
{{#if selectedItem.param_names}}
|
||||
<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}}
|
||||
{{#each selectedItem.param_names as |pname|}}
|
||||
<div class="param">
|
||||
{{param-field params=selectedItem.params pname=pname}}
|
||||
<span class="param-name">{{pname}}</span>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="bool-options">
|
||||
<label>{{input type="checkbox" checked=explain name="explain"}} {{i18n "explorer.explain_label"}}</label>
|
||||
</div>
|
||||
{{d-button action="run" label="explorer.run" disabled=runDisabled}}
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
{{/if}}
|
||||
{{conditional-loading-spinner condition=loading}}
|
||||
{{#unless selectedItem.fake}}
|
||||
{{#if results}}
|
||||
<div class="query-results">
|
||||
{{#if showResults}}
|
||||
{{query-result query=selectedItem content=results}}
|
||||
{{else}}
|
||||
{{#each results.errors as |err|}}
|
||||
<pre class="query-error"><code>{{~err}}</code></pre>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="bool-options">
|
||||
<label>{{input type="checkbox" checked=explain name="explain"}} {{i18n "explorer.explain_label"}}</label>
|
||||
</div>
|
||||
{{d-button action="run" label="explorer.run" disabled=runDisabled}}
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
{{conditional-loading-spinner condition=loading}}
|
||||
|
||||
{{#if results}}
|
||||
<div class="query-results">
|
||||
{{#if showResults}}
|
||||
{{query-result query=selectedItem content=results}}
|
||||
{{else}}
|
||||
{{#each results.errors as |err|}}
|
||||
<pre class="query-error"><code>{{~err}}</code></pre>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
|
|
|
@ -41,3 +41,5 @@ en:
|
|||
save_params: "Set Defaults"
|
||||
reset_params: "Reset"
|
||||
https_warning: "Use of the Data Explorer on sites not protected by HTTPS is discouraged. Please be careful to not retrieve sensitive information over insecure links."
|
||||
no_queries: "There are no queries. Why not "
|
||||
no_queries_hook: "create one?"
|
||||
|
|
Loading…
Reference in New Issue