2016-07-20 12:25:51 +02:00
|
|
|
/**
|
|
|
|
* File: edit.js
|
|
|
|
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
|
|
|
|
* Date: 05.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-06-28 22:05:54 +02:00
|
|
|
import Ember from 'ember';
|
2016-10-12 09:10:41 +02:00
|
|
|
import FetchLiveDataMixin from '../../mixins/fetch-live-data';
|
2016-06-28 22:05:54 +02:00
|
|
|
|
2016-10-12 09:10:41 +02:00
|
|
|
export default Ember.Controller.extend(FetchLiveDataMixin, {
|
2016-11-02 18:32:24 +01:00
|
|
|
isShowingWidgetValueModal: false,
|
2016-10-12 11:29:09 +02:00
|
|
|
|
|
|
|
errorMessage: null,
|
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
widget: null,
|
2016-10-12 11:29:09 +02:00
|
|
|
name: null,
|
|
|
|
simulator: null,
|
2016-10-12 22:06:24 +02:00
|
|
|
simulatorName: null,
|
2016-10-12 11:29:09 +02:00
|
|
|
signal: null,
|
|
|
|
|
2016-06-28 22:05:54 +02:00
|
|
|
actions: {
|
2017-01-12 16:24:46 +01:00
|
|
|
addWidget(name, position) {
|
2016-11-24 12:19:34 +01:00
|
|
|
// get first simulator id
|
|
|
|
let defaultSimulatorid = 0;
|
|
|
|
|
|
|
|
this.get('model.project').then((project) => {
|
|
|
|
project.get('simulation').then((simulation) => {
|
|
|
|
simulation.get('models').then((simulationModels) => {
|
|
|
|
simulationModels.toArray()[0].get('simulator').then((simulator) => {
|
|
|
|
defaultSimulatorid = simulator.get('simulatorid');
|
|
|
|
|
|
|
|
// create widget
|
|
|
|
let widget = null;
|
2017-01-13 17:11:48 +01:00
|
|
|
let properties = {
|
|
|
|
x: position.x,
|
|
|
|
y: position.y,
|
|
|
|
name: 'widget',
|
|
|
|
type: null
|
|
|
|
};
|
2016-11-24 12:19:34 +01:00
|
|
|
|
|
|
|
if (name === 'label') {
|
2017-01-13 17:11:48 +01:00
|
|
|
properties.type = 'widget-label';
|
|
|
|
properties.width = 100;
|
|
|
|
properties.height = 20;
|
|
|
|
properties.name = 'Label';
|
2016-11-24 12:19:34 +01:00
|
|
|
} else if (name === 'table') {
|
2017-01-13 17:11:48 +01:00
|
|
|
properties.type = 'widget-table';
|
|
|
|
properties.name = "Table";
|
|
|
|
properties.width = 500;
|
2017-01-25 19:36:23 +01:00
|
|
|
properties.height = 200;
|
2017-01-13 17:11:48 +01:00
|
|
|
properties.widgetData = { simulator: defaultSimulatorid };
|
2016-11-24 12:19:34 +01:00
|
|
|
} else if (name === 'value') {
|
2017-01-13 17:11:48 +01:00
|
|
|
properties.type = 'widget-value';
|
|
|
|
properties.name = 'Value';
|
|
|
|
properties.width = 250;
|
|
|
|
properties.height = 20;
|
|
|
|
properties.widgetData = { signal: 0, simulator: defaultSimulatorid };
|
|
|
|
} else if (name === 'plot') {
|
|
|
|
properties.type = 'widget-plot';
|
|
|
|
properties.name = 'Plot';
|
|
|
|
properties.width = 500;
|
2017-01-25 12:54:34 +01:00
|
|
|
properties.height = 400;
|
2017-02-01 13:33:55 +01:00
|
|
|
properties.widgetData = { signals: [0], simulator: defaultSimulatorid, type: 'multiple', time: 300 };
|
2017-01-25 19:36:23 +01:00
|
|
|
} else if (name === 'image') {
|
|
|
|
properties.type = 'widget-image';
|
|
|
|
properties.name = 'Image';
|
|
|
|
properties.width = 300;
|
|
|
|
properties.height = 300;
|
|
|
|
properties.widgetData = { path: null };
|
2016-11-24 12:19:34 +01:00
|
|
|
} else {
|
|
|
|
// DEBUG
|
2017-01-13 17:11:48 +01:00
|
|
|
console.log('Add unknown widget ' + name);
|
2016-11-24 12:19:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-13 17:11:48 +01:00
|
|
|
if (properties.type != null) {
|
|
|
|
// create widget
|
|
|
|
widget = this.store.createRecord('widget', properties);
|
|
|
|
|
2016-11-24 12:19:34 +01:00
|
|
|
// add widget to visualization
|
|
|
|
this.get('model.widgets').pushObject(widget);
|
|
|
|
|
|
|
|
// save new widget
|
|
|
|
var visualization = this.get('model');
|
|
|
|
|
|
|
|
widget.save().then(function() {
|
|
|
|
// save the widget in the visualization
|
|
|
|
visualization.get('widgets').pushObject(widget);
|
|
|
|
visualization.save();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.error('Unknown widget type: ' + name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-06-28 22:05:54 +02:00
|
|
|
});
|
2016-11-24 12:19:34 +01:00
|
|
|
});
|
2016-07-17 18:43:08 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
saveEdit() {
|
|
|
|
// save changes to store
|
2016-11-02 18:32:24 +01:00
|
|
|
var widgets = this.get('model.widgets');
|
|
|
|
widgets.forEach(function(widget) {
|
|
|
|
widget.save();
|
2016-07-17 18:43:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// go back to index
|
|
|
|
var id = this.get('model.id');
|
|
|
|
this.transitionToRoute('/visualization/' + id);
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelEdit() {
|
|
|
|
// TODO: revert changes
|
|
|
|
|
|
|
|
let id = this.get('model.id');
|
|
|
|
this.transitionToRoute('/visualization/' + id);
|
2016-10-12 11:29:09 +02:00
|
|
|
},
|
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
showWidgetDialog(widget) {
|
|
|
|
// show dialog by widget type
|
|
|
|
let widgetType = widget.get('type');
|
|
|
|
if (widgetType === 'value') {
|
2016-10-12 11:29:09 +02:00
|
|
|
// set properties
|
2016-11-02 18:32:24 +01:00
|
|
|
this.set('widget', widget);
|
2016-10-12 22:06:24 +02:00
|
|
|
/*this.set('name', plot.get('name'));
|
|
|
|
this.set('signal', plot.get('signal'));*/
|
|
|
|
|
|
|
|
//this.set('simulatorName', simulatorName);
|
2016-10-12 11:29:09 +02:00
|
|
|
|
2016-11-02 18:32:24 +01:00
|
|
|
this.set('isShowingWidgetValueModal', true);
|
2016-10-12 11:29:09 +02:00
|
|
|
}
|
2016-06-28 22:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|