Step one, move up to pod root

This commit is contained in:
Matthew Dillon 2015-11-10 14:35:17 -07:00
parent fa5b741e35
commit 48cd1f4f39
8 changed files with 3 additions and 4 deletions

View file

@ -1 +0,0 @@
{{loading-panel}}

View file

@ -1,49 +0,0 @@
import Ember from 'ember';
import ajaxError from '../../../../../utils/ajax-error';
const { Component } = Ember;
export default Component.extend({
tagName: 'tr',
isEditing: false,
oldCharacteristicId: function() {
let json = this.get('row').toJSON();
return json.characteristic;
}.property(),
rowChanged: Ember.computed('row.notes', 'row.value', 'row.characteristic.id', function() {
return this.get('row.hasDirtyAttributes') ||
this.get('oldCharacteristicId') !== this.get('row.characteristic.id');
}),
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() {
if (this.get('rowChanged')) {
this.get('row').save().then(() => {
this.get('flashMessages').clearMessages();
this.toggleProperty('isEditing');
}, () => {
ajaxError(this.get('row.errors'), this.get('flashMessages'));
});
} else {
this.toggleProperty('isEditing');
}
},
delete: function() {
let char = this.get('row.characteristic');
if (char.get('isNew')) {
char.destroyRecord();
}
this.get('row').destroyRecord();
}
},
});

View file

@ -1,54 +0,0 @@
{{#if isEditing}}
<td></td>
<td>
{{
select-2
multiple=false
content=characteristics
value=row.characteristic
optionLabelPath="characteristicName"
}}
</td>
<td>
{{input value=row.value}}
</td>
<td>
{{input value=row.notes}}
</td>
{{#if canEdit}}
<td>
{{#if rowChanged}}
<button class="button-green smaller" {{action 'save'}}>
Save
</button>
{{else}}
<button class="button-gray smaller" {{action 'save'}}>
Cancel
</button>
{{/if}}
</td>
{{/if}}
{{else}}
<td>
{{{row.characteristic.characteristicTypeName}}}
</td>
<td>
{{#link-to 'protected.characteristics.show' row.characteristic.id}}
{{{row.characteristic.characteristicName}}}
{{/link-to}}
</td>
<td>
{{row.value}}
</td>
<td>
{{row.notes}}
</td>
{{#if canEdit}}
<td>
<button class="button-gray smaller" {{action 'edit'}}>
Edit
</button>
{{delete-button delete=(action 'delete')}}
</td>
{{/if}}
{{/if}}

View file

@ -1,49 +0,0 @@
import Ember from 'ember';
const { Component } = Ember;
export default Component.extend({
measurementsPresent: function() {
return this.get('model.measurements.length') > 0;
}.property('model.measurements'),
fetchCharacteristics: function() {
if (this.get('canEdit')) {
this.store.findAll('characteristic');
}
}.on('didInsertElement'),
sortParams: ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName'],
sortAsc: true,
paramsChanged: false,
sortedMeasurements: Ember.computed.sort('model.measurements', 'sortParams'),
actions: {
addCharacteristic: function() {
const c = this.store.createRecord('characteristic', {
sortOrder: -999
});
const m = this.store.createRecord('measurement', {
characteristic: c
});
this.get('model.measurements').addObject(m);
},
changeSortParam: function(col) {
let sort = this.get('sortAsc') ? 'asc' : 'desc';
let sortCol = `${col}:${sort}`;
this.set('sortParams', [sortCol]);
this.set('paramsChanged', true);
this.toggleProperty('sortAsc');
return false;
},
resetSortParam: function() {
this.set('sortParams', ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName']);
this.set('paramsChanged', false);
this.set('sortAsc', true);
return false;
},
},
});

View file

@ -1,53 +0,0 @@
{{#if canAdd}}
<br>
<button class="button-green smaller" {{action "addCharacteristic"}}>
Add characteristic
</button>
<br><br>
{{/if}}
{{#if measurementsPresent}}
{{#if paramsChanged}}
<button class="button-gray smaller" {{action 'resetSortParam'}}>
Reset sort
</button>
{{/if}}
<table class="flakes-table">
<colgroup>
{{#if canEdit}}
<col span="1" style="width:10%">
<col span="1" style="width:30%">
<col span="1" style="width:20%">
<col span="1" style="width:20%">
<col span="1" style="width:20%">
{{else}}
<col span="1" style="width:10%">
<col span="1" style="width:30%">
<col span="1" style="width:30%">
<col span="1" style="width:30%">
{{/if}}
</colgroup>
<thead>
<tr>
<th {{action "changeSortParam" "characteristic.characteristicTypeName"}} class="click">Type</th>
<th {{action "changeSortParam" "characteristic.characteristicName"}} class="click">Characteristic</th>
<th {{action "changeSortParam" "value"}} class="click">Value</th>
<th {{action "changeSortParam" "notes"}} class="click">Notes</th>
{{#if canEdit}}
<th>Edit</th>
{{/if}}
</tr>
</thead>
<tbody>
{{#each sortedMeasurements as |measurement|}}
{{
protected/strains/show/measurements-table-row
row=measurement
canEdit=canEdit
}}
{{/each}}
</tbody>
</table>
{{else}}
No measurements on record.
{{/if}}

View file

@ -74,7 +74,7 @@
<dt>Characteristics</dt>
<dd>
{{
protected/strains/show/measurements-table
protected/strains/measurements-table
model=strain
canEdit=false
canAdd=false