Clean up characteristics dropdown

This commit is contained in:
Matthew Dillon 2015-12-01 19:25:29 -07:00
parent 2811143066
commit 9496de21d9
3 changed files with 24 additions and 8 deletions

View file

@ -1,5 +1,7 @@
{{#if isEditing}}
<td></td>
<td>
{{{characteristic.characteristicTypeName}}}
</td>
<td>
<select onchange={{action "characteristicDidChange" value="target.value"}}>
{{#each allCharacteristics as |characteristicChoice|}}

View file

@ -35,10 +35,29 @@ export default Component.extend(SetupMetaData, {
notes: null,
measurements: [],
// Dropdown menu
characteristics: [],
sortParams: ['characteristicTypeName', 'sortOrder', 'characteristicName'],
sortedCharacteristics: sort('characteristics', 'sortParams'),
setupCharacteristics: Ember.on('init', function() {
const tempArray = this._resetArray(this.get('allCharacteristics'));
this.set('characteristics', tempArray);
}),
resetOnInit: Ember.on('init', function() {
this._resetProperties();
}),
_resetArray: function(arr) {
let tempArray = [];
arr.forEach((val) => {
if (!val.get('isNew')) {
tempArray.push(val);
}
});
return tempArray;
},
_resetProperties: function() {
// Still some coupling going on here because of adding strain to measurement
this.get('measurements').forEach((val) => {
@ -52,12 +71,7 @@ export default Component.extend(SetupMetaData, {
this.get('propertiesList').forEach((field) => {
const valueInStrain = this.get('strain').get(field);
if (field === 'measurements') {
let tempArray = [];
valueInStrain.forEach((val) => {
if (!val.get('isNew')) {
tempArray.push(val);
}
});
const tempArray = this._resetArray(valueInStrain);
this.set(field, tempArray);
} else {
this.set(field, valueInStrain);

View file

@ -63,7 +63,7 @@
protected/strains/measurements-table
measurements=measurements
add-characteristic=(action "addCharacteristic")
allCharacteristics=allCharacteristics
allCharacteristics=sortedCharacteristics
save-measurement=(action "saveMeasurement")
delete-measurement=(action "deleteMeasurement")
canEdit=strain.canEdit