Created
April 18, 2019 15:43
-
-
Save tabiodun/53b7505d1d7287260fadad0872bcf8d3 to your computer and use it in GitHub Desktop.
New Twiddle
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'; | |
export default Ember.Component.extend({ | |
}); |
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'; | |
export default Ember.Component.extend({ | |
}); |
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'; | |
export default Mixin.create({ | |
didInsertElement() { | |
this.get('registerFilter')(this.packFilter) | |
}, | |
packFilter() { | |
} | |
}); |
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'; | |
export default Ember.Component.extend({ | |
filterFunctions: [], | |
actions: { | |
registerFilter(action) { | |
this.get('filterFunctions').pushObject(action); | |
}, | |
filterAction() { | |
let filters = []; | |
this.get('filterFunctions').forEach(f => { | |
filters.addObject(f()); | |
}); | |
this.get('updateState')({ | |
filters: filters | |
}); | |
} | |
} | |
}); |
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'; | |
import { computed } from '@ember/object'; | |
export default Ember.Component.extend({ | |
value: computed('selected.[]', 'data.[]', function() { | |
return this.get('selected').length === this.get('data').length; | |
}), | |
actions: { | |
toggle() { | |
if (event.target.checked) { | |
this.get('addAll')() | |
} else { | |
this.get('removeAll')() | |
} | |
} | |
} | |
}); |
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'; | |
export default Ember.Component.extend({ | |
}); |
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'; | |
export default Ember.Component.extend({ | |
didInsertElement() { | |
this.get('registerFilter')(() => { | |
return { | |
type: 'range', | |
from: this.get('from'), | |
to: this.get('to'), | |
property: this.get('property') | |
}; | |
}) | |
} | |
}); |
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'; | |
export default Ember.Component.extend({ | |
}); |
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'; | |
export default Ember.Component.extend({ | |
actions: { | |
searchAction() { | |
this.get('updateState')({ | |
search: { | |
text: this.get('text'), | |
} | |
}); | |
} | |
} | |
}); |
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'; | |
import { computed } from '@ember/object'; | |
export default Ember.Component.extend({ | |
value: computed('selected.[]', function() { | |
return this.get('selected').includes(this.get('row')); | |
}), | |
actions: { | |
toggle(event) { | |
if (event.target.checked) { | |
this.get('addSelected')(this.get('row')) | |
} else { | |
this.get('removeSelected')(this.get('row')) | |
} | |
} | |
} | |
}); |
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'; | |
export default Ember.Component.extend({ | |
didInsertElement() { | |
this.get('registerFilter')(() => { | |
return { | |
type: 'selection', | |
value: this.get('value'), | |
property: this.get('property') | |
}; | |
}) | |
} | |
}); | |
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'; | |
import { alias, equal } from '@ember/object/computed'; | |
export default Ember.Component.extend({ | |
actions: { | |
sortAction() { | |
// this.get('sortAction')(); | |
let direction = ''; | |
if (this.get('direction') === 'asc') { | |
direction = 'desc' | |
} | |
else if (this.get('direction') === 'desc') { | |
direction = '' | |
} | |
else if (this.get('direction') === undefined || this.get('direction') === '') { | |
direction = 'asc' | |
} | |
this.set('direction', direction); | |
this.get('updateState')({ | |
sort: { | |
property: this.get('key'), | |
direction: direction | |
} | |
}); | |
} | |
} | |
}); |
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'; | |
export default Ember.Component.extend({ | |
didInsertElement() { | |
this.get('registerFilter')(() => { | |
return { | |
type: 'value', | |
value: this.get('value'), | |
property: this.get('property') | |
}; | |
}) | |
}, | |
actions: { | |
selectOption(value) { | |
this.set('value', value) | |
} | |
} | |
}); |
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'; | |
export default Ember.Component.extend({ | |
init() { | |
this._super(...arguments); | |
this.set('state', {}) | |
this.set('selected', []) | |
}, | |
actions: { | |
updateState(state) { | |
Object.assign(this.get('state'), state); | |
this.get('reloadTable')(this.get('state')) | |
console.log(this.get('state')) | |
}, | |
addSelected(item) { | |
this.get('selected').pushObject(item); | |
this.set('selected', Object.assign([], this.get('selected'))) | |
// console.log(item, this.get('selected')); | |
}, | |
removeSelected(item) { | |
this.get('selected').removeObject(item); | |
this.set('selected', Object.assign([], this.get('selected'))) | |
// console.log(item, this.get('selected')); | |
}, | |
addAll() { | |
this.set('selected', Object.assign([], this.get('data'))); | |
console.log(this.get('selected')); | |
}, | |
removeAll() { | |
this.set('selected', Object.assign([], [])); | |
console.log(this.get('selected')); | |
} | |
} | |
}); |
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'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
filterOptions: ['a', 'b', 'c'], | |
data: [{ | |
projectName: 2, | |
clientName: 'b', | |
members: ['1', '2'] | |
},{ | |
projectName: 3, | |
clientName: 'c', | |
members: ['3', '4'] | |
},{ | |
projectName: 4, | |
clientName: 'c', | |
members: [] | |
},{ | |
projectName: 1, | |
clientName: 'a', | |
members: [] | |
}], | |
originalData: [{ | |
projectName: 2, | |
clientName: 'b', | |
members: ['1', '2'] | |
},{ | |
projectName: 3, | |
clientName: 'c', | |
members: ['3', '4'] | |
},{ | |
projectName: 4, | |
clientName: 'c', | |
members: [] | |
},{ | |
projectName: 1, | |
clientName: 'a', | |
members: [] | |
}], | |
sortDirection: '', | |
sort(key, direction) { | |
if (direction == 'asc') { | |
this.set('data', (this.get('data').sortBy(key))) | |
} else if (direction == 'desc') { | |
this.set('data', (this.get('data').sortBy(key).reverse())) | |
} else if (direction == '') { | |
this.set('data', (this.get('data'))) | |
} | |
}, | |
applyFilters(filters, data) { | |
let filteredData = this.get('data'); | |
filters.forEach((f) => { | |
if (f.type === 'range') { | |
if (!f.from && !f.to) { | |
return; | |
} | |
filteredData = this.get('data').filter(function(item){ | |
return f.from <= item[f.property] && item[f.property] <= f.to; | |
}); | |
} | |
if (f.type === 'value') { | |
if (f.value === undefined) { | |
return; | |
} | |
filteredData = filteredData.filter(function(item){ | |
return f.value === item[f.property] | |
}); | |
} | |
if (f.type === 'selection') { | |
if(f.value) { | |
filteredData = filteredData.filter(function(item){ | |
return f.value === (item[f.property].length > 0) | |
}); | |
} | |
} | |
}) | |
this.set('data', filteredData) | |
}, | |
search(text) { | |
if (!text) { | |
this.set('data', (this.get('data'))) | |
} else { | |
this.set('data', (this.get('data').filterBy('clientName', text))) | |
} | |
}, | |
actions: { | |
reloadTable({sort, search, filters}) { | |
this.set('data', this.get('originalData')); | |
if (sort) { | |
this.sort(sort.property, sort.direction); | |
} | |
if (filters) { | |
this.applyFilters(filters); | |
} | |
if (search) { | |
this.search(search.text); | |
} | |
} | |
} | |
}); |
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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment