Skip to content

Commit 4166948

Browse files
Yelinzanehx
authored andcommitted
feat: add ember-can for visibility rules
1 parent 8ef07c3 commit 4166948

File tree

8 files changed

+95
-52
lines changed

8 files changed

+95
-52
lines changed

addon/abilities/category.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Ability } from "ember-can";
2+
3+
export default class CategoryAbility extends Ability {
4+
get can() {
5+
return true;
6+
}
7+
}

addon/abilities/document.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Ability } from "ember-can";
2+
3+
export default class DocumentAbility extends Ability {
4+
get can() {
5+
return true;
6+
}
7+
}

addon/abilities/tag.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Ability } from "ember-can";
2+
3+
export default class TagAbility extends Ability {
4+
get can() {
5+
return true;
6+
}
7+
}

addon/components/document-upload-button.hbs

+57-51
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
<div
2-
class="uk-height-1-1"
3-
uk-form-custom
4-
...attributes
5-
>
1+
<div class="uk-height-1-1" uk-form-custom ...attributes>
62
<UkButton
73
@color="primary"
84
@size="small"
@@ -15,55 +11,65 @@
1511
</UkButton>
1612

1713
{{#if @category}}
18-
<input
19-
type="file"
20-
multiple="multiple"
21-
data-test-input
22-
aria-label="Category name"
23-
{{on "change" (perform this.upload @category)}}
24-
/>
14+
{{#if can "upload document" @category}}
15+
<input
16+
type="file"
17+
multiple="multiple"
18+
data-test-input
19+
aria-label="Category name"
20+
{{on "change" (perform this.upload @category)}}
21+
/>
22+
{{/if}}
2523
{{else}}
2624
<Drop @width="uk-with-medium" as |Item|>
2725
{{#each this.categories.records as |category|}}
28-
<Item uk-form-custom data-test-upload-category>
29-
<input
30-
type="file"
31-
multiple="multiple"
32-
data-test-input
33-
aria-label="file input"
34-
{{on "change" (perform this.upload category)}}
35-
/>
36-
<FaIcon
37-
@prefix="far"
38-
@icon="folder"
39-
@size="2x"
40-
class="uk-margin-small-right"
41-
data-test-folder-icon
42-
{{set-style color=category.color}}
43-
/>
44-
{{category.name}}
45-
</Item>
46-
{{#if category.children.length}}
47-
{{#each category.children as |child|}}
48-
<Item class="item--indent" uk-form-custom data-test-upload-category>
49-
<input
50-
type="file"
51-
multiple="multiple"
52-
data-test-input
53-
aria-label="file input"
54-
{{on "change" (perform this.upload child)}}
55-
/>
56-
<FaIcon
57-
@prefix="far"
58-
@icon="folder"
59-
@size="2x"
60-
class="uk-margin-small-right"
61-
data-test-folder-icon
62-
{{set-style color=child.color}}
63-
/>
64-
{{child.name}}
65-
</Item>
66-
{{/each}}
26+
{{#if can "upload to category" @category}}
27+
<Item uk-form-custom data-test-upload-category>
28+
<input
29+
type="file"
30+
multiple="multiple"
31+
data-test-input
32+
aria-label="file input"
33+
{{on "change" (perform this.upload category)}}
34+
/>
35+
<FaIcon
36+
@prefix="far"
37+
@icon="folder"
38+
@size="2x"
39+
class="uk-margin-small-right"
40+
data-test-folder-icon
41+
{{set-style color=category.color}}
42+
/>
43+
{{category.name}}
44+
</Item>
45+
{{#if category.children.length}}
46+
{{#each category.children as |child|}}
47+
{{#if can "upload to category" @category}}
48+
<Item
49+
class="item--indent"
50+
uk-form-custom
51+
data-test-upload-category
52+
>
53+
<input
54+
type="file"
55+
multiple="multiple"
56+
data-test-input
57+
aria-label="file input"
58+
{{on "change" (perform this.upload child)}}
59+
/>
60+
<FaIcon
61+
@prefix="far"
62+
@icon="folder"
63+
@size="2x"
64+
class="uk-margin-small-right"
65+
data-test-folder-icon
66+
{{set-style color=child.color}}
67+
/>
68+
{{child.name}}
69+
</Item>
70+
{{/if}}
71+
{{/each}}
72+
{{/if}}
6773
{{/if}}
6874
{{else}}
6975
<span data-test-no-categories>

addon/engine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class EmberAlexandriaEngine extends Engine {
1111
Resolver = Resolver;
1212

1313
dependencies = {
14-
services: ["session", "intl", "notification", "config"],
14+
services: ["abilities", "session", "intl", "notification", "config"],
1515
};
1616
}
1717

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@glimmer/tracking": "^1.1.2",
4343
"animate-css-grid": "^1.5.1",
4444
"ember-auto-import": "^2.6.3",
45+
"ember-can": "^4.2.0",
4546
"ember-cli-babel": "^8.2.0",
4647
"ember-cli-htmlbars": "^6.3.0",
4748
"ember-composable-helpers": "^5.0.0",

pnpm-lock.yaml

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/dummy/app/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class App extends Application {
1313
"ember-alexandria": {
1414
dependencies: {
1515
services: [
16+
"abilities",
1617
"session",
1718
"intl",
1819
"notification",

0 commit comments

Comments
 (0)