@projectcaluma/ember-distribution 11.0.0-beta.29 → 11.0.0-beta.31
Sign up to get free protection for your applications and to get access to all the features.
- package/addon/abilities/distribution.js +9 -0
- package/addon/abilities/inquiry.js +1 -1
- package/addon/components/cd-document-header.hbs +3 -12
- package/addon/components/cd-inquiry-answer-form.hbs +140 -57
- package/addon/components/cd-inquiry-answer-form.js +20 -2
- package/addon/components/cd-inquiry-dialog/inquiry-deadline.hbs +5 -10
- package/addon/components/cd-inquiry-dialog/inquiry-deadline.js +14 -0
- package/addon/components/cd-inquiry-dialog/inquiry-part.hbs +116 -89
- package/addon/components/cd-inquiry-dialog.js +11 -15
- package/addon/components/cd-inquiry-edit-form.hbs +12 -4
- package/addon/components/cd-inquiry-edit-form.js +2 -2
- package/addon/components/cd-inquiry-new-form/bulk-edit.hbs +20 -0
- package/addon/components/cd-inquiry-new-form/bulk-edit.js +116 -0
- package/addon/components/cd-inquiry-new-form/select.hbs +71 -0
- package/addon/components/cd-inquiry-new-form/select.js +76 -0
- package/addon/components/cd-inquiry-new-form.hbs +29 -86
- package/addon/components/cd-inquiry-new-form.js +1 -100
- package/addon/components/cd-navigation/controls.hbs +112 -66
- package/addon/components/cd-navigation/controls.js +29 -14
- package/addon/components/cd-navigation/item.hbs +22 -11
- package/addon/components/cd-navigation/section.hbs +15 -21
- package/addon/components/cd-navigation/section.js +5 -13
- package/addon/components/cd-navigation.hbs +4 -9
- package/addon/config.js +19 -0
- package/addon/gql/fragments/inquiry-answer.graphql +57 -0
- package/addon/gql/fragments/inquiry-request.graphql +26 -0
- package/addon/gql/mutations/complete-inquiry-work-item.graphql +24 -13
- package/addon/gql/mutations/reopen-inquiry.graphql +3 -13
- package/addon/gql/queries/{control-work-items.graphql → controls.graphql} +18 -1
- package/addon/gql/queries/incomplete-inquiries.graphql +1 -1
- package/addon/gql/queries/inquiry-answer.graphql +5 -1
- package/addon/gql/queries/inquiry-dialog.graphql +31 -2
- package/addon/gql/queries/inquiry-form.graphql +26 -0
- package/addon/gql/queries/{inquiry-navigation.graphql → navigation.graphql} +24 -6
- package/addon/routes/application.js +7 -0
- package/addon/routes/index.js +15 -28
- package/addon/routes/inquiry/index.js +1 -4
- package/addon/routes/new.js +1 -5
- package/addon/services/distribution.js +81 -9
- package/addon/templates/application.hbs +7 -5
- package/addon/templates/index.hbs +1 -5
- package/addon/templates/inquiry/index.hbs +1 -5
- package/addon/templates/new.hbs +0 -1
- package/addon/utils/inquiry-deadline.js +3 -1
- package/app/components/cd-inquiry-new-form/bulk-edit.js +1 -0
- package/app/components/cd-inquiry-new-form/select.js +1 -0
- package/app/styles/_answer-form.scss +4 -0
- package/package.json +17 -17
- package/translations/de.yaml +31 -9
- package/translations/en.yaml +31 -10
- package/translations/fr.yaml +31 -9
- package/addon/components/cd-navigation.js +0 -53
- package/addon/gql/fragments/inquiry.graphql +0 -117
- package/addon/modifiers/pikaday.js +0 -2
@@ -11,11 +11,8 @@
|
|
11
11
|
(eq this.inquiry.status "SUSPENDED")
|
12
12
|
(t "caluma.distribution.status.draft")
|
13
13
|
}}
|
14
|
-
@modifiedAt={{this.inquiry.document.modifiedContentAt}}
|
15
|
-
@modifiedBy={{this.inquiry.document.modifiedContentByUser}}
|
16
14
|
/>
|
17
15
|
|
18
|
-
<hr />
|
19
16
|
{{#if
|
20
17
|
(and
|
21
18
|
(cannot "send inquiry" this.inquiry)
|
@@ -23,12 +20,23 @@
|
|
23
20
|
)
|
24
21
|
}}
|
25
22
|
<div class="uk-alert uk-alert-warning uk-flex uk-flex-middle">
|
26
|
-
<UkIcon @icon="warning" class="uk-margin-small-right" />
|
23
|
+
<UkIcon @icon="warning" class="uk-margin-small-right uk-flex-none" />
|
27
24
|
{{t "caluma.distribution.edit.send-not-allowed"}}
|
28
25
|
{{t "caluma.distribution.not-allowed-hint"}}
|
29
26
|
</div>
|
30
27
|
{{/if}}
|
31
28
|
|
29
|
+
{{#if
|
30
|
+
(and (can "edit inquiry" this.inquiry) (eq this.inquiry.status "READY"))
|
31
|
+
}}
|
32
|
+
<div class="uk-alert uk-alert-warning uk-flex uk-flex-middle">
|
33
|
+
<UkIcon @icon="warning" class="uk-margin-small-right uk-flex-none" />
|
34
|
+
<p class="uk-margin-remove">
|
35
|
+
{{t "caluma.distribution.edit.edit-sent" htmlSafe=true}}
|
36
|
+
</p>
|
37
|
+
</div>
|
38
|
+
{{/if}}
|
39
|
+
|
32
40
|
<content.form />
|
33
41
|
|
34
42
|
{{#if
|
@@ -24,11 +24,11 @@ export default class CdInquiryEditFormComponent extends Component {
|
|
24
24
|
}
|
25
25
|
|
26
26
|
@dropTask
|
27
|
-
*fetchInquiry() {
|
27
|
+
*fetchInquiry(inquiry) {
|
28
28
|
return yield this.apollo.watchQuery(
|
29
29
|
{
|
30
30
|
query: inquiryEditQuery,
|
31
|
-
variables: { inquiry
|
31
|
+
variables: { inquiry },
|
32
32
|
},
|
33
33
|
"allWorkItems.edges"
|
34
34
|
);
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{{#if this.document.isLoading}}
|
2
|
+
<div class="uk-text-center"><UkSpinner @ratio={{2}} /></div>
|
3
|
+
{{else if this.document.value}}
|
4
|
+
<CfFormWrapper
|
5
|
+
@document={{this.document.value}}
|
6
|
+
@fieldset={{this.fieldset}}
|
7
|
+
@onSave={{this.saveField}}
|
8
|
+
/>
|
9
|
+
<DocumentValidity @document={{this.document.value}} as |isValid validate|>
|
10
|
+
<UkButton
|
11
|
+
@color="primary"
|
12
|
+
@label={{t "caluma.distribution.new.create-draft"}}
|
13
|
+
@type="submit"
|
14
|
+
@loading={{this.submit.isRunning}}
|
15
|
+
@disabled={{or (not isValid) this.submit.isRunning}}
|
16
|
+
@onClick={{perform this.submit validate}}
|
17
|
+
data-test-submit
|
18
|
+
/>
|
19
|
+
</DocumentValidity>
|
20
|
+
{{/if}}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import { getOwner } from "@ember/application";
|
2
|
+
import { action } from "@ember/object";
|
3
|
+
import { guidFor } from "@ember/object/internals";
|
4
|
+
import { inject as service } from "@ember/service";
|
5
|
+
import Component from "@glimmer/component";
|
6
|
+
import { queryManager } from "ember-apollo-client";
|
7
|
+
import { dropTask } from "ember-concurrency";
|
8
|
+
import { trackedFunction } from "ember-resources/util/function";
|
9
|
+
import { DateTime } from "luxon";
|
10
|
+
|
11
|
+
import { decodeId } from "@projectcaluma/ember-core/helpers/decode-id";
|
12
|
+
import config from "@projectcaluma/ember-distribution/config";
|
13
|
+
import inquiryFormQuery from "@projectcaluma/ember-distribution/gql/queries/inquiry-form.graphql";
|
14
|
+
import { parseDocument } from "@projectcaluma/ember-form/lib/parsers";
|
15
|
+
|
16
|
+
export default class CdInquiryNewFormBulkEditComponent extends Component {
|
17
|
+
@service router;
|
18
|
+
@service distribution;
|
19
|
+
|
20
|
+
@queryManager apollo;
|
21
|
+
|
22
|
+
@config config;
|
23
|
+
|
24
|
+
answers = {};
|
25
|
+
|
26
|
+
document = trackedFunction(this, async () => {
|
27
|
+
// Fetch the full form (like in cf-content) of the inquiry task
|
28
|
+
const response = await this.apollo.query({
|
29
|
+
query: inquiryFormQuery,
|
30
|
+
variables: {
|
31
|
+
inquiryTask: this.config.inquiry.task,
|
32
|
+
},
|
33
|
+
});
|
34
|
+
const form = response.allTasks.edges[0].node.form;
|
35
|
+
const answers = { edges: [] };
|
36
|
+
|
37
|
+
// If we configured a default deadline lead time, we need to calculate the
|
38
|
+
// deadline that should be displayed in the form per default and add it to
|
39
|
+
// the fake document data
|
40
|
+
if (this.config.new.defaultDeadlineLeadTime) {
|
41
|
+
const deadline = DateTime.now()
|
42
|
+
.plus({ days: this.config.new.defaultDeadlineLeadTime })
|
43
|
+
.toISODate();
|
44
|
+
|
45
|
+
answers.edges.push({
|
46
|
+
node: {
|
47
|
+
dateValue: deadline,
|
48
|
+
question: {
|
49
|
+
slug: this.config.inquiry.deadlineQuestion,
|
50
|
+
},
|
51
|
+
__typename: "DateAnswer",
|
52
|
+
},
|
53
|
+
});
|
54
|
+
|
55
|
+
this.answers[this.config.inquiry.deadlineQuestion] = deadline;
|
56
|
+
}
|
57
|
+
|
58
|
+
// Generate a parsed raw data object which can be used for creating a caluma
|
59
|
+
// form lib layer document which we need for displaying a form. This is
|
60
|
+
// normally done in the cf-content component which fetches the form (like we
|
61
|
+
// do above) and the document from the backend and then merges it together
|
62
|
+
// with this function. However, since we need a document without existence
|
63
|
+
// in the backend, we need to create this object ourselves.
|
64
|
+
const raw = parseDocument({
|
65
|
+
id: btoa(`Document:inquiry-document-${guidFor(this)}`),
|
66
|
+
__typename: "Document",
|
67
|
+
answers,
|
68
|
+
form,
|
69
|
+
});
|
70
|
+
|
71
|
+
const owner = getOwner(this);
|
72
|
+
const Document = owner.factoryFor("caluma-model:document").class;
|
73
|
+
|
74
|
+
return new Document({ raw, owner });
|
75
|
+
});
|
76
|
+
|
77
|
+
get fieldset() {
|
78
|
+
return this.document.value?.fieldsets[0];
|
79
|
+
}
|
80
|
+
|
81
|
+
@action
|
82
|
+
async saveField(field, value) {
|
83
|
+
field.answer.value = value;
|
84
|
+
|
85
|
+
await field.validate.perform();
|
86
|
+
|
87
|
+
this.answers[field.question.slug] = value;
|
88
|
+
}
|
89
|
+
|
90
|
+
@dropTask
|
91
|
+
*submit(validate, e) {
|
92
|
+
e.preventDefault();
|
93
|
+
|
94
|
+
if (!this.args.selectedGroups.length || !(yield validate())) return;
|
95
|
+
|
96
|
+
yield this.distribution.createInquiry.perform(this.args.selectedGroups, {
|
97
|
+
answers: this.answers,
|
98
|
+
});
|
99
|
+
|
100
|
+
const firstCreated = this.distribution.navigation.value.controlling.edges
|
101
|
+
.map((edge) => edge.node)
|
102
|
+
.find((node) =>
|
103
|
+
node.addressedGroups.includes(String(this.args.selectedGroups[0]))
|
104
|
+
);
|
105
|
+
|
106
|
+
// transition to inquiry addressed to the first selected group
|
107
|
+
this.router.transitionTo(
|
108
|
+
"inquiry.detail.index",
|
109
|
+
{
|
110
|
+
from: firstCreated.controllingGroups[0],
|
111
|
+
to: firstCreated.addressedGroups[0],
|
112
|
+
},
|
113
|
+
decodeId(firstCreated.id)
|
114
|
+
);
|
115
|
+
}
|
116
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
<div class="uk-margin-bottom uk-button-group">
|
2
|
+
{{#each-in this.config.new.types as |slug config|}}
|
3
|
+
{{#unless config.disabled}}
|
4
|
+
<UkButton
|
5
|
+
data-test-type={{slug}}
|
6
|
+
@label={{t config.label}}
|
7
|
+
@color={{if (includes slug @selectedTypes) "primary" "default"}}
|
8
|
+
@onClick={{fn this.updateSelectedTypes slug}}
|
9
|
+
/>
|
10
|
+
{{/unless}}
|
11
|
+
{{/each-in}}
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="uk-search uk-search-default uk-width-1-1">
|
15
|
+
<span class="uk-search-icon-flip" uk-search-icon></span>
|
16
|
+
<input
|
17
|
+
placeholder={{t "caluma.distribution.new.search"}}
|
18
|
+
aria-label={{t "caluma.distribution.new.search"}}
|
19
|
+
class="uk-search-input"
|
20
|
+
type="search"
|
21
|
+
value={{@search}}
|
22
|
+
data-test-search
|
23
|
+
{{on "input" (perform this.updateSearch)}}
|
24
|
+
/>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
{{#if this.groups.isRunning}}
|
28
|
+
<div class="uk-text-center uk-margin">
|
29
|
+
<UkSpinner @ratio={{2}} />
|
30
|
+
</div>
|
31
|
+
{{else if this.groups.value.length}}
|
32
|
+
<table
|
33
|
+
class="uk-table uk-table-striped uk-table-hover uk-table-small uk-table-middle group-list"
|
34
|
+
>
|
35
|
+
<tbody>
|
36
|
+
{{#each this.groups.value as |group|}}
|
37
|
+
{{! template-lint-disable require-presentational-children }}
|
38
|
+
<tr
|
39
|
+
role="checkbox"
|
40
|
+
data-test-group={{group.identifier}}
|
41
|
+
{{on "click" (fn this.updateSelectedGroups group.identifier)}}
|
42
|
+
>
|
43
|
+
<td class="uk-padding-remove-right">
|
44
|
+
{{! template-lint-disable require-input-label no-nested-interactive }}
|
45
|
+
<input
|
46
|
+
type="checkbox"
|
47
|
+
class="uk-checkbox"
|
48
|
+
checked={{includes group.identifier @selectedGroups}}
|
49
|
+
/>
|
50
|
+
</td>
|
51
|
+
<td class="uk-width-expand">{{group-name group.identifier}}</td>
|
52
|
+
<td class="uk-text-right">
|
53
|
+
{{#if group.config.icon}}
|
54
|
+
<UkIcon
|
55
|
+
@icon={{group.config.icon}}
|
56
|
+
class="uk-display-block uk-text-{{group.config.iconColor}}"
|
57
|
+
/>
|
58
|
+
{{/if}}
|
59
|
+
</td>
|
60
|
+
</tr>
|
61
|
+
{{/each}}
|
62
|
+
</tbody>
|
63
|
+
</table>
|
64
|
+
{{else}}
|
65
|
+
<div class="uk-text-center">
|
66
|
+
<UkIcon @icon="search" @ratio={{10}} class="uk-margin-top" />
|
67
|
+
<p class="uk-text-muted">
|
68
|
+
{{t "caluma.distribution.new.empty"}}
|
69
|
+
</p>
|
70
|
+
</div>
|
71
|
+
{{/if}}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { action } from "@ember/object";
|
2
|
+
import { inject as service } from "@ember/service";
|
3
|
+
import { macroCondition, isTesting } from "@embroider/macros";
|
4
|
+
import Component from "@glimmer/component";
|
5
|
+
import { timeout, restartableTask } from "ember-concurrency";
|
6
|
+
import { trackedTask } from "ember-resources/util/ember-concurrency";
|
7
|
+
|
8
|
+
import config from "@projectcaluma/ember-distribution/config";
|
9
|
+
|
10
|
+
const toggle = (value, array) => {
|
11
|
+
const set = new Set(array);
|
12
|
+
|
13
|
+
set.delete(value) || set.add(value);
|
14
|
+
|
15
|
+
return [...set];
|
16
|
+
};
|
17
|
+
|
18
|
+
export default class CdInquiryNewFormSelectComponent extends Component {
|
19
|
+
@service calumaOptions;
|
20
|
+
|
21
|
+
@config config;
|
22
|
+
|
23
|
+
groups = trackedTask(this, this.fetchGroups, () => [
|
24
|
+
this.args.selectedTypes,
|
25
|
+
this.args.search,
|
26
|
+
]);
|
27
|
+
|
28
|
+
@action
|
29
|
+
updateSelectedTypes(type, e) {
|
30
|
+
e.preventDefault();
|
31
|
+
|
32
|
+
this.args.onChangeSelectedTypes(toggle(type, this.args.selectedTypes));
|
33
|
+
}
|
34
|
+
|
35
|
+
@action
|
36
|
+
updateSelectedGroups(identifier) {
|
37
|
+
this.args.onChangeSelectedGroups(
|
38
|
+
toggle(identifier, this.args.selectedGroups)
|
39
|
+
);
|
40
|
+
}
|
41
|
+
|
42
|
+
@restartableTask
|
43
|
+
*updateSearch(e) {
|
44
|
+
e.preventDefault();
|
45
|
+
|
46
|
+
/* istanbul ignore next */
|
47
|
+
if (macroCondition(isTesting())) {
|
48
|
+
// no timeout
|
49
|
+
} else {
|
50
|
+
yield timeout(500);
|
51
|
+
}
|
52
|
+
|
53
|
+
this.args.onChangeSearch(e.target.value);
|
54
|
+
}
|
55
|
+
|
56
|
+
@restartableTask
|
57
|
+
*fetchGroups(types, search) {
|
58
|
+
// https://github.com/ember-cli/eslint-plugin-ember/issues/1413
|
59
|
+
yield Promise.resolve();
|
60
|
+
|
61
|
+
const typedGroups = yield this.calumaOptions.fetchTypedGroups(
|
62
|
+
types,
|
63
|
+
search
|
64
|
+
);
|
65
|
+
|
66
|
+
return Object.entries(typedGroups)
|
67
|
+
.flatMap(([type, groups]) => {
|
68
|
+
return groups.map((group) => ({
|
69
|
+
identifier: group[this.calumaOptions.groupIdentifierProperty],
|
70
|
+
name: group[this.calumaOptions.groupNameProperty],
|
71
|
+
config: this.config.new.types[type],
|
72
|
+
}));
|
73
|
+
})
|
74
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
75
|
+
}
|
76
|
+
}
|
@@ -1,6 +1,4 @@
|
|
1
|
-
{{#if
|
2
|
-
<div class="uk-text-center"><UkSpinner @ratio={{2}} /></div>
|
3
|
-
{{else if (can "create inquiry of distribution")}}
|
1
|
+
{{#if (can "create inquiry of distribution")}}
|
4
2
|
<p class="uk-text-large">{{t "caluma.distribution.new.title"}}</p>
|
5
3
|
|
6
4
|
<hr />
|
@@ -30,95 +28,40 @@
|
|
30
28
|
}}
|
31
29
|
</div>
|
32
30
|
<div>
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
31
|
+
{{#if this.edit}}
|
32
|
+
<UkButton
|
33
|
+
@label={{t "caluma.distribution.new.back"}}
|
34
|
+
@onClick={{fn (mut this.edit) false}}
|
35
|
+
/>
|
36
|
+
{{else}}
|
37
|
+
<UkButton
|
38
|
+
@label={{t "caluma.distribution.new.reset"}}
|
39
|
+
@onClick={{this.clearSelectedGroups}}
|
40
|
+
data-test-reset
|
41
|
+
/>
|
42
|
+
<UkButton
|
43
|
+
@color="primary"
|
44
|
+
@label={{t "caluma.distribution.new.continue"}}
|
45
|
+
@onClick={{fn (mut this.edit) true}}
|
46
|
+
data-test-continue
|
47
|
+
/>
|
48
|
+
{{/if}}
|
47
49
|
</div>
|
48
50
|
</div>
|
49
51
|
<hr />
|
50
52
|
{{/if}}
|
51
53
|
|
52
|
-
|
53
|
-
{{
|
54
|
-
{{#unless config.disabled}}
|
55
|
-
<UkButton
|
56
|
-
data-test-type={{slug}}
|
57
|
-
@label={{t config.label}}
|
58
|
-
@color={{if (includes slug @selectedTypes) "primary" "default"}}
|
59
|
-
@onClick={{fn this.updateSelectedTypes slug}}
|
60
|
-
/>
|
61
|
-
{{/unless}}
|
62
|
-
{{/each-in}}
|
63
|
-
</div>
|
64
|
-
|
65
|
-
<div class="uk-search uk-search-default uk-width-1-1">
|
66
|
-
<span class="uk-search-icon-flip" uk-search-icon></span>
|
67
|
-
<input
|
68
|
-
placeholder={{t "caluma.distribution.new.search"}}
|
69
|
-
aria-label={{t "caluma.distribution.new.search"}}
|
70
|
-
class="uk-search-input"
|
71
|
-
type="search"
|
72
|
-
value={{@search}}
|
73
|
-
data-test-search
|
74
|
-
{{on "input" (perform this.updateSearch)}}
|
75
|
-
/>
|
76
|
-
</div>
|
77
|
-
|
78
|
-
{{#if this.groups.isRunning}}
|
79
|
-
<div class="uk-text-center uk-margin">
|
80
|
-
<UkSpinner @ratio={{2}} />
|
81
|
-
</div>
|
82
|
-
{{else if this.groups.value.length}}
|
83
|
-
<table
|
84
|
-
class="uk-table uk-table-striped uk-table-hover uk-table-small uk-table-middle group-list"
|
85
|
-
>
|
86
|
-
<tbody>
|
87
|
-
{{#each this.groups.value as |group|}}
|
88
|
-
{{! template-lint-disable require-presentational-children }}
|
89
|
-
<tr
|
90
|
-
role="checkbox"
|
91
|
-
data-test-group={{group.identifier}}
|
92
|
-
{{on "click" (fn this.updateSelectedGroups group.identifier)}}
|
93
|
-
>
|
94
|
-
<td class="uk-padding-remove-right">
|
95
|
-
{{! template-lint-disable require-input-label no-nested-interactive }}
|
96
|
-
<input
|
97
|
-
type="checkbox"
|
98
|
-
class="uk-checkbox"
|
99
|
-
checked={{includes group.identifier this.selectedGroups}}
|
100
|
-
/>
|
101
|
-
</td>
|
102
|
-
<td class="uk-width-expand">{{group-name group.identifier}}</td>
|
103
|
-
<td class="uk-text-right">
|
104
|
-
{{#if group.config.icon}}
|
105
|
-
<UkIcon
|
106
|
-
@icon={{group.config.icon}}
|
107
|
-
class="uk-display-block uk-text-{{group.config.iconColor}}"
|
108
|
-
/>
|
109
|
-
{{/if}}
|
110
|
-
</td>
|
111
|
-
</tr>
|
112
|
-
{{/each}}
|
113
|
-
</tbody>
|
114
|
-
</table>
|
54
|
+
{{#if this.edit}}
|
55
|
+
<CdInquiryNewForm::BulkEdit @selectedGroups={{this.selectedGroups}} />
|
115
56
|
{{else}}
|
116
|
-
<
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
57
|
+
<CdInquiryNewForm::Select
|
58
|
+
@search={{@search}}
|
59
|
+
@selectedGroups={{this.selectedGroups}}
|
60
|
+
@selectedTypes={{@selectedTypes}}
|
61
|
+
@onChangeSearch={{@onChangeSearch}}
|
62
|
+
@onChangeSelectedGroups={{fn (mut this.selectedGroups)}}
|
63
|
+
@onChangeSelectedTypes={{@onChangeSelectedTypes}}
|
64
|
+
/>
|
122
65
|
{{/if}}
|
123
66
|
{{else}}
|
124
67
|
<CdNotfound />
|
@@ -1,114 +1,15 @@
|
|
1
1
|
import { action } from "@ember/object";
|
2
|
-
import { inject as service } from "@ember/service";
|
3
|
-
import { macroCondition, isTesting } from "@embroider/macros";
|
4
2
|
import Component from "@glimmer/component";
|
5
3
|
import { tracked } from "@glimmer/tracking";
|
6
|
-
import { queryManager } from "ember-apollo-client";
|
7
|
-
import { timeout, restartableTask, dropTask, task } from "ember-concurrency";
|
8
|
-
import { trackedTask } from "ember-resources/util/ember-concurrency";
|
9
|
-
|
10
|
-
import { decodeId } from "@projectcaluma/ember-core/helpers/decode-id";
|
11
|
-
import config from "@projectcaluma/ember-distribution/config";
|
12
|
-
|
13
|
-
const toggle = (value, array) => {
|
14
|
-
const set = new Set(array);
|
15
|
-
|
16
|
-
set.delete(value) || set.add(value);
|
17
|
-
|
18
|
-
return [...set];
|
19
|
-
};
|
20
4
|
|
21
5
|
export default class CdInquiryNewFormComponent extends Component {
|
22
|
-
@
|
23
|
-
@service notification;
|
24
|
-
@service intl;
|
25
|
-
@service router;
|
26
|
-
@service distribution;
|
27
|
-
|
28
|
-
@queryManager apollo;
|
29
|
-
|
30
|
-
@config config;
|
31
|
-
|
6
|
+
@tracked edit = false;
|
32
7
|
@tracked selectedGroups = [];
|
33
8
|
|
34
|
-
groups = trackedTask(this, this.fetchGroups, () => [
|
35
|
-
this.args.selectedTypes,
|
36
|
-
this.args.search,
|
37
|
-
]);
|
38
|
-
|
39
|
-
@action
|
40
|
-
updateSelectedTypes(type, e) {
|
41
|
-
e.preventDefault();
|
42
|
-
|
43
|
-
this.args.onChangeSelectedTypes(toggle(type, this.args.selectedTypes));
|
44
|
-
}
|
45
|
-
|
46
|
-
@action
|
47
|
-
updateSelectedGroups(identifier) {
|
48
|
-
this.selectedGroups = toggle(identifier, this.selectedGroups);
|
49
|
-
}
|
50
|
-
|
51
9
|
@action
|
52
10
|
clearSelectedGroups(e) {
|
53
11
|
e.preventDefault();
|
54
12
|
|
55
13
|
this.selectedGroups = [];
|
56
14
|
}
|
57
|
-
|
58
|
-
@restartableTask
|
59
|
-
*updateSearch(e) {
|
60
|
-
e.preventDefault();
|
61
|
-
|
62
|
-
/* istanbul ignore next */
|
63
|
-
if (macroCondition(isTesting())) {
|
64
|
-
// no timeout
|
65
|
-
} else {
|
66
|
-
yield timeout(500);
|
67
|
-
}
|
68
|
-
|
69
|
-
this.args.onChangeSearch(e.target.value);
|
70
|
-
}
|
71
|
-
|
72
|
-
@dropTask
|
73
|
-
*submit(e) {
|
74
|
-
e.preventDefault();
|
75
|
-
|
76
|
-
if (!this.selectedGroups.length) return;
|
77
|
-
|
78
|
-
yield this.distribution.createInquiry.perform(this.selectedGroups);
|
79
|
-
|
80
|
-
const lastControlling =
|
81
|
-
this.distribution.navigation.value.controlling.edges[0].node;
|
82
|
-
|
83
|
-
// transition to last added inquiry
|
84
|
-
this.router.transitionTo(
|
85
|
-
"inquiry.detail.index",
|
86
|
-
{
|
87
|
-
from: lastControlling.controllingGroups[0],
|
88
|
-
to: lastControlling.addressedGroups[0],
|
89
|
-
},
|
90
|
-
decodeId(lastControlling.id)
|
91
|
-
);
|
92
|
-
}
|
93
|
-
|
94
|
-
@task
|
95
|
-
*fetchGroups(types, search) {
|
96
|
-
// https://github.com/ember-cli/eslint-plugin-ember/issues/1413
|
97
|
-
yield Promise.resolve();
|
98
|
-
|
99
|
-
const typedGroups = yield this.calumaOptions.fetchTypedGroups(
|
100
|
-
types,
|
101
|
-
search
|
102
|
-
);
|
103
|
-
|
104
|
-
return Object.entries(typedGroups)
|
105
|
-
.flatMap(([type, groups]) => {
|
106
|
-
return groups.map((group) => ({
|
107
|
-
identifier: group[this.calumaOptions.groupIdentifierProperty],
|
108
|
-
name: group[this.calumaOptions.groupNameProperty],
|
109
|
-
config: this.config.new.types[type],
|
110
|
-
}));
|
111
|
-
})
|
112
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
113
|
-
}
|
114
15
|
}
|