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'; import Query from 'discourse/plugins/discourse-data-explorer/discourse/models/query';
export default Ember.ArrayController.extend({ export default Ember.ArrayController.extend({
selectedItem: null, selectedQueryId: null,
dirty: false, dirty: false,
loading: false, loading: false,
markDirty: function() { explain: false,
this.set('dirty', true);
}.observes('selectedItem.name', 'selectedItem.description', 'selectedItem.sql'), 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: { actions: {
selectItem(item) {
this.setProperties({
selectedItem: item,
editName: false
});
this.set('dirty', false);
},
dummy() {}, dummy() {},
create() { create() {
@ -28,7 +29,7 @@ export default Ember.ArrayController.extend({
newQuery.save().then(function(result) { newQuery.save().then(function(result) {
self.pushObject(result.target); self.pushObject(result.target);
self.set('selectedItem', result.target); self.set('selectedItem', result.target);
self.set('dirty', false); self.set('selectedItem.dirty', false);
}).finally(function() { }).finally(function() {
self.set('loading', false); self.set('loading', false);
}); });
@ -39,17 +40,16 @@ export default Ember.ArrayController.extend({
}, },
editName() { editName() {
this.setProperties({ this.set('editName', true);
editName: true,
dirty: true
});
}, },
save() { save() {
const self = this; const self = this;
this.set('loading', true); this.set('loading', true);
this.get('selectedItem').save().then(function(result) { this.get('selectedItem').save().then(function() {
debugger; const query = self.get('selectedItem');
query.markNotDirty();
self.set('editName', false);
}).finally(function() { }).finally(function() {
self.set('loading', false); self.set('loading', false);
}); });
@ -58,21 +58,25 @@ export default Ember.ArrayController.extend({
discard() { discard() {
const self = this; const self = this;
this.set('loading', true); this.set('loading', true);
this.store.find('query', this.selectedItem.id).then(function(result) { this.store.find('query', this.get('selectedItem.id')).then(function(result) {
self.set('selectedItem', result); debugger;
const query = self.get('selectedItem');
query.setProperties(result.getProperties(Query.updatePropertyNames));
query.markNotDirty();
self.set('editName', false);
}).finally(function() { }).finally(function() {
self.set('loading', false); self.set('loading', false);
}); });
}, },
run() { run() {
if (this.get('dirty')) { if (this.get('selectedItem.dirty')) {
self.set('results', {errors: [I18n.t('errors.explorer.dirty')]}); self.set('results', {errors: [I18n.t('errors.explorer.dirty')]});
return; return;
} }
const self = this; const self = this;
this.set('loading', true); 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", type: "POST",
data: { data: {
params: JSON.stringify({foo: 34}), params: JSON.stringify({foo: 34}),

View File

@ -1,12 +1,30 @@
import RestModel from 'discourse/models/rest'; 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() { createProperties() {
return this.getProperties("name"); return this.getProperties("name");
}, },
updateProperties() { updateProperties() {
return this.getProperties("name", "description", "sql", "defaults"); return this.getProperties(Query.updatePropertyNames);
}, },
run() { run() {
@ -14,4 +32,8 @@ const Query = RestModel.extend({
} }
}); });
Query.reopenClass({
updatePropertyNames: ["name", "description", "sql", "defaults"]
});
export default Query; export default Query;

View File

@ -4,7 +4,7 @@
{{text-field value=selectedItem.name}} {{text-field value=selectedItem.name}}
{{else}} {{else}}
<h2>{{selectedItem.name}}</h2> <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}} {{/if}}
</div> </div>
<div class="desc"> <div class="desc">
@ -18,6 +18,6 @@
{{textarea value=selectedItem.sql}} {{textarea value=selectedItem.sql}}
</div> </div>
{{d-button action="save" label="explorer.save" disabled=saveDisabled}} {{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}} {{d-button action="run" label="explorer.run" disabled=runDisabled}}
{{/if}} {{/if}}

View File

@ -2,25 +2,9 @@
{{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}} {{text-field value=newQueryName placeholderKey="explorer.create_placeholder"}}
{{d-button action="create" label="explorer.create" icon="plus"}} {{d-button action="create" label="explorer.create" icon="plus"}}
{{d-button action="importQuery" label="explorer.import.label" icon="upload" class="import-button"}} {{d-button action="importQuery" label="explorer.import.label" icon="upload" class="import-button"}}
<div class="query-list">
<table> {{combo-box valueAttribute="id" value=selectedQueryId nameProperty="name" content=content castInteger="true"}}
<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>
<div class="query-edit"> <div class="query-edit">
{{partial "admin/plugins-explorer-show" model=selectedItem}} {{partial "admin/plugins-explorer-show" model=selectedItem}}
</div> </div>

View File

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

View File

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