Dropping ember-can
This commit is contained in:
		
							parent
							
								
									3501dc1986
								
							
						
					
					
						commit
						53be80d617
					
				
					 13 changed files with 57 additions and 75 deletions
				
			
		| 
						 | 
				
			
			@ -1,17 +0,0 @@
 | 
			
		|||
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')
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -1,17 +0,0 @@
 | 
			
		|||
import { Ability } from 'ember-can';
 | 
			
		||||
 | 
			
		||||
export default Ability.extend({
 | 
			
		||||
  // Only admins and writers can create a new strain
 | 
			
		||||
  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')
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										8
									
								
								app/pods/components/add-button/component.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								app/pods/components/add-button/component.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
 | 
			
		||||
export default Ember.Component.extend({
 | 
			
		||||
  canAdd: function() {
 | 
			
		||||
    let role = this.get('session.currentUser.role');
 | 
			
		||||
    return (role === 'W') || (role === 'A');
 | 
			
		||||
  }.property('session.currentUser.role')
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										5
									
								
								app/pods/components/add-button/template.hbs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/pods/components/add-button/template.hbs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
{{#if canAdd}}
 | 
			
		||||
  {{#link-to link class="button-gray smaller"}}
 | 
			
		||||
    {{label}}
 | 
			
		||||
  {{/link-to}}
 | 
			
		||||
{{/if}}
 | 
			
		||||
| 
						 | 
				
			
			@ -3,6 +3,14 @@ import Ember from 'ember';
 | 
			
		|||
export default Ember.Component.extend({
 | 
			
		||||
  classNames: ['grid-1'],
 | 
			
		||||
  isEditing: false,
 | 
			
		||||
 | 
			
		||||
  canEdit: function() {
 | 
			
		||||
    let role = this.get('session.currentUser.role');
 | 
			
		||||
    let id = this.get('session.currentUser.id');
 | 
			
		||||
    let author = this.get('species.createdBy');
 | 
			
		||||
    return (role === 'W' && (+id === author)) || (role === 'A');
 | 
			
		||||
  }.property('session.currentUser.role', 'session.currentUser.id', 'species.createdBy'),
 | 
			
		||||
 | 
			
		||||
  actions: {
 | 
			
		||||
    save: function() {
 | 
			
		||||
      this.sendAction('save');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,16 +21,9 @@
 | 
			
		|||
              {{strain.strainName}}
 | 
			
		||||
            {{/link-to}}
 | 
			
		||||
          {{/each}}
 | 
			
		||||
          {{#if (can "edit species" species)}}
 | 
			
		||||
            {{#if species.isNew}}
 | 
			
		||||
              PENDING SAVE
 | 
			
		||||
            {{else}}
 | 
			
		||||
              <br>
 | 
			
		||||
              {{#link-to 'strains.new' class="button-gray smaller"}}
 | 
			
		||||
                Add Strain
 | 
			
		||||
              {{/link-to}}
 | 
			
		||||
            {{/if}}
 | 
			
		||||
          {{/if}}
 | 
			
		||||
          {{#unless species.isNew}}
 | 
			
		||||
            {{add-button label="Add Strain" link="strains.new"}}
 | 
			
		||||
          {{/unless}}
 | 
			
		||||
        </dd>
 | 
			
		||||
      </dl>
 | 
			
		||||
      <dl class="span-2">
 | 
			
		||||
| 
						 | 
				
			
			@ -78,10 +71,9 @@
 | 
			
		|||
    </div>
 | 
			
		||||
 | 
			
		||||
    {{! ROW 4 }}
 | 
			
		||||
    {{#if (can "edit species" species)}}
 | 
			
		||||
    {{#if canEdit}}
 | 
			
		||||
      <div class="grid-4">
 | 
			
		||||
        <div class="span-1">
 | 
			
		||||
          {{! Does nothing ATM }}
 | 
			
		||||
          <a {{bind-attr class=":smaller isEditing:button-red:button-gray"}} {{action 'cancel'}}>
 | 
			
		||||
            {{#if isEditing}}Cancel{{else}}Edit{{/if}}
 | 
			
		||||
          </a>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,14 @@ import Ember from 'ember';
 | 
			
		|||
export default Ember.Component.extend({
 | 
			
		||||
  classNames: ['grid-1'],
 | 
			
		||||
  isEditing: false,
 | 
			
		||||
 | 
			
		||||
  canEdit: function() {
 | 
			
		||||
    let role = this.get('session.currentUser.role');
 | 
			
		||||
    let id = this.get('session.currentUser.id');
 | 
			
		||||
    let author = this.get('strain.createdBy');
 | 
			
		||||
    return (role === 'W' && (+id === author)) || (role === 'A');
 | 
			
		||||
  }.property('session.currentUser.role', 'session.currentUser.id', 'strain.createdBy'),
 | 
			
		||||
 | 
			
		||||
  actions: {
 | 
			
		||||
    save: function() {
 | 
			
		||||
      this.sendAction('save');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -116,7 +116,7 @@
 | 
			
		|||
    </div>
 | 
			
		||||
 | 
			
		||||
    {{! ROW 6 }}
 | 
			
		||||
    {{#if (can "edit strain" strain)}}
 | 
			
		||||
    {{#if canEdit}}
 | 
			
		||||
      <div class="grid-4">
 | 
			
		||||
        <div class="span-1">
 | 
			
		||||
          {{! Does nothing ATM }}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,6 @@
 | 
			
		|||
<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}}
 | 
			
		||||
{{add-button label="Add Species" link="species.new"}}
 | 
			
		||||
 | 
			
		||||
{{sortable-table content=model tableAttrs=tableAttrs row=row}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,6 @@
 | 
			
		|||
<h2>{{genus-name}} Strains</h2>
 | 
			
		||||
<h3>Total strains: {{model.length}}</h3>
 | 
			
		||||
 | 
			
		||||
{{#if (can "add strain")}}
 | 
			
		||||
  {{! Does nothing ATM }}
 | 
			
		||||
  {{#link-to 'strains.new' class="button-gray smaller"}}
 | 
			
		||||
    Add Strain
 | 
			
		||||
  {{/link-to}}
 | 
			
		||||
{{/if}}
 | 
			
		||||
{{add-button label="Add Strain" link="strains.new"}}
 | 
			
		||||
 | 
			
		||||
{{sortable-table content=model tableAttrs=tableAttrs row=row}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue