Skip to content

Instantly share code, notes, and snippets.

@selvagsz
Last active August 23, 2018 10:05
Show Gist options
  • Save selvagsz/dda60118011cd5c57f30f2b5a59cc2cb to your computer and use it in GitHub Desktop.
Save selvagsz/dda60118011cd5c57f30f2b5a59cc2cb to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
const Grouped = Ember.ArrayProxy.extend({
});
export default Ember.Component.extend({
groupedSettings: Ember.computed('appSettings.[]', function() {
let appSettings = this.appSettings;
return appSettings.reduce((iter, curr) => {
let existingGroup
iter.some((item) => {
let found = item.findBy('oauth_applications_id', curr.oauth_applications_id);
if (found) {
existingGroup = item;
return true
}
})
if (existingGroup) {
existingGroup.pushObject(curr)
} else {
iter.pushObject(Grouped.create({
content: Ember.makeArray(curr),
oauth_applications_id: curr.oauth_applications_id
}))
}
return iter;
}, [])
})
});
import Ember from 'ember';
export default Ember.Component.extend({
label: Ember.computed('groupedSetting', {
get() {
// should be computed based on channel
return 'All boo'
}
}),
isGrouped: Ember.computed('groupedSetting.[]', {
get() {
return this.get('groupedSetting.length') > 1
}
})
});
import Ember from 'ember';
const data = { "app_settings": [{ "id": 82, "account_id": 4, "channel_id": 4, "default_sales_ledger_account_id": "7", "default_shipping_revenue_ledger_account_id": null, "oauth_applications_id": 6 }, { "id": 79, "account_id": 4, "channel_id": 3, "default_sales_ledger_account_id": null, "default_shipping_revenue_ledger_account_id": null, "oauth_applications_id": 5 }, { "id": 78, "account_id": 4, "channel_id": 3, "default_sales_ledger_account_id": "7", "default_shipping_revenue_ledger_account_id": "7", "oauth_applications_id": 4 }, { "id": 75, "account_id": 4, "channel_id": 2, "default_sales_ledger_account_id": null, "default_shipping_revenue_ledger_account_id": "1", "oauth_applications_id": 5 }, { "id": 74, "account_id": 4, "channel_id": 2, "default_sales_ledger_account_id": "1", "default_shipping_revenue_ledger_account_id": null, "oauth_applications_id": 4 }, { "id": 73, "account_id": 4, "channel_id": null, "default_sales_ledger_account_id": null, "default_shipping_revenue_ledger_account_id": "1", "oauth_applications_id": 34 }] }
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
data: data,
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{app-settings appSettings=data.app_settings}}
<br>
<br>
{{#each groupedSettings as |groupedSetting|}}
{{grouped-app-settings groupedSetting=groupedSetting}}
{{/each}}
<h1>{{label}}</h1>
<input checked={{isGrouped}} type="checkbox" />
{{#if isGrouped}}
{{!grouped-channel-setting onLedgerChange=(action "bulkSetLedger")}}
{{else}}
{{!channel-setting}}
{{/if}}
{
"version": "0.15.0",
"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.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment