From 3c1fca43b8c6e3667000d766b7f36599c84e197b Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 16 Jun 2015 15:47:29 -0800 Subject: [PATCH] Rough in characteristic types, add meas optgroups --- app/models/characteristic-type.js | 12 +++ app/models/characteristic.js | 2 +- app/pods/characteristics/route.js | 11 ++- .../characteristic-index-row/template.hbs | 2 +- app/pods/measurements/route.js | 22 +++-- app/pods/measurements/template.hbs | 4 +- package.json | 2 +- server/mocks/characteristic-types.js | 81 +++++++++++++++++++ server/mocks/characteristics.js | 10 +-- 9 files changed, 126 insertions(+), 20 deletions(-) create mode 100644 app/models/characteristic-type.js create mode 100644 server/mocks/characteristic-types.js diff --git a/app/models/characteristic-type.js b/app/models/characteristic-type.js new file mode 100644 index 0000000..31f793a --- /dev/null +++ b/app/models/characteristic-type.js @@ -0,0 +1,12 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + characteristicTypeName: DS.attr('string'), + characteristics: DS.hasMany('characteristic', { async: true }), + createdAt: DS.attr('date'), + updatedAt: DS.attr('date'), + deletedAt: DS.attr('date'), + createdBy: DS.attr('number'), + updatedBy: DS.attr('number'), + deletedBy: DS.attr('number') +}); diff --git a/app/models/characteristic.js b/app/models/characteristic.js index 1303b86..eeeafe4 100644 --- a/app/models/characteristic.js +++ b/app/models/characteristic.js @@ -2,7 +2,7 @@ import DS from 'ember-data'; export default DS.Model.extend({ characteristicName: DS.attr('string'), - characteristicType: DS.attr('string'), + characteristicType: DS.belongsTo('characteristicType', { async: true }), strains : DS.hasMany('strain', { async: true }), measurements : DS.hasMany('measurements', { async: true }), createdAt : DS.attr('date'), diff --git a/app/pods/characteristics/route.js b/app/pods/characteristics/route.js index 32143d9..bde4ffa 100644 --- a/app/pods/characteristics/route.js +++ b/app/pods/characteristics/route.js @@ -3,14 +3,17 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi export default Ember.Route.extend(AuthenticatedRouteMixin, { model: function() { - return this.store.findAll('characteristic'); + return Ember.RSVP.hash({ + characteristicTypes: this.store.findAll('characteristic-type'), + characteristics: this.store.findAll('characteristic'), + }); }, - setupController: function(controller, model) { + setupController: function(controller, models) { var tableAttrs = [ { name: 'Name', attr: 'characteristicName' }, - { name: 'Type', attr: 'characteristicType' } + { name: 'Type', attr: 'characteristicType.characteristicTypeName' } ]; - controller.set('model', model); + controller.set('model', models.characteristics); controller.set('tableAttrs', tableAttrs); controller.set('row', 'characteristic-index-row'); controller.set('sort', ['characteristicName']); diff --git a/app/pods/components/characteristic-index-row/template.hbs b/app/pods/components/characteristic-index-row/template.hbs index 6d045bb..c829365 100644 --- a/app/pods/components/characteristic-index-row/template.hbs +++ b/app/pods/components/characteristic-index-row/template.hbs @@ -2,5 +2,5 @@ {{data.characteristicName}} - {{data.characteristicType}} + {{data.characteristicType.characteristicTypeName}} diff --git a/app/pods/measurements/route.js b/app/pods/measurements/route.js index 271d58c..385add1 100644 --- a/app/pods/measurements/route.js +++ b/app/pods/measurements/route.js @@ -4,25 +4,35 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi export default Ember.Route.extend(AuthenticatedRouteMixin, { model: function() { return Ember.RSVP.hash({ - species: this.store.findAll('species'), // need this bc async + species: this.store.findAll('species'), strains: this.store.findAll('strain'), + characteristicTypes: this.store.findAll('characteristic-type'), characteristics: this.store.findAll('characteristic'), }); }, setupController: function(controller, models) { // Set up search parameters let selects = [ - { model: 'strains', id: 'id', text: 'fullName' }, - { model: 'characteristics', id: 'id', text: 'characteristicName' }, + { model: 'species', id: 'id', text: 'speciesName', + children: 'strains', cid: 'id', ctext: 'fullName' }, + { model: 'characteristicTypes', id: 'id', text: 'characteristicTypeName', + children: 'characteristics', cid: 'id', ctext: 'characteristicName' }, ]; selects.forEach((item /*, index, enumerable*/) => { + models[item.model] = models[item.model].filter((i) => { + if (!Ember.isEmpty(i.get(item.children))) { return true; } + }); models[item.model] = models[item.model].sortBy(item.text); let temp = models[item.model].map((data) => { - return Ember.Object.create({ - id: data.get(item.id), - text: data.get(item.text), + let temp_children = []; + data.get(item.children).forEach((child) => { + temp_children.push({id: child.get(item.cid), text: child.get(item.ctext)}); }); + return { + text: data.get(item.text), + children: temp_children, + }; }); controller.set(item.model, temp); }); diff --git a/app/pods/measurements/template.hbs b/app/pods/measurements/template.hbs index 6f0d79d..0b6521d 100644 --- a/app/pods/measurements/template.hbs +++ b/app/pods/measurements/template.hbs @@ -9,7 +9,7 @@ {{ select-2 multiple=true - content=strains + content=species value=selectedStrains optionValuePath="id" placeholder="All strains" @@ -20,7 +20,7 @@ {{ select-2 multiple=true - content=characteristics + content=characteristicTypes value=selectedCharacteristics optionValuePath="id" placeholder="All characteristics" diff --git a/package.json b/package.json index daa4961..f39391f 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,6 @@ "express": "^4.12.4", "glob": "^4.5.3", "jsonwebtoken": "^5.0.0", - "morgan": "^1.5.3" + "morgan": "^1.6.0" } } diff --git a/server/mocks/characteristic-types.js b/server/mocks/characteristic-types.js new file mode 100644 index 0000000..906a454 --- /dev/null +++ b/server/mocks/characteristic-types.js @@ -0,0 +1,81 @@ +module.exports = function(app) { + var express = require('express'); + var characteristicTypesRouter = express.Router(); + + var CHARACTERISTIC_TYPES = [ + { + id: 1, + characteristicTypeName: 'Type 1', + characteristics: [1,4], + createdAt: "0001-01-01T00:00:00Z", + updatedAt: "0001-01-01T00:00:00Z", + deletedAt: null, + createdBy: 1, + updatedBy: 1, + deletedBy: null + }, + { + id: 2, + characteristicTypeName: 'Type 2', + characteristics: [2,5], + createdAt: "0001-01-01T00:00:00Z", + updatedAt: "0001-01-01T00:00:00Z", + deletedAt: null, + createdBy: 1, + updatedBy: 1, + deletedBy: null + }, + { + id: 3, + characteristicTypeName: 'Type 3', + characteristics: [3], + createdAt: "0001-01-01T00:00:00Z", + updatedAt: "0001-01-01T00:00:00Z", + deletedAt: null, + createdBy: 1, + updatedBy: 1, + deletedBy: null + }, + ] + + characteristicTypesRouter.get('/', function(req, res) { + var characteristics; + if (req.query.ids) { + characteristic_types = CHARACTERISTIC_TYPES.filter(function(c) { + return req.query.ids.indexOf(c.id.toString()) > -1; + }); + } else { + characteristic_types = CHARACTERISTIC_TYPES; + } + res.send({ + 'characteristicTypes': characteristic_types + }); + }); + + characteristicTypesRouter.post('/', function(req, res) { + res.status(201).end(); + }); + + characteristicTypesRouter.get('/:id', function(req, res) { + var characteristic_type = CHARACTERISTIC_TYPES.filter(function(c) { + return c.id == req.params.id; + }); + res.send({ + 'characteristicType': characteristic_type + }); + }); + + characteristicTypesRouter.put('/:id', function(req, res) { + res.send({ + 'characteristicTypes': { + id: req.params.id + } + }); + }); + + characteristicTypesRouter.delete('/:id', function(req, res) { + res.status(204).end(); + }); + + app.use('/api/hymenobacter/characteristicTypes', characteristicTypesRouter); +}; diff --git a/server/mocks/characteristics.js b/server/mocks/characteristics.js index 49d4cdf..3be513c 100644 --- a/server/mocks/characteristics.js +++ b/server/mocks/characteristics.js @@ -6,7 +6,7 @@ module.exports = function(app) { { id: 1, characteristicName: 'α-fucosidase (API ZYM)', - characteristicType: 'Type 1', + characteristicType: 1, strains: [1,2], measurements: [1,6], createdAt: "0001-01-01T00:00:00Z", @@ -19,7 +19,7 @@ module.exports = function(app) { { id: 2, characteristicName: 'α-glucosidase', - characteristicType: 'Type 2', + characteristicType: 2, strains: [1,2], measurements: [2,7], createdAt: "0001-01-01T00:00:00Z", @@ -32,7 +32,7 @@ module.exports = function(app) { { id: 3, characteristicName: 'Chloramphenicol', - characteristicType: 'Type 3', + characteristicType: 3, strains: [1,2], measurements: [3,8], createdAt: "0001-01-01T00:00:00Z", @@ -45,7 +45,7 @@ module.exports = function(app) { { id: 4, characteristicName: 'Bacitracin', - characteristicType: 'Type 1', + characteristicType: 1, strains: [1,2], measurements: [4,9], createdAt: "0001-01-01T00:00:00Z", @@ -58,7 +58,7 @@ module.exports = function(app) { { id: 5, characteristicName: 'Indole', - characteristicType: 'Type 2', + characteristicType: 2, strains: [1,2], measurements: [5,10], createdAt: "0001-01-01T00:00:00Z",