Add text for no queries, keep results in query object

This commit is contained in:
Kane York 2015-07-02 09:15:55 -07:00
parent 052fb97396
commit d9dbfc8408
4 changed files with 49 additions and 43 deletions

View File

@ -2,10 +2,11 @@ import showModal from 'discourse/lib/show-modal';
import Query from 'discourse/plugins/discourse-data-explorer/discourse/models/query'; import Query from 'discourse/plugins/discourse-data-explorer/discourse/models/query';
import { popupAjaxError } from 'discourse/lib/ajax-error'; import { popupAjaxError } from 'discourse/lib/ajax-error';
const NoQuery = Query.create({name: "No queries", fake: true});
export default Ember.ArrayController.extend({ export default Ember.ArrayController.extend({
queryParams: { selectedQueryId: "id" }, queryParams: { selectedQueryId: "id" },
selectedQueryId: null, selectedQueryId: null,
results: null,
showResults: false, showResults: false,
loading: false, loading: false,
@ -17,15 +18,13 @@ export default Ember.ArrayController.extend({
selectedItem: function() { selectedItem: function() {
const _id = this.get('selectedQueryId'); const _id = this.get('selectedQueryId');
const id = parseInt(_id); 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 q.get('id') === id;
}); });
return item || NoQuery;
}.property('selectedQueryId'), }.property('selectedQueryId'),
clearResults: function() { results: Em.computed.alias('selectedItem.results'),
this.set('showResults', false);
this.set('results', null);
}.observes('selectedQueryId'),
addCreatedRecord(record) { addCreatedRecord(record) {
this.pushObject(record); this.pushObject(record);
@ -103,7 +102,6 @@ export default Ember.ArrayController.extend({
query.setProperties(result.getProperties(Query.updatePropertyNames)); query.setProperties(result.getProperties(Query.updatePropertyNames));
query.markNotDirty(); query.markNotDirty();
self.set('editName', false); self.set('editName', false);
self.set('results', null);
}).catch(popupAjaxError).finally(function() { }).catch(popupAjaxError).finally(function() {
self.set('loading', false); self.set('loading', false);
}); });
@ -138,6 +136,7 @@ export default Ember.ArrayController.extend({
} }
this.set('loading', true); this.set('loading', true);
this.set('showResults', false);
Discourse.ajax("/admin/plugins/explorer/queries/" + this.get('selectedItem.id') + "/run", { Discourse.ajax("/admin/plugins/explorer/queries/" + this.get('selectedItem.id') + "/run", {
type: "POST", type: "POST",
data: { data: {

View File

@ -4,6 +4,7 @@ let Query;
Query = RestModel.extend({ Query = RestModel.extend({
dirty: false, dirty: false,
params: {}, params: {},
results: null,
_init: function() { _init: function() {
this._super(); this._super();

View File

@ -22,11 +22,14 @@
<hr> <hr>
<div class="query-edit {{if editName "editing"}}"> {{#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}} {{partial "admin/plugins-explorer-show" model=selectedItem}}
</div> </div>
<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"> <div class="param-save">
@ -45,13 +48,13 @@
<label>{{input type="checkbox" checked=explain name="explain"}} {{i18n "explorer.explain_label"}}</label> <label>{{input type="checkbox" checked=explain name="explain"}} {{i18n "explorer.explain_label"}}</label>
</div> </div>
{{d-button action="run" label="explorer.run" disabled=runDisabled}} {{d-button action="run" label="explorer.run" disabled=runDisabled}}
</div> </div>
<hr>
<hr>
{{/if}}
{{conditional-loading-spinner condition=loading}} {{conditional-loading-spinner condition=loading}}
{{#unless selectedItem.fake}}
{{#if results}} {{#if results}}
<div class="query-results"> <div class="query-results">
{{#if showResults}} {{#if showResults}}
{{query-result query=selectedItem content=results}} {{query-result query=selectedItem content=results}}
@ -61,4 +64,5 @@
{{/each}} {{/each}}
{{/if}} {{/if}}
</div> </div>
{{/if}} {{/if}}
{{/unless}}

View File

@ -41,3 +41,5 @@ en:
save_params: "Set Defaults" save_params: "Set Defaults"
reset_params: "Reset" 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." 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?"