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

Add signal naming

Simulation model length changes adopt to the mapping size.
This commit is contained in:
Markus Grigull 2016-10-20 12:38:48 +02:00
parent 68d33e0b18
commit 0423d7f3dc
3 changed files with 76 additions and 22 deletions

View file

@ -10,4 +10,39 @@
import Ember from 'ember';
export default Ember.Controller.extend({
_setSignalNames: Ember.observer('model', 'model.length', function() {
// loop through signals
let length = this.get('model.length');
let mapping = this.get('model.mapping');
for (let i = 0; i < length; i++) {
this.set('name' + i, mapping[i]);
}
}),
actions: {
saveMapping() {
// save all signal names
let length = this.get('model.length');
let mapping = this.get('model.mapping');
for (let i = 0; i < length; i++) {
mapping[i] = this.get('name' + i);
}
this.set('model.mapping', mapping);
// save the changed model
let self = this;
this.get('model').save().then(function() {
// go back to simulation
self.get('model.simulation').then((simulation) => {
self.transitionToRoute('/simulation/' + simulation.get('id'));
});
}, function() {
Ember.debug('Unable to save simulation model');
});
}
}
});

View file

@ -94,7 +94,7 @@ export default Ember.Controller.extend({
let mapping = [];
for (let i = 0; i < properties['length']; i++) {
mapping.pushObject("Signal " + (i + 1));
mapping.push('Signal ' + (i + 1));
}
properties['mapping'] = mapping;
@ -140,6 +140,23 @@ export default Ember.Controller.extend({
}
});
// change mapping
let mapping = this.get('simulationModel.mapping');
if (mapping.length < properties['length']) {
// add more signals
for (let i = mapping.length; i < properties['length']; i++) {
mapping.push('Signal ' + (i + 1));
}
} else if (mapping.length > properties['length']) {
// remove signals
mapping = mapping.slice(0, Number(properties['length']));
}
console.log(mapping);
properties['mapping'] = mapping;
// save properties
let controller = this;

View file

@ -2,28 +2,30 @@
<h1>{{model.name}}</h1>
<h3>Mapping</h3>
<form {{action 'saveMapping' on='submit'}}>
<h3>Mapping</h3>
<div class="simulation-model-index-mapping">
<table class="table-full-width">
<tr>
<th width="80px">Signal</th>
<th>Name</th>
</tr>
{{#each-in model.mapping as |signal name|}}
<div class="simulation-model-index-mapping">
<table class="table-full-width">
<tr>
<td>
{{signal}}
</td>
<td>
{{name}}
</td>
<th width="80px">Signal</th>
<th>Name</th>
</tr>
{{/each-in}}
</table>
</div>
{{#each-in model.mapping as |signal name|}}
<tr>
<td>
{{signal}}
</td>
<td>
{{input value=(mut (get this (concat 'name' signal)))}}
</td>
</tr>
{{/each-in}}
</table>
</div>
<div class="simulation-model-index-buttons">
<!-- <button {{action 'cancelMapping'}}>Cancel</button> -->
<button {{action 'saveMapping'}}>Save</button>
</div>
<div class="simulation-model-index-buttons">
<!-- <button {{action 'cancelMapping'}}>Cancel</button> -->
<button type="submit">Save</button>
</div>
</form>