Skip to content

Commit 1802db9

Browse files
committed
feat: add ember-can for visibility rules
1 parent a076899 commit 1802db9

File tree

8 files changed

+91
-53
lines changed

8 files changed

+91
-53
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
@@ -70,6 +70,7 @@
7070
"@faker-js/faker": "8.1.0",
7171
"broccoli-asset-rev": "3.0.0",
7272
"concurrently": "8.2.1",
73+
"ember-can": "^4.2.0",
7374
"ember-cli": "4.12.1",
7475
"ember-cli-dependency-checker": "3.3.2",
7576
"ember-cli-inject-live-reload": "2.1.0",

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",

yarn.lock

+10-1
Original file line numberDiff line numberDiff line change
@@ -6500,6 +6500,15 @@ ember-cached-decorator-polyfill@^1.0.1:
65006500
ember-cli-babel "^7.26.11"
65016501
ember-cli-babel-plugin-helpers "^1.1.1"
65026502

6503+
ember-can@^4.2.0:
6504+
version "4.2.0"
6505+
resolved "https://registry.yarnpkg.com/ember-can/-/ember-can-4.2.0.tgz#08bfec3b2b57aad3dc6e4dc36fe9692bd1794dab"
6506+
integrity sha512-hiaWZspmI4zWeWmmFWgyw1+yEStSo6edGRHHUXCUPR+vBoqlT/hEfmndlfDGso2GFP8IV59DORMVY0KReMcO+w==
6507+
dependencies:
6508+
ember-cli-babel "^7.26.6"
6509+
ember-cli-htmlbars "^6.0.0"
6510+
ember-inflector "^4.0.2"
6511+
65036512
ember-cli-babel-plugin-helpers@^1.0.0, ember-cli-babel-plugin-helpers@^1.1.1:
65046513
version "1.1.1"
65056514
resolved "https://registry.yarnpkg.com/ember-cli-babel-plugin-helpers/-/ember-cli-babel-plugin-helpers-1.1.1.tgz#5016b80cdef37036c4282eef2d863e1d73576879"
@@ -6579,7 +6588,7 @@ ember-cli-htmlbars@^5.1.1, ember-cli-htmlbars@^5.3.1, ember-cli-htmlbars@^5.7.1:
65796588
strip-bom "^4.0.0"
65806589
walk-sync "^2.2.0"
65816590

6582-
ember-cli-htmlbars@^6.0.1, ember-cli-htmlbars@^6.2.0, ember-cli-htmlbars@^6.3.0:
6591+
ember-cli-htmlbars@^6.0.0, ember-cli-htmlbars@^6.0.1, ember-cli-htmlbars@^6.2.0, ember-cli-htmlbars@^6.3.0:
65836592
version "6.3.0"
65846593
resolved "https://registry.yarnpkg.com/ember-cli-htmlbars/-/ember-cli-htmlbars-6.3.0.tgz#ac85f2bbd09788992ab7f9ca832cd044fb8e5798"
65856594
integrity sha512-N9Y80oZfcfWLsqickMfRd9YByVcTGyhYRnYQ2XVPVrp6jyUyOeRWmEAPh7ERSXpp8Ws4hr/JB9QVQrn/yZa+Ag==

0 commit comments

Comments
 (0)