1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Fix default simulator on creating widgets

This commit is contained in:
Markus Grigull 2016-11-24 12:19:34 +01:00
parent 7099651272
commit 021457a141
2 changed files with 39 additions and 24 deletions

View file

@ -8,6 +8,7 @@
**********************************************************************************/
import WidgetAbstract from './widget-abstract';
import Ember from 'ember';
export default WidgetAbstract.extend({
classNames: [ 'widgetTable' ],

View file

@ -23,35 +23,49 @@ export default Ember.Controller.extend(FetchLiveDataMixin, {
actions: {
addWidget(name) {
let widget = null;
// get first simulator id
let defaultSimulatorid = 0;
if (name === 'label') {
widget = this.store.createRecord('widget', { name: 'Label', type: 'widget-label', width: 100, height: 20 });
} else if (name === 'table') {
widget = this.store.createRecord('widget', { name: 'Table 1', type: 'widget-table', width: 500, height: 200, widgetData: { simulator: 2 } });
} else if (name === 'value') {
widget = this.store.createRecord('widget', { name: 'Value 1', type: 'widget-value', width: 250, height: 20, widgetData: { signal: 0, simulator: 2 } });
} else {
// DEBUG
console.log('Add widget ' + name);
return;
}
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');
if (widget != null) {
// add widget to visualization
this.get('model.widgets').pushObject(widget);
// create widget
let widget = null;
// save new widget
var visualization = this.get('model');
if (name === 'label') {
widget = this.store.createRecord('widget', { name: 'Label', type: 'widget-label', width: 100, height: 20 });
} else if (name === 'table') {
widget = this.store.createRecord('widget', { name: 'Table 1', type: 'widget-table', width: 500, height: 200, widgetData: { simulator: defaultSimulatorid } });
} else if (name === 'value') {
widget = this.store.createRecord('widget', { name: 'Value 1', type: 'widget-value', width: 250, height: 20, widgetData: { signal: 0, simulator: defaultSimulatorid } });
} else {
// DEBUG
console.log('Add widget ' + name);
return;
}
widget.save().then(function() {
// save the widget in the visualization
visualization.get('widgets').pushObject(widget);
visualization.save();
if (widget != null) {
// 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);
}
});
});
});
} else {
console.error('Unknown widget type: ' + name);
}
});
},
saveEdit() {