From 77d1bd3ed5d991adea94548fac702261ab8fae76 Mon Sep 17 00:00:00 2001 From: yelinz Date: Wed, 27 Sep 2023 16:43:27 +0200 Subject: [PATCH] feat: add ember-can for visibility rules --- addon/abilities/category.js | 7 ++ addon/abilities/document.js | 7 ++ addon/abilities/tag.js | 7 ++ addon/components/document-upload-button.hbs | 108 +++++++++++--------- addon/engine.js | 2 +- package.json | 1 + pnpm-lock.yaml | 14 +++ tests/dummy/app/app.js | 1 + 8 files changed, 95 insertions(+), 52 deletions(-) create mode 100644 addon/abilities/category.js create mode 100644 addon/abilities/document.js create mode 100644 addon/abilities/tag.js diff --git a/addon/abilities/category.js b/addon/abilities/category.js new file mode 100644 index 000000000..ecf58bda1 --- /dev/null +++ b/addon/abilities/category.js @@ -0,0 +1,7 @@ +import { Ability } from "ember-can"; + +export default class CategoryAbility extends Ability { + get can() { + return true; + } +} diff --git a/addon/abilities/document.js b/addon/abilities/document.js new file mode 100644 index 000000000..3faf4ff23 --- /dev/null +++ b/addon/abilities/document.js @@ -0,0 +1,7 @@ +import { Ability } from "ember-can"; + +export default class DocumentAbility extends Ability { + get can() { + return true; + } +} diff --git a/addon/abilities/tag.js b/addon/abilities/tag.js new file mode 100644 index 000000000..63718f10e --- /dev/null +++ b/addon/abilities/tag.js @@ -0,0 +1,7 @@ +import { Ability } from "ember-can"; + +export default class TagAbility extends Ability { + get can() { + return true; + } +} diff --git a/addon/components/document-upload-button.hbs b/addon/components/document-upload-button.hbs index dc6f5c4de..5710363bc 100644 --- a/addon/components/document-upload-button.hbs +++ b/addon/components/document-upload-button.hbs @@ -1,8 +1,4 @@ -
+
{{#if @category}} - + {{#if can "upload document" @category}} + + {{/if}} {{else}} {{#each this.categories.records as |category|}} - - - - {{category.name}} - - {{#if category.children.length}} - {{#each category.children as |child|}} - - - - {{child.name}} - - {{/each}} + {{#if can "upload to category" @category}} + + + + {{category.name}} + + {{#if category.children.length}} + {{#each category.children as |child|}} + {{#if can "upload to category" @category}} + + + + {{child.name}} + + {{/if}} + {{/each}} + {{/if}} {{/if}} {{else}} diff --git a/addon/engine.js b/addon/engine.js index 1c1c30eaa..115abf666 100644 --- a/addon/engine.js +++ b/addon/engine.js @@ -11,7 +11,7 @@ export default class EmberAlexandriaEngine extends Engine { Resolver = Resolver; dependencies = { - services: ["session", "intl", "notification", "config"], + services: ["abilities", "session", "intl", "notification", "config"], }; } diff --git a/package.json b/package.json index 12af092b9..0d21f174d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b2273b29a..b07c54954 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,9 @@ dependencies: ember-auto-import: specifier: ^2.6.3 version: 2.7.0(@glint/template@1.2.1)(webpack@5.89.0) + ember-can: + specifier: ^4.2.0 + version: 4.2.0 ember-cli-babel: specifier: ^8.2.0 version: 8.2.0(@babel/core@7.23.5) @@ -6251,6 +6254,17 @@ packages: - '@glint/template' - supports-color + /ember-can@4.2.0: + resolution: {integrity: sha512-hiaWZspmI4zWeWmmFWgyw1+yEStSo6edGRHHUXCUPR+vBoqlT/hEfmndlfDGso2GFP8IV59DORMVY0KReMcO+w==} + engines: {node: 12.* || 14.* || >= 16} + dependencies: + ember-cli-babel: 7.26.11 + ember-cli-htmlbars: 6.3.0 + ember-inflector: 4.0.2 + transitivePeerDependencies: + - supports-color + dev: false + /ember-cli-babel-plugin-helpers@1.1.1: resolution: {integrity: sha512-sKvOiPNHr5F/60NLd7SFzMpYPte/nnGkq/tMIfXejfKHIhaiIkYFqX8Z9UFTKWLLn+V7NOaby6niNPZUdvKCRw==} engines: {node: 6.* || 8.* || >= 10.*} diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index 05a20724f..bb1eb0dfe 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -13,6 +13,7 @@ export default class App extends Application { "ember-alexandria": { dependencies: { services: [ + "abilities", "session", "intl", "notification",