Refactoring strains

This commit is contained in:
Matthew Dillon 2015-07-08 14:44:24 -08:00
parent 5290e7efd7
commit 01a3075655
23 changed files with 275 additions and 223 deletions

View file

@ -1,3 +0,0 @@
{{#each a as |error|}}
<div class="flakes-message error">{{error.message}}</div>
{{/each}}

View file

@ -5,6 +5,7 @@ export default Ember.Component.extend({
save: function() { save: function() {
this.sendAction('save'); this.sendAction('save');
}, },
cancel: function() { cancel: function() {
this.sendAction('cancel'); this.sendAction('cancel');
}, },

View file

@ -0,0 +1,17 @@
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
save: function() {
// Need to override the string id for some reason
let strain = this.get('strain');
let id = strain.get('species.id');
strain.set('species.id', +id);
this.sendAction('save');
},
cancel: function() {
this.sendAction('cancel');
},
}
});

View file

@ -0,0 +1,61 @@
<form class="grid-form">
<fieldset>
<legend><em>{{strain.strainName}}</em></legend>
<div data-row-span="2">
<div data-field-span="1">
<label>Strain Name</label>
{{input value=strain.strainName}}
</div>
<div data-field-span="1">
<label>Type Strain?</label>
{{input type="checkbox" checked=strain.typeStrain}} {{if strain.typeStrain 'Yes' 'No'}}
</div>
</div>
<div data-row-span="2">
<div data-field-span="2">
<label>Species</label>
{{
select-2
content=species
optionLabelPath="speciesName"
value=strain.species
}}
</div>
</div>
<div data-row-span="2">
<div data-field-span="2">
<label>Isolated From</label>
{{textarea value=strain.isolatedFrom cols="70" rows="5"}}
</div>
</div>
<div data-row-span="3">
<div data-field-span="1">
<label>Accession Numbers</label>
{{input value=strain.accessionNumbers}}
</div>
<div data-field-span="1">
<label>GenBank</label>
{{input value=strain.genbank}}
</div>
<div data-field-span="1">
<label>Whole Genome Sequence</label>
{{input value=strain.wholeGenomeSequence}}
</div>
</div>
<div data-row-span="2">
<div data-field-span="2">
<label>Notes</label>
{{textarea value=strain.notes cols="70" rows="5"}}
</div>
</div>
</fieldset>
</form>
<br>
<a class="button-red smaller" {{action 'cancel'}}>
Cancel
</a>
{{#if strain.isDirty}}
<a class="button-green smaller" {{action 'save'}}>
Save
</a>
{{/if}}

View file

@ -1,20 +0,0 @@
import Ember from 'ember';
import userCanEdit from '../../../utils/user-can-edit';
export default Ember.Component.extend({
classNames: ['grid-1'],
isEditing: false,
canEdit: function() {
return userCanEdit(this.get('session.currentUser'), this.get('strain.createdBy'));
}.property('session.currentUser', 'strain.createdBy').readOnly(),
actions: {
save: function() {
this.sendAction('save');
},
cancel: function() {
this.sendAction('cancel');
},
}
});

View file

@ -1,145 +0,0 @@
<div class="span-1">
<fieldset class="flakes-information-box {{if isEditing 'is-editing'}}">
<legend>
Strain
{{#if isEditing}}
{{input value=strain.strainName}}
{{else}}
{{strain.strainNameMU}}
{{/if}}
{{display-errors a=strain.errors.strainName}}
</legend>
{{! ROW 1 }}
<div class="grid-4 gutter-50">
<dl class="span-2">
<dt>Species</dt>
<dd>
{{#if isEditing}}
{{
select-2
content=species
optionLabelPath="speciesName"
value=strain.species
}}
{{else}}
{{#link-to 'species.show' strain.species}}
<em>{{strain.species.speciesName}}</em>
{{/link-to}}
{{/if}}
</dd>
</dl>
<dl class="span-2">
<dt>Type Strain?</dt>
<dd>
{{#if isEditing}}
{{input type="checkbox" checked=strain.typeStrain}}
{{/if}}
{{if strain.typeStrain 'Yes' 'No'}}
{{display-errors a=strain.errors.typeStrain}}
</dd>
</dl>
</div>
{{! ROW 2 }}
<div class="grid-6">
<dl class="span-2">
<dt>Accession Numbers</dt>
<dd>
{{#if isEditing}}
{{input value=strain.accessionNumbers}}
{{else}}
{{strain.accessionNumbers}}
{{/if}}
{{display-errors a=strain.errors.accessionNumbers}}
</dd>
</dl>
<dl class="span-2">
<dt>Genbank</dt>
<dd>
{{#if isEditing}}
{{input value=strain.genbank}}
{{else}}
{{genbank-url genbank=strain.genbank}}
{{/if}}
{{display-errors a=strain.errors.genbank}}
</dd>
</dl>
<dl class="span-2">
<dt>Whole Genome Sequence</dt>
<dd>
{{#if isEditing}}
{{input value=strain.wholeGenomeSequence}}
{{else}}
{{strain.wholeGenomeSequence}}
{{/if}}
{{display-errors a=strain.errors.wholeGenomeSequence}}
</dd>
</dl>
</div>
{{! ROW 3 }}
<div class="grid-4">
<dl class="span-4">
<dt>Isolated From</dt>
<dd>
{{#if isEditing}}
{{textarea value=strain.isolatedFrom cols="70" rows="3"}}
{{else}}
{{strain.isolatedFrom}}
{{/if}}
{{display-errors a=strain.errors.isolatedFrom}}
</dd>
</dl>
</div>
{{! ROW 4 }}
<div class="grid-4">
<dl class="span-4">
<dt>Notes</dt>
<dd>
{{#if isEditing}}
{{textarea value=strain.notes cols="70" rows="3"}}
{{else}}
{{strain.notes}}
{{/if}}
{{display-errors a=strain.errors.notes}}
</dd>
</dl>
</div>
{{! ROW 5 }}
<div class="grid-4">
<dl class="span-1">
<dt>Record Created</dt>
<dd>{{null-time strain.createdAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Updated</dt>
<dd>{{null-time strain.updatedAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Deleted</dt>
<dd>{{null-time strain.deletedAt 'LL'}}</dd>
</dl>
<dl class="span-1"></dl>
</div>
{{! ROW 6 }}
{{#if canEdit}}
<div class="grid-4">
<div class="span-1">
{{! Does nothing ATM }}
<a class="smaller {{if isEditing 'button-red' 'button-gray'}}" {{action 'cancel'}}>
{{#if isEditing}}Cancel{{else}}Edit{{/if}}
</a>
{{#if isEditing}}
<a class="button-green smaller" {{action 'save'}}>
Save
</a>
{{/if}}
</div>
</div>
{{/if}}
</fieldset>
</div>

View file

@ -7,12 +7,12 @@ export default Ember.Controller.extend({
if (species.get('isDirty')) { if (species.get('isDirty')) {
species.save().then((species) => { species.save().then((species) => {
this.transitionToRoute('species.show', species.get('id')); this.transitionToRoute('species.show', species);
}, (err) => { }, (err) => {
this.get('flashMessages').error(err.responseJSON.error); this.get('flashMessages').error(err.responseJSON.error);
}); });
} else { } else {
this.transitionToRoute('species.show', species.get('id')); this.transitionToRoute('species.show', species);
} }
}, },
@ -22,7 +22,7 @@ export default Ember.Controller.extend({
species.get('errors').clear(); species.get('errors').clear();
species.rollback(); species.rollback();
this.transitionToRoute('species.show', species.get('id')); this.transitionToRoute('species.show', species);
}, },
}, },

View file

@ -12,6 +12,7 @@ export default Ember.Controller.extend({
this.get('flashMessages').error(err.responseJSON.error); this.get('flashMessages').error(err.responseJSON.error);
}); });
} else { } else {
species.deleteRecord();
this.transitionToRoute('species.index'); this.transitionToRoute('species.index');
} }
}, },

View file

@ -6,7 +6,7 @@ export default Ember.Controller.extend({
let id = this.get('model.id'); let id = this.get('model.id');
if (meta.canEdit.indexOf( +id ) === -1) { if (meta.canEdit.indexOf( +id ) === -1) {
return false return false;
} }
return true; return true;
}.property('model.isLoaded').readOnly(), }.property('model.isLoaded').readOnly(),

View file

@ -1,4 +1,8 @@
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, {
model: function(params) {
return this.store.find('species', params.species_id);
}
});

View file

@ -0,0 +1,30 @@
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
save: function() {
let strain = this.get('strain');
if (strain.get('isDirty')) {
strain.save().then((strain) => {
this.transitionToRoute('strains.show', strain);
}, (err) => {
this.get('flashMessages').error(err.responseJSON.error);
});
} else {
strain.deleteRecord();
this.transitionToRoute('strains.show', strain);
}
},
cancel: function() {
let strain = this.get('strain');
strain.get('errors').clear();
strain.rollback();
this.transitionToRoute('strains.show', strain);
},
},
});

View file

@ -0,0 +1,16 @@
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
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'),
});
},
setupController: function(controller, models) {
controller.setProperties(models);
},
});

View file

@ -0,0 +1,7 @@
{{
forms/strain-form
strain=strain
species=species
save="save"
cancel="cancel"
}}

View file

@ -2,5 +2,10 @@ import Ember from 'ember';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
sortParams: ['fullNameMU', 'totalMeasurements'], sortParams: ['fullNameMU', 'totalMeasurements'],
sortedStrains: Ember.computed.sort('strains', 'sortParams'), sortedStrains: Ember.computed.sort('model', 'sortParams'),
metaData: function() {
return this.store.metadataFor('strain');
}.property('model.isLoaded').readOnly(),
}); });

View file

@ -3,12 +3,6 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi
export default Ember.Route.extend(AuthenticatedRouteMixin, { export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() { model: function() {
return Ember.RSVP.hash({ return this.store.findAll('strain');
strains: this.store.findAll('strain'),
});
},
setupController: function(controller, model) {
controller.setProperties(model);
}, },
}); });

View file

@ -1,7 +1,7 @@
<h2>{{genus-name}} Strains</h2> <h2>{{genus-name}} Strains</h2>
<h3>Total strains: {{strains.length}}</h3> <h3>Total strains: {{model.length}}</h3>
{{add-button label="Add Strain" link="strains.new"}} {{add-button label="Add Strain" link="strains.new" canAdd=metaData.canAdd}}
<table class="flakes-table"> <table class="flakes-table">
<thead> <thead>

View file

@ -1,21 +1,30 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
isEditing: true,
actions: { actions: {
save: function() { save: function() {
var strain = this.get('strain'); let strain = this.get('strain');
if (strain.get('isDirty')) { if (strain.get('isDirty')) {
strain.save(); strain.save().then((strain) => {
this.transitionToRoute('strains.show', strain);
}, (err) => {
this.get('flashMessages').error(err.responseJSON.error);
});
} else {
this.transitionToRoute('strains.index');
} }
this.transitionToRoute('strains.index');
}, },
cancel: function() { cancel: function() {
var strain = this.get('strain'); let strain = this.get('strain');
if (strain.get('isNew')) { if (strain.get('isNew')) {
strain.deleteRecord(); strain.deleteRecord();
} }
this.transitionToRoute('strains.index'); this.transitionToRoute('strains.index');
} },
}
},
}); });

View file

@ -5,10 +5,12 @@ 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'),
}); });
}, },
setupController: function(controller, models) { setupController: function(controller, models) {
controller.setProperties(models); controller.setProperties(models);
}, },
}); });

View file

@ -1,8 +1,7 @@
{{ {{
strain-details forms/strain-form
strain=strain strain=strain
species=species species=species
isEditing=true
save="save" save="save"
cancel="cancel" cancel="cancel"
}} }}

View file

@ -1,19 +1,14 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
isEditing: false, userCanEdit: function() {
actions: { let meta = this.store.metadataFor('strain');
save: function() { let id = this.get('model.id');
var strain = this.get('strain');
if (strain.get('isDirty')) { if (meta.canEdit.indexOf( +id ) === -1) {
strain.save(); return false;
}
this.toggleProperty('isEditing');
},
cancel: function() {
this.get('strain').get('errors').clear();
this.get('strain').rollback();
this.toggleProperty('isEditing');
} }
} return true;
}.property('model.isLoaded').readOnly(),
}); });

View file

@ -3,12 +3,6 @@ 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 Ember.RSVP.hash({ return this.store.find('strain', params.strain_id);
strain: this.store.find('strain', params.strain_id), }
species: this.store.findAll('species')
});
},
setupController: function(controller, models) {
controller.setProperties(models);
},
}); });

View file

@ -1,8 +1,90 @@
{{ <div class="span-1">
strain-details <fieldset class="flakes-information-box {{if isEditing 'is-editing'}}">
strain=strain <legend>
species=species Strain {{model.strainNameMU}}
isEditing=isEditing </legend>
save="save"
cancel="cancel" {{! ROW 1 }}
}} <div class="grid-4 gutter-50">
<dl class="span-2">
<dt>Species</dt>
<dd>
{{#link-to 'species.show' model.species.id}}
<em>{{model.species.speciesNameMU}}</em>
{{/link-to}}
</dd>
</dl>
<dl class="span-2">
<dt>Type Strain?</dt>
<dd>
{{if model.typeStrain 'Yes' 'No'}}
</dd>
</dl>
</div>
{{! ROW 2 }}
<div class="grid-6">
<dl class="span-2">
<dt>Accession Numbers</dt>
<dd>
{{model.accessionNumbers}}
</dd>
</dl>
<dl class="span-2">
<dt>Genbank</dt>
<dd>
{{genbank-url genbank=model.genbank}}
</dd>
</dl>
<dl class="span-2">
<dt>Whole Genome Sequence</dt>
<dd>
{{model.wholeGenomeSequence}}
</dd>
</dl>
</div>
{{! ROW 3 }}
<div class="grid-4">
<dl class="span-4">
<dt>Isolated From</dt>
<dd>
{{model.isolatedFrom}}
</dd>
</dl>
</div>
{{! ROW 4 }}
<div class="grid-4">
<dl class="span-4">
<dt>Notes</dt>
<dd>
{{model.notes}}
</dd>
</dl>
</div>
{{! ROW 5 }}
<div class="grid-4">
<dl class="span-1">
<dt>Record Created</dt>
<dd>{{null-time model.createdAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Updated</dt>
<dd>{{null-time model.updatedAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Deleted</dt>
<dd>{{null-time model.deletedAt 'LL'}}</dd>
</dl>
<dl class="span-1"></dl>
</div>
</fieldset>
</div>
{{#if userCanEdit}}
<br>
{{#link-to 'species.edit' model class="button-gray smaller"}}
Edit
{{/link-to}}
{{/if}}

View file

@ -17,10 +17,13 @@ Router.map(function() {
this.route('show', { path: ':species_id' }); this.route('show', { path: ':species_id' });
this.route('edit', { path: ':species_id/edit' }); this.route('edit', { path: ':species_id/edit' });
}); });
this.route('strains', function() { this.route('strains', function() {
this.route('new'); this.route('new');
this.route('show', { path: ':strain_id' }); this.route('show', { path: ':strain_id' });
this.route('edit', { path: ':strain_id/edit' });
}); });
this.route('users', function() { this.route('users', function() {
this.route('new', function() { this.route('new', function() {
this.route('fail'); this.route('fail');