Last active
May 29, 2018 21:48
-
-
Save vasilionjea/9911bcd1bcccdae610e181b355c51b1f to your computer and use it in GitHub Desktop.
Ember Array CP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const STATES = ['REJECTED', 'APPROVED', 'REQUESTED']; | |
function getRandomState() { | |
return STATES[Math.floor(Math.random() * STATES.length)]; | |
} | |
export default Ember.Controller.extend({ | |
appName: 'Ember Array CP', | |
items: Ember.A([ | |
{ id: 1, data: {}, permission: { state: getRandomState() } }, | |
{ id: 2, data: {}, permission: { state: getRandomState() } }, | |
{ id: 3, data: { owner: true }, permission: { state: 'APPROVED' } }, | |
{ id: 4, data: {}, permission: { state: getRandomState() } }, | |
{ id: 5, data: {}, permission: { state: getRandomState() } }, | |
{ id: 6, data: {}, permission: { state: getRandomState() } }, | |
{ id: 7, data: {}, permission: { state: getRandomState() } }, | |
{ id: 8, data: {}, permission: { state: getRandomState() } }, | |
{ id: 9, data: {}, permission: { state: getRandomState() } }, | |
{ id: 10, data: {}, permission: { state: getRandomState() } }, | |
]), | |
sortedItems: Ember.computed('items.[]', function() { | |
const owner = []; | |
const approved = []; | |
const requested = []; | |
this.get('items').forEach(item => { | |
if (item.data.owner && item.permission.state !== 'REJECTED') { | |
owner.push(item); | |
} else if (item.permission.state === 'APPROVED') { | |
approved.push(item); | |
} else if (item.permission.state === 'REQUESTED') { | |
requested.push(item); | |
} | |
}); | |
return owner.concat(approved, requested); | |
}), | |
actions: { | |
addNewItem() { | |
this.get('items').pushObject({ | |
id: Math.floor(Math.random() * 100), | |
data: { owner: false }, | |
permission: { state: getRandomState() }, | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.13.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment