1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-23 00:00:02 +01:00
VILLASweb/app/controllers/visualization/index.js
Markus Grigull 59c9438ce1 Add live data flow from visualization to plots
Fix live-data mixin
2016-10-12 08:30:15 +02:00

74 lines
2.4 KiB
JavaScript

/**
* File: index.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 28.06.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.Controller.extend({
data: {},
/*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);
}
}
});