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}} {{#if isEditing}}
<td></td> <td>
{{{characteristic.characteristicTypeName}}}
</td>
<td> <td>
<select onchange={{action "characteristicDidChange" value="target.value"}}> <select onchange={{action "characteristicDidChange" value="target.value"}}>
{{#each allCharacteristics as |characteristicChoice|}} {{#each allCharacteristics as |characteristicChoice|}}

View file

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

View file

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