const app = require('../app') const { Set } = require('immutable') app.component('appPermissionsSelect', { template: html` Permissions

{{permission.key}}

{{permission.description}}

`, bindings: { ngModel: '=' }, controller: function(api, $scope) { api.get('/api/auth/permissions').then(x => { this.permissions = x }) const modelWatcher = $scope.$watch('$ctrl.ngModel', (model) => { if (model) { this.set = new Set(model.split(',')) } else { this.set = new Set() } }) $scope.$on('$destroy', () => modelWatcher()) this.toggle = permission => { if (this.set.has(permission)) { this.set = this.set.remove(permission) } else { this.set = this.set.add(permission) } this.ngModel = this.set.join(',') } } })