Rough in species
This commit is contained in:
parent
dfc62cd1ac
commit
afcf24a8d8
22 changed files with 399 additions and 2 deletions
17
app/abilities/species.js
Normal file
17
app/abilities/species.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { Ability } from 'ember-can';
|
||||
|
||||
export default Ability.extend({
|
||||
// Only admins and writers can create a new species
|
||||
canAdd: function() {
|
||||
let role = this.get('session.currentUser.role');
|
||||
return (role === 'W') || (role === 'A');
|
||||
}.property('session.currentUser.role'),
|
||||
|
||||
// Only admins and the person who created can edit
|
||||
canEdit: function() {
|
||||
let role = this.get('session.currentUser.role');
|
||||
let id = this.get('session.currentUser.id');
|
||||
let author = this.get('model.createdBy');
|
||||
return (role === 'W' && (+id === author)) || (role === 'A');
|
||||
}.property('session.currentUser.role', 'session.currentUser.id', 'model.createdBy')
|
||||
});
|
20
app/components/species/species-details.js
Normal file
20
app/components/species/species-details.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNames: ['grid-1'],
|
||||
isEditing: false,
|
||||
isNew: false,
|
||||
actions: {
|
||||
editSpecies: function() {
|
||||
this.get('species').get('errors').clear();
|
||||
if (this.get('isNew')) {
|
||||
this.get('species').destroyRecord().then(this.sendAction());
|
||||
}
|
||||
this.toggleProperty('isEditing');
|
||||
this.get('species').rollback();
|
||||
},
|
||||
saveSpecies: function() {
|
||||
this.get('species').save().then(this.toggleProperty('isEditing'));
|
||||
}
|
||||
}
|
||||
});
|
16
app/models/species.js
Normal file
16
app/models/species.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import DS from 'ember-data';
|
||||
|
||||
export default DS.Model.extend({
|
||||
speciesName: DS.attr('string'),
|
||||
typeSpecies: DS.attr('boolean'),
|
||||
etymology: DS.attr('string'),
|
||||
genusName: DS.attr('string'),
|
||||
strains: DS.hasMany('strain'),
|
||||
totalStrains: DS.attr('number'),
|
||||
createdAt: DS.attr('date'),
|
||||
updatedAt: DS.attr('date'),
|
||||
deletedAt: DS.attr('date'),
|
||||
createdBy: DS.attr('number'),
|
||||
updatedBy: DS.attr('number'),
|
||||
deletedBy: DS.attr('number'),
|
||||
});
|
|
@ -8,6 +8,10 @@ var Router = Ember.Router.extend({
|
|||
Router.map(function() {
|
||||
this.route('login');
|
||||
this.route('about');
|
||||
this.resource('species', function() {
|
||||
this.route('show', { path: ':species_id' });
|
||||
this.route('new');
|
||||
});
|
||||
this.resource('strains', function() {
|
||||
this.route('new');
|
||||
this.route('show', { path: ':strain_id' }, function() {
|
||||
|
|
4
app/routes/species.js
Normal file
4
app/routes/species.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin);
|
7
app/routes/species/index.js
Normal file
7
app/routes/species/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
model: function() {
|
||||
return this.store.findAll('species');
|
||||
}
|
||||
});
|
12
app/routes/species/new.js
Normal file
12
app/routes/species/new.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
model: function() {
|
||||
return this.store.createRecord('species');
|
||||
},
|
||||
actions: {
|
||||
cancelSpecies: function() {
|
||||
this.transitionTo('species.index');
|
||||
}
|
||||
}
|
||||
});
|
4
app/routes/species/show.js
Normal file
4
app/routes/species/show.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
});
|
|
@ -4,6 +4,9 @@
|
|||
{{/link-to}}
|
||||
{{#if session.isAuthenticated}}
|
||||
<ul>
|
||||
{{#link-to 'species' tagName='li' href=false}}
|
||||
{{#link-to 'species'}}Species{{/link-to}}
|
||||
{{/link-to}}
|
||||
{{#link-to 'strains' tagName='li' href=false}}
|
||||
{{#link-to 'strains'}}Strains{{/link-to}}
|
||||
{{/link-to}}
|
||||
|
|
76
app/templates/components/species/species-details.hbs
Normal file
76
app/templates/components/species/species-details.hbs
Normal file
|
@ -0,0 +1,76 @@
|
|||
<div class="span-1">
|
||||
<fieldset {{bind-attr class=":flakes-information-box isEditing"}}>
|
||||
<legend>
|
||||
Species
|
||||
{{#if isEditing}}
|
||||
{{input value=species.speciesName}}
|
||||
{{else}}
|
||||
{{species.speciesName}}
|
||||
{{/if}}
|
||||
{{display-errors a=species.errors.speciesName}}
|
||||
</legend>
|
||||
|
||||
{{! ROW 1 }}
|
||||
<div class="grid-4">
|
||||
<dl class="span-4">
|
||||
<dt>Type Species?</dt>
|
||||
<dd>
|
||||
{{#if isEditing}}
|
||||
{{input type="checkbox" checked=species.typeSpecies}}
|
||||
{{/if}}
|
||||
{{if species.typeSpecies 'Yes' 'No'}}
|
||||
{{display-errors a=species.errors.typeSpecies}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 2 }}
|
||||
<div class="grid-4">
|
||||
<dl class="span-4">
|
||||
<dt>Etymology</dt>
|
||||
<dd>
|
||||
{{#if isEditing}}
|
||||
{{textarea value=species.etymology cols="70" rows="3"}}
|
||||
{{else}}
|
||||
{{species.etymology}}
|
||||
{{/if}}
|
||||
{{display-errors a=species.errors.etymology}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 3 }}
|
||||
<div class="grid-4">
|
||||
<dl class="span-1">
|
||||
<dt>Record Created</dt>
|
||||
<dd>{{null-time species.createdAt 'LL'}}</dd>
|
||||
</dl>
|
||||
<dl class="span-1">
|
||||
<dt>Record Updated</dt>
|
||||
<dd>{{null-time species.updatedAt 'LL'}}</dd>
|
||||
</dl>
|
||||
<dl class="span-1">
|
||||
<dt>Record Deleted</dt>
|
||||
<dd>{{null-time species.deletedAt 'LL'}}</dd>
|
||||
</dl>
|
||||
<dl class="span-1"></dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 4 }}
|
||||
{{#if (can "edit species" strain)}}
|
||||
<div class="grid-4">
|
||||
<div class="span-1">
|
||||
{{! Does nothing ATM }}
|
||||
<a {{bind-attr class=":smaller isEditing:button-red:button-gray"}} {{action 'editSpecies'}}>
|
||||
{{#if isEditing}}Cancel{{else}}Edit{{/if}}
|
||||
</a>
|
||||
{{#if isEditing}}
|
||||
<a class="button-green smaller" {{action 'saveSpecies'}}>
|
||||
Save
|
||||
</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
</fieldset>
|
||||
</div>
|
1
app/templates/species.hbs
Normal file
1
app/templates/species.hbs
Normal file
|
@ -0,0 +1 @@
|
|||
{{outlet}}
|
30
app/templates/species/index.hbs
Normal file
30
app/templates/species/index.hbs
Normal file
|
@ -0,0 +1,30 @@
|
|||
<h2>{{genus-name}} Species</h2>
|
||||
<h3>Total species: {{controller.length}}</h3>
|
||||
|
||||
{{#if (can "add species")}}
|
||||
{{! Does nothing ATM }}
|
||||
{{#link-to 'species.new' class="button-gray smaller"}}
|
||||
Add Species
|
||||
{{/link-to}}
|
||||
{{/if}}
|
||||
|
||||
<table class="flakes-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th {{action "setSortBy" "speciesName"}}>Name</th>
|
||||
<th {{action "setSortBy" "totalStrains"}}>Strains</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each species in controller}}
|
||||
<tr>
|
||||
<td>
|
||||
{{#link-to 'species.show' species}}
|
||||
{{species.speciesName}}
|
||||
{{/link-to}}
|
||||
</td>
|
||||
<td>{{species.totalStrains}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
1
app/templates/species/new.hbs
Normal file
1
app/templates/species/new.hbs
Normal file
|
@ -0,0 +1 @@
|
|||
{{species/species-details species=model isEditing=true isNew=true action="cancelSpecies"}}
|
1
app/templates/species/show.hbs
Normal file
1
app/templates/species/show.hbs
Normal file
|
@ -0,0 +1 @@
|
|||
{{species/species-details species=model}}
|
Reference in a new issue