Cleaning up species and strains

This commit is contained in:
Matthew Dillon 2015-07-09 09:26:55 -08:00
parent 01a3075655
commit 780b5ddb6c
13 changed files with 59 additions and 65 deletions

View file

@ -16,6 +16,7 @@ export default DS.Model.extend({
updatedBy : DS.attr('number'), updatedBy : DS.attr('number'),
deletedBy : DS.attr('number'), deletedBy : DS.attr('number'),
sortOrder : DS.attr('number'), sortOrder : DS.attr('number'),
canEdit : DS.attr('boolean'),
speciesNameMU: function() { speciesNameMU: function() {
return Ember.String.htmlSafe(`<em>${this.get('speciesName')}</em>`); return Ember.String.htmlSafe(`<em>${this.get('speciesName')}</em>`);

View file

@ -19,6 +19,7 @@ export default DS.Model.extend({
deletedBy : DS.attr('number'), deletedBy : DS.attr('number'),
totalMeasurements : DS.attr('number'), totalMeasurements : DS.attr('number'),
sortOrder : DS.attr('number'), sortOrder : DS.attr('number'),
canEdit : DS.attr('boolean'),
strainNameMU: function() { strainNameMU: function() {
let type = this.get('typeStrain') ? '<sup>T</sup>' : ''; let type = this.get('typeStrain') ? '<sup>T</sup>' : '';

View file

@ -1,4 +1,11 @@
import Ember from 'ember'; import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {}); export default Ember.Route.extend(AuthenticatedRouteMixin, {
afterModel: function(species) {
if (!species.get('canEdit')) {
this.transitionTo('species.show', species.get('id'));
}
},
});

View file

@ -5,7 +5,7 @@ export default Ember.Controller.extend({
sortedSpecies: Ember.computed.sort('model', 'sortParams'), sortedSpecies: Ember.computed.sort('model', 'sortParams'),
metaData: function() { metaData: function() {
return this.store.metadataFor('species'); return Ember.copy(this.store.metadataFor('species'));
}.property('model.isLoaded').readOnly(), }.property('model.isLoaded').readOnly(),
}); });

View file

@ -1,14 +0,0 @@
import Ember from 'ember';
export default Ember.Controller.extend({
userCanEdit: function() {
let meta = this.store.metadataFor('species');
let id = this.get('model.id');
if (meta.canEdit.indexOf( +id ) === -1) {
return false;
}
return true;
}.property('model.isLoaded').readOnly(),
});

View file

@ -3,6 +3,7 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi
export default Ember.Route.extend(AuthenticatedRouteMixin, { export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function(params) { model: function(params) {
return this.store.find('species', params.species_id); return this.store.findRecord('species', params.species_id, { reload: true });
} },
}); });

View file

@ -6,19 +6,22 @@
</legend> </legend>
{{! ROW 1 }} {{! ROW 1 }}
<div class="grid-4"> <div class="grid-2 gutter-20">
<dl class="span-2"> <dl class="span-1">
<dt>Strains</dt> <dt>Strains</dt>
<dd> <dd>
{{#each model.strains as |strain index|}} <ul>
{{if index ","}} {{#each model.strains as |strain index|}}
{{#link-to 'strains.show' strain.id}} <li>
{{{strain.strainNameMU}}} {{#link-to 'strains.show' strain.id}}
{{/link-to}} {{{strain.strainNameMU}}}
{{/each}} {{/link-to}}
</li>
{{/each}}
</ul>
</dd> </dd>
</dl> </dl>
<dl class="span-2"> <dl class="span-1">
<dt>Type Species?</dt> <dt>Type Species?</dt>
<dd> <dd>
{{if model.typeSpecies 'Yes' 'No'}} {{if model.typeSpecies 'Yes' 'No'}}
@ -27,8 +30,8 @@
</div> </div>
{{! ROW 2 }} {{! ROW 2 }}
<div class="grid-4"> <div class="grid-1 gutter-20">
<dl class="span-4"> <dl class="span-1">
<dt>Etymology</dt> <dt>Etymology</dt>
<dd> <dd>
{{model.etymology}} {{model.etymology}}
@ -37,7 +40,7 @@
</div> </div>
{{! ROW 3 }} {{! ROW 3 }}
<div class="grid-4"> <div class="grid-3 gutter-20">
<dl class="span-1"> <dl class="span-1">
<dt>Record Created</dt> <dt>Record Created</dt>
<dd>{{null-time model.createdAt 'LL'}}</dd> <dd>{{null-time model.createdAt 'LL'}}</dd>
@ -50,12 +53,11 @@
<dt>Record Deleted</dt> <dt>Record Deleted</dt>
<dd>{{null-time model.deletedAt 'LL'}}</dd> <dd>{{null-time model.deletedAt 'LL'}}</dd>
</dl> </dl>
<dl class="span-1"></dl>
</div> </div>
</fieldset> </fieldset>
</div> </div>
</div> </div>
{{#if userCanEdit}} {{#if model.canEdit}}
<br> <br>
{{#link-to 'species.edit' model class="button-gray smaller"}} {{#link-to 'species.edit' model class="button-gray smaller"}}
Edit Edit

View file

@ -5,10 +5,16 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function(params) { model: function(params) {
return Ember.RSVP.hash({ return Ember.RSVP.hash({
strain: this.store.find('strain', params.strain_id), strain: this.store.find('strain', params.strain_id),
species: this.store.findAll('species'), species: this.store.findAll('species'), // Need for dropdown
}); });
}, },
afterModel: function(models) {
if (!models.strain.get('canEdit')) {
this.transitionTo('strains.show', models.strain.get('id'));
}
},
setupController: function(controller, models) { setupController: function(controller, models) {
controller.setProperties(models); controller.setProperties(models);
}, },

View file

@ -5,7 +5,7 @@ export default Ember.Controller.extend({
sortedStrains: Ember.computed.sort('model', 'sortParams'), sortedStrains: Ember.computed.sort('model', 'sortParams'),
metaData: function() { metaData: function() {
return this.store.metadataFor('strain'); return Ember.copy(this.store.metadataFor('strain'));
}.property('model.isLoaded').readOnly(), }.property('model.isLoaded').readOnly(),
}); });

View file

@ -5,10 +5,14 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() { model: function() {
return Ember.RSVP.hash({ return Ember.RSVP.hash({
strain: this.store.createRecord('strain'), strain: this.store.createRecord('strain'),
species: this.store.findAll('species'), species: this.store.findAll('species'), // Need for dropdown
}); });
}, },
afterModel: function(models) {
console.log('after model');
},
setupController: function(controller, models) { setupController: function(controller, models) {
controller.setProperties(models); controller.setProperties(models);
}, },

View file

@ -1,14 +0,0 @@
import Ember from 'ember';
export default Ember.Controller.extend({
userCanEdit: function() {
let meta = this.store.metadataFor('strain');
let id = this.get('model.id');
if (meta.canEdit.indexOf( +id ) === -1) {
return false;
}
return true;
}.property('model.isLoaded').readOnly(),
});

View file

@ -3,6 +3,7 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi
export default Ember.Route.extend(AuthenticatedRouteMixin, { export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function(params) { model: function(params) {
return this.store.find('strain', params.strain_id); return this.store.findRecord('strain', params.strain_id, { reload: true });
} },
}); });

View file

@ -5,8 +5,8 @@
</legend> </legend>
{{! ROW 1 }} {{! ROW 1 }}
<div class="grid-4 gutter-50"> <div class="grid-2 gutter-20">
<dl class="span-2"> <dl class="span-1">
<dt>Species</dt> <dt>Species</dt>
<dd> <dd>
{{#link-to 'species.show' model.species.id}} {{#link-to 'species.show' model.species.id}}
@ -14,7 +14,7 @@
{{/link-to}} {{/link-to}}
</dd> </dd>
</dl> </dl>
<dl class="span-2"> <dl class="span-1">
<dt>Type Strain?</dt> <dt>Type Strain?</dt>
<dd> <dd>
{{if model.typeStrain 'Yes' 'No'}} {{if model.typeStrain 'Yes' 'No'}}
@ -23,20 +23,20 @@
</div> </div>
{{! ROW 2 }} {{! ROW 2 }}
<div class="grid-6"> <div class="grid-3 gutter-20">
<dl class="span-2"> <dl class="span-1">
<dt>Accession Numbers</dt> <dt>Accession Numbers</dt>
<dd> <dd>
{{model.accessionNumbers}} {{model.accessionNumbers}}
</dd> </dd>
</dl> </dl>
<dl class="span-2"> <dl class="span-1">
<dt>Genbank</dt> <dt>Genbank</dt>
<dd> <dd>
{{genbank-url genbank=model.genbank}} {{genbank-url genbank=model.genbank}}
</dd> </dd>
</dl> </dl>
<dl class="span-2"> <dl class="span-1">
<dt>Whole Genome Sequence</dt> <dt>Whole Genome Sequence</dt>
<dd> <dd>
{{model.wholeGenomeSequence}} {{model.wholeGenomeSequence}}
@ -45,8 +45,8 @@
</div> </div>
{{! ROW 3 }} {{! ROW 3 }}
<div class="grid-4"> <div class="grid-1 gutter-20">
<dl class="span-4"> <dl class="span-1">
<dt>Isolated From</dt> <dt>Isolated From</dt>
<dd> <dd>
{{model.isolatedFrom}} {{model.isolatedFrom}}
@ -55,8 +55,8 @@
</div> </div>
{{! ROW 4 }} {{! ROW 4 }}
<div class="grid-4"> <div class="grid-1 gutter-20">
<dl class="span-4"> <dl class="span-1">
<dt>Notes</dt> <dt>Notes</dt>
<dd> <dd>
{{model.notes}} {{model.notes}}
@ -65,7 +65,7 @@
</div> </div>
{{! ROW 5 }} {{! ROW 5 }}
<div class="grid-4"> <div class="grid-3 gutter-20">
<dl class="span-1"> <dl class="span-1">
<dt>Record Created</dt> <dt>Record Created</dt>
<dd>{{null-time model.createdAt 'LL'}}</dd> <dd>{{null-time model.createdAt 'LL'}}</dd>
@ -78,11 +78,10 @@
<dt>Record Deleted</dt> <dt>Record Deleted</dt>
<dd>{{null-time model.deletedAt 'LL'}}</dd> <dd>{{null-time model.deletedAt 'LL'}}</dd>
</dl> </dl>
<dl class="span-1"></dl>
</div> </div>
</fieldset> </fieldset>
</div> </div>
{{#if userCanEdit}} {{#if model.canEdit}}
<br> <br>
{{#link-to 'species.edit' model class="button-gray smaller"}} {{#link-to 'species.edit' model class="button-gray smaller"}}
Edit Edit