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'),
deletedBy : DS.attr('number'),
sortOrder : DS.attr('number'),
canEdit : DS.attr('boolean'),
speciesNameMU: function() {
return Ember.String.htmlSafe(`<em>${this.get('speciesName')}</em>`);

View file

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

View file

@ -1,4 +1,11 @@
import Ember from 'ember';
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'),
metaData: function() {
return this.store.metadataFor('species');
return Ember.copy(this.store.metadataFor('species'));
}.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, {
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>
{{! ROW 1 }}
<div class="grid-4">
<dl class="span-2">
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Strains</dt>
<dd>
<ul>
{{#each model.strains as |strain index|}}
{{if index ","}}
<li>
{{#link-to 'strains.show' strain.id}}
{{{strain.strainNameMU}}}
{{/link-to}}
</li>
{{/each}}
</ul>
</dd>
</dl>
<dl class="span-2">
<dl class="span-1">
<dt>Type Species?</dt>
<dd>
{{if model.typeSpecies 'Yes' 'No'}}
@ -27,8 +30,8 @@
</div>
{{! ROW 2 }}
<div class="grid-4">
<dl class="span-4">
<div class="grid-1 gutter-20">
<dl class="span-1">
<dt>Etymology</dt>
<dd>
{{model.etymology}}
@ -37,7 +40,7 @@
</div>
{{! ROW 3 }}
<div class="grid-4">
<div class="grid-3 gutter-20">
<dl class="span-1">
<dt>Record Created</dt>
<dd>{{null-time model.createdAt 'LL'}}</dd>
@ -50,12 +53,11 @@
<dt>Record Deleted</dt>
<dd>{{null-time model.deletedAt 'LL'}}</dd>
</dl>
<dl class="span-1"></dl>
</div>
</fieldset>
</div>
</div>
{{#if userCanEdit}}
{{#if model.canEdit}}
<br>
{{#link-to 'species.edit' model class="button-gray smaller"}}
Edit

View file

@ -5,10 +5,16 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function(params) {
return Ember.RSVP.hash({
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) {
controller.setProperties(models);
},

View file

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

View file

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