@projectcaluma/ember-form 11.0.0-beta.10 → 11.0.0-beta.13

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,38 @@
1
+ # [@projectcaluma/ember-form-v11.0.0-beta.13](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.12...@projectcaluma/ember-form-v11.0.0-beta.13) (2022-03-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **form:** don't refetch dynamic options on validation ([27061c6](https://github.com/projectcaluma/ember-caluma/commit/27061c67f0562508f558305247cb51d615fa36b0))
7
+ * **form:** fix input in date fields ([cf54bf5](https://github.com/projectcaluma/ember-caluma/commit/cf54bf5542e35fd7dbe293a9e22288afae6a517a))
8
+ * **navigation:** exclude static questions from visible fields ([6ebd085](https://github.com/projectcaluma/ember-caluma/commit/6ebd085098df71fab693dec5282ea4b81d5b9836))
9
+ * **workflow:** return case status on complete / skip work-item mutation ([524453c](https://github.com/projectcaluma/ember-caluma/commit/524453c1189b4375ca792fca7d35056b916696f8))
10
+
11
+
12
+ ### Features
13
+
14
+ * **form:** support passing component override classes ([9409c7c](https://github.com/projectcaluma/ember-caluma/commit/9409c7cb5901dcdffec1c0294046da64b74b9922))
15
+
16
+ # [@projectcaluma/ember-form-v11.0.0-beta.12](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.11...@projectcaluma/ember-form-v11.0.0-beta.12) (2022-02-23)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **form:** fix textarea size in tables ([efba737](https://github.com/projectcaluma/ember-caluma/commit/efba737f0a6314225a851ee0c57c2c506403bc06))
22
+
23
+ # [@projectcaluma/ember-form-v11.0.0-beta.11](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.10...@projectcaluma/ember-form-v11.0.0-beta.11) (2022-02-16)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * **form:** always use monday as first day of the week in datepicker ([7008a90](https://github.com/projectcaluma/ember-caluma/commit/7008a90d737d2dca714f4799f846f4c4086ecd4d))
29
+ * **form:** use action button type "button" ([3e9795f](https://github.com/projectcaluma/ember-caluma/commit/3e9795f28b73dcf376ec9ecabcd4c1b6a8085beb))
30
+
31
+
32
+ ### Features
33
+
34
+ * **form:** add notfound named block in cf-content if no document found ([f1861c1](https://github.com/projectcaluma/ember-caluma/commit/f1861c1f3b2da9843771aa1b12956190c98799a6))
35
+
1
36
  # [@projectcaluma/ember-form-v11.0.0-beta.10](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.9...@projectcaluma/ember-form-v11.0.0-beta.10) (2022-02-09)
2
37
 
3
38
 
@@ -36,4 +36,6 @@
36
36
  <content.form />
37
37
  {{/if}}
38
38
  {{/let}}
39
+ {{else}}
40
+ {{yield to="notfound"}}
39
41
  {{/if}}
@@ -12,7 +12,6 @@
12
12
  @beforeMutate={{fn this.beforeMutate validate}}
13
13
  @onSuccess={{this.onSuccess}}
14
14
  @onError={{this.onError}}
15
- @type={{this.type}}
16
15
  class={{if @disabled "uk-hidden"}}
17
16
  />
18
17
  </DocumentValidity>
@@ -38,12 +38,6 @@ export default class CfFieldInputActionButtonComponent extends Component {
38
38
  return this.args.field.question.raw.color.toLowerCase();
39
39
  }
40
40
 
41
- get type() {
42
- return this.args.field.question.raw.action === "COMPLETE"
43
- ? "submit"
44
- : "button";
45
- }
46
-
47
41
  get validateOnEnter() {
48
42
  return (
49
43
  this.args.field.question.raw.action === "COMPLETE" &&
@@ -19,10 +19,12 @@
19
19
  name={{@field.pk}}
20
20
  id={{@field.pk}}
21
21
  {{pikaday
22
+ firstDay=1
22
23
  toString=this.formatDate
23
24
  i18n=this.pikadayTranslations
24
25
  value=@field.answer.value
25
26
  onSelect=this.onChange
27
+ parse=this.parseDate
26
28
  }}
27
29
  />
28
30
  {{/if}}
@@ -4,6 +4,9 @@ import Component from "@glimmer/component";
4
4
  import { DateTime, Info } from "luxon";
5
5
  import { cached } from "tracked-toolbox";
6
6
 
7
+ // put the last element to the front of the array
8
+ const shift = (array) => [...array.slice(-1), ...array.slice(0, -1)];
9
+
7
10
  export default class CfFieldInputDateComponent extends Component {
8
11
  @service intl;
9
12
 
@@ -13,6 +16,15 @@ export default class CfFieldInputDateComponent extends Component {
13
16
  this.args.onSave(date ? DateTime.fromJSDate(date).toISODate() : null);
14
17
  }
15
18
 
19
+ @action
20
+ parseDate(value) {
21
+ const date = DateTime.fromFormat(value, "D", {
22
+ locale: this.intl.primaryLocale,
23
+ });
24
+
25
+ return date.isValid ? date.toJSDate() : null;
26
+ }
27
+
16
28
  @action
17
29
  formatDate(date) {
18
30
  return this.intl.formatDate(date, {
@@ -30,8 +42,8 @@ export default class CfFieldInputDateComponent extends Component {
30
42
  previousMonth: this.intl.t("caluma.form.pikaday.month-previous"),
31
43
  nextMonth: this.intl.t("caluma.form.pikaday.month-next"),
32
44
  months: Info.months("long", { locale }),
33
- weekdays: Info.weekdays("long", { locale }),
34
- weekdaysShort: Info.weekdays("short", { locale }),
45
+ weekdays: shift(Info.weekdays("long", { locale })),
46
+ weekdaysShort: shift(Info.weekdays("short", { locale })),
35
47
  };
36
48
  }
37
49
  }
@@ -14,7 +14,10 @@
14
14
 
15
15
  <div class="uk-flex">
16
16
  <div class="uk-width-expand">
17
- {{#let (component (get-widget @field.question)) as |FieldComponent|}}
17
+ {{#let
18
+ (component (ensure-safe-component (get-widget @field.question)))
19
+ as |FieldComponent|
20
+ }}
18
21
  <FieldComponent
19
22
  @field={{@field}}
20
23
  @disabled={{@disabled}}
@@ -1,5 +1,5 @@
1
- import { getOwner } from "@ember/application";
2
1
  import { action } from "@ember/object";
2
+ import { macroCondition, isTesting } from "@embroider/macros";
3
3
  import Component from "@glimmer/component";
4
4
  import { timeout, restartableTask } from "ember-concurrency";
5
5
 
@@ -60,11 +60,10 @@ export default class CfFieldComponent extends Component {
60
60
  */
61
61
  @restartableTask
62
62
  *save(value) {
63
- const { environment } =
64
- getOwner(this).resolveRegistration("config:environment");
65
-
66
63
  /* istanbul ignore next */
67
- if (environment !== "test") {
64
+ if (macroCondition(isTesting())) {
65
+ // no timeout
66
+ } else {
68
67
  yield timeout(500);
69
68
  }
70
69
 
@@ -1,6 +1,8 @@
1
1
  {{#let
2
2
  (component
3
- (get-widget @fieldset.field.question @fieldset.form default="cf-form")
3
+ (ensure-safe-component
4
+ (get-widget @fieldset.field.question @fieldset.form default="cf-form")
5
+ )
4
6
  )
5
7
  as |FormComponent|
6
8
  }}
@@ -1,6 +1,15 @@
1
1
  import Helper from "@ember/component/helper";
2
2
  import { warn } from "@ember/debug";
3
3
  import { inject as service } from "@ember/service";
4
+ import { ensureSafeComponent } from "@embroider/util";
5
+
6
+ import InputComponent from "@projectcaluma/ember-form/components/cf-field/input";
7
+ import FormComponent from "@projectcaluma/ember-form/components/cf-form";
8
+
9
+ const DEFAULT_WIDGETS = {
10
+ "cf-field/input": InputComponent,
11
+ "cf-form": FormComponent,
12
+ };
4
13
 
5
14
  /**
6
15
  * Helper for getting the right widget.
@@ -42,9 +51,14 @@ export default class GetWidgetHelper extends Helper {
42
51
  { id: "ember-caluma.unregistered-override" }
43
52
  );
44
53
 
45
- if (override) return widget;
54
+ if (override) {
55
+ return ensureSafeComponent(
56
+ override.componentClass ?? override.component,
57
+ this
58
+ );
59
+ }
46
60
  }
47
61
 
48
- return defaultWidget;
62
+ return ensureSafeComponent(DEFAULT_WIDGETS[defaultWidget], this);
49
63
  }
50
64
  }
@@ -0,0 +1,52 @@
1
+ import { setOwner } from "@ember/application";
2
+ import { inject as service } from "@ember/service";
3
+
4
+ import HiddenComponent from "@projectcaluma/ember-form/components/cf-field/input/hidden";
5
+ import PowerSelectComponent from "@projectcaluma/ember-form/components/cf-field/input/powerselect";
6
+
7
+ class HiddenOverride {
8
+ @service intl;
9
+
10
+ get label() {
11
+ return this.intl.t("caluma.form-builder.question.widgetOverrides.hidden");
12
+ }
13
+
14
+ component = "cf-field/input/hidden";
15
+ componentClass = HiddenComponent;
16
+ }
17
+
18
+ class PowerSelectOverride {
19
+ @service intl;
20
+
21
+ get label() {
22
+ return this.intl.t(
23
+ "caluma.form-builder.question.widgetOverrides.powerselect"
24
+ );
25
+ }
26
+
27
+ component = "cf-field/input/powerselect";
28
+ componentClass = PowerSelectComponent;
29
+ types = [
30
+ "ChoiceQuestion",
31
+ "MultipleChoiceQuestion",
32
+ "DynamicChoiceQuestion",
33
+ "DynamicMultipleChoiceQuestion",
34
+ ];
35
+ }
36
+
37
+ export function initialize(appInstance) {
38
+ const options = appInstance.lookup("service:caluma-options");
39
+
40
+ const hiddenOverride = new HiddenOverride();
41
+ const powerSelectOverride = new PowerSelectOverride();
42
+
43
+ setOwner(hiddenOverride, appInstance);
44
+ setOwner(powerSelectOverride, appInstance);
45
+
46
+ options.registerComponentOverride(hiddenOverride);
47
+ options.registerComponentOverride(powerSelectOverride);
48
+ }
49
+
50
+ export default {
51
+ initialize,
52
+ };
@@ -83,18 +83,12 @@ export default class Field extends Base {
83
83
  _createQuestion() {
84
84
  const owner = getOwner(this);
85
85
 
86
- const question =
86
+ this.question =
87
87
  this.calumaStore.find(`Question:${this.raw.question.slug}`) ||
88
88
  new (owner.factoryFor("caluma-model:question").class)({
89
89
  raw: this.raw.question,
90
90
  owner,
91
91
  });
92
-
93
- if (question.isDynamic) {
94
- question.loadDynamicOptions.perform();
95
- }
96
-
97
- this.question = question;
98
92
  }
99
93
 
100
94
  _createAnswer() {
@@ -783,8 +777,6 @@ export default class Field extends Base {
783
777
  * @private
784
778
  */
785
779
  async _validateDynamicChoiceQuestion() {
786
- await this.question.loadDynamicOptions.perform();
787
-
788
780
  return validate("inclusion", this.answer.value, {
789
781
  in: (this.options || []).map(({ slug }) => slug),
790
782
  });
@@ -805,8 +797,6 @@ export default class Field extends Base {
805
797
  return true;
806
798
  }
807
799
 
808
- await this.question.loadDynamicOptions.perform();
809
-
810
800
  return value.map((value) => {
811
801
  return validate("inclusion", value, {
812
802
  in: (this.options || []).map(({ slug }) => slug),
@@ -232,7 +232,9 @@ export class NavigationItem extends Base {
232
232
  @cached
233
233
  get visibleFields() {
234
234
  return this.fieldset.fields.filter(
235
- (f) => f.questionType !== "FormQuestion" && !f.hidden
235
+ (f) =>
236
+ !["FormQuestion", "StaticQuestion"].includes(f.questionType) &&
237
+ !f.hidden
236
238
  );
237
239
  }
238
240
 
@@ -1,7 +1,8 @@
1
1
  import { assert } from "@ember/debug";
2
2
  import { camelize } from "@ember/string";
3
3
  import { queryManager } from "ember-apollo-client";
4
- import { dropTask, lastValue } from "ember-concurrency";
4
+ import { dropTask } from "ember-concurrency";
5
+ import { useTask } from "ember-resources";
5
6
  import { cached } from "tracked-toolbox";
6
7
 
7
8
  import getDynamicOptions from "@projectcaluma/ember-form/gql/queries/dynamic-options.graphql";
@@ -71,13 +72,20 @@ export default class Question extends Base {
71
72
  );
72
73
 
73
74
  return (
74
- question.node.dynamicChoiceOptions ||
75
+ question.node.dynamicChoiceOptions ??
75
76
  question.node.dynamicMultipleChoiceOptions
76
77
  );
77
78
  }
78
79
 
79
- @lastValue("loadDynamicOptions") dynamicChoiceOptions;
80
- @lastValue("loadDynamicOptions") dynamicMultipleChoiceOptions;
80
+ dynamicOptions = useTask(this, this.loadDynamicOptions, () => []);
81
+
82
+ get dynamicChoiceOptions() {
83
+ return this.dynamicOptions.value ?? [];
84
+ }
85
+
86
+ get dynamicMultipleChoiceOptions() {
87
+ return this.dynamicOptions.value ?? [];
88
+ }
81
89
 
82
90
  /**
83
91
  * Whether the question is a single choice question
@@ -0,0 +1,16 @@
1
+ import { inject as service } from "@ember/service";
2
+ import AutoresizeModifier from "ember-autoresize-modifier/modifiers/autoresize";
3
+
4
+ export default class CustomAutoresizeModifier extends AutoresizeModifier {
5
+ @service inViewport;
6
+
7
+ didInstall() {
8
+ super.didInstall();
9
+
10
+ this.inViewport.watchElement(this.element).onEnter(this.resize);
11
+ }
12
+
13
+ willRemove() {
14
+ this.inViewport.stopWatching(this.element);
15
+ }
16
+ }
@@ -0,0 +1,4 @@
1
+ export {
2
+ default,
3
+ initialize,
4
+ } from "@projectcaluma/ember-form/instance-initializers/form-widget-overrides";
@@ -0,0 +1 @@
1
+ export { default } from "@projectcaluma/ember-form/modifiers/autoresize";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-form",
3
- "version": "11.0.0-beta.10",
3
+ "version": "11.0.0-beta.13",
4
4
  "description": "Ember addon for rendering Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -14,9 +14,10 @@
14
14
  "test:ember-compatibility": "ember try:each"
15
15
  },
16
16
  "dependencies": {
17
+ "@embroider/macros": "^1.5.0",
17
18
  "@glimmer/component": "^1.0.4",
18
19
  "@glimmer/tracking": "^1.0.4",
19
- "@projectcaluma/ember-core": "^11.0.0-beta.4",
20
+ "@projectcaluma/ember-core": "^11.0.0-beta.5",
20
21
  "ember-apollo-client": "^3.2.0",
21
22
  "ember-auto-import": "^2.4.0",
22
23
  "ember-autoresize-modifier": "^0.5.0",
@@ -30,29 +31,29 @@
30
31
  "ember-intl": "^5.7.2",
31
32
  "ember-math-helpers": "^2.18.1",
32
33
  "ember-pikaday": "^4.0.0",
33
- "ember-power-select": "^5.0.3",
34
- "ember-resources": "^4.3.1",
34
+ "ember-power-select": "^5.0.4",
35
+ "ember-resources": "^4.4.0",
35
36
  "ember-uikit": "^5.0.0",
36
37
  "ember-validators": "^4.1.2",
37
38
  "graphql": "^15.8.0",
38
39
  "jexl": "^2.3.0",
39
40
  "lodash.isequal": "^4.5.0",
40
- "luxon": "^2.3.0",
41
+ "luxon": "^2.3.1",
41
42
  "tracked-toolbox": "^1.2.3"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@ember/optional-features": "2.0.0",
45
46
  "@ember/test-helpers": "2.6.0",
46
- "@embroider/test-setup": "1.1.0",
47
- "@faker-js/faker": "6.0.0-alpha.5",
48
- "@projectcaluma/ember-testing": "11.0.0-beta.2",
47
+ "@embroider/test-setup": "1.5.0",
48
+ "@faker-js/faker": "6.0.0-beta.0",
49
+ "@projectcaluma/ember-testing": "11.0.0-beta.4",
49
50
  "@projectcaluma/ember-workflow": "11.0.0-beta.4",
50
51
  "broccoli-asset-rev": "3.0.0",
51
52
  "ember-cli": "3.28.5",
52
53
  "ember-cli-code-coverage": "1.0.3",
53
54
  "ember-cli-dependency-checker": "3.2.0",
54
55
  "ember-cli-inject-live-reload": "2.1.0",
55
- "ember-cli-mirage": "2.4.0",
56
+ "ember-cli-mirage": "3.0.0-alpha.2",
56
57
  "ember-cli-sri": "2.1.1",
57
58
  "ember-cli-terser": "4.0.2",
58
59
  "ember-disable-prototype-extensions": "1.1.3",
@@ -67,10 +68,10 @@
67
68
  "loader.js": "4.7.0",
68
69
  "miragejs": "0.1.43",
69
70
  "npm-run-all": "4.1.5",
70
- "qunit": "2.17.2",
71
+ "qunit": "2.18.0",
71
72
  "qunit-dom": "2.0.0",
72
73
  "uuid": "8.3.2",
73
- "webpack": "5.68.0"
74
+ "webpack": "5.70.0"
74
75
  },
75
76
  "engines": {
76
77
  "node": "12.* || 14.* || >= 16"
@@ -34,7 +34,6 @@ caluma:
34
34
  options-empty: "Keine Optionen vorhanden"
35
35
  search-placeholder: "Hier tippen um zu suchen"
36
36
  search-empty: "Keine Optionen gefunden"
37
- null: "Keine Auswahl"
38
37
 
39
38
  validation:
40
39
  blank: "Dieses Feld darf nicht leer gelassen werden"
@@ -44,6 +43,7 @@ caluma:
44
43
  lessThanOrEqualTo: "Die Eingabe in diesem Feld darf nicht grösser als {lte} sein"
45
44
  notAnInteger: "Bitte geben Sie eine ganze Zahl ein"
46
45
  inclusion: "'{value}' ist kein gültiger Wert für dieses Feld"
46
+ deleteFailed: "Beim Löschen ist ein Fehler aufgetreten."
47
47
  uploadFailed: "Beim Hochladen ist ein Fehler aufgetreten."
48
48
  format: "{errorMsg}"
49
49
  table: "Mindestens eine Zeile der Tabelle wurde nicht korrekt ausgefüllt"
@@ -34,7 +34,6 @@ caluma:
34
34
  options-empty: "No options available"
35
35
  search-placeholder: "Type here to search options"
36
36
  search-empty: "Search didn't match any options"
37
- null: "No selection"
38
37
 
39
38
  validation:
40
39
  blank: "This field can't be blank"
@@ -44,6 +43,7 @@ caluma:
44
43
  lessThanOrEqualTo: "The value of this field must be less than or equal to {lte}"
45
44
  notAnInteger: "The value of this field must be an integer"
46
45
  inclusion: "'{value}' is not a valid value for this field"
46
+ deleteFailed: "An error occured during deletion."
47
47
  uploadFailed: "An error occured during upload."
48
48
  format: "{errorMsg}"
49
49
  table: "At least one row of the table was not filled in correctly"
@@ -34,7 +34,6 @@ caluma:
34
34
  options-empty: "Pas d'options disponibles"
35
35
  search-placeholder: "Tapez ici pour rechercher"
36
36
  search-empty: "Pas d'options trouvées"
37
- null: "Aucune sélection"
38
37
 
39
38
  validation:
40
39
  blank: "Ce champ ne doit pas être laissé vide"
@@ -44,6 +43,7 @@ caluma:
44
43
  lessThanOrEqualTo: "L'entrée dans ce champ ne doit pas être supérieure à {lte} "
45
44
  notAnInteger: "Veuillez entrer un nombre entier"
46
45
  inclusion: "'{value}' n'est pas une valeur valide pour ce champ"
46
+ deleteFailed: "Une erreur est survenue lors de la suppression."
47
47
  uploadFailed: "Une erreur s'est produite pendant le téléchargement."
48
48
  format: "{errorMsg}"
49
49
  table: "Au moins une ligne du tableau n'a pas été remplie correctement"