diff --git a/app/pods/characteristics/controller.js b/app/pods/characteristics/controller.js deleted file mode 100644 index fe6b361..0000000 --- a/app/pods/characteristics/controller.js +++ /dev/null @@ -1,5 +0,0 @@ -import SortableController from '../../controllers/sortable'; - -export default SortableController.extend({ - sortBy: 'characteristicName', -}); diff --git a/app/pods/characteristics/route.js b/app/pods/characteristics/route.js index df69651..873f8b3 100644 --- a/app/pods/characteristics/route.js +++ b/app/pods/characteristics/route.js @@ -4,5 +4,14 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi export default Ember.Route.extend(AuthenticatedRouteMixin, { model: function() { return this.store.findAll('characteristic'); - } + }, + setupController: function(controller, model) { + var tableAttrs = [ + { name: 'Name', attr: 'characteristicName' }, + { name: 'Type', attr: 'characteristicType' } + ]; + controller.set('model', model); + controller.set('tableAttrs', tableAttrs); + controller.set('row', 'characteristic-index-row'); + }, }); diff --git a/app/pods/characteristics/template.hbs b/app/pods/characteristics/template.hbs index e9d8ece..3ee1315 100644 --- a/app/pods/characteristics/template.hbs +++ b/app/pods/characteristics/template.hbs @@ -1,19 +1,4 @@

{{genus-name}} Characteristics

-

Total characteristics: {{controller.length}}

+

Total characteristics: {{model.length}}

- - - - - - - - - {{#each characteristic in controller}} - - - - - {{/each}} - -
NameType
{{characteristic.characteristicName}}{{characteristic.characteristicType}}
+{{sortable-table content=model tableAttrs=tableAttrs row=row}} diff --git a/app/pods/components/characteristic-index-row/component.js b/app/pods/components/characteristic-index-row/component.js new file mode 100644 index 0000000..f48ea57 --- /dev/null +++ b/app/pods/components/characteristic-index-row/component.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: 'tr', +}); diff --git a/app/pods/components/characteristic-index-row/template.hbs b/app/pods/components/characteristic-index-row/template.hbs new file mode 100644 index 0000000..6d045bb --- /dev/null +++ b/app/pods/components/characteristic-index-row/template.hbs @@ -0,0 +1,6 @@ + + {{data.characteristicName}} + + + {{data.characteristicType}} + diff --git a/app/pods/components/sortable-table-header/component.js b/app/pods/components/sortable-table-header/component.js new file mode 100644 index 0000000..638b078 --- /dev/null +++ b/app/pods/components/sortable-table-header/component.js @@ -0,0 +1,13 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: 'th', + upArrow: '▲', + downArrow: '▼', + + actions: { + sortBy: function(sortProperty, ascending) { + this.sendAction('action', sortProperty, ascending); + } + }, +}); diff --git a/app/pods/components/sortable-table-header/template.hbs b/app/pods/components/sortable-table-header/template.hbs new file mode 100644 index 0000000..7710080 --- /dev/null +++ b/app/pods/components/sortable-table-header/template.hbs @@ -0,0 +1,3 @@ +{{title}} +{{{upArrow}}} +{{{downArrow}}} diff --git a/app/pods/components/sortable-table/component.js b/app/pods/components/sortable-table/component.js new file mode 100644 index 0000000..39ab6c0 --- /dev/null +++ b/app/pods/components/sortable-table/component.js @@ -0,0 +1,13 @@ +import Ember from 'ember'; + +export default Ember.Component.extend(Ember.SortableMixin, { + tagName: 'table', + classNames: ['flakes-table'], + + actions: { + sortBy: function(property, ascending) { + this.set('sortAscending', ascending); + this.set('sortProperties', [property]); + } + }, +}); diff --git a/app/pods/components/sortable-table/template.hbs b/app/pods/components/sortable-table/template.hbs new file mode 100644 index 0000000..0874743 --- /dev/null +++ b/app/pods/components/sortable-table/template.hbs @@ -0,0 +1,13 @@ + + + {{#each a in tableAttrs}} + {{sortable-table-header title=a.name sortProperty=a.attr action="sortBy"}} + {{/each}} + + + + + {{#each item in arrangedContent}} + {{component row data=item}} + {{/each}} + diff --git a/app/pods/components/species-index-row/component.js b/app/pods/components/species-index-row/component.js new file mode 100644 index 0000000..f48ea57 --- /dev/null +++ b/app/pods/components/species-index-row/component.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: 'tr', +}); diff --git a/app/pods/components/species-index-row/template.hbs b/app/pods/components/species-index-row/template.hbs new file mode 100644 index 0000000..6e75b2c --- /dev/null +++ b/app/pods/components/species-index-row/template.hbs @@ -0,0 +1,13 @@ + + {{#link-to 'species.show' data}} + {{data.speciesName}} + {{/link-to}} + + + {{#each data.strains as |strain index|}} + {{if index ","}} + {{#link-to 'strains.show' strain.id}} + {{strain.strainName}} + {{/link-to}} + {{/each}} + diff --git a/app/pods/components/strain-index-row/component.js b/app/pods/components/strain-index-row/component.js new file mode 100644 index 0000000..f48ea57 --- /dev/null +++ b/app/pods/components/strain-index-row/component.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: 'tr', +}); diff --git a/app/pods/components/strain-index-row/template.hbs b/app/pods/components/strain-index-row/template.hbs new file mode 100644 index 0000000..acd0c58 --- /dev/null +++ b/app/pods/components/strain-index-row/template.hbs @@ -0,0 +1,8 @@ + + {{#link-to 'strains.show' data.id}} + {{scientific-name strain=data}} + {{/link-to}} + + + {{data.totalMeasurements}} + diff --git a/app/pods/species/index/route.js b/app/pods/species/index/route.js index 6b02e0e..9208cec 100644 --- a/app/pods/species/index/route.js +++ b/app/pods/species/index/route.js @@ -4,5 +4,14 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi export default Ember.Route.extend(AuthenticatedRouteMixin, { model: function() { return this.store.findAll('species'); - } + }, + setupController: function(controller, model) { + var tableAttrs = [ + { name: 'Name', attr: 'speciesName' }, + { name: 'Strains', attr: 'totalStrains' } + ]; + controller.set('model', model); + controller.set('tableAttrs', tableAttrs); + controller.set('row', 'species-index-row'); + }, }); diff --git a/app/pods/species/index/template.hbs b/app/pods/species/index/template.hbs index d31940f..21ce1cc 100644 --- a/app/pods/species/index/template.hbs +++ b/app/pods/species/index/template.hbs @@ -8,30 +8,4 @@ {{/link-to}} {{/if}} - - - - - - - - - {{#each species in controller}} - - - - - {{/each}} - -
NameStrains
- {{#link-to 'species.show' species}} - {{species.speciesName}} - {{/link-to}} - - {{#each species.strains as |strain index|}} - {{if index ","}} - {{#link-to 'strains.show' strain.id}} - {{strain.strainName}} - {{/link-to}} - {{/each}} -
+{{sortable-table content=model tableAttrs=tableAttrs row=row}} diff --git a/app/pods/strains/index/route.js b/app/pods/strains/index/route.js index 0bcd81a..53d3820 100644 --- a/app/pods/strains/index/route.js +++ b/app/pods/strains/index/route.js @@ -4,5 +4,14 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi export default Ember.Route.extend(AuthenticatedRouteMixin, { model: function() { return this.store.findAll('strain'); - } + }, + setupController: function(controller, model) { + var tableAttrs = [ + { name: 'Name', attr: 'fullName' }, + { name: 'Total Measurements', attr: 'totalMeasurements' } + ]; + controller.set('model', model); + controller.set('tableAttrs', tableAttrs); + controller.set('row', 'strain-index-row'); + }, }); diff --git a/app/pods/strains/index/template.hbs b/app/pods/strains/index/template.hbs index 4e8c0ea..edb1048 100644 --- a/app/pods/strains/index/template.hbs +++ b/app/pods/strains/index/template.hbs @@ -1,5 +1,5 @@

{{genus-name}} Strains

-

Total strains: {{controller.length}}

+

Total strains: {{model.length}}

{{#if (can "add strain")}} {{! Does nothing ATM }} @@ -8,23 +8,4 @@ {{/link-to}} {{/if}} - - - - - - - - - {{#each strain in controller}} - - - - - {{/each}} - -
NameTotal Measurements
- {{#link-to 'strains.show' strain.id}} - {{scientific-name strain=strain}} - {{/link-to}} - {{strain.totalMeasurements}}
+{{sortable-table content=model tableAttrs=tableAttrs row=row}} diff --git a/app/styles/app.css b/app/styles/app.css index 9d1b1df..61a0502 100644 --- a/app/styles/app.css +++ b/app/styles/app.css @@ -2,7 +2,7 @@ padding: 2em 0em 0em 0em; } -.flakes-table thead tr { +.flakes-table thead tr th span { cursor: pointer; } diff --git a/tests/unit/pods/components/characteristic-index-row/component-test.js b/tests/unit/pods/components/characteristic-index-row/component-test.js new file mode 100644 index 0000000..0964cf7 --- /dev/null +++ b/tests/unit/pods/components/characteristic-index-row/component-test.js @@ -0,0 +1,21 @@ +import { + moduleForComponent, + test +} from 'ember-qunit'; + +moduleForComponent('characteristic-index-row', { + // Specify the other units that are required for this test + // needs: ['component:foo', 'helper:bar'] +}); + +test('it renders', function(assert) { + assert.expect(2); + + // Creates the component instance + var component = this.subject(); + assert.equal(component._state, 'preRender'); + + // Renders the component to the page + this.render(); + assert.equal(component._state, 'inDOM'); +}); diff --git a/tests/unit/pods/components/sortable-table-header/component-test.js b/tests/unit/pods/components/sortable-table-header/component-test.js new file mode 100644 index 0000000..adb3489 --- /dev/null +++ b/tests/unit/pods/components/sortable-table-header/component-test.js @@ -0,0 +1,21 @@ +import { + moduleForComponent, + test +} from 'ember-qunit'; + +moduleForComponent('sortable-table-header', { + // Specify the other units that are required for this test + // needs: ['component:foo', 'helper:bar'] +}); + +test('it renders', function(assert) { + assert.expect(2); + + // Creates the component instance + var component = this.subject(); + assert.equal(component._state, 'preRender'); + + // Renders the component to the page + this.render(); + assert.equal(component._state, 'inDOM'); +}); diff --git a/tests/unit/pods/components/sortable-table/component-test.js b/tests/unit/pods/components/sortable-table/component-test.js new file mode 100644 index 0000000..2d888ff --- /dev/null +++ b/tests/unit/pods/components/sortable-table/component-test.js @@ -0,0 +1,21 @@ +import { + moduleForComponent, + test +} from 'ember-qunit'; + +moduleForComponent('sortable-table', { + // Specify the other units that are required for this test + // needs: ['component:foo', 'helper:bar'] +}); + +test('it renders', function(assert) { + assert.expect(2); + + // Creates the component instance + var component = this.subject(); + assert.equal(component._state, 'preRender'); + + // Renders the component to the page + this.render(); + assert.equal(component._state, 'inDOM'); +}); diff --git a/tests/unit/pods/components/species-index-row/component-test.js b/tests/unit/pods/components/species-index-row/component-test.js new file mode 100644 index 0000000..2b6b389 --- /dev/null +++ b/tests/unit/pods/components/species-index-row/component-test.js @@ -0,0 +1,21 @@ +import { + moduleForComponent, + test +} from 'ember-qunit'; + +moduleForComponent('species-index-row', { + // Specify the other units that are required for this test + // needs: ['component:foo', 'helper:bar'] +}); + +test('it renders', function(assert) { + assert.expect(2); + + // Creates the component instance + var component = this.subject(); + assert.equal(component._state, 'preRender'); + + // Renders the component to the page + this.render(); + assert.equal(component._state, 'inDOM'); +}); diff --git a/tests/unit/pods/components/strain-index-row/component-test.js b/tests/unit/pods/components/strain-index-row/component-test.js new file mode 100644 index 0000000..819c0e9 --- /dev/null +++ b/tests/unit/pods/components/strain-index-row/component-test.js @@ -0,0 +1,21 @@ +import { + moduleForComponent, + test +} from 'ember-qunit'; + +moduleForComponent('strain-index-row', { + // Specify the other units that are required for this test + // needs: ['component:foo', 'helper:bar'] +}); + +test('it renders', function(assert) { + assert.expect(2); + + // Creates the component instance + var component = this.subject(); + assert.equal(component._state, 'preRender'); + + // Renders the component to the page + this.render(); + assert.equal(component._state, 'inDOM'); +});