diff --git a/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 index 1a1ee9e..fb19a66 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 @@ -6,18 +6,17 @@ export default Discourse.Route.extend({ model() { const p1 = this.store.findAll('query'); const p2 = Discourse.ajax('/admin/plugins/explorer/schema.json', {cache: true}); - return p1.then(function(model) { - model.forEach(function(query) { - query.markNotDirty(); - }); - return p2.then(function(schema) { - return { content: model, schema: schema }; - }); + return p1.then(model => { + model.forEach(query => query.markNotDirty()); + + return p2.then(schema => {return {model, schema};}); + }).catch(() => { + p2.catch(() => {}); + return { model: null, schema: null, disallow: true }; }); }, setupController: function(controller, model) { - controller.set('model', model.content); - controller.set('schema', model.schema); + controller.setProperties(model); } }); diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index 9680a81..ff80dfd 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -1,131 +1,136 @@ -
- {{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="importQuery" label="explorer.import.label" icon="upload"}} -
- -{{#if showCreate}} -
- {{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}} - {{d-button action="create" label="explorer.create" icon="plus" class="btn-primary"}} -
-{{/if}} - -{{#if othersDirty}} -
- {{fa-icon "warning"}} - {{i18n "explorer.others_dirty"}} -
-{{/if}} - -
- -{{#if selectedItem.fake}} - {{i18n "explorer.no_queries"}} {{i18n "explorer.no_queries_hook"}} +{{#if disallow}} +

{{i18n "explorer.admins_only"}}

{{else}} -
- {{#if selectedItem}} - {{#if editing}} -
- {{text-field value=selectedItem.name}} -
-
- {{textarea value=selectedItem.description}} -
- {{else}} -
-

{{selectedItem.name}}

- {{d-button action="editName" icon="pencil" class="no-text btn-small"}} -
-
- {{selectedItem.description}} -
- {{/if}} - - {{! the SQL editor will show the first time you }} - {{#if everEditing}} -
-
-
- {{explorer-schema schema=schema hideSchema=hideSchema}} -
-
-
- {{ace-editor content=selectedItem.sql mode="sql"}} -
-
-
-
- {{else}} -
- {{hljs-code-view value=selectedItem.sql codeClass="sql"}} -
- {{/if}} - - - -
-
- {{#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"}} -
-
- {{#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}} -
-
- {{/if}} +
+ {{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="importQuery" label="explorer.import.label" icon="upload"}}
-
- {{#if selectedItem.hasParams}} -
- {{#each selectedItem.param_info as |pinfo|}} - {{param-input params=selectedItem.params info=pinfo}} + {{#if showCreate}} +
+ {{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}} + {{d-button action="create" label="explorer.create" icon="plus" class="btn-primary"}} +
+ {{/if}} + + {{#if othersDirty}} +
+ {{fa-icon "warning"}} + {{i18n "explorer.others_dirty"}} +
+ {{/if}} + +
+ + {{#if selectedItem.fake}} + {{i18n "explorer.no_queries"}} {{i18n "explorer.no_queries_hook"}} + {{else}} +
+ {{#if selectedItem}} + {{#if editing}} +
+ {{text-field value=selectedItem.name}} +
+
+ {{textarea value=selectedItem.description}} +
+ {{else}} +
+

{{selectedItem.name}}

+ {{d-button action="editName" icon="pencil" class="no-text btn-small"}} +
+
+ {{selectedItem.description}} +
+ {{/if}} + + {{! the SQL editor will show the first time you }} + {{#if everEditing}} +
+
+
+ {{explorer-schema schema=schema hideSchema=hideSchema}} +
+
+
+ {{ace-editor content=selectedItem.sql mode="sql"}} +
+
+
+
+ {{else}} +
+ {{hljs-code-view value=selectedItem.sql codeClass="sql"}} +
+ {{/if}} + + + +
+
+ {{#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"}} +
+
+ {{#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}} +
+
+ {{/if}} +
+ + + {{#if selectedItem.hasParams}} +
+ {{#each selectedItem.param_info as |pinfo|}} + {{param-input params=selectedItem.params info=pinfo}} {{!
{{param-field params=selectedItem.params pname=pinfo.identifier type=pinfo.type} {{pinfo.identifier}
}} - {{/each}} + {{/each}} +
+ {{/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}} + + + +
+ {{/if}} + {{conditional-loading-spinner condition=loading}} + {{#unless selectedItem.fake}} + {{#if results}} +
+ {{#if showResults}} + {{query-result query=selectedItem content=results}} + {{else}} + {{#each results.errors as |err|}} +
{{~err}}
+ {{/each}} + {{/if}}
{{/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}} - - + {{/unless}} + +
-
{{/if}} -{{conditional-loading-spinner condition=loading}} -{{#unless selectedItem.fake}} - {{#if results}} -
- {{#if showResults}} - {{query-result query=selectedItem content=results}} - {{else}} - {{#each results.errors as |err|}} -
{{~err}}
- {{/each}} - {{/if}} -
- {{/if}} -{{/unless}} - -
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 393c7c3..8e2d007 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -22,6 +22,7 @@ en: no_semicolons: "Remove the semicolons from the query." dirty: "You must save the query before running." explorer: + admins_only: "The data explorer is only available to admins." title: "Data Explorer" create: "Create New" create_placeholder: "Query name..."