@projectcaluma/ember-form 10.0.2 → 11.0.0-beta.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/CHANGELOG.md +1194 -0
  2. package/addon/components/cf-content.hbs +38 -41
  3. package/addon/components/cf-content.js +48 -29
  4. package/addon/components/cf-field/info.hbs +2 -2
  5. package/addon/components/cf-field/info.js +0 -15
  6. package/addon/components/cf-field/input/action-button.hbs +17 -19
  7. package/addon/components/cf-field/input/action-button.js +6 -10
  8. package/addon/components/cf-field/input/checkbox.hbs +6 -2
  9. package/addon/components/cf-field/input/checkbox.js +9 -29
  10. package/addon/components/cf-field/input/date.hbs +9 -5
  11. package/addon/components/cf-field/input/date.js +31 -10
  12. package/addon/components/cf-field/input/file.hbs +2 -2
  13. package/addon/components/cf-field/input/file.js +10 -11
  14. package/addon/components/cf-field/input/float.hbs +4 -4
  15. package/addon/components/cf-field/input/integer.hbs +5 -5
  16. package/addon/components/cf-field/input/radio.hbs +4 -1
  17. package/addon/components/cf-field/input/static.hbs +1 -1
  18. package/addon/components/cf-field/input/table.hbs +24 -24
  19. package/addon/components/cf-field/input/table.js +12 -10
  20. package/addon/components/cf-field/input/text.hbs +5 -5
  21. package/addon/components/cf-field/input/textarea.hbs +6 -5
  22. package/addon/components/cf-field/input.hbs +10 -1
  23. package/addon/components/cf-field/input.js +1 -1
  24. package/addon/components/cf-field/label.hbs +1 -1
  25. package/addon/components/cf-field-value.hbs +22 -7
  26. package/addon/components/cf-field-value.js +8 -38
  27. package/addon/components/cf-field.hbs +14 -6
  28. package/addon/components/cf-field.js +22 -8
  29. package/addon/components/cf-navigation-item.hbs +2 -2
  30. package/addon/components/cf-navigation.hbs +4 -1
  31. package/addon/components/document-validity.js +17 -2
  32. package/addon/gql/fragments/field.graphql +40 -0
  33. package/addon/gql/mutations/save-document-table-answer.graphql +1 -1
  34. package/addon/gql/mutations/save-document.graphql +1 -0
  35. package/addon/gql/queries/{get-document-answers.graphql → document-answers.graphql} +2 -1
  36. package/addon/gql/queries/{get-document-forms.graphql → document-forms.graphql} +2 -1
  37. package/addon/gql/queries/{get-document-used-dynamic-options.graphql → document-used-dynamic-options.graphql} +2 -1
  38. package/addon/gql/queries/{get-dynamic-options.graphql → dynamic-options.graphql} +2 -1
  39. package/addon/gql/queries/{get-fileanswer-info.graphql → fileanswer-info.graphql} +2 -1
  40. package/addon/helpers/get-widget.js +50 -0
  41. package/addon/lib/answer.js +108 -72
  42. package/addon/lib/base.js +32 -23
  43. package/addon/lib/dependencies.js +36 -71
  44. package/addon/lib/document.js +92 -96
  45. package/addon/lib/field.js +374 -407
  46. package/addon/lib/fieldset.js +46 -47
  47. package/addon/lib/form.js +27 -15
  48. package/addon/lib/navigation.js +211 -192
  49. package/addon/lib/question.js +103 -94
  50. package/addon/services/caluma-store.js +10 -6
  51. package/app/helpers/get-widget.js +4 -0
  52. package/blueprints/@projectcaluma/ember-form/index.js +1 -0
  53. package/package.json +30 -25
  54. package/addon/components/cf-navigation.js +0 -9
  55. package/addon/instance-initializers/setup-pikaday-i18n.js +0 -35
@@ -1,7 +1,7 @@
1
1
  import { getOwner } from "@ember/application";
2
2
  import { assert } from "@ember/debug";
3
- import { computed, get, defineProperty } from "@ember/object";
4
- import { inject as service } from "@ember/service";
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.extend({
14
- calumaStore: service(),
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
- this.raw && this.raw.form && this.raw.form.__typename === "Form"
19
+ raw?.form?.__typename === "Form"
20
20
  );
21
-
22
21
  assert(
23
22
  "A collection of graphql answers `raw.answers` must be passed",
24
- this.raw &&
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
- defineProperty(this, "pk", {
31
- writable: false,
32
- value: `${this.document.pk}:Form:${this.raw.form.slug}`,
33
- });
26
+ super({ raw, ...args });
34
27
 
35
- this._super(...args);
28
+ this.document = document;
36
29
 
37
- this.set("fields", []);
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
- getOwner(this)
55
- .factoryFor("caluma-model:form")
56
- .create({ raw: this.raw.form });
41
+ new (owner.factoryFor("caluma-model:form").class)({
42
+ raw: this.raw.form,
43
+ owner,
44
+ });
57
45
 
58
- this.set("form", form);
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
- getOwner(this)
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) => get(answer, "question.slug") === question.slug
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.set("fields", fields);
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
- field: computed("form.slug", "document.fields.[]", function () {
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: null,
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: null,
112
- });
110
+ fields = [];
111
+ }
package/addon/lib/form.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { assert } from "@ember/debug";
2
- import { defineProperty } from "@ember/object";
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.extend({
12
- init(...args) {
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
- defineProperty(this, "pk", {
19
- writable: false,
20
- value: `Form:${this.raw.slug}`,
21
- });
15
+ super({ raw, ...args });
22
16
 
23
- this._super(...args);
17
+ this.pushIntoStore();
18
+ }
24
19
 
25
- this.setProperties(this.raw);
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
+ }