Refactor strains/index

This commit is contained in:
Matthew Dillon 2015-11-10 11:13:22 -07:00
parent 35475c2b92
commit 85d861da27
6 changed files with 46 additions and 42 deletions

View file

@ -1,12 +1,12 @@
import Ember from 'ember'; import Ember from 'ember';
import SetupMetaData from '../../../../../mixins/setup-metadata'; import SetupMetaData from '../../../../../mixins/setup-metadata';
const { Component } = Ember; const { Component, computed: { sort } } = Ember;
export default Component.extend(SetupMetaData, { export default Component.extend(SetupMetaData, {
species: null, species: null,
sortParams: ['speciesName', 'strainCount'], sortParams: ['speciesName', 'strainCount'],
sortedSpecies: Ember.computed.sort('species', 'sortParams'), sortedSpecies: sort('species', 'sortParams'),
}); });

View file

@ -1,6 +0,0 @@
import Ember from 'ember';
export default Ember.Controller.extend({
sortParams: ['sortOrder'],
sortedStrains: Ember.computed.sort('model', 'sortParams'),
});

View file

@ -1,17 +1,10 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Route.extend({ const { Route } = Ember;
currentUser: Ember.inject.service('session-account'),
export default Route.extend({
model: function() { model: function() {
return this.store.findAll('strain'); return this.store.findAll('strain');
}, },
setupController: function(controller, model) {
controller.set('model', model);
this.get('currentUser.account').then((user) => {
controller.set('metaData', user.get('metaData'));
});
},
}); });

View file

@ -0,0 +1,12 @@
import Ember from 'ember';
import SetupMetaData from '../../../../../mixins/setup-metadata';
const { Component, computed: { sort } } = Ember;
export default Component.extend(SetupMetaData, {
strains: null,
sortParams: ['fullNameMU'],
sortedStrains: sort('strains', 'sortParams'),
});

View file

@ -0,0 +1,26 @@
<h3 id="total-strains">Total strains: {{strains.length}}</h3>
{{add-button label="Add Strain" link="protected.strains.new" canAdd=metaData.canAdd}}
<table class="flakes-table">
<thead>
<tr>
<th>Species</th>
<th>Total Measurements</th>
</tr>
</thead>
<tbody>
{{#each sortedStrains as |strain|}}
<tr>
<td>
{{#link-to 'protected.strains.show' strain classBinding="data.typeStrain:type-strain"}}
{{strain.fullNameMU}}
{{/link-to}}
</td>
<td>
{{strain.totalMeasurements}}
</td>
</tr>
{{/each}}
</tbody>
</table>

View file

@ -1,27 +1,6 @@
<h2>{{genus-name}} Strains</h2> <h2>{{genus-name}} Strains</h2>
<h3 id="total-strains">Total strains: {{model.length}}</h3>
{{add-button label="Add Strain" link="protected.strains.new" canAdd=metaData.canAdd}} {{
protected/strains/index/strain-table
<table class="flakes-table"> strains=model
<thead> }}
<tr>
<th>Species</th>
<th>Total Measurements</th>
</tr>
</thead>
<tbody>
{{#each sortedStrains as |row|}}
<tr>
<td>
{{#link-to 'protected.strains.show' row classBinding="data.typeStrain:type-strain"}}
{{row.fullNameMU}}
{{/link-to}}
</td>
<td>
{{row.totalMeasurements}}
</td>
</tr>
{{/each}}
</tbody>
</table>