Last active
May 11, 2021 19:06
-
-
Save dbachet/83f815aaa725a67a6ead23b372193157 to your computer and use it in GitHub Desktop.
New Twiddle
This file contains hidden or 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 Component from '@glimmer/component'; | |
| import { get } from "@ember/object"; | |
| export default class extends Component { | |
| // get isRowSelected(){ | |
| // return this.args.rowStates[this.args.rowId]; | |
| // }; | |
| } |
This file contains hidden or 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 Component from '@glimmer/component'; | |
| import { action } from '@ember/object'; | |
| import { tracked } from '@glimmer/tracking'; | |
| import { set } from "@ember/object"; | |
| import { A } from '@ember/array'; | |
| import EmberObject from '@ember/object'; | |
| export default class extends Component { | |
| constructor(){ | |
| super(...arguments); | |
| this.rowStates = this.args.shareholders.reduce((result, item) => { | |
| result[String(item.id)] = false; | |
| return result; | |
| }, EmberObject) | |
| this.numberOfRows = Object.keys(this.rowStates).length; | |
| }; | |
| @tracked rowStates = {}; | |
| @tracked numberOfRows; | |
| get isMasterCheckboxSelected() { | |
| const numberOfSelectedRows = Object.keys(this.rowStates).filter((key) => this.rowStates[key]).length | |
| return numberOfSelectedRows == this.numberOfRows; | |
| }; | |
| @action | |
| toggleAllCheckboxes(event) { | |
| Object.keys(this.rowStates).forEach((key) => { | |
| this.rowStates[key] = event.target.checked; | |
| }); | |
| this.rowStates = this.rowStates; | |
| return false; | |
| }; | |
| @action | |
| updateSelectedRows(event) { | |
| const rowId = event.target.getAttribute("data-row-id"); | |
| this.rowStates[rowId] = event.target.checked | |
| this.rowStates =this.rowStates; | |
| return false; | |
| }; | |
| } |
This file contains hidden or 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 Controller from '@ember/controller'; | |
| import { tracked } from '@glimmer/tracking'; | |
| export default class ApplicationController extends Controller { | |
| appName = 'Ember Twiddle'; | |
| @tracked shareholders = [ | |
| { | |
| name: 'SH 1', | |
| id: '1' | |
| }, | |
| { | |
| name: 'SH 2', | |
| id: '2' | |
| }, | |
| { | |
| name: 'SH 3', | |
| id: '3' | |
| } | |
| ] | |
| } |
This file contains hidden or 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.17.1", | |
| "EmberENV": { | |
| "FEATURES": {}, | |
| "_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
| "_APPLICATION_TEMPLATE_WRAPPER": true, | |
| "_JQUERY_INTEGRATION": true | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
| "ember": "3.18.1", | |
| "ember-template-compiler": "3.18.1", | |
| "ember-testing": "3.18.1" | |
| }, | |
| "addons": { | |
| "@glimmer/component": "1.0.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment