protected route
This commit is contained in:
parent
72c957f8dc
commit
eb1a8bb6e3
41 changed files with 56 additions and 43 deletions
30
app/pods/protected/strains/edit/controller.js
Normal file
30
app/pods/protected/strains/edit/controller.js
Normal 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);
|
||||
},
|
||||
|
||||
},
|
||||
});
|
22
app/pods/protected/strains/edit/route.js
Normal file
22
app/pods/protected/strains/edit/route.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
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'), // 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);
|
||||
},
|
||||
|
||||
});
|
7
app/pods/protected/strains/edit/template.hbs
Normal file
7
app/pods/protected/strains/edit/template.hbs
Normal file
|
@ -0,0 +1,7 @@
|
|||
{{
|
||||
forms/strain-form
|
||||
strain=strain
|
||||
species=species
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
11
app/pods/protected/strains/index/controller.js
Normal file
11
app/pods/protected/strains/index/controller.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
sortParams: ['fullNameMU', 'totalMeasurements'],
|
||||
sortedStrains: Ember.computed.sort('model', 'sortParams'),
|
||||
|
||||
metaData: function() {
|
||||
return Ember.copy(this.store.metadataFor('strain'));
|
||||
}.property('model.isLoaded').readOnly(),
|
||||
|
||||
});
|
8
app/pods/protected/strains/index/route.js
Normal file
8
app/pods/protected/strains/index/route.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
model: function() {
|
||||
return this.store.findAll('strain');
|
||||
},
|
||||
});
|
27
app/pods/protected/strains/index/template.hbs
Normal file
27
app/pods/protected/strains/index/template.hbs
Normal file
|
@ -0,0 +1,27 @@
|
|||
<h2>{{genus-name}} Strains</h2>
|
||||
<h3>Total strains: {{model.length}}</h3>
|
||||
|
||||
{{add-button label="Add Strain" link="strains.new" canAdd=metaData.canAdd}}
|
||||
|
||||
<table class="flakes-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Species</th>
|
||||
<th>Total Measurements</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each sortedStrains as |row|}}
|
||||
<tr>
|
||||
<td>
|
||||
{{#link-to 'protected.strains.show' row.id classBinding="data.typeStrain:type-strain"}}
|
||||
{{row.fullNameMU}}
|
||||
{{/link-to}}
|
||||
</td>
|
||||
<td>
|
||||
{{row.totalMeasurements}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
24
app/pods/protected/strains/new/controller.js
Normal file
24
app/pods/protected/strains/new/controller.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
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 {
|
||||
this.transitionToRoute('strains.index');
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
this.transitionToRoute('strains.index');
|
||||
},
|
||||
|
||||
},
|
||||
});
|
34
app/pods/protected/strains/new/route.js
Normal file
34
app/pods/protected/strains/new/route.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
beforeModel: function(transition) {
|
||||
this._super(transition);
|
||||
if (this.get('session.currentUser.role') === 'R') {
|
||||
this.transitionTo('strains.index');
|
||||
}
|
||||
},
|
||||
|
||||
model: function() {
|
||||
return Ember.RSVP.hash({
|
||||
strain: this.store.createRecord('strain'),
|
||||
species: this.store.findAll('species'), // Need for dropdown
|
||||
});
|
||||
},
|
||||
|
||||
setupController: function(controller, models) {
|
||||
controller.setProperties(models);
|
||||
},
|
||||
|
||||
actions: {
|
||||
willTransition: function(transition) {
|
||||
let controller = this.get('controller');
|
||||
let strain = controller.get('strain');
|
||||
|
||||
if (strain.get('isNew')) {
|
||||
strain.deleteRecord();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
});
|
7
app/pods/protected/strains/new/template.hbs
Normal file
7
app/pods/protected/strains/new/template.hbs
Normal file
|
@ -0,0 +1,7 @@
|
|||
{{
|
||||
forms/strain-form
|
||||
strain=strain
|
||||
species=species
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
9
app/pods/protected/strains/show/route.js
Normal file
9
app/pods/protected/strains/show/route.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
model: function(params) {
|
||||
return this.store.findRecord('strain', params.strain_id, { reload: true });
|
||||
},
|
||||
|
||||
});
|
89
app/pods/protected/strains/show/template.hbs
Normal file
89
app/pods/protected/strains/show/template.hbs
Normal file
|
@ -0,0 +1,89 @@
|
|||
<div class="span-1">
|
||||
<fieldset class="flakes-information-box {{if isEditing 'is-editing'}}">
|
||||
<legend>
|
||||
Strain {{model.strainNameMU}}
|
||||
</legend>
|
||||
|
||||
{{! ROW 1 }}
|
||||
<div class="grid-2 gutter-20">
|
||||
<dl class="span-1">
|
||||
<dt>Species</dt>
|
||||
<dd>
|
||||
{{#link-to 'protected.species.show' model.species.id}}
|
||||
<em>{{model.species.speciesNameMU}}</em>
|
||||
{{/link-to}}
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="span-1">
|
||||
<dt>Type Strain?</dt>
|
||||
<dd>
|
||||
{{if model.typeStrain 'Yes' 'No'}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 2 }}
|
||||
<div class="grid-3 gutter-20">
|
||||
<dl class="span-1">
|
||||
<dt>Accession Numbers</dt>
|
||||
<dd>
|
||||
{{model.accessionNumbers}}
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="span-1">
|
||||
<dt>Genbank</dt>
|
||||
<dd>
|
||||
{{genbank-url genbank=model.genbank}}
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="span-1">
|
||||
<dt>Whole Genome Sequence</dt>
|
||||
<dd>
|
||||
{{model.wholeGenomeSequence}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 3 }}
|
||||
<div class="grid-1 gutter-20">
|
||||
<dl class="span-1">
|
||||
<dt>Isolated From</dt>
|
||||
<dd>
|
||||
{{model.isolatedFrom}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 4 }}
|
||||
<div class="grid-1 gutter-20">
|
||||
<dl class="span-1">
|
||||
<dt>Notes</dt>
|
||||
<dd>
|
||||
{{model.notes}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 5 }}
|
||||
<div class="grid-3 gutter-20">
|
||||
<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>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{#if model.canEdit}}
|
||||
<br>
|
||||
{{#link-to 'protected.species.edit' model class="button-gray smaller"}}
|
||||
Edit
|
||||
{{/link-to}}
|
||||
{{/if}}
|
Reference in a new issue