diff --git a/.eslintrc.js b/.eslintrc.js index 0c585b6..cc589c7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -36,6 +36,8 @@ module.exports = { 'postcss-mixins', 'postcss-conditionals-renewed', 'postcss-at-rules-variables', + 'broccoli-funnel', + 'broccoli-merge-trees', 'autoprefixer', 'tailwindcss', '@tailwindcss/forms', diff --git a/addon/components/button.hbs b/addon/components/button.hbs index e426e0f..7d0ef9a 100644 --- a/addon/components/button.hbs +++ b/addon/components/button.hbs @@ -31,7 +31,11 @@ {{/if}} {{yield}} - {{#if @helpText}} + {{#if this.disabledByPermission}} + + + + {{else if @helpText}} diff --git a/addon/components/button.js b/addon/components/button.js index af13414..cd00a8f 100644 --- a/addon/components/button.js +++ b/addon/components/button.js @@ -1,17 +1,26 @@ import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { inject as service } from '@ember/service'; import { computed, action } from '@ember/object'; import { not, equal } from '@ember/object/computed'; export default class ButtonComponent extends Component { + /** + * Inject abilities service. + * + * @memberof ButtonComponent + */ + @service abilities; + /** * Determines if the button should be disabled * * @var {Boolean} */ - @computed('args.{isLoading,disabled}') get isDisabled() { + @computed('args.{disabled,disabledByPermission,isLoading}', 'disabledByPermission') get isDisabled() { const { isLoading, disabled } = this.args; - return disabled || isLoading; + return this.disabledByPermission || disabled || isLoading; } /** @@ -39,6 +48,27 @@ export default class ButtonComponent extends Component { return icon && !isLoading; } + /** + * If the button is disabled by permissions. + * + * @memberof ButtonComponent + */ + @tracked disabledByPermission = false; + + /** + * Creates an instance of ButtonComponent. + * @param {*} owner + * @param {*} { permission = null } + * @memberof ButtonComponent + */ + constructor(owner, { permission = null, disabled = false }) { + super(...arguments); + this.permissionRequired = permission; + if (!disabled) { + this.disabledByPermission = permission && this.abilities.cannot(permission); + } + } + /** * Setup this component * diff --git a/addon/components/content-panel.hbs b/addon/components/content-panel.hbs index 2fe04fe..9f95b8f 100644 --- a/addon/components/content-panel.hbs +++ b/addon/components/content-panel.hbs @@ -81,7 +81,16 @@ {{/if}} {{#each @actionButtons as |button|}} - {{/if}} + {{#if this.doesntHavePermissions}} + + + + {{/if}} {{yield dd}} diff --git a/addon/components/dropdown-button.js b/addon/components/dropdown-button.js index d7d385b..3b591a5 100644 --- a/addon/components/dropdown-button.js +++ b/addon/components/dropdown-button.js @@ -1,14 +1,19 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; +import { inject as service } from '@ember/service'; import { action } from '@ember/object'; export default class DropdownButtonComponent extends Component { + @service abilities; @tracked type = 'default'; @tracked buttonSize = 'md'; @tracked buttonComponentArgs = {}; @tracked _onInsertFired = false; @tracked _onTriggerInsertFired = false; @tracked _onButtonInsertFired = false; + @tracked disabled = false; + @tracked permissionRequired = false; + @tracked doesntHavePermissions = false; /** * Creates an instance of DropdownButtonComponent. @@ -16,12 +21,18 @@ export default class DropdownButtonComponent extends Component { * @param {Object} { type = 'default', size = 'md', buttonComponentArgs = {}} * @memberof DropdownButtonComponent */ - constructor(owner, { type = 'default', size = 'md', buttonComponentArgs = {} }) { + constructor(owner, { type = 'default', size = 'md', buttonComponentArgs = {}, permission = null, disabled = false }) { super(...arguments); this.type = type; this.buttonSize = size; this.buttonComponentArgs = buttonComponentArgs; + this.permissionRequired = permission; + this.disabled = disabled; + // If no permissions disable + if (!disabled) { + this.disabled = this.doesntHavePermissions = permission && this.abilities.cannot(permission); + } } @action onRegisterAPI() { diff --git a/addon/components/file-upload.hbs b/addon/components/file-upload.hbs index a27a461..b1d88f7 100644 --- a/addon/components/file-upload.hbs +++ b/addon/components/file-upload.hbs @@ -2,8 +2,8 @@ (file-queue name=@name onFileAdded=@onFileAdded onFileRemoved=@onFileRemoved onUploadStarted=@onUploadStarted onUploadSucceeded=@onUploadSucceeded onUploadFailed=@onUploadFailed) as |queue| }} -