@projectcaluma/ember-form-builder 11.0.0-beta.1 → 11.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1152 -0
- package/addon/components/cfb-code-editor.hbs +2 -1
- package/addon/components/cfb-code-editor.js +53 -8
- package/addon/components/cfb-form-editor/general.hbs +2 -4
- package/addon/components/cfb-form-editor/general.js +5 -7
- package/addon/components/cfb-form-editor/question/options.hbs +1 -1
- package/addon/components/cfb-form-editor/question/validation.hbs +3 -2
- package/addon/components/cfb-form-editor/question/validation.js +17 -13
- package/addon/components/cfb-form-editor/question-list/item.hbs +4 -4
- package/addon/components/cfb-form-editor/question-list/item.js +2 -2
- package/addon/components/cfb-form-editor/question-list.hbs +6 -6
- package/addon/components/cfb-form-editor/question-list.js +11 -6
- package/addon/components/cfb-form-editor/question.hbs +23 -14
- package/addon/components/cfb-form-editor/question.js +22 -20
- package/addon/components/cfb-form-editor.hbs +5 -5
- package/addon/components/cfb-form-list/item.hbs +1 -1
- package/addon/components/cfb-form-list.hbs +9 -9
- package/addon/components/cfb-form-list.js +44 -11
- package/addon/components/cfb-toggle-switch.hbs +1 -1
- package/addon/controllers/index.js +6 -0
- package/addon/engine.js +8 -11
- package/addon/gql/queries/all-format-validators.graphql +10 -0
- package/addon/gql/queries/form-editor-question.graphql +14 -0
- package/addon/instance-initializers/form-builder-widget-overrides.js +15 -0
- package/addon/modifiers/pikaday.js +2 -0
- package/addon/templates/edit/questions/edit.hbs +1 -1
- package/addon/templates/edit/questions/new.hbs +1 -4
- package/addon/templates/edit.hbs +5 -5
- package/addon/templates/index.hbs +8 -1
- package/addon/templates/new.hbs +1 -1
- package/addon/utils/and.js +47 -0
- package/addon/utils/or.js +40 -0
- package/addon/validations/option.js +1 -1
- package/addon/validations/question.js +2 -2
- package/addon/validators/slug.js +1 -1
- package/app/instance-initializers/form-builder-widget-overrides.js +4 -0
- package/app/styles/@projectcaluma/ember-form-builder.scss +1 -1
- package/app/utils/and.js +1 -0
- package/app/utils/or.js +1 -0
- package/index.js +6 -4
- package/package.json +31 -24
- package/translations/de.yaml +5 -5
- package/translations/en.yaml +2 -2
- package/translations/fr.yaml +154 -1
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
<div
|
|
4
4
|
name={{@name}}
|
|
5
|
-
class=
|
|
5
|
+
class="uk-textarea cfb-code-editor {{concat 'language-' @language}}"
|
|
6
6
|
{{did-insert this.didInsertNode}}
|
|
7
7
|
{{will-destroy this.willDestroyNode}}
|
|
8
|
+
{{autoresize mode="height"}}
|
|
8
9
|
></div>
|
|
9
10
|
|
|
10
11
|
{{component @hintComponent}}
|
|
@@ -1,25 +1,70 @@
|
|
|
1
1
|
import { action } from "@ember/object";
|
|
2
|
+
import { addObserver } from "@ember/object/observers";
|
|
2
3
|
import Component from "@glimmer/component";
|
|
3
|
-
import { tracked } from "@glimmer/tracking";
|
|
4
4
|
import { CodeJar } from "codejar";
|
|
5
5
|
import Prism from "prismjs";
|
|
6
|
+
|
|
7
|
+
import "prismjs/components/prism-json.js";
|
|
6
8
|
import "prismjs/components/prism-jexl.js";
|
|
7
9
|
import "prismjs/components/prism-markdown.js";
|
|
8
10
|
|
|
9
11
|
export default class CfbCodeEditorComponent extends Component {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
_editor = null;
|
|
13
|
+
_cursor = null;
|
|
14
|
+
_lastValue = null;
|
|
15
|
+
|
|
16
|
+
get value() {
|
|
17
|
+
const value = this.args.value;
|
|
18
|
+
|
|
19
|
+
if (this.args.language === "json" && typeof value === "object") {
|
|
20
|
+
return JSON.stringify(value?.unwrap?.() ?? value, null, 2);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this.args.value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@action
|
|
27
|
+
onUpdate(value) {
|
|
28
|
+
if (this._lastValue === value) return;
|
|
29
|
+
|
|
30
|
+
this._cursor = this._editor.save();
|
|
31
|
+
|
|
32
|
+
if (this.args.language === "json") {
|
|
33
|
+
try {
|
|
34
|
+
value = JSON.parse(value);
|
|
35
|
+
} catch {
|
|
36
|
+
// update value directly
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this._lastValue = value;
|
|
41
|
+
this.args.update(value);
|
|
42
|
+
this.args.setDirty();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@action
|
|
46
|
+
updateCode() {
|
|
47
|
+
this._editor.updateCode(this.value);
|
|
48
|
+
|
|
49
|
+
if (this._cursor) {
|
|
50
|
+
this._editor.restore(this._cursor);
|
|
51
|
+
this._cursor = null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
12
54
|
|
|
13
55
|
@action
|
|
14
56
|
didInsertNode(element) {
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
this.
|
|
57
|
+
this._editor = CodeJar(element, (editor) => Prism.highlightElement(editor));
|
|
58
|
+
this._editor.onUpdate(this.onUpdate);
|
|
59
|
+
|
|
60
|
+
this.updateCode();
|
|
61
|
+
|
|
62
|
+
// eslint-disable-next-line ember/no-observers
|
|
63
|
+
addObserver(this.args, "value", this, "updateCode");
|
|
19
64
|
}
|
|
20
65
|
|
|
21
66
|
@action
|
|
22
67
|
willDestroyNode() {
|
|
23
|
-
this.
|
|
68
|
+
this._editor.destroy();
|
|
24
69
|
}
|
|
25
70
|
}
|
|
@@ -55,11 +55,10 @@
|
|
|
55
55
|
@name="description"
|
|
56
56
|
@type="textarea"
|
|
57
57
|
@label={{t "caluma.form-builder.form.description"}}
|
|
58
|
-
|
|
58
|
+
{{autoresize mode="height"}}
|
|
59
59
|
/>
|
|
60
60
|
|
|
61
61
|
<f.input
|
|
62
|
-
class="uk-flex uk-flex-between uk-flex-column"
|
|
63
62
|
@name="isArchived"
|
|
64
63
|
@label={{t "caluma.form-builder.form.isArchived"}}
|
|
65
64
|
@required={{true}}
|
|
@@ -67,7 +66,6 @@
|
|
|
67
66
|
/>
|
|
68
67
|
|
|
69
68
|
<f.input
|
|
70
|
-
class="uk-flex uk-flex-between uk-flex-column"
|
|
71
69
|
@name="isPublished"
|
|
72
70
|
@label={{t "caluma.form-builder.form.isPublished"}}
|
|
73
71
|
@required={{true}}
|
|
@@ -85,7 +83,7 @@
|
|
|
85
83
|
<div
|
|
86
84
|
class="uk-text-center uk-text-muted uk-padding uk-padding-remove-horizontal"
|
|
87
85
|
>
|
|
88
|
-
|
|
86
|
+
<UkIcon @icon="bolt" @ratio={{5}} />
|
|
89
87
|
<p>{{t "caluma.form-builder.form.not-found" slug=@slug}}</p>
|
|
90
88
|
</div>
|
|
91
89
|
{{/if}}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getOwner } from "@ember/application";
|
|
2
1
|
import { action } from "@ember/object";
|
|
3
2
|
import { inject as service } from "@ember/service";
|
|
3
|
+
import { macroCondition, isTesting } from "@embroider/macros";
|
|
4
4
|
import Component from "@glimmer/component";
|
|
5
5
|
import { queryManager } from "ember-apollo-client";
|
|
6
|
-
import { optional } from "ember-composable-helpers/helpers/optional";
|
|
7
6
|
import { timeout, restartableTask, dropTask } from "ember-concurrency";
|
|
8
7
|
import { useTask } from "ember-resources";
|
|
9
8
|
|
|
@@ -89,7 +88,7 @@ export default class CfbFormEditorGeneral extends Component {
|
|
|
89
88
|
)
|
|
90
89
|
);
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
this.args.onAfterSubmit?.(form);
|
|
93
92
|
} catch (e) {
|
|
94
93
|
this.notification.danger(
|
|
95
94
|
this.intl.t(
|
|
@@ -104,10 +103,9 @@ export default class CfbFormEditorGeneral extends Component {
|
|
|
104
103
|
@restartableTask
|
|
105
104
|
*validateSlug(slug, changeset) {
|
|
106
105
|
/* istanbul ignore next */
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
) {
|
|
106
|
+
if (macroCondition(isTesting())) {
|
|
107
|
+
// no timeout
|
|
108
|
+
} else {
|
|
111
109
|
yield timeout(500);
|
|
112
110
|
}
|
|
113
111
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
<div class="uk-margin"
|
|
1
|
+
<div class="uk-margin">
|
|
2
2
|
{{component @labelComponent}}
|
|
3
3
|
|
|
4
4
|
<PowerSelectMultiple
|
|
5
5
|
@selected={{this.selected}}
|
|
6
|
-
@placeholder={{
|
|
6
|
+
@placeholder={{@placeholder}}
|
|
7
7
|
@options={{this.validators}}
|
|
8
8
|
@onChange={{this.updateValidators}}
|
|
9
|
+
@renderInPlace={{true}}
|
|
9
10
|
as |item|
|
|
10
11
|
>
|
|
11
12
|
{{item.name}}
|
|
@@ -2,34 +2,38 @@ import { action } from "@ember/object";
|
|
|
2
2
|
import Component from "@glimmer/component";
|
|
3
3
|
import { queryManager } from "ember-apollo-client";
|
|
4
4
|
import { dropTask } from "ember-concurrency";
|
|
5
|
+
import { useTask } from "ember-resources";
|
|
5
6
|
|
|
6
|
-
import allFormatValidatorsQuery from "@projectcaluma/ember-
|
|
7
|
+
import allFormatValidatorsQuery from "@projectcaluma/ember-form-builder/gql/queries/all-format-validators.graphql";
|
|
7
8
|
|
|
8
9
|
export default class CfbFormEditorQuestionValidation extends Component {
|
|
9
10
|
@queryManager apollo;
|
|
10
11
|
|
|
11
|
-
@dropTask
|
|
12
|
-
*availableFormatValidators() {
|
|
13
|
-
const formatValidators = yield this.apollo.watchQuery(
|
|
14
|
-
{ query: allFormatValidatorsQuery, fetchPolicy: "cache-and-network" },
|
|
15
|
-
"allFormatValidators.edges"
|
|
16
|
-
);
|
|
17
|
-
return formatValidators.map((edge) => edge.node);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
12
|
get validators() {
|
|
21
|
-
return this.
|
|
13
|
+
return this._validators.value?.map((edge) => edge.node) ?? [];
|
|
22
14
|
}
|
|
23
15
|
|
|
24
16
|
get selected() {
|
|
25
17
|
return this.validators.filter((validator) =>
|
|
26
|
-
(this.args.value || []).includes(
|
|
18
|
+
(this.args.value?.edges.map((edge) => edge.node.slug) || []).includes(
|
|
19
|
+
validator.slug
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
_validators = useTask(this, this.fetchFormatValidators, () => []);
|
|
25
|
+
|
|
26
|
+
@dropTask
|
|
27
|
+
*fetchFormatValidators() {
|
|
28
|
+
return yield this.apollo.watchQuery(
|
|
29
|
+
{ query: allFormatValidatorsQuery, fetchPolicy: "cache-and-network" },
|
|
30
|
+
"allFormatValidators.edges"
|
|
27
31
|
);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
@action
|
|
31
35
|
updateValidators(value) {
|
|
32
|
-
this.args.update(value.map((
|
|
36
|
+
this.args.update({ edges: value.map(({ slug }) => ({ node: { slug } })) });
|
|
33
37
|
this.args.setDirty();
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
@question.isArchived
|
|
5
5
|
"cfb-form-editor__question-list__item__archived"
|
|
6
6
|
}}
|
|
7
|
-
{{did-insert (fn (optional @
|
|
8
|
-
{{will-destroy (fn (optional @
|
|
7
|
+
{{did-insert (fn (optional @onRegister) this.elementId @question.slug)}}
|
|
8
|
+
{{will-destroy (fn (optional @onUnregister) this.elementId @question.slug)}}
|
|
9
9
|
...attributes
|
|
10
10
|
>
|
|
11
11
|
<div class="uk-flex uk-flex-middle">
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
data-test-remove-item
|
|
25
25
|
uk-icon="minus"
|
|
26
26
|
class="cfb-pointer uk-text-danger"
|
|
27
|
-
{{on "click" (fn (optional @
|
|
27
|
+
{{on "click" (fn (optional @onRemoveQuestion) @question)}}
|
|
28
28
|
>
|
|
29
29
|
</i>
|
|
30
30
|
{{else if (eq @mode "add")}}
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
data-test-add-item
|
|
34
34
|
uk-icon="plus"
|
|
35
35
|
class="cfb-pointer uk-text-success"
|
|
36
|
-
{{on "click" (fn (optional @
|
|
36
|
+
{{on "click" (fn (optional @onAddQuestion) @question)}}
|
|
37
37
|
>
|
|
38
38
|
</i>
|
|
39
39
|
{{/if}}
|
|
@@ -51,12 +51,12 @@ export default class CfbFormEditorQuestionListItem extends Component {
|
|
|
51
51
|
@action
|
|
52
52
|
editQuestion(question, e) {
|
|
53
53
|
e.preventDefault();
|
|
54
|
-
this.args
|
|
54
|
+
this.args.onEditQuestion?.(question);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
@action
|
|
58
58
|
clickForm(form, e) {
|
|
59
59
|
e.preventDefault();
|
|
60
|
-
this.args
|
|
60
|
+
this.args.onClickForm?.(form);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -76,12 +76,12 @@
|
|
|
76
76
|
data-test-question-list-item={{item.node.slug}}
|
|
77
77
|
@mode={{this.mode}}
|
|
78
78
|
@question={{item.node}}
|
|
79
|
-
@
|
|
80
|
-
@
|
|
81
|
-
@
|
|
82
|
-
@
|
|
83
|
-
@
|
|
84
|
-
@
|
|
79
|
+
@onEditQuestion={{@onEditQuestion}}
|
|
80
|
+
@onRemoveQuestion={{perform this.removeQuestion}}
|
|
81
|
+
@onAddQuestion={{perform this.addQuestion}}
|
|
82
|
+
@onClickForm={{@onClickForm}}
|
|
83
|
+
@onRegister={{this.registerChild}}
|
|
84
|
+
@onUnregister={{this.unregisterChild}}
|
|
85
85
|
/>
|
|
86
86
|
{{else}}
|
|
87
87
|
<li
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { action } from "@ember/object";
|
|
2
2
|
import { run } from "@ember/runloop";
|
|
3
3
|
import { inject as service } from "@ember/service";
|
|
4
|
+
import { macroCondition, isTesting } from "@embroider/macros";
|
|
4
5
|
import Component from "@glimmer/component";
|
|
5
6
|
import { tracked } from "@glimmer/tracking";
|
|
6
7
|
import { queryManager } from "ember-apollo-client";
|
|
7
|
-
import { optional } from "ember-composable-helpers/helpers/optional";
|
|
8
8
|
import {
|
|
9
9
|
timeout,
|
|
10
10
|
enqueueTask,
|
|
@@ -56,8 +56,13 @@ export default class ComponentsCfbFormEditorQuestionList extends Component {
|
|
|
56
56
|
const mode = this.mode;
|
|
57
57
|
const search = mode !== "reorder" ? this.search : "";
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
/* istanbul ignore next */
|
|
60
|
+
if (macroCondition(isTesting())) {
|
|
61
|
+
// no timeout
|
|
62
|
+
} else {
|
|
63
|
+
if (search) {
|
|
64
|
+
yield timeout(500);
|
|
65
|
+
}
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
if (mode === "add" && this.hasNextPage) {
|
|
@@ -148,7 +153,7 @@ export default class ComponentsCfbFormEditorQuestionList extends Component {
|
|
|
148
153
|
|
|
149
154
|
this.questionTask.perform();
|
|
150
155
|
|
|
151
|
-
|
|
156
|
+
this.args.onAfterAddQuestion?.(question);
|
|
152
157
|
} catch (e) {
|
|
153
158
|
this.notification.danger(
|
|
154
159
|
this.intl.t("caluma.form-builder.notification.form.add-question.error")
|
|
@@ -176,7 +181,7 @@ export default class ComponentsCfbFormEditorQuestionList extends Component {
|
|
|
176
181
|
)
|
|
177
182
|
);
|
|
178
183
|
|
|
179
|
-
|
|
184
|
+
this.args.onAfterRemoveQuestion?.(question);
|
|
180
185
|
} catch (e) {
|
|
181
186
|
this.notification.danger(
|
|
182
187
|
this.intl.t(
|
|
@@ -238,7 +243,7 @@ export default class ComponentsCfbFormEditorQuestionList extends Component {
|
|
|
238
243
|
createNewQuestion(e) {
|
|
239
244
|
e.preventDefault();
|
|
240
245
|
|
|
241
|
-
this.args
|
|
246
|
+
this.args.onCreateQuestion?.();
|
|
242
247
|
this.setMode("reorder");
|
|
243
248
|
}
|
|
244
249
|
}
|
|
@@ -140,6 +140,7 @@
|
|
|
140
140
|
@label={{t "caluma.form-builder.question.confirmationText"}}
|
|
141
141
|
@name="infoText"
|
|
142
142
|
@type="textarea"
|
|
143
|
+
{{autoresize mode="height"}}
|
|
143
144
|
/>
|
|
144
145
|
{{else}}
|
|
145
146
|
<div class="uk-margin">
|
|
@@ -207,13 +208,13 @@
|
|
|
207
208
|
/>
|
|
208
209
|
|
|
209
210
|
<f.input
|
|
210
|
-
@name="
|
|
211
|
+
@name="formatValidators"
|
|
211
212
|
@label={{t "caluma.form-builder.question.formatValidators"}}
|
|
212
|
-
@placeholder={{t "caluma.form-builder.question.
|
|
213
|
+
@placeholder={{t "caluma.form-builder.question.no-selection"}}
|
|
213
214
|
@required={{false}}
|
|
214
215
|
@renderComponent={{component "cfb-form-editor/question/validation"}}
|
|
215
|
-
@on-update={{changeset-set f.model "
|
|
216
|
-
@value={{changeset-get f.model "
|
|
216
|
+
@on-update={{changeset-set f.model "formatValidators"}}
|
|
217
|
+
@value={{changeset-get f.model "formatValidators"}}
|
|
217
218
|
/>
|
|
218
219
|
{{/if}}
|
|
219
220
|
|
|
@@ -295,10 +296,10 @@
|
|
|
295
296
|
@type="select"
|
|
296
297
|
@required={{true}}
|
|
297
298
|
@label={{t "caluma.form-builder.question.dataSource"}}
|
|
298
|
-
@options={{or this.availableDataSources.lastSuccessful.value array}}
|
|
299
|
+
@options={{or this.availableDataSources.lastSuccessful.value (array)}}
|
|
299
300
|
@optionTargetPath="name"
|
|
300
301
|
@optionLabelPath="info"
|
|
301
|
-
@
|
|
302
|
+
@prompt={{t "caluma.form-builder.question.no-selection"}}
|
|
302
303
|
/>
|
|
303
304
|
{{/if}}
|
|
304
305
|
|
|
@@ -328,9 +329,9 @@
|
|
|
328
329
|
as |fi|
|
|
329
330
|
>
|
|
330
331
|
<PowerSelect
|
|
331
|
-
@options={{or this.availableForms.lastSuccessful.value array}}
|
|
332
|
+
@options={{or this.availableForms.lastSuccessful.value (array)}}
|
|
332
333
|
@selected={{fi.value}}
|
|
333
|
-
@placeholder={{t "caluma.form-builder.question.
|
|
334
|
+
@placeholder={{t "caluma.form-builder.question.no-selection"}}
|
|
334
335
|
@onBlur={{fi.setDirty}}
|
|
335
336
|
@onChange={{fi.update}}
|
|
336
337
|
@searchField="slug"
|
|
@@ -341,6 +342,7 @@
|
|
|
341
342
|
@noMatchesMessage={{t
|
|
342
343
|
"caluma.form-builder.question.search-empty"
|
|
343
344
|
}}
|
|
345
|
+
@renderInPlace={{true}}
|
|
344
346
|
as |form|
|
|
345
347
|
>
|
|
346
348
|
<span
|
|
@@ -402,9 +404,9 @@
|
|
|
402
404
|
as |fi|
|
|
403
405
|
>
|
|
404
406
|
<PowerSelect
|
|
405
|
-
@options={{or this.availableForms.lastSuccessful.value array}}
|
|
407
|
+
@options={{or this.availableForms.lastSuccessful.value (array)}}
|
|
406
408
|
@selected={{fi.value}}
|
|
407
|
-
@placeholder={{t "caluma.form-builder.question.
|
|
409
|
+
@placeholder={{t "caluma.form-builder.question.no-selection"}}
|
|
408
410
|
@onBlur={{fi.setDirty}}
|
|
409
411
|
@onChange={{fi.update}}
|
|
410
412
|
@searchField="slug"
|
|
@@ -413,6 +415,7 @@
|
|
|
413
415
|
"caluma.form-builder.question.search-placeholder"
|
|
414
416
|
}}
|
|
415
417
|
@noMatchesMessage={{t "caluma.form-builder.question.search-empty"}}
|
|
418
|
+
@renderInPlace={{true}}
|
|
416
419
|
as |form|
|
|
417
420
|
>
|
|
418
421
|
<span class="uk-width-auto uk-margin-small-right uk-text-truncate">
|
|
@@ -435,7 +438,7 @@
|
|
|
435
438
|
@optionTargetPath="component"
|
|
436
439
|
@optionLabelPath="label"
|
|
437
440
|
@options={{this.availableOverrides}}
|
|
438
|
-
|
|
441
|
+
@prompt={{t "caluma.form-builder.question.no-selection"}}
|
|
439
442
|
/>
|
|
440
443
|
|
|
441
444
|
<f.input
|
|
@@ -443,12 +446,11 @@
|
|
|
443
446
|
@label={{t "caluma.form-builder.question.isArchived"}}
|
|
444
447
|
@required={{true}}
|
|
445
448
|
@renderComponent={{component "cfb-toggle-switch" size="small"}}
|
|
446
|
-
class="uk-flex uk-flex-between uk-flex-column"
|
|
447
449
|
/>
|
|
448
450
|
|
|
449
451
|
<UkButton
|
|
450
452
|
@color="link"
|
|
451
|
-
@
|
|
453
|
+
@onClick={{toggle-action "showAdvanced" this}}
|
|
452
454
|
class="uk-flex uk-flex-middle uk-margin"
|
|
453
455
|
>
|
|
454
456
|
{{#if this.showAdvanced}}
|
|
@@ -466,7 +468,6 @@
|
|
|
466
468
|
@required={{true}}
|
|
467
469
|
@label={{t "caluma.form-builder.question.validateOnEnter"}}
|
|
468
470
|
@renderComponent={{component "cfb-toggle-switch" size="small"}}
|
|
469
|
-
class="uk-flex uk-flex-between uk-flex-column"
|
|
470
471
|
/>
|
|
471
472
|
{{/if}}
|
|
472
473
|
|
|
@@ -493,6 +494,14 @@
|
|
|
493
494
|
/>
|
|
494
495
|
</div>
|
|
495
496
|
{{/if}}
|
|
497
|
+
|
|
498
|
+
<div class="uk-margin">
|
|
499
|
+
<f.input
|
|
500
|
+
@label={{t "caluma.form-builder.question.meta"}}
|
|
501
|
+
@name="meta"
|
|
502
|
+
@renderComponent={{component "cfb-code-editor" language="json"}}
|
|
503
|
+
/>
|
|
504
|
+
</div>
|
|
496
505
|
{{/if}}
|
|
497
506
|
|
|
498
507
|
<div class="uk-text-right">
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { getOwner } from "@ember/application";
|
|
2
1
|
import { A } from "@ember/array";
|
|
3
2
|
import { action } from "@ember/object";
|
|
4
3
|
import { inject as service } from "@ember/service";
|
|
5
4
|
import { camelize } from "@ember/string";
|
|
5
|
+
import { macroCondition, isTesting } from "@embroider/macros";
|
|
6
6
|
import Component from "@glimmer/component";
|
|
7
7
|
import { tracked } from "@glimmer/tracking";
|
|
8
8
|
import { queryManager } from "ember-apollo-client";
|
|
9
9
|
import Changeset from "ember-changeset";
|
|
10
10
|
import lookupValidator from "ember-changeset-validations";
|
|
11
|
-
import { optional } from "ember-composable-helpers/helpers/optional";
|
|
12
11
|
import { dropTask, restartableTask, task, timeout } from "ember-concurrency";
|
|
13
|
-
import { all } from "rsvp";
|
|
14
12
|
|
|
15
13
|
import { hasQuestionType } from "@projectcaluma/ember-core/helpers/has-question-type";
|
|
16
14
|
import slugify from "@projectcaluma/ember-core/utils/slugify";
|
|
@@ -107,6 +105,7 @@ export default class CfbFormEditorQuestion extends Component {
|
|
|
107
105
|
subForm: {},
|
|
108
106
|
meta: {},
|
|
109
107
|
dataSource: "",
|
|
108
|
+
formatValidators: null,
|
|
110
109
|
// action button
|
|
111
110
|
action: ACTIONS[0],
|
|
112
111
|
color: COLORS[0],
|
|
@@ -183,16 +182,10 @@ export default class CfbFormEditorQuestion extends Component {
|
|
|
183
182
|
|
|
184
183
|
get availableOverrides() {
|
|
185
184
|
const type = this.changeset.get("__typename");
|
|
186
|
-
const overrides = this.calumaOptions
|
|
187
|
-
.getComponentOverrides()
|
|
188
|
-
.filter((override) => {
|
|
189
|
-
return !override.types || override.types.includes(type);
|
|
190
|
-
});
|
|
191
185
|
|
|
192
|
-
return
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
];
|
|
186
|
+
return this.calumaOptions.getComponentOverrides().filter((override) => {
|
|
187
|
+
return !override.types || override.types.includes(type);
|
|
188
|
+
});
|
|
196
189
|
}
|
|
197
190
|
|
|
198
191
|
get model() {
|
|
@@ -213,16 +206,20 @@ export default class CfbFormEditorQuestion extends Component {
|
|
|
213
206
|
const slug =
|
|
214
207
|
((!this.args.slug && this.prefix) || "") + changeset.get("slug");
|
|
215
208
|
|
|
209
|
+
const rawMeta = changeset.get("meta");
|
|
210
|
+
|
|
216
211
|
const input = {
|
|
217
212
|
slug,
|
|
218
213
|
label: changeset.get("label"),
|
|
219
214
|
isHidden: changeset.get("isHidden"),
|
|
220
215
|
infoText: changeset.get("infoText"),
|
|
221
|
-
meta: JSON.stringify(
|
|
216
|
+
meta: JSON.stringify(rawMeta?.unwrap?.() ?? rawMeta),
|
|
222
217
|
isArchived: changeset.get("isArchived"),
|
|
223
218
|
};
|
|
224
219
|
|
|
225
|
-
if (
|
|
220
|
+
if (
|
|
221
|
+
!hasQuestionType(changeset, "static", "calculated-float", "action-button")
|
|
222
|
+
) {
|
|
226
223
|
Object.assign(input, {
|
|
227
224
|
isRequired: changeset.get("isRequired"),
|
|
228
225
|
});
|
|
@@ -257,6 +254,9 @@ export default class CfbFormEditorQuestion extends Component {
|
|
|
257
254
|
minLength: parseInt(changeset.get("minLength")),
|
|
258
255
|
maxLength: parseInt(changeset.get("maxLength")),
|
|
259
256
|
placeholder: changeset.get("placeholder"),
|
|
257
|
+
formatValidators: changeset
|
|
258
|
+
.get("formatValidators")
|
|
259
|
+
?.edges.map((edge) => edge.node.slug),
|
|
260
260
|
};
|
|
261
261
|
}
|
|
262
262
|
|
|
@@ -265,6 +265,9 @@ export default class CfbFormEditorQuestion extends Component {
|
|
|
265
265
|
minLength: parseInt(changeset.get("minLength")),
|
|
266
266
|
maxLength: parseInt(changeset.get("maxLength")),
|
|
267
267
|
placeholder: changeset.get("placeholder"),
|
|
268
|
+
formatValidators: changeset
|
|
269
|
+
.get("formatValidators")
|
|
270
|
+
?.edges.map((edge) => edge.node.slug),
|
|
268
271
|
};
|
|
269
272
|
}
|
|
270
273
|
|
|
@@ -326,7 +329,7 @@ export default class CfbFormEditorQuestion extends Component {
|
|
|
326
329
|
|
|
327
330
|
@task
|
|
328
331
|
*saveOptions(changeset) {
|
|
329
|
-
yield all(
|
|
332
|
+
yield Promise.all(
|
|
330
333
|
(changeset.get("options.edges") || []).map(async ({ node: option }) => {
|
|
331
334
|
const { label, slug, isArchived } = option;
|
|
332
335
|
|
|
@@ -406,7 +409,7 @@ export default class CfbFormEditorQuestion extends Component {
|
|
|
406
409
|
this.intl.t("caluma.form-builder.notification.question.save.success")
|
|
407
410
|
);
|
|
408
411
|
|
|
409
|
-
|
|
412
|
+
this.args.onAfterSubmit?.(question);
|
|
410
413
|
} catch (e) {
|
|
411
414
|
// eslint-disable-next-line no-console
|
|
412
415
|
console.error(e);
|
|
@@ -419,10 +422,9 @@ export default class CfbFormEditorQuestion extends Component {
|
|
|
419
422
|
@restartableTask
|
|
420
423
|
*validateSlug(slug, changeset) {
|
|
421
424
|
/* istanbul ignore next */
|
|
422
|
-
if (
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
) {
|
|
425
|
+
if (macroCondition(isTesting())) {
|
|
426
|
+
// no timeout
|
|
427
|
+
} else {
|
|
426
428
|
yield timeout(500);
|
|
427
429
|
}
|
|
428
430
|
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
{{else}}
|
|
13
13
|
<CfbFormEditor::QuestionList
|
|
14
14
|
@form={{@slug}}
|
|
15
|
-
@
|
|
16
|
-
@
|
|
17
|
-
@
|
|
18
|
-
@
|
|
19
|
-
@
|
|
15
|
+
@onEditQuestion={{@onEditQuestion}}
|
|
16
|
+
@onCreateQuestion={{@onCreateQuestion}}
|
|
17
|
+
@onAfterAddQuestion={{@onAfterAddQuestion}}
|
|
18
|
+
@onAfterRemoveQuestion={{@onAfterRemoveQuestion}}
|
|
19
|
+
@onClickForm={{@onClickForm}}
|
|
20
20
|
/>
|
|
21
21
|
{{/if}}
|
|
22
22
|
</div>
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
<div class="uk-flex uk-flex-between">
|
|
2
2
|
<div class="uk-button-group">
|
|
3
|
-
{{#each
|
|
3
|
+
{{#each this.categories as |category|}}
|
|
4
4
|
<UkButton
|
|
5
|
-
data-test-filter={{category}}
|
|
6
|
-
@
|
|
7
|
-
@label={{
|
|
8
|
-
@
|
|
5
|
+
data-test-filter={{category.value}}
|
|
6
|
+
@onClick={{fn @onUpdateCategory category.value}}
|
|
7
|
+
@label={{category.label}}
|
|
8
|
+
@color={{if (eq @category category.value) "primary"}}
|
|
9
9
|
/>
|
|
10
10
|
{{/each}}
|
|
11
11
|
</div>
|
|
12
12
|
<div>
|
|
13
13
|
<UkButton
|
|
14
14
|
data-test-new-form
|
|
15
|
-
@
|
|
15
|
+
@onClick={{optional @onNewForm}}
|
|
16
16
|
@label={{t "caluma.form-builder.form.new"}}
|
|
17
17
|
/>
|
|
18
18
|
</div>
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
type="search"
|
|
27
27
|
placeholder="{{t 'caluma.form-builder.global.search'}}..."
|
|
28
28
|
aria-label="{{t 'caluma.form-builder.global.search'}}"
|
|
29
|
-
value={{
|
|
30
|
-
{{on "input" (
|
|
29
|
+
value={{@search}}
|
|
30
|
+
{{on "input" (perform this.search)}}
|
|
31
31
|
/>
|
|
32
32
|
</div>
|
|
33
33
|
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
<CfbFormList::Item
|
|
38
38
|
data-test-form-list-item={{item.slug}}
|
|
39
39
|
@item={{item}}
|
|
40
|
-
@
|
|
40
|
+
@onEditForm={{@onEditForm}}
|
|
41
41
|
/>
|
|
42
42
|
{{/each}}
|
|
43
43
|
{{#if this.formsQuery.isLoading}}
|