More work on interface, fixes for backend
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
import buildPluginAdapter from 'discourse/adapters/build-plugin';
|
||||
|
||||
export default buildPluginAdapter('explorer');
|
||||
export default buildPluginAdapter('explorer').extend({
|
||||
|
||||
createRecord(store, type, args) {
|
||||
const typeField = Ember.String.underscore(type);
|
||||
return Discourse.ajax(this.pathFor(store, type), {method: 'POST', data: args}).then(function (json) {
|
||||
return new Result(json[typeField], json);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
selectedItem: null,
|
||||
|
||||
actions: {
|
||||
selectItem(item) {
|
||||
this.set('selectedItem', item);
|
||||
},
|
||||
|
||||
dummy() {},
|
||||
|
||||
create() {
|
||||
var newQuery = this.store.createRecord('query', {name: this.get('newQueryName')});
|
||||
newQuery.save();
|
||||
},
|
||||
|
||||
importQuery() {
|
||||
showModal('import-query');
|
||||
},
|
||||
|
||||
run() {
|
||||
const self = this;
|
||||
this.set('loading', true);
|
||||
Discourse.ajax("/admin/plugins/explorer/query/" + this.get('selectedItem.id') + "/run", {
|
||||
type: "POST",
|
||||
data: {
|
||||
params: JSON.stringify({foo: 34}),
|
||||
explain: true
|
||||
}
|
||||
}).then(function(result) {
|
||||
console.log(result);
|
||||
self.set('results', result);
|
||||
}).finally(function() {
|
||||
self.set('loading', false);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
|
||||
export default Ember.ArrayController.extend({
|
||||
|
||||
});
|
||||
@@ -22,7 +22,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||
const object = JSON.parse(this.get('queryFile')).query;
|
||||
|
||||
// Slight fixup before creating object
|
||||
delete object.id;
|
||||
object.id = 0; // 0 means no Id yet
|
||||
|
||||
this.set('loading', true);
|
||||
this.store.createRecord('query', object).save().then(function(query) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import RestModel from 'discourse/models/rest';
|
||||
|
||||
const Query = RestModel.extend({
|
||||
createProperties() {
|
||||
return this.getProperties("name", "description");
|
||||
},
|
||||
|
||||
run() {
|
||||
console.log("Called query#run");
|
||||
}
|
||||
});
|
||||
|
||||
console.log('query model loaded');
|
||||
|
||||
export default Query;
|
||||
@@ -1,22 +1,9 @@
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
controllerName: 'admin-plugins-explorer',
|
||||
|
||||
model() {
|
||||
return this.store.findAll('query');
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
|
||||
},
|
||||
|
||||
actions: {
|
||||
create() {
|
||||
|
||||
},
|
||||
importQuery() {
|
||||
showModal('import-query');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{{#if model}}
|
||||
<h2>{{model.name}}</h2>
|
||||
<div>{{model.description}}</div>
|
||||
{{textarea value=model.sql}}
|
||||
{{d-button action="run" label="explorer.run"}}
|
||||
{{/if}}
|
||||
@@ -1,8 +1,23 @@
|
||||
{{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}}
|
||||
{{d-button action="create" label="explorer.create" icon="plus"}}
|
||||
{{d-button action="importQuery" label="explorer.import.label" icon="upload"}}
|
||||
{{d-button action="importQuery" label="explorer.import.label" icon="upload" class="import-button"}}
|
||||
|
||||
{{#each query in model}}
|
||||
<div class="row">
|
||||
{{query.name}}
|
||||
</div>
|
||||
{{/each}}
|
||||
<h3>Queries</h3>
|
||||
<table class="query-list">
|
||||
<thead>
|
||||
<th class="q-name">Name</th>
|
||||
<th class="q-desc">Description</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each query in content}}
|
||||
<tr {{action "selectItem" query}}>
|
||||
<td class="q-name">{{query.name}}</td>
|
||||
<td class="q-desc">{{query.description}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{render "admin/plugins-explorer-show" selectedItem}}
|
||||
|
||||
{{! results }}
|
||||
|
||||
Reference in New Issue
Block a user