Rough in characteristic types, add meas optgroups

This commit is contained in:
Matthew Dillon 2015-06-16 15:47:29 -08:00
parent f17707fb6d
commit 3c1fca43b8
9 changed files with 126 additions and 20 deletions

View file

@ -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')
});

View file

@ -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'),

View file

@ -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']);

View file

@ -2,5 +2,5 @@
{{data.characteristicName}}
</td>
<td>
{{data.characteristicType}}
{{data.characteristicType.characteristicTypeName}}
</td>

View file

@ -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);
});

View file

@ -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"

View file

@ -42,6 +42,6 @@
"express": "^4.12.4",
"glob": "^4.5.3",
"jsonwebtoken": "^5.0.0",
"morgan": "^1.5.3"
"morgan": "^1.6.0"
}
}

View file

@ -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);
};

View file

@ -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",