Add characteristic/measurement to strain

This commit is contained in:
Matthew Dillon 2015-09-29 15:55:34 -07:00
parent 34aa59caf3
commit da27b42f76
6 changed files with 25 additions and 1 deletions

View file

@ -17,6 +17,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
setupController: function(controller, models) { setupController: function(controller, models) {
controller.setProperties(models); controller.setProperties(models);
controller.set('metaData', this.store.metadataFor('strain'));
}, },
}); });

View file

@ -2,6 +2,7 @@
protected/strains/strain-form protected/strains/strain-form
strain=strain strain=strain
species=species species=species
canAdd=metaData.canAdd
save="save" save="save"
cancel="cancel" cancel="cancel"
}} }}

View file

@ -11,7 +11,19 @@ export default Ember.Component.extend({
} }
}.on('didInsertElement'), }.on('didInsertElement'),
sortParams: ['characteristicTypeName', 'sortOrder', 'characteristicName'], sortParams: ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName'],
sortedMeasurements: Ember.computed.sort('model.measurements', 'sortParams'), 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);
},
},
}); });

View file

@ -1,3 +1,11 @@
{{#if canAdd}}
<br>
<button class="button-green smaller" {{action "addCharacteristic"}}>
Add characteristic
</button>
<br><br>
{{/if}}
{{#if measurementsPresent}} {{#if measurementsPresent}}
<table class="flakes-table"> <table class="flakes-table">
<colgroup> <colgroup>

View file

@ -77,6 +77,7 @@
protected/strains/show/measurements-table protected/strains/show/measurements-table
model=model model=model
canEdit=false canEdit=false
canAdd=false
}} }}
</dd> </dd>
</dl> </dl>

View file

@ -54,6 +54,7 @@
protected/strains/show/measurements-table protected/strains/show/measurements-table
model=strain model=strain
canEdit=strain.canEdit canEdit=strain.canEdit
canAdd=canAdd
}} }}
</div> </div>
<br> <br>