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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/CHANGELOG.md +1112 -0
  2. package/addon/components/cf-content.hbs +36 -39
  3. package/addon/components/cf-content.js +48 -29
  4. package/addon/components/cf-field/info.hbs +1 -1
  5. package/addon/components/cf-field/input/action-button.hbs +1 -1
  6. package/addon/components/cf-field/input/action-button.js +9 -7
  7. package/addon/components/cf-field/input/checkbox.hbs +6 -2
  8. package/addon/components/cf-field/input/checkbox.js +9 -29
  9. package/addon/components/cf-field/input/file.hbs +1 -1
  10. package/addon/components/cf-field/input/file.js +8 -9
  11. package/addon/components/cf-field/input/float.hbs +4 -4
  12. package/addon/components/cf-field/input/integer.hbs +5 -5
  13. package/addon/components/cf-field/input/radio.hbs +4 -1
  14. package/addon/components/cf-field/input/table.hbs +7 -7
  15. package/addon/components/cf-field/input/table.js +12 -10
  16. package/addon/components/cf-field/input/text.hbs +5 -5
  17. package/addon/components/cf-field/input/textarea.hbs +6 -5
  18. package/addon/components/cf-field/input.hbs +10 -1
  19. package/addon/components/cf-field/input.js +1 -1
  20. package/addon/components/cf-field/label.hbs +1 -1
  21. package/addon/components/cf-field-value.hbs +1 -1
  22. package/addon/components/cf-field-value.js +8 -13
  23. package/addon/components/cf-field.hbs +2 -2
  24. package/addon/components/cf-field.js +2 -3
  25. package/addon/components/cf-navigation-item.hbs +2 -2
  26. package/addon/components/cf-navigation.hbs +4 -1
  27. package/addon/components/document-validity.js +1 -1
  28. package/addon/gql/fragments/field.graphql +22 -0
  29. package/addon/gql/mutations/save-document-table-answer.graphql +1 -1
  30. package/addon/gql/mutations/save-document.graphql +1 -0
  31. package/addon/gql/queries/{get-document-answers.graphql → document-answers.graphql} +2 -1
  32. package/addon/gql/queries/{get-document-forms.graphql → document-forms.graphql} +2 -1
  33. package/addon/gql/queries/{get-document-used-dynamic-options.graphql → document-used-dynamic-options.graphql} +2 -1
  34. package/addon/gql/queries/{get-dynamic-options.graphql → dynamic-options.graphql} +2 -1
  35. package/addon/gql/queries/{get-fileanswer-info.graphql → fileanswer-info.graphql} +2 -1
  36. package/addon/helpers/get-widget.js +50 -0
  37. package/addon/lib/answer.js +108 -72
  38. package/addon/lib/base.js +32 -23
  39. package/addon/lib/dependencies.js +36 -71
  40. package/addon/lib/document.js +92 -96
  41. package/addon/lib/field.js +334 -401
  42. package/addon/lib/fieldset.js +46 -47
  43. package/addon/lib/form.js +27 -15
  44. package/addon/lib/navigation.js +211 -192
  45. package/addon/lib/question.js +103 -94
  46. package/addon/services/caluma-store.js +10 -6
  47. package/app/helpers/get-widget.js +4 -0
  48. package/blueprints/@projectcaluma/ember-form/index.js +1 -0
  49. package/package.json +27 -23
  50. package/addon/components/cf-navigation.js +0 -9
@@ -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
+ }