Skip to content

Commit

Permalink
feat: add ember-can for visibility rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz authored and anehx committed Dec 5, 2023
1 parent 8ef07c3 commit 4166948
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 52 deletions.
7 changes: 7 additions & 0 deletions addon/abilities/category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Ability } from "ember-can";

export default class CategoryAbility extends Ability {
get can() {
return true;
}
}
7 changes: 7 additions & 0 deletions addon/abilities/document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Ability } from "ember-can";

export default class DocumentAbility extends Ability {
get can() {
return true;
}
}
7 changes: 7 additions & 0 deletions addon/abilities/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Ability } from "ember-can";

export default class TagAbility extends Ability {
get can() {
return true;
}
}
108 changes: 57 additions & 51 deletions addon/components/document-upload-button.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<div
class="uk-height-1-1"
uk-form-custom
...attributes
>
<div class="uk-height-1-1" uk-form-custom ...attributes>
<UkButton
@color="primary"
@size="small"
Expand All @@ -15,55 +11,65 @@
</UkButton>

{{#if @category}}
<input
type="file"
multiple="multiple"
data-test-input
aria-label="Category name"
{{on "change" (perform this.upload @category)}}
/>
{{#if can "upload document" @category}}
<input
type="file"
multiple="multiple"
data-test-input
aria-label="Category name"
{{on "change" (perform this.upload @category)}}
/>
{{/if}}
{{else}}
<Drop @width="uk-with-medium" as |Item|>
{{#each this.categories.records as |category|}}
<Item uk-form-custom data-test-upload-category>
<input
type="file"
multiple="multiple"
data-test-input
aria-label="file input"
{{on "change" (perform this.upload category)}}
/>
<FaIcon
@prefix="far"
@icon="folder"
@size="2x"
class="uk-margin-small-right"
data-test-folder-icon
{{set-style color=category.color}}
/>
{{category.name}}
</Item>
{{#if category.children.length}}
{{#each category.children as |child|}}
<Item class="item--indent" uk-form-custom data-test-upload-category>
<input
type="file"
multiple="multiple"
data-test-input
aria-label="file input"
{{on "change" (perform this.upload child)}}
/>
<FaIcon
@prefix="far"
@icon="folder"
@size="2x"
class="uk-margin-small-right"
data-test-folder-icon
{{set-style color=child.color}}
/>
{{child.name}}
</Item>
{{/each}}
{{#if can "upload to category" @category}}
<Item uk-form-custom data-test-upload-category>
<input
type="file"
multiple="multiple"
data-test-input
aria-label="file input"
{{on "change" (perform this.upload category)}}
/>
<FaIcon
@prefix="far"
@icon="folder"
@size="2x"
class="uk-margin-small-right"
data-test-folder-icon
{{set-style color=category.color}}
/>
{{category.name}}
</Item>
{{#if category.children.length}}
{{#each category.children as |child|}}
{{#if can "upload to category" @category}}
<Item
class="item--indent"
uk-form-custom
data-test-upload-category
>
<input
type="file"
multiple="multiple"
data-test-input
aria-label="file input"
{{on "change" (perform this.upload child)}}
/>
<FaIcon
@prefix="far"
@icon="folder"
@size="2x"
class="uk-margin-small-right"
data-test-folder-icon
{{set-style color=child.color}}
/>
{{child.name}}
</Item>
{{/if}}
{{/each}}
{{/if}}
{{/if}}
{{else}}
<span data-test-no-categories>
Expand Down
2 changes: 1 addition & 1 deletion addon/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class EmberAlexandriaEngine extends Engine {
Resolver = Resolver;

dependencies = {
services: ["session", "intl", "notification", "config"],
services: ["abilities", "session", "intl", "notification", "config"],
};
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@glimmer/tracking": "^1.1.2",
"animate-css-grid": "^1.5.1",
"ember-auto-import": "^2.6.3",
"ember-can": "^4.2.0",
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.3.0",
"ember-composable-helpers": "^5.0.0",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class App extends Application {
"ember-alexandria": {
dependencies: {
services: [
"abilities",
"session",
"intl",
"notification",
Expand Down

0 comments on commit 4166948

Please sign in to comment.