Refactor characteristics/show

This commit is contained in:
Matthew Dillon 2015-11-05 13:46:29 -07:00
parent 9715aac1f5
commit 31c4ff4d52
6 changed files with 95 additions and 72 deletions

View file

@ -0,0 +1,14 @@
import Ember from 'ember';
const { Component } = Ember;
export default Component.extend({
characteristic: null,
"on-delete": null,
actions: {
deleteCharacteristic: function() {
return this.attrs['on-delete']();
},
},
});

View file

@ -0,0 +1,55 @@
<div class="grid-1">
<div class="span-1">
<fieldset class="flakes-information-box">
<legend>
{{characteristic.characteristicName}}
</legend>
{{! ROW 1 }}
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Characteristic Type</dt>
<dd>
{{characteristic.characteristicTypeName}}
</dd>
</dl>
<dl class="span-1">
<dt>Sort Order</dt>
<dd>
{{characteristic.sortOrder}}
</dd>
</dl>
</div>
{{! ROW 2 }}
<div class="grid-2 gutter-20">
<dl class="span-2">
<dt>Measurements</dt>
<dd>
<p>To add/edit/remove a measurement, please visit the strain's page (links below)</p>
{{protected/characteristics/show/measurements-table characteristic=characteristic}}
</dd>
</dl>
</div>
{{! ROW 3 }}
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Record Created</dt>
<dd>{{null-time characteristic.createdAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Updated</dt>
<dd>{{null-time characteristic.updatedAt 'LL'}}</dd>
</dl>
</div>
</fieldset>
</div>
</div>
{{#if characteristic.canEdit}}
<br>
{{#link-to 'protected.characteristics.edit' characteristic.id class="button-gray smaller"}}
Edit
{{/link-to}}
{{delete-button delete=(action 'deleteCharacteristic')}}
{{/if}}

View file

@ -1,12 +1,9 @@
import Ember from 'ember';
import DeleteModel from '../../../../mixins/delete-model';
export default Ember.Controller.extend({
actions: {
delete: function() {
this.get('model').destroyRecord().then(() => {
this.transitionToRoute('protected.characteristics.index');
});
},
},
const { Controller } = Ember;
export default Controller.extend(DeleteModel, {
// Required for DeleteModel mixin
transitionRoute: 'protected.characteristics.index',
});

View file

@ -1,19 +1,24 @@
import Ember from 'ember';
export default Ember.Component.extend({
measurementsPresent: function() {
return this.get('model.measurements.length') > 0;
}.property('model.measurements'),
const { Component, computed } = Ember;
const { sort } = computed;
export default Component.extend({
characteristic: null,
measurementsPresent: computed('characteristic', function() {
return this.get('characteristic.measurements.length') > 0;
}),
sortParams: ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName'],
sortAsc: true,
paramsChanged: false,
sortedMeasurements: Ember.computed.sort('model.measurements', 'sortParams'),
sortedMeasurements: sort('characteristic.measurements', 'sortParams'),
actions: {
changeSortParam: function(col) {
let sort = this.get('sortAsc') ? 'asc' : 'desc';
let sortCol = `${col}:${sort}`;
const sort = this.get('sortAsc') ? 'asc' : 'desc';
const sortCol = `${col}:${sort}`;
this.set('sortParams', [sortCol]);
this.set('paramsChanged', true);
this.toggleProperty('sortAsc');

View file

@ -1,8 +1,10 @@
import Ember from 'ember';
export default Ember.Route.extend({
const { Route } = Ember;
export default Route.extend({
model: function(params) {
return this.store.findRecord('characteristic', params.characteristic_id, { reload: true });
return this.store.findRecord('characteristic', params.characteristic_id);
},
});

View file

@ -1,55 +1,5 @@
<div class="grid-1">
<div class="span-1">
<fieldset class="flakes-information-box">
<legend>
{{model.characteristicName}}
</legend>
{{! ROW 1 }}
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Characteristic Type</dt>
<dd>
{{model.characteristicTypeName}}
</dd>
</dl>
<dl class="span-1">
<dt>Sort Order</dt>
<dd>
{{model.sortOrder}}
</dd>
</dl>
</div>
{{! ROW 2 }}
<div class="grid-2 gutter-20">
<dl class="span-2">
<dt>Measurements</dt>
<dd>
<p>To add/edit/remove a measurement, please visit the strain's page (links below)</p>
{{protected/characteristics/show/measurements-table model=model}}
</dd>
</dl>
</div>
{{! ROW 3 }}
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Record Created</dt>
<dd>{{null-time model.createdAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Updated</dt>
<dd>{{null-time model.updatedAt 'LL'}}</dd>
</dl>
</div>
</fieldset>
</div>
</div>
{{#if model.canEdit}}
<br>
{{#link-to 'protected.characteristics.edit' model.id class="button-gray smaller"}}
Edit
{{/link-to}}
{{delete-button delete=(action 'delete')}}
{{/if}}
{{
protected/characteristics/show/characteristic-card
characteristic=model
on-delete=(action 'delete')
}}