diff --git a/app/components/plot-abstract.js b/app/components/plot-abstract.js index 9192ef8..9b6377d 100644 --- a/app/components/plot-abstract.js +++ b/app/components/plot-abstract.js @@ -21,7 +21,7 @@ export default Ember.Component.extend(Resizable, Draggable, { grid: false, data: null, - simulator: 0 + simulator: 0, disabled_resize: false, autoHide_resize: false, diff --git a/app/controllers/visualization/edit.js b/app/controllers/visualization/edit.js index 063bd58..f9eaae7 100644 --- a/app/controllers/visualization/edit.js +++ b/app/controllers/visualization/edit.js @@ -8,8 +8,9 @@ **********************************************************************************/ import Ember from 'ember'; +import FetchLiveDataMixin from '../../mixins/fetch-live-data'; -export default Ember.Controller.extend({ +export default Ember.Controller.extend(FetchLiveDataMixin, { actions: { addPlot(name) { var plot = null; diff --git a/app/controllers/visualization/index.js b/app/controllers/visualization/index.js index 9da9763..bf51cbe 100644 --- a/app/controllers/visualization/index.js +++ b/app/controllers/visualization/index.js @@ -8,67 +8,8 @@ **********************************************************************************/ import Ember from 'ember'; +import FetchLiveDataMixin from '../../mixins/fetch-live-data'; -export default Ember.Controller.extend({ - data: {}, +export default Ember.Controller.extend(FetchLiveDataMixin, { - /*values: function() { - console.log('update'); - return this.get('data'); - }.property('data.2.values'),*/ - - _getData: function() { - // check if simulation is running - let self = this; - - this.get('model.project').then((project) => { - project.get('simulation').then((simulation) => { - if (simulation.get('running')) { - // get all models to access data - simulation.get('models').then((simulationModels) => { - simulationModels.forEach(function(simulationModel) { - // get simulator - simulationModel.get('simulator').then((simulator) => { - let simulatorID = simulator.get('simulatorid'); - if (simulatorID) { - // add simulation data to list - self._loadDataForSimulator(simulatorID); - } else { - Ember.debug('undefined simulator id'); - } - }); - }); - }); - } 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 - this.notifyPropertyChange('model'); - }, 1000); - } - }); - }); - }.observes('model'), - - _loadDataForSimulator(simulatorID) { - // get data by simulator id - 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'); - } else { - // try to load data later - Ember.run.later(this, function() { - this._loadDataForSimulator(simulatorID); - }, 1000); - } - } }); diff --git a/app/mixins/fetch-live-data.js b/app/mixins/fetch-live-data.js new file mode 100644 index 0000000..811f104 --- /dev/null +++ b/app/mixins/fetch-live-data.js @@ -0,0 +1,69 @@ +/** + * File: fetch-live-data.js + * Author: Markus Grigull + * Date: 12.10.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + +import Ember from 'ember'; + +export default Ember.Mixin.create({ + data: {}, + + _getData: function() { + // check if simulation is running + let self = this; + + this.get('model.project').then((project) => { + project.get('simulation').then((simulation) => { + if (simulation.get('running')) { + // get all models to access data + simulation.get('models').then((simulationModels) => { + simulationModels.forEach(function(simulationModel) { + // get simulator + simulationModel.get('simulator').then((simulator) => { + let simulatorID = simulator.get('simulatorid'); + if (simulatorID) { + // add simulation data to list + self._loadDataForSimulator(simulatorID); + } else { + Ember.debug('undefined simulator id'); + } + }); + }); + }); + } 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 + this.notifyPropertyChange('model'); + }, 1000); + } + }); + }); + }.observes('model'), + + _loadDataForSimulator(simulatorID) { + // get data by simulator id + 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'); + } else { + // try to load data later + Ember.run.later(this, function() { + this._loadDataForSimulator(simulatorID); + }, 1000); + } + } +}); diff --git a/app/mixins/live-data.js b/app/mixins/live-data.js index 54d9323..139b77d 100644 --- a/app/mixins/live-data.js +++ b/app/mixins/live-data.js @@ -29,7 +29,7 @@ export default Ember.Mixin.create({ setInterval((function(self) { return function() { self._fetchRunningSimulations(); - } + }; })(this), this.INTERVAL); }, diff --git a/app/styles/app.scss b/app/styles/app.scss index c740665..3c17c3b 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -7,11 +7,11 @@ * Unauthorized copying of this file, via any medium is strictly prohibited. **********************************************************************************/ -@import 'plots.css'; -@import 'models.css'; -@import 'simulations.css'; -@import 'projects.css'; -@import 'simulators.css'; +@import 'plots'; +@import 'models'; +@import 'simulations'; +@import 'projects'; +@import 'simulators'; @import "ember-modal-dialog/ember-modal-structure"; @import "ember-modal-dialog/ember-modal-appearance"; diff --git a/app/styles/models.css b/app/styles/models.scss similarity index 100% rename from app/styles/models.css rename to app/styles/models.scss diff --git a/app/styles/plots.css b/app/styles/plots.scss similarity index 100% rename from app/styles/plots.css rename to app/styles/plots.scss diff --git a/app/styles/projects.css b/app/styles/projects.scss similarity index 97% rename from app/styles/projects.css rename to app/styles/projects.scss index 43f0f1b..5f4e5ec 100644 --- a/app/styles/projects.css +++ b/app/styles/projects.scss @@ -38,7 +38,7 @@ } .project-index-row-controls a { - margin:left: 10px; + margin-left: 10px; } .project-index-new-visualization { diff --git a/app/styles/simulations.css b/app/styles/simulations.scss similarity index 100% rename from app/styles/simulations.css rename to app/styles/simulations.scss diff --git a/app/styles/simulators.css b/app/styles/simulators.scss similarity index 100% rename from app/styles/simulators.css rename to app/styles/simulators.scss diff --git a/app/templates/visualization/edit.hbs b/app/templates/visualization/edit.hbs index ea00cf5..80e78f3 100644 --- a/app/templates/visualization/edit.hbs +++ b/app/templates/visualization/edit.hbs @@ -16,7 +16,7 @@ {{#draggable-dropzone dropped='addPlot'}} - {{plot-container plots=model.plots editing=true}} + {{plot-container plots=model.plots editing=true data=data}} {{/draggable-dropzone}}

diff --git a/tests/unit/mixins/fetch-live-data-test.js b/tests/unit/mixins/fetch-live-data-test.js new file mode 100644 index 0000000..de5b41e --- /dev/null +++ b/tests/unit/mixins/fetch-live-data-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import FetchLiveDataMixin from 'villasweb-frontend/mixins/fetch-live-data'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | fetch live data'); + +// Replace this with your real tests. +test('it works', function(assert) { + let FetchLiveDataObject = Ember.Object.extend(FetchLiveDataMixin); + let subject = FetchLiveDataObject.create(); + assert.ok(subject); +});