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 { 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: {

View File

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

View File

@ -22,11 +22,14 @@
<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}}
</div>
</div>
<div class="query-run">
<div class="query-run">
{{#if selectedItem.param_names}}
<div class="query-params">
<div class="param-save">
@ -45,13 +48,13 @@
<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>
</div>
<hr>
{{/if}}
{{conditional-loading-spinner condition=loading}}
{{#if results}}
{{#unless selectedItem.fake}}
{{#if results}}
<div class="query-results">
{{#if showResults}}
{{query-result query=selectedItem content=results}}
@ -61,4 +64,5 @@
{{/each}}
{{/if}}
</div>
{{/if}}
{{/if}}
{{/unless}}

View File

@ -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?"