From 68d33e0b1814cc12bc37f7590b2a28add5bb4dfd Mon Sep 17 00:00:00 2001 From: Markus Grigull Date: Tue, 18 Oct 2016 19:45:14 +0200 Subject: [PATCH] Change live data observer Fix last extend prototype changes --- app/components/plot-value.js | 43 ++++++++------------------- app/controllers/simulation/index.js | 4 +-- app/controllers/user/index.js | 4 +-- app/controllers/visualization/edit.js | 2 +- app/mixins/fetch-live-data.js | 12 ++------ app/models/simulation-data.js | 4 +-- 6 files changed, 21 insertions(+), 48 deletions(-) diff --git a/app/components/plot-value.js b/app/components/plot-value.js index d5f0ac2..6cdfab3 100644 --- a/app/components/plot-value.js +++ b/app/components/plot-value.js @@ -16,37 +16,18 @@ export default PlotAbstract.extend({ minWidth_resize: 50, minHeight_resize: 20, - value: Ember.computed('data.2.values', 'plot.simulator', 'plot.signal', function() { - // get all values for the choosen simulator - let values = this.get('data.' + this.get('plot.simulator') + '.values'); - if (values) { - return values[this.get('plot.signal')]; - } - - // values is null, try to reload later - Ember.run.later(this, function() { - this.notifyPropertyChange('data.' + this.get('plot.simulator') + '.values'); - }, 1000); - }), - - /*_updateValue() { - let values = this.get('data.' + this.get('plot.simulator') + '.values'); - if (values) { - console.log('update value'); - return; - } - - // values is null, try to reload later - Ember.run.later(this, this._updateValue, 1000); - - console.log('update later'); - }, - - _updateDataObserver: function() { - let query = 'data.' + this.get('plot.simulator') + '.values'; - this.addObserver(query, this, this._updateValue); - console.log('Add observer: ' + query); - }.observes('plot.simulator', 'plot.signal').on('init'),*/ + _updateDataObserver: Ember.on('init', Ember.observer('plot.simulator', 'plot.signal', function() { + let query = 'data.' + this.get('plot.simulator') + '.sequence'; + this.addObserver(query, function() { + // get value from array + let values = this.get('data.' + this.get('plot.simulator') + '.values'); + if (values) { + this.set('value', values[this.get('plot.signal')]); + } else { + this.set('value', null); + } + }); + })), doubleClick() { if (this.get('editing') === true) { diff --git a/app/controllers/simulation/index.js b/app/controllers/simulation/index.js index 8db5c58..ffc0051 100644 --- a/app/controllers/simulation/index.js +++ b/app/controllers/simulation/index.js @@ -19,12 +19,12 @@ export default Ember.Controller.extend({ simulationModel: null, simulatorName: null, - _updateSimulators: function() { + _updateSimulators: Ember.observer('model', function() { if (this.get('model.simulators') != null && this.get('model.simulators.length') > 0) { let simulators = this.get('model.simulators'); this.set('simulatorName', simulators.toArray()[0].get('name')); } - }.observes('model'), + }), actions: { showNewModal() { diff --git a/app/controllers/user/index.js b/app/controllers/user/index.js index 6a44737..021b80b 100644 --- a/app/controllers/user/index.js +++ b/app/controllers/user/index.js @@ -10,7 +10,7 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - users: function() { + users: Ember.computed('model.@each', function() { var filteredUsers = this.get('model'); filteredUsers.forEach(function(user) { // catch undefined user @@ -22,5 +22,5 @@ export default Ember.Controller.extend({ }); return filteredUsers; - }.property('model.@each') + }) }); diff --git a/app/controllers/visualization/edit.js b/app/controllers/visualization/edit.js index 8062829..3e068b9 100644 --- a/app/controllers/visualization/edit.js +++ b/app/controllers/visualization/edit.js @@ -27,7 +27,7 @@ export default Ember.Controller.extend(FetchLiveDataMixin, { this.set('simulatorName', simulators.toArray()[0].get('name')); } }), - + actions: { addPlot(name) { var plot = null; diff --git a/app/mixins/fetch-live-data.js b/app/mixins/fetch-live-data.js index 0398f6d..a3d2b06 100644 --- a/app/mixins/fetch-live-data.js +++ b/app/mixins/fetch-live-data.js @@ -10,7 +10,7 @@ import Ember from 'ember'; export default Ember.Mixin.create({ - data: {}, + data: Ember.Object.create(), _getData: Ember.observer('model', function() { // check if simulation is running @@ -35,11 +35,6 @@ export default Ember.Mixin.create({ }); }); } else { - // clear simulation data - this.set('data', {}); - - //Ember.debug('Simulation not running'); - // check again if simulation is running Ember.run.later(this, function() { // trigger _getData observer @@ -55,10 +50,7 @@ export default Ember.Mixin.create({ let simulationData = this.store.peekRecord('simulation-data', simulatorID); if (simulationData) { // add data to list - this.get('data')[simulatorID] = simulationData; - - // notify object for property changes - this.notifyPropertyChange('data.' + simulatorID + '.values'); + this.set('data.' + simulatorID, simulationData); } else { // try to load data later Ember.run.later(this, function() { diff --git a/app/models/simulation-data.js b/app/models/simulation-data.js index 6764464..b145faf 100644 --- a/app/models/simulation-data.js +++ b/app/models/simulation-data.js @@ -17,7 +17,7 @@ export default Model.extend({ sequence: attr('number'), values: attr('array'), - historyValues() { + /*historyValues() { return this._history; }, @@ -28,5 +28,5 @@ export default Model.extend({ while (this._history.length > 5) { this._history.shift(); } - }) + })*/ });