Skip to content

Commit 2f45c98

Browse files
committed
feat(distribution): add readonly mode
1 parent b7cab5d commit 2f45c98

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

packages/distribution/addon/abilities/distribution.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { inject as service } from "@ember/service";
22
import { Ability } from "ember-can";
33

4+
import config from "@projectcaluma/ember-distribution/config";
5+
46
const hasStatus = (status) => (edge) => edge.node.status === status;
57

68
export default class DistributionAbility extends Ability {
79
@service distribution;
810

11+
@config config;
12+
913
get canSendInquiries() {
1014
return (
15+
!this.config.ui.readonly &&
1116
this.distribution.controls.value?.send.edges.filter(
1217
hasStatus("SUSPENDED")
1318
).length > 0
@@ -16,13 +21,15 @@ export default class DistributionAbility extends Ability {
1621

1722
get canCreateInquiry() {
1823
return (
24+
!this.config.ui.readonly &&
1925
this.distribution.controls.value?.create.edges.filter(hasStatus("READY"))
2026
.length > 0
2127
);
2228
}
2329

2430
get canComplete() {
2531
return (
32+
!this.config.ui.readonly &&
2633
this.distribution.controls.value?.complete.edges.filter(
2734
hasStatus("READY")
2835
).length > 0

packages/distribution/addon/abilities/inquiry.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class InquiryAbility extends Ability {
1010

1111
get canEdit() {
1212
return (
13+
!this.config.ui.readonly &&
1314
this.model?.task.slug === this.config.inquiry.task &&
1415
this.model?.status === "SUSPENDED" &&
1516
this.model?.controllingGroups
@@ -20,6 +21,7 @@ export default class InquiryAbility extends Ability {
2021

2122
get canAnswer() {
2223
return (
24+
!this.config.ui.readonly &&
2325
this.model?.task.slug === this.config.inquiry.task &&
2426
this.model?.status === "READY" &&
2527
this.model?.addressedGroups
@@ -30,6 +32,7 @@ export default class InquiryAbility extends Ability {
3032

3133
get canEditAnswerForm() {
3234
return (
35+
!this.config.ui.readonly &&
3336
this.canAnswer &&
3437
this.model?.childCase.workItems.edges.some(
3538
(edge) => edge.node.task.__typename === "CompleteWorkflowFormTask"

packages/distribution/addon/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function config(target, property) {
1515
get() {
1616
return merge(
1717
{
18-
ui: { stack: false, small: false },
18+
ui: { stack: false, small: false, readonly: false },
1919
controls: {
2020
createTask: "create-inquiry",
2121
completeTask: "complete-distribution",

packages/distribution/tests/unit/config-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module("Unit | config", function (hooks) {
7878
},
7979
},
8080
},
81-
ui: { small: false, stack: false },
81+
ui: { small: false, stack: false, readonly: false },
8282
warningPeriod: 1,
8383
});
8484
});

0 commit comments

Comments
 (0)