Cleaning up measurement edit
This commit is contained in:
parent
40f2b789e4
commit
4b6a776b63
6 changed files with 29 additions and 42 deletions
|
@ -6,12 +6,15 @@ export default Ember.Component.extend({
|
|||
|
||||
actions: {
|
||||
edit: function() {
|
||||
// The parent table fetches all of the characteristics ahead of time
|
||||
this.set('characteristics', this.store.peekAll('characteristic'));
|
||||
this.toggleProperty('isEditing');
|
||||
},
|
||||
|
||||
save: function() {
|
||||
this.toggleProperty('isEditing');
|
||||
console.log('saved');
|
||||
}
|
||||
this.get('row').save();
|
||||
},
|
||||
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
{{#if isEditing}}
|
||||
<td>
|
||||
{{input value='Foo'}}
|
||||
{{
|
||||
select-2
|
||||
multiple=false
|
||||
content=characteristics
|
||||
value=row.characteristic
|
||||
optionLabelPath="characteristicName"
|
||||
}}
|
||||
</td>
|
||||
<td>
|
||||
{{input value='Bar'}}
|
||||
{{input value=row.value}}
|
||||
</td>
|
||||
<td>
|
||||
{{input value='Baz'}}
|
||||
{{input value=row.notes}}
|
||||
</td>
|
||||
{{#if canEdit}}
|
||||
<td>
|
||||
<button class="button-gray smaller" {{action 'save'}}>
|
||||
<button class="button-red smaller" {{action 'save'}}>
|
||||
Save
|
||||
</button>
|
||||
</td>
|
||||
|
@ -22,10 +28,10 @@
|
|||
{{/link-to}}
|
||||
</td>
|
||||
<td>
|
||||
{{row.measurement.value}}
|
||||
{{row.value}}
|
||||
</td>
|
||||
<td>
|
||||
{{row.measurement.notes}}
|
||||
{{row.notes}}
|
||||
</td>
|
||||
{{#if canEdit}}
|
||||
<td>
|
||||
|
|
|
@ -5,21 +5,13 @@ export default Ember.Component.extend({
|
|||
return this.get('model.measurements.length') > 0;
|
||||
}.property('model.measurements'),
|
||||
|
||||
measurementsTable: function() {
|
||||
let measurements = this.get('model.measurements');
|
||||
let table = [];
|
||||
measurements.forEach((measurement) => {
|
||||
let row = {};
|
||||
row['measurement'] = measurement;
|
||||
row['characteristic'] = this.store.peekRecord('characteristic', measurement.get('characteristic.id'));
|
||||
table.push(row);
|
||||
});
|
||||
table.sort((a, b) => {
|
||||
let a_sort = a['characteristic'] && a['characteristic'].get('sortOrder');
|
||||
let b_sort = b['characteristic'] && b['characteristic'].get('sortOrder');
|
||||
return a_sort - b_sort;
|
||||
});
|
||||
return table;
|
||||
}.property(),
|
||||
fetchCharacteristics: function() {
|
||||
if (this.get('canEdit')) {
|
||||
this.store.findAll('characteristic');
|
||||
}
|
||||
}.on('didInsertElement'),
|
||||
|
||||
sortParams: ['characteristicTypeName', 'sortOrder', 'characteristicName'],
|
||||
sortedMeasurements: Ember.computed.sort('model.measurements', 'sortParams'),
|
||||
|
||||
});
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each measurementsTable as |row|}}
|
||||
{{#each sortedMeasurements as |measurement|}}
|
||||
{{
|
||||
protected/strains/show/measurements-table-row
|
||||
row=row
|
||||
row=measurement
|
||||
canEdit=canEdit
|
||||
}}
|
||||
{{/each}}
|
||||
|
|
|
@ -4,6 +4,7 @@ export default Ember.Component.extend({
|
|||
actions: {
|
||||
save: function() {
|
||||
// Need to override the string id for some reason
|
||||
// TODO: check this
|
||||
let strain = this.get('strain');
|
||||
let id = strain.get('species.id');
|
||||
strain.set('species.id', +id);
|
||||
|
|
Reference in a new issue