Skip to content

Commit

Permalink
Transition back to detail page after saving experiment.
Browse files Browse the repository at this point in the history
Also, change code to emphasize ember.computed over function prototype extensions (per ember evolving recommendations)

http://blog.ksol.fr/ember-js-declaring-computed-property-and-observers/
emberjs/guides#110

[#LEI-157]
  • Loading branch information
abought committed Mar 15, 2016
1 parent d989978 commit 370934e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 8 additions & 5 deletions app/components/ace-editor/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export default Ember.Component.extend({
_initValue: null,
isValidSyntax: true,

ctx: function() {
ctx: Ember.computed('isValidSyntax', function () {
return {
submit: this.get('actions.onClick').bind(this),
validSyntax: this.get('isValidSyntax'),
notValidSyntax: !this.get('isValidSyntax')
};
}.property('isValidSyntax'),
}),

didInsertElement() {
this.set('_initValue', this.get('value') || '{}');
Expand All @@ -34,27 +34,30 @@ export default Ember.Component.extend({
_onChange(e, session) {
this.set('value', this.editor.getSession().getValue());
},

_onChangeAnnotation(e, session) {
if (session.getValue().length < 1) {
this.set('isValidSyntax', false);
}

let annotations = session.getAnnotations();

for(var i = 0; i < annotations.length; i++) {
for (var i = 0; i < annotations.length; i++) {
if (annotations[i].type === 'error') {
this.set('isValidSyntax', false);
}
}
this.set('isValidSyntax', true);
},
valueChanged: function() {

valueChanged: Ember.observer('value', function () {
if (!this.get('value')) {
this.editor.getSession().setValue('');
} else if (this.editor.getSession().getValue() !== this.get('value')) {
this.editor.getSession().setValue(this.get('value'));
}
}.observes('value'),
}),

actions: {
onClick() {
this.sendAction('submit', this.get('editor'));
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/experiments/info/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export default Ember.Controller.extend({
breadCrumb: 'Edit',
toast: Ember.inject.service('toast'),

experimentJson: function() {
experimentJson: Ember.computed('model', function () {
return JSON.stringify(this.get('model.structure'), null, 4);
}.property('model'),
}),

actions: {
submit(editor) {
Expand All @@ -86,7 +86,7 @@ export default Ember.Controller.extend({
patternProperties: createSchema(getOwner(this), parsed.sequence, parsed.frames),
additionalProperties: false
};
} catch(e) {
} catch (e) {
this.toast.error('Error Parsing Experiment: ' + e);
return;
}
Expand All @@ -97,7 +97,9 @@ export default Ember.Controller.extend({
//But calling get returns the value returned by set....
this.get('model.schema', schema).then(() => this.get('model').save())
.then(() => this.toast.success('Experiment updated'))
.catch(() => this.toast.error('The server refused to save the data, likely due to a schema error'));
.catch(() => this.toast.error('The server refused to save the data, likely due to a schema error'))
.then(() => this.transitionToRoute('experiments.info.index', this.get('model.id')))
.catch(() => this.toast.error('Error: could not find the summary page for this experiment'));
}
}
});

0 comments on commit 370934e

Please sign in to comment.