@projectcaluma/ember-form 10.0.0 → 11.0.0-beta.1
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/addon/components/cf-content.hbs +36 -39
- package/addon/components/cf-content.js +47 -20
- package/addon/components/cf-field/input/action-button.hbs +1 -1
- package/addon/components/cf-field/input/action-button.js +9 -7
- package/addon/components/cf-field/input/checkbox.hbs +2 -2
- package/addon/components/cf-field/input/checkbox.js +9 -29
- package/addon/components/cf-field/input/file.js +8 -9
- package/addon/components/cf-field/input/float.hbs +4 -4
- package/addon/components/cf-field/input/integer.hbs +5 -5
- package/addon/components/cf-field/input/table.js +12 -10
- package/addon/components/cf-field/input/text.hbs +5 -5
- package/addon/components/cf-field/input/textarea.hbs +5 -5
- package/addon/components/cf-field/input.js +1 -1
- package/addon/components/cf-field/label.hbs +1 -1
- package/addon/components/cf-field-value.js +8 -13
- package/addon/components/cf-field.hbs +2 -2
- package/addon/components/cf-field.js +2 -3
- package/addon/components/cf-navigation-item.hbs +2 -2
- package/addon/components/document-validity.js +1 -1
- package/addon/gql/fragments/field.graphql +27 -0
- package/addon/gql/mutations/save-document-table-answer.graphql +1 -1
- package/addon/gql/mutations/save-document.graphql +1 -0
- package/addon/gql/queries/{get-document-answers.graphql → document-answers.graphql} +2 -1
- package/addon/gql/queries/{get-document-forms.graphql → document-forms.graphql} +2 -1
- package/addon/gql/queries/{get-document-used-dynamic-options.graphql → document-used-dynamic-options.graphql} +2 -1
- package/addon/gql/queries/{get-dynamic-options.graphql → dynamic-options.graphql} +2 -1
- package/addon/gql/queries/{get-fileanswer-info.graphql → fileanswer-info.graphql} +2 -1
- package/addon/helpers/get-widget.js +50 -0
- package/addon/lib/answer.js +108 -72
- package/addon/lib/base.js +32 -23
- package/addon/lib/dependencies.js +36 -71
- package/addon/lib/document.js +92 -96
- package/addon/lib/field.js +334 -401
- package/addon/lib/fieldset.js +46 -47
- package/addon/lib/form.js +27 -15
- package/addon/lib/navigation.js +187 -181
- package/addon/lib/question.js +103 -94
- package/addon/services/caluma-store.js +10 -6
- package/app/helpers/get-widget.js +4 -0
- package/package.json +19 -18
- package/CHANGELOG.md +0 -21
package/addon/lib/fieldset.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { getOwner } from "@ember/application";
|
2
2
|
import { assert } from "@ember/debug";
|
3
|
-
import {
|
4
|
-
import {
|
3
|
+
import { associateDestroyableChild } from "@ember/destroyable";
|
4
|
+
import { cached } from "tracked-toolbox";
|
5
5
|
|
6
6
|
import Base from "@projectcaluma/ember-form/lib/base";
|
7
7
|
|
@@ -10,103 +10,102 @@ import Base from "@projectcaluma/ember-form/lib/base";
|
|
10
10
|
*
|
11
11
|
* @class Fieldset
|
12
12
|
*/
|
13
|
-
export default Base
|
14
|
-
|
13
|
+
export default class Fieldset extends Base {
|
14
|
+
constructor({ document, raw, ...args }) {
|
15
|
+
assert("`document` must be passed as an argument", document);
|
15
16
|
|
16
|
-
init(...args) {
|
17
17
|
assert(
|
18
18
|
"A graphql form `raw.form` must be passed",
|
19
|
-
|
19
|
+
raw?.form?.__typename === "Form"
|
20
20
|
);
|
21
|
-
|
22
21
|
assert(
|
23
22
|
"A collection of graphql answers `raw.answers` must be passed",
|
24
|
-
|
25
|
-
this.raw.answers &&
|
26
|
-
(!this.raw.answers.length ||
|
27
|
-
/Answer$/.test(this.raw.answers[0].__typename))
|
23
|
+
raw?.answers?.every((answer) => /Answer$/.test(answer.__typename))
|
28
24
|
);
|
29
25
|
|
30
|
-
|
31
|
-
writable: false,
|
32
|
-
value: `${this.document.pk}:Form:${this.raw.form.slug}`,
|
33
|
-
});
|
26
|
+
super({ raw, ...args });
|
34
27
|
|
35
|
-
this.
|
28
|
+
this.document = document;
|
36
29
|
|
37
|
-
this.
|
30
|
+
this.pushIntoStore();
|
38
31
|
|
39
32
|
this._createForm();
|
40
33
|
this._createFields();
|
41
|
-
}
|
42
|
-
|
43
|
-
willDestroy(...args) {
|
44
|
-
this._super(...args);
|
45
|
-
|
46
|
-
const fields = this.fields;
|
47
|
-
this.set("fields", []);
|
48
|
-
fields.forEach((field) => field.destroy());
|
49
|
-
},
|
34
|
+
}
|
50
35
|
|
51
36
|
_createForm() {
|
37
|
+
const owner = getOwner(this);
|
38
|
+
|
52
39
|
const form =
|
53
40
|
this.calumaStore.find(`Form:${this.raw.form.slug}`) ||
|
54
|
-
|
55
|
-
.
|
56
|
-
|
41
|
+
new (owner.factoryFor("caluma-model:form").class)({
|
42
|
+
raw: this.raw.form,
|
43
|
+
owner,
|
44
|
+
});
|
57
45
|
|
58
|
-
this.
|
59
|
-
}
|
46
|
+
this.form = form;
|
47
|
+
}
|
60
48
|
|
61
49
|
_createFields() {
|
50
|
+
const owner = getOwner(this);
|
51
|
+
|
62
52
|
const fields = this.raw.form.questions.map((question) => {
|
63
|
-
return (
|
53
|
+
return associateDestroyableChild(
|
54
|
+
this,
|
64
55
|
this.calumaStore.find(
|
65
56
|
`${this.document.pk}:Question:${question.slug}`
|
66
57
|
) ||
|
67
|
-
|
68
|
-
.factoryFor("caluma-model:field")
|
69
|
-
.create({
|
58
|
+
new (owner.factoryFor("caluma-model:field").class)({
|
70
59
|
raw: {
|
71
60
|
question,
|
72
61
|
answer: this.raw.answers.find(
|
73
|
-
(answer) =>
|
62
|
+
(answer) => answer?.question?.slug === question.slug
|
74
63
|
),
|
75
64
|
},
|
76
65
|
fieldset: this,
|
66
|
+
owner,
|
77
67
|
})
|
78
68
|
);
|
79
69
|
});
|
80
70
|
|
81
|
-
this.
|
82
|
-
}
|
71
|
+
this.fields = fields;
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* The primary key of the fieldset. Consists of the document and form primary
|
76
|
+
* keys.
|
77
|
+
*
|
78
|
+
* @property {String} pk
|
79
|
+
*/
|
80
|
+
@cached
|
81
|
+
get pk() {
|
82
|
+
return `${this.document.pk}:Form:${this.raw.form.slug}`;
|
83
|
+
}
|
83
84
|
|
84
85
|
/**
|
85
86
|
* The field for this fieldset. A fieldset has a `field` if there is a form
|
86
87
|
* question pointing to the fieldsets form in the document.
|
87
88
|
*
|
88
89
|
* @property {Field} field
|
89
|
-
* @accessor
|
90
90
|
*/
|
91
|
-
|
91
|
+
@cached
|
92
|
+
get field() {
|
92
93
|
return this.document.fields
|
93
94
|
.filter((field) => field.questionType === "FormQuestion")
|
94
|
-
.find((field) => field.question.subForm.slug === this.form.slug);
|
95
|
-
}
|
95
|
+
.find((field) => field.question.raw.subForm.slug === this.form.slug);
|
96
|
+
}
|
96
97
|
|
97
98
|
/**
|
98
99
|
* The form for this fieldset
|
99
100
|
*
|
100
101
|
* @property {Form} form
|
101
|
-
* @accessor
|
102
102
|
*/
|
103
|
-
form
|
103
|
+
form = null;
|
104
104
|
|
105
105
|
/**
|
106
106
|
* The fields in this fieldset
|
107
107
|
*
|
108
108
|
* @property {Field[]} fields
|
109
|
-
* @accessor
|
110
109
|
*/
|
111
|
-
fields
|
112
|
-
}
|
110
|
+
fields = [];
|
111
|
+
}
|
package/addon/lib/form.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { assert } from "@ember/debug";
|
2
|
-
import {
|
2
|
+
import { cached } from "tracked-toolbox";
|
3
3
|
|
4
4
|
import Base from "@projectcaluma/ember-form/lib/base";
|
5
5
|
|
@@ -8,20 +8,32 @@ import Base from "@projectcaluma/ember-form/lib/base";
|
|
8
8
|
*
|
9
9
|
* @class Form
|
10
10
|
*/
|
11
|
-
export default Base
|
12
|
-
|
13
|
-
assert(
|
14
|
-
"A graphql form `raw` must be passed",
|
15
|
-
this.raw && this.raw.__typename === "Form"
|
16
|
-
);
|
11
|
+
export default class Form extends Base {
|
12
|
+
constructor({ raw, ...args }) {
|
13
|
+
assert("A graphql form `raw` must be passed", raw?.__typename === "Form");
|
17
14
|
|
18
|
-
|
19
|
-
writable: false,
|
20
|
-
value: `Form:${this.raw.slug}`,
|
21
|
-
});
|
15
|
+
super({ raw, ...args });
|
22
16
|
|
23
|
-
this.
|
17
|
+
this.pushIntoStore();
|
18
|
+
}
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
/**
|
21
|
+
* The primary key of the form.
|
22
|
+
*
|
23
|
+
* @property {String} pk
|
24
|
+
*/
|
25
|
+
@cached
|
26
|
+
get pk() {
|
27
|
+
return `Form:${this.slug}`;
|
28
|
+
}
|
29
|
+
|
30
|
+
/**
|
31
|
+
* The slug of the form
|
32
|
+
*
|
33
|
+
* @property {String} slug
|
34
|
+
*/
|
35
|
+
@cached
|
36
|
+
get slug() {
|
37
|
+
return this.raw.slug;
|
38
|
+
}
|
39
|
+
}
|