2016-07-20 12:25:51 +02:00
|
|
|
/**
|
2016-11-02 18:32:24 +01:00
|
|
|
* File: widget-value.js
|
2016-07-20 12:25:51 +02:00
|
|
|
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
|
|
|
|
* Date: 04.07.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.
|
|
|
|
**********************************************************************************/
|
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
import WidgetAbstract from './widget-abstract';
|
2016-10-18 13:01:55 +02:00
|
|
|
import Ember from 'ember';
|
2016-06-28 14:23:49 +02:00
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
export default WidgetAbstract.extend({
|
|
|
|
classNames: [ 'widgetValue' ],
|
2016-07-15 12:09:31 +02:00
|
|
|
|
|
|
|
minWidth_resize: 50,
|
2016-10-12 08:30:15 +02:00
|
|
|
minHeight_resize: 20,
|
|
|
|
|
2017-01-31 22:12:24 +01:00
|
|
|
observeQuery: null,
|
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
_updateDataObserver: Ember.on('init', Ember.observer('widget.widgetData.simulator', 'widget.widgetData.signal', function() {
|
2017-01-31 22:12:24 +01:00
|
|
|
// update observer
|
2016-11-02 18:32:24 +01:00
|
|
|
let query = 'data.' + this.get('widget.widgetData.simulator') + '.sequence';
|
2017-01-31 22:12:24 +01:00
|
|
|
let observeQuery = this.get('observeQuery');
|
|
|
|
if (observeQuery != null) {
|
|
|
|
this.removeObserver(observeQuery, this._updateData);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addObserver(query, this._updateData);
|
|
|
|
this.set('observeQuery', query);
|
2016-10-18 19:45:14 +02:00
|
|
|
})),
|
2016-10-12 22:06:24 +02:00
|
|
|
|
2017-01-31 22:12:24 +01:00
|
|
|
_updateData() {
|
|
|
|
// get value from array
|
|
|
|
let values = this.get('data.' + this.get('widget.widgetData.simulator') + '.values');
|
|
|
|
if (values) {
|
|
|
|
this.set('value', values[this.get('widget.widgetData.signal')]);
|
|
|
|
} else {
|
|
|
|
this.set('value', null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-10-12 22:06:24 +02:00
|
|
|
doubleClick() {
|
|
|
|
if (this.get('editing') === true) {
|
|
|
|
// prepare modal
|
2016-11-02 18:32:24 +01:00
|
|
|
this.set('name', this.get('widget.name'));
|
2017-02-04 15:31:57 +01:00
|
|
|
this.set('errorMessage', null);
|
2016-10-12 22:06:24 +02:00
|
|
|
|
|
|
|
// get signal mapping for simulation model
|
|
|
|
let self = this;
|
2016-11-02 18:32:24 +01:00
|
|
|
let simulatorid = this.get('widget.widgetData.simulator');
|
2016-10-12 22:06:24 +02:00
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
this.get('widget.visualization').then((visualization) => {
|
2016-10-12 22:06:24 +02:00
|
|
|
visualization.get('project').then((project) => {
|
|
|
|
project.get('simulation').then((simulation) => {
|
|
|
|
simulation.get('models').then((simulationModels) => {
|
|
|
|
// find simulation model by simulatorid
|
|
|
|
simulationModels.forEach(function(simulationModel) {
|
|
|
|
simulationModel.get('simulator').then((simulator) => {
|
|
|
|
if (simulator.get('simulatorid') === simulatorid) {
|
|
|
|
// set simulation model
|
|
|
|
self.set('simulationModel', simulationModel);
|
|
|
|
self.set('simulationModelName', simulationModel.get('name'));
|
|
|
|
|
|
|
|
// set signal
|
|
|
|
let mapping = simulationModel.get('mapping');
|
2016-11-02 18:32:24 +01:00
|
|
|
self.set('signalName', mapping[self.get('widget.widgetData.signal')]);
|
2016-10-12 22:06:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-03 09:42:16 +01:00
|
|
|
// show modal
|
2016-10-12 22:06:24 +02:00
|
|
|
this.set('isShowingModal', true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
submitModal() {
|
|
|
|
// verify properties
|
|
|
|
let properties = this.getProperties('name');
|
2016-11-02 18:32:24 +01:00
|
|
|
|
2016-10-12 22:06:24 +02:00
|
|
|
// set simulator by simulation model name
|
|
|
|
let simulationModelName = this.get('simulationModelName');
|
|
|
|
let self = this;
|
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
this.get('widget.visualization').then((visualization) => {
|
2016-10-12 22:06:24 +02:00
|
|
|
visualization.get('project').then((project) => {
|
|
|
|
project.get('simulation').then((simulation) => {
|
|
|
|
simulation.get('models').then((simulationModels) => {
|
|
|
|
// find simulation model by name
|
|
|
|
simulationModels.forEach(function(simulationModel) {
|
|
|
|
if (simulationModel.get('name') === simulationModelName) {
|
|
|
|
simulationModel.get('simulator').then((simulator) => {
|
|
|
|
// set simulator
|
2016-11-02 18:32:24 +01:00
|
|
|
let widgetData = {};
|
|
|
|
widgetData.simulator = simulator.get('simulatorid');
|
2016-10-12 22:06:24 +02:00
|
|
|
|
|
|
|
// set signal by name
|
|
|
|
let mapping = simulationModel.get('mapping');
|
|
|
|
let signalName = self.get('signalName');
|
|
|
|
|
|
|
|
for (let i = 0; i < mapping.length; i++) {
|
|
|
|
if (mapping[i] === signalName) {
|
2016-11-02 18:32:24 +01:00
|
|
|
widgetData.signal = i;
|
2016-10-12 22:06:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save properties
|
2016-11-02 18:32:24 +01:00
|
|
|
properties['widgetData'] = widgetData;
|
|
|
|
|
|
|
|
self.get('widget').setProperties(properties);
|
2016-10-12 22:06:24 +02:00
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
self.get('widget').save().then(function() {
|
2016-10-12 22:06:24 +02:00
|
|
|
self.set('isShowingModal', false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelModal() {
|
|
|
|
this.set('isShowingModal', false);
|
|
|
|
},
|
|
|
|
|
2017-01-12 16:24:46 +01:00
|
|
|
deleteModal() {
|
|
|
|
// delete widget
|
|
|
|
this.get('widget').destroyRecord();
|
|
|
|
|
|
|
|
this.set('isShowingModal', false);
|
|
|
|
},
|
|
|
|
|
2016-10-12 22:06:24 +02:00
|
|
|
selectSimulationModel(simulationModelName) {
|
|
|
|
// save simulation model
|
|
|
|
this.set('simulationModelName', simulationModelName);
|
|
|
|
|
|
|
|
// get signal mapping for simulation model
|
|
|
|
let self = this;
|
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
this.get('widget.visualization').then((visualization) => {
|
2016-10-12 22:06:24 +02:00
|
|
|
visualization.get('project').then((project) => {
|
|
|
|
project.get('simulation').then((simulation) => {
|
|
|
|
simulation.get('models').then((simulationModels) => {
|
|
|
|
// find simulation model by name
|
|
|
|
simulationModels.forEach(function(simulationModel) {
|
|
|
|
if (simulationModel.get('name') === simulationModelName) {
|
|
|
|
self.set('simulationModel', simulationModel);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
selectSignal(signalName) {
|
|
|
|
this.set('signalName', signalName);
|
|
|
|
}
|
|
|
|
}
|
2016-06-28 14:23:49 +02:00
|
|
|
});
|