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/edit.js

138 lines
4.5 KiB
JavaScript
Raw Normal View History

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.
**********************************************************************************/
import Ember from 'ember';
import FetchLiveDataMixin from '../../mixins/fetch-live-data';
export default Ember.Controller.extend(FetchLiveDataMixin, {
isShowingWidgetValueModal: false,
2016-10-12 11:29:09 +02:00
errorMessage: null,
widget: null,
2016-10-12 11:29:09 +02:00
name: null,
simulator: null,
simulatorName: null,
2016-10-12 11:29:09 +02:00
signal: null,
actions: {
addWidget(name, position) {
// 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;
let properties = {
x: position.x,
y: position.y,
name: 'widget',
type: null
};
if (name === 'label') {
properties.type = 'widget-label';
properties.width = 100;
properties.height = 20;
properties.name = 'Label';
} else if (name === 'table') {
properties.type = 'widget-table';
properties.name = "Table";
properties.width = 500;
properties.height = 200;
properties.widgetData = { simulator: defaultSimulatorid };
} else if (name === 'value') {
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;
properties.widgetData = { signals: [0], simulator: defaultSimulatorid, type: 'multiple', time: 300 };
} else if (name === 'image') {
properties.type = 'widget-image';
properties.name = 'Image';
properties.width = 300;
properties.height = 300;
properties.widgetData = { path: null };
} else {
// DEBUG
console.log('Add unknown widget ' + name);
return;
}
if (properties.type != null) {
// create widget
widget = this.store.createRecord('widget', properties);
// 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);
}
});
});
});
});
},
saveEdit() {
// save changes to store
var widgets = this.get('model.widgets');
widgets.forEach(function(widget) {
widget.save();
});
// 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
},
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
this.set('widget', widget);
/*this.set('name', plot.get('name'));
this.set('signal', plot.get('signal'));*/
//this.set('simulatorName', simulatorName);
2016-10-12 11:29:09 +02:00
this.set('isShowingWidgetValueModal', true);
2016-10-12 11:29:09 +02:00
}
}
}
});