Tuesday morning, 10AM

This commit is contained in:
Kane York 2015-06-30 10:20:22 -07:00
parent 95a50e1116
commit ee1cc2d96d
6 changed files with 79 additions and 64 deletions

View File

@ -2,23 +2,24 @@ import showModal from 'discourse/lib/show-modal';
import Query from 'discourse/plugins/discourse-data-explorer/discourse/models/query';
export default Ember.ArrayController.extend({
selectedItem: null,
selectedQueryId: null,
dirty: false,
loading: false,
markDirty: function() {
this.set('dirty', true);
}.observes('selectedItem.name', 'selectedItem.description', 'selectedItem.sql'),
explain: false,
saveDisabled: Ember.computed.not('selectedItem.dirty'),
runDisabled: Ember.computed.alias('selectedItem.dirty'),
selectedItem: function() {
const _id = this.get('selectedQueryId');
const id = parseInt(_id);
return this.get('content').find(function(q) {
return q.get('id') === id;
});
}.property('selectedQueryId'),
actions: {
selectItem(item) {
this.setProperties({
selectedItem: item,
editName: false
});
this.set('dirty', false);
},
dummy() {},
create() {
@ -28,7 +29,7 @@ export default Ember.ArrayController.extend({
newQuery.save().then(function(result) {
self.pushObject(result.target);
self.set('selectedItem', result.target);
self.set('dirty', false);
self.set('selectedItem.dirty', false);
}).finally(function() {
self.set('loading', false);
});
@ -39,17 +40,16 @@ export default Ember.ArrayController.extend({
},
editName() {
this.setProperties({
editName: true,
dirty: true
});
this.set('editName', true);
},
save() {
const self = this;
this.set('loading', true);
this.get('selectedItem').save().then(function(result) {
debugger;
this.get('selectedItem').save().then(function() {
const query = self.get('selectedItem');
query.markNotDirty();
self.set('editName', false);
}).finally(function() {
self.set('loading', false);
});
@ -58,21 +58,25 @@ export default Ember.ArrayController.extend({
discard() {
const self = this;
this.set('loading', true);
this.store.find('query', this.selectedItem.id).then(function(result) {
self.set('selectedItem', result);
this.store.find('query', this.get('selectedItem.id')).then(function(result) {
debugger;
const query = self.get('selectedItem');
query.setProperties(result.getProperties(Query.updatePropertyNames));
query.markNotDirty();
self.set('editName', false);
}).finally(function() {
self.set('loading', false);
});
},
run() {
if (this.get('dirty')) {
if (this.get('selectedItem.dirty')) {
self.set('results', {errors: [I18n.t('errors.explorer.dirty')]});
return;
}
const self = this;
this.set('loading', true);
Discourse.ajax("/admin/plugins/explorer/query/" + this.get('selectedItem.id') + "/run", {
Discourse.ajax("/admin/plugins/explorer/queries/" + this.get('selectedItem.id') + "/run", {
type: "POST",
data: {
params: JSON.stringify({foo: 34}),

View File

@ -1,12 +1,30 @@
import RestModel from 'discourse/models/rest';
const Query = RestModel.extend({
let Query;
Query = RestModel.extend({
dirty: false,
markDirty: function() {
this.set('dirty', true);
}.observes('name', 'description', 'sql', 'defaults'),
markNotDirty() {
this.set('dirty', false);
},
listName: function() {
if (this.get('dirty')) {
return this.get('name') + " (*)";
}
return this.get('name');
}.property('name', 'dirty'),
createProperties() {
return this.getProperties("name");
},
updateProperties() {
return this.getProperties("name", "description", "sql", "defaults");
return this.getProperties(Query.updatePropertyNames);
},
run() {
@ -14,4 +32,8 @@ const Query = RestModel.extend({
}
});
Query.reopenClass({
updatePropertyNames: ["name", "description", "sql", "defaults"]
});
export default Query;

View File

@ -4,7 +4,7 @@
{{text-field value=selectedItem.name}}
{{else}}
<h2>{{selectedItem.name}}</h2>
{{d-button action="editName" icon="pencil" class="no-text"}}
{{d-button action="editName" icon="pencil" class="no-text btn-small"}}
{{/if}}
</div>
<div class="desc">
@ -18,6 +18,6 @@
{{textarea value=selectedItem.sql}}
</div>
{{d-button action="save" label="explorer.save" disabled=saveDisabled}}
{{d-button action="discard" class="no-text danger" icon="trash" disabled=saveDisabled}}
{{d-button action="discard" class="no-text btn-danger" icon="undo" disabled=saveDisabled}}
{{d-button action="run" label="explorer.run" disabled=runDisabled}}
{{/if}}

View File

@ -2,25 +2,9 @@
{{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" class="import-button"}}
<div class="query-list">
<table>
<thead>
<tr>
<th class="q-name">Name</th>
<th class="q-desc">Description</th>
</tr>
</thead>
<tbody>
{{#each content as |query|}}
<tr {{action "selectItem" query}}>
<td class="q-name">{{query.name}}</td>
<td class="q-desc">{{query.description}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
<hr>
{{combo-box valueAttribute="id" value=selectedQueryId nameProperty="name" content=content castInteger="true"}}
<div class="query-edit">
{{partial "admin/plugins-explorer-show" model=selectedItem}}
</div>

View File

@ -4,15 +4,19 @@
max-height: 15em;
}
.query-edit .sql textarea {
.query-edit {
.name h2 {
display: inline-block;
}
.desc textarea {
width: 200px;
}
.sql textarea {
width: 800px;
height: 100px;
font-family: monospace;
border-color: $tertiary;
}
.query-edit .desc textarea {
width: 200px;
}
.query-list, .query-edit, .query-results {

View File

@ -179,7 +179,9 @@ SQL
end
def self.find(id)
from_hash DataExplorer.pstore_get("q:#{id}")
hash = DataExplorer.pstore_get("q:#{id}")
raise Discourse::NotFound unless hash
from_hash hash
end
def save
@ -254,11 +256,11 @@ SQL
query = DataExplorer::Query.find(params[:id].to_i)
hash = params.require(:query)
[:name, :sql, :defaults, :description].each do |sym|
query.send("#{sym}=", params[sym]) if hash[sym]
query.send("#{sym}=", hash[sym]) if hash[sym]
end
query.save
render_serialized query, DataExplorer::QuerySerializer, root: 'queries'
render_serialized query, DataExplorer::QuerySerializer, root: true
end
def destroy
@ -323,12 +325,11 @@ SQL
root to: "query#index"
get 'queries' => "query#index"
post 'queries' => "query#create"
# GET /query/:id -> explorer#show
# PUT /query/:id -> explorer#update
# DELETE /query/:id -> explorer#destroy
resources :query
get 'query/parse_params' => "query#parse_params"
post 'query/:id/run' => "query#run"
get 'queries/:id' => "query#show"
put 'queries/:id' => "query#update"
delete 'queries/:id' => "query#destroy"
get 'queries/parse_params' => "query#parse_params"
post 'queries/:id/run' => "query#run"
end
Discourse::Application.routes.append do