diff --git a/app/controllers/simulation-model/index.js b/app/controllers/simulation-model/index.js index e8ba731..88463c1 100644 --- a/app/controllers/simulation-model/index.js +++ b/app/controllers/simulation-model/index.js @@ -10,4 +10,39 @@ import Ember from 'ember'; export default Ember.Controller.extend({ + _setSignalNames: Ember.observer('model', 'model.length', function() { + // loop through signals + let length = this.get('model.length'); + let mapping = this.get('model.mapping'); + + for (let i = 0; i < length; i++) { + this.set('name' + i, mapping[i]); + } + }), + + actions: { + saveMapping() { + // save all signal names + let length = this.get('model.length'); + let mapping = this.get('model.mapping'); + + for (let i = 0; i < length; i++) { + mapping[i] = this.get('name' + i); + } + + this.set('model.mapping', mapping); + + // save the changed model + let self = this; + + this.get('model').save().then(function() { + // go back to simulation + self.get('model.simulation').then((simulation) => { + self.transitionToRoute('/simulation/' + simulation.get('id')); + }); + }, function() { + Ember.debug('Unable to save simulation model'); + }); + } + } }); diff --git a/app/controllers/simulation/index.js b/app/controllers/simulation/index.js index ffc0051..86d063a 100644 --- a/app/controllers/simulation/index.js +++ b/app/controllers/simulation/index.js @@ -94,7 +94,7 @@ export default Ember.Controller.extend({ let mapping = []; for (let i = 0; i < properties['length']; i++) { - mapping.pushObject("Signal " + (i + 1)); + mapping.push('Signal ' + (i + 1)); } properties['mapping'] = mapping; @@ -140,6 +140,23 @@ export default Ember.Controller.extend({ } }); + // change mapping + let mapping = this.get('simulationModel.mapping'); + + if (mapping.length < properties['length']) { + // add more signals + for (let i = mapping.length; i < properties['length']; i++) { + mapping.push('Signal ' + (i + 1)); + } + } else if (mapping.length > properties['length']) { + // remove signals + mapping = mapping.slice(0, Number(properties['length'])); + } + + console.log(mapping); + + properties['mapping'] = mapping; + // save properties let controller = this; diff --git a/app/templates/simulation-model/index.hbs b/app/templates/simulation-model/index.hbs index b1d2c6c..91872be 100644 --- a/app/templates/simulation-model/index.hbs +++ b/app/templates/simulation-model/index.hbs @@ -2,28 +2,30 @@