-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcontroller.js
155 lines (131 loc) · 4.11 KB
/
controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
import { useCalumaQuery } from "@projectcaluma/ember-core/caluma-query";
import { allCases } from "@projectcaluma/ember-core/caluma-query/queries";
import { queryManager } from "ember-apollo-client";
import { trackedFunction } from "reactiveweb/function";
import ENV from "mysagw/config/environment";
import casesCountQuery from "mysagw/gql/queries/cases-count.graphql";
import { arrayFromString, serializeOrder } from "mysagw/utils/query-params";
import TableController from "mysagw/utils/table-controller";
export default class CasesIndexController extends TableController {
@service store;
@service notification;
@queryManager apollo;
@tracked editMode = false;
@tracked selectedCases = [];
@tracked refreshList = 0;
caseQuery = useCalumaQuery(this, allCases, () => ({
options: { pageSize: 20 },
filter: this.caseFilters.value,
order: [serializeOrder(this.order, "documentAnswer")],
}));
showEmpty = trackedFunction(this, async () => {
return (
this.apollo.query({ query: casesCountQuery }, "allCases.totalCount") === 0
);
});
caseFilters = trackedFunction(this, async () => {
// needed to trigger a re-fetch after editing (e.g. transfer)
this.refreshList;
this.selectedCases = [];
// access to attributes must happen before await, otherwise no reactivity
const { identities } = this.filters;
const { identities: invertedIdentites } = this.invertedFilters;
const filters = [
{ workflow: "circulation", invert: true },
{ status: "CANCELED", invert: true },
];
if (this.filters.documentNumber) {
filters.push({
hasAnswer: [
{
question: "dossier-nr",
value: this.filters.documentNumber,
lookup: "ICONTAINS",
},
],
invert: Boolean(this.invertedFilters.documentNumber),
});
}
if (this.filters.answerSearch) {
filters.push({
searchAnswers: [
{
forms: this.forms,
value: this.filters.answerSearch,
},
],
invert: Boolean(this.invertedFilters.answerSearch),
});
}
if (this.filters.forms) {
filters.push({
documentForms: arrayFromString(this.filters.forms),
invert: Boolean(this.invertedFilters.forms),
});
}
Object.keys(ENV.APP.caluma.filterableQuestions).forEach((question) => {
if (!this.filters[question]) {
return;
}
filters.push({
hasAnswer: [
{
question: ENV.APP.caluma.filterableQuestions[question],
lookup: "IN",
value: arrayFromString(this.filters[question]),
},
],
invert: Boolean(this.invertedFilters[question]),
});
});
if (identities) {
filters.push({
ids: await this.fetchAccesses(arrayFromString(identities)),
invert: Boolean(invertedIdentites),
});
}
return filters;
});
async fetchAccesses(ids) {
if (!ids) {
return [];
}
try {
const accesses = (
await this.store.query("case-access", {
filter: { identityIds: ids.join(",") },
})
).map((access) => access.get("caseId"));
// filtering against an empty list is treated as a no-op, therefore return a dummy value
return accesses.length
? accesses
: ["00000000-0000-0000-0000-000000000000"];
} catch (error) {
console.error(error);
this.notification.fromError(error);
}
}
@action
selectCase(value) {
const deselection = this.selectedCases.filter((c) => c.id !== value.id);
if (deselection.length < this.selectedCases.length) {
this.selectedCases = deselection;
return;
}
this.selectedCases = [...this.selectedCases, value];
}
get selectedCaseIds() {
return this.selectedCases.map((c) => c.id);
}
get accessToRemove() {
return arrayFromString(this.filters.identities);
}
@action
afterTransfer() {
this.editMode = false;
this.refreshList++;
}
}