FIX: Show error message, not exception page, to mods

This commit is contained in:
Kane York 2015-09-21 11:19:31 -07:00
parent d4d541747e
commit 9145e32162
3 changed files with 134 additions and 129 deletions

View File

@ -6,18 +6,17 @@ export default Discourse.Route.extend({
model() { model() {
const p1 = this.store.findAll('query'); const p1 = this.store.findAll('query');
const p2 = Discourse.ajax('/admin/plugins/explorer/schema.json', {cache: true}); const p2 = Discourse.ajax('/admin/plugins/explorer/schema.json', {cache: true});
return p1.then(function(model) { return p1.then(model => {
model.forEach(function(query) { model.forEach(query => query.markNotDirty());
query.markNotDirty();
}); return p2.then(schema => {return {model, schema};});
return p2.then(function(schema) { }).catch(() => {
return { content: model, schema: schema }; p2.catch(() => {});
}); return { model: null, schema: null, disallow: true };
}); });
}, },
setupController: function(controller, model) { setupController: function(controller, model) {
controller.set('model', model.content); controller.setProperties(model);
controller.set('schema', model.schema);
} }
}); });

View File

@ -1,131 +1,136 @@
<div class="query-list"> {{#if disallow}}
{{combo-box valueAttribute="id" value=selectedQueryId nameProperty="listName" content=content castInteger="true" nameChanges="true"}} <h2>{{i18n "explorer.admins_only"}}</h2>
{{d-button action="showCreate" icon="plus" class="no-text"}}
{{d-button action="importQuery" label="explorer.import.label" icon="upload"}}
</div>
{{#if showCreate}}
<div class="query-create">
{{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}}
{{d-button action="create" label="explorer.create" icon="plus" class="btn-primary"}}
</div>
{{/if}}
{{#if othersDirty}}
<div class="warning">
{{fa-icon "warning"}}
{{i18n "explorer.others_dirty"}}
</div>
{{/if}}
<hr>
{{#if selectedItem.fake}}
{{i18n "explorer.no_queries"}} <a {{action "showCreate"}}>{{i18n "explorer.no_queries_hook"}}</a>
{{else}} {{else}}
<div class="query-edit {{if editName "editing"}}"> <div class="query-list">
{{#if selectedItem}} {{combo-box valueAttribute="id" value=selectedQueryId nameProperty="listName" content=content castInteger="true" nameChanges="true"}}
{{#if editing}} {{d-button action="showCreate" icon="plus" class="no-text"}}
<div class="name"> {{d-button action="importQuery" label="explorer.import.label" icon="upload"}}
{{text-field value=selectedItem.name}}
</div>
<div class="desc">
{{textarea value=selectedItem.description}}
</div>
{{else}}
<div class="name">
<h2>{{selectedItem.name}}</h2>
{{d-button action="editName" icon="pencil" class="no-text btn-small"}}
</div>
<div class="desc">
{{selectedItem.description}}
</div>
{{/if}}
{{! the SQL editor will show the first time you }}
{{#if everEditing}}
<div class="query-editor {{if hideSchema "no-schema"}}">
<div class="right-panel">
<div class="schema grippie-target">
{{explorer-schema schema=schema hideSchema=hideSchema}}
</div>
</div>
<div class="editor-panel">
{{ace-editor content=selectedItem.sql mode="sql"}}
</div>
<div class="grippie"></div>
<div class="clear"></div>
</div>
{{else}}
<div class="sql">
{{hljs-code-view value=selectedItem.sql codeClass="sql"}}
</div>
{{/if}}
<div class="clear"></div>
<div class="pull-left">
{{#if everEditing}}
{{d-button action="save" label="explorer.save" disabled=saveDisabled class="btn-primary"}}
{{else}}
{{d-button action="editName" label="explorer.edit" icon="pencil" class="btn-primary"}}
{{/if}}
{{d-button action="download" label="explorer.export" disabled=runDisabled icon="download"}}
</div>
<div class="pull-right">
{{#if selectedItem.destroyed}}
{{d-button action="recover" class="" icon="undo" label="explorer.recover"}}
{{else}}
{{#if everEditing}}
{{d-button action="discard" class="btn-danger" icon="undo" label="explorer.undo" disabled=saveDisabled}}
{{/if}}
{{d-button action="destroy" class="btn-danger" icon="trash" label="explorer.delete"}}
{{/if}}
</div>
<div class="clear"></div>
{{/if}}
</div> </div>
<form class="query-run" {{action "run" on="submit"}}> {{#if showCreate}}
{{#if selectedItem.hasParams}} <div class="query-create">
<div class="query-params"> {{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}}
{{#each selectedItem.param_info as |pinfo|}} {{d-button action="create" label="explorer.create" icon="plus" class="btn-primary"}}
{{param-input params=selectedItem.params info=pinfo}} </div>
{{/if}}
{{#if othersDirty}}
<div class="warning">
{{fa-icon "warning"}}
{{i18n "explorer.others_dirty"}}
</div>
{{/if}}
<hr>
{{#if selectedItem.fake}}
{{i18n "explorer.no_queries"}} <a {{action "showCreate"}}>{{i18n "explorer.no_queries_hook"}}</a>
{{else}}
<div class="query-edit {{if editName "editing"}}">
{{#if selectedItem}}
{{#if editing}}
<div class="name">
{{text-field value=selectedItem.name}}
</div>
<div class="desc">
{{textarea value=selectedItem.description}}
</div>
{{else}}
<div class="name">
<h2>{{selectedItem.name}}</h2>
{{d-button action="editName" icon="pencil" class="no-text btn-small"}}
</div>
<div class="desc">
{{selectedItem.description}}
</div>
{{/if}}
{{! the SQL editor will show the first time you }}
{{#if everEditing}}
<div class="query-editor {{if hideSchema "no-schema"}}">
<div class="right-panel">
<div class="schema grippie-target">
{{explorer-schema schema=schema hideSchema=hideSchema}}
</div>
</div>
<div class="editor-panel">
{{ace-editor content=selectedItem.sql mode="sql"}}
</div>
<div class="grippie"></div>
<div class="clear"></div>
</div>
{{else}}
<div class="sql">
{{hljs-code-view value=selectedItem.sql codeClass="sql"}}
</div>
{{/if}}
<div class="clear"></div>
<div class="pull-left">
{{#if everEditing}}
{{d-button action="save" label="explorer.save" disabled=saveDisabled class="btn-primary"}}
{{else}}
{{d-button action="editName" label="explorer.edit" icon="pencil" class="btn-primary"}}
{{/if}}
{{d-button action="download" label="explorer.export" disabled=runDisabled icon="download"}}
</div>
<div class="pull-right">
{{#if selectedItem.destroyed}}
{{d-button action="recover" class="" icon="undo" label="explorer.recover"}}
{{else}}
{{#if everEditing}}
{{d-button action="discard" class="btn-danger" icon="undo" label="explorer.undo" disabled=saveDisabled}}
{{/if}}
{{d-button action="destroy" class="btn-danger" icon="trash" label="explorer.delete"}}
{{/if}}
</div>
<div class="clear"></div>
{{/if}}
</div>
<form class="query-run" {{action "run" on="submit"}}>
{{#if selectedItem.hasParams}}
<div class="query-params">
{{#each selectedItem.param_info as |pinfo|}}
{{param-input params=selectedItem.params info=pinfo}}
{{! <div class="param"> {{! <div class="param">
{{param-field params=selectedItem.params pname=pinfo.identifier type=pinfo.type} {{param-field params=selectedItem.params pname=pinfo.identifier type=pinfo.type}
<span class="param-name">{{pinfo.identifier}</span> <span class="param-name">{{pinfo.identifier}</span>
</div> }} </div> }}
{{/each}} {{/each}}
</div>
{{/if}}
{{#if runDisabled}}
{{#if saveDisabled}}
{{d-button label="explorer.run" disabled="true" class="btn-primary"}}
{{else}}
{{d-button action="saverun" label="explorer.saverun"}}
{{/if}}
{{else}}
{{d-button action="run" label="explorer.run" disabled=runDisabled class="btn-primary" type="submit"}}
{{/if}}
<label class="query-plan">{{input type="checkbox" checked=explain name="explain"}} {{i18n "explorer.explain_label"}}</label>
</form>
<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> </div>
{{/if}} {{/if}}
{{#if runDisabled}} {{/unless}}
{{#if saveDisabled}}
{{d-button label="explorer.run" disabled="true" class="btn-primary"}} <div class="explorer-pad-bottom"></div>
{{else}}
{{d-button action="saverun" label="explorer.saverun"}}
{{/if}}
{{else}}
{{d-button action="run" label="explorer.run" disabled=runDisabled class="btn-primary" type="submit"}}
{{/if}}
<label class="query-plan">{{input type="checkbox" checked=explain name="explain"}} {{i18n "explorer.explain_label"}}</label>
</form>
<hr>
{{/if}} {{/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}}
{{/unless}}
<div class="explorer-pad-bottom"></div>

View File

@ -22,6 +22,7 @@ en:
no_semicolons: "Remove the semicolons from the query." no_semicolons: "Remove the semicolons from the query."
dirty: "You must save the query before running." dirty: "You must save the query before running."
explorer: explorer:
admins_only: "The data explorer is only available to admins."
title: "Data Explorer" title: "Data Explorer"
create: "Create New" create: "Create New"
create_placeholder: "Query name..." create_placeholder: "Query name..."