From 370934e9721bf5fc2cc4261b8b2a6bc444ee3640 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 15 Mar 2016 10:33:10 -0400 Subject: [PATCH] Transition back to detail page after saving experiment. 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/ https://github.com/emberjs/guides/pull/110 [#LEI-157] --- app/components/ace-editor/component.js | 13 ++++++++----- app/controllers/experiments/info/edit.js | 10 ++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/components/ace-editor/component.js b/app/components/ace-editor/component.js index dde0360..9198841 100644 --- a/app/components/ace-editor/component.js +++ b/app/components/ace-editor/component.js @@ -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') || '{}'); @@ -34,6 +34,7 @@ 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); @@ -41,20 +42,22 @@ export default Ember.Component.extend({ 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')); diff --git a/app/controllers/experiments/info/edit.js b/app/controllers/experiments/info/edit.js index edbb8db..84dd803 100644 --- a/app/controllers/experiments/info/edit.js +++ b/app/controllers/experiments/info/edit.js @@ -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) { @@ -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; } @@ -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')); } } });