@projectcaluma/ember-form 12.9.0 → 12.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ <input
2
+ type="text"
3
+ class="uk-input
4
+ {{if @field.isInvalid 'uk-form-danger'}}
5
+ {{if this.disabled 'uk-disabled'}}"
6
+ name={{@field.pk}}
7
+ id={{@field.pk}}
8
+ value={{this.displayValue}}
9
+ placeholder={{@field.question.raw.placeholder}}
10
+ readonly={{this.disabled}}
11
+ {{on "input" this.input}}
12
+ />
@@ -0,0 +1,46 @@
1
+ import { action } from "@ember/object";
2
+ import { inject as service } from "@ember/service";
3
+ import Component from "@glimmer/component";
4
+ import { cached } from "tracked-toolbox";
5
+
6
+ export default class CfFieldInputNumberSeparatorComponent extends Component {
7
+ @service intl;
8
+
9
+ get disabled() {
10
+ return this.args.disabled || this.args.field?.question.isCalculated;
11
+ }
12
+
13
+ get displayValue() {
14
+ if (!this.args.field.value) {
15
+ return "";
16
+ }
17
+
18
+ return this.intl.formatNumber(this.args.field.value, {
19
+ maximumFractionDigits: 20,
20
+ });
21
+ }
22
+
23
+ @cached
24
+ get thousandSeparator() {
25
+ return this.intl.formatNumber(11111).replace(/\p{Number}/gu, "");
26
+ }
27
+
28
+ @cached
29
+ get decimalSeparator() {
30
+ return this.intl.formatNumber(1.1).replace(/\p{Number}/gu, "");
31
+ }
32
+
33
+ @action
34
+ input({ target: { value } }) {
35
+ // We need to remove the thousand separator and replace the decimal
36
+ // separator with a dot in order to parse it into a number. Which character
37
+ // those are is determined per locale in the getters above.
38
+ const serialized = Number(
39
+ value
40
+ .replace(new RegExp(`\\${this.thousandSeparator}`, "g"), "")
41
+ .replace(new RegExp(`\\${this.decimalSeparator}`), "."),
42
+ );
43
+
44
+ this.args.onSave(isNaN(serialized) ? null : serialized);
45
+ }
46
+ }
@@ -23,7 +23,7 @@
23
23
  {{/if}}
24
24
  </label>
25
25
  {{/each}}
26
- {{#if (and @field.optional @field.answer.value)}}
26
+ {{#if (and @field.optional @field.answer.value (not @disabled))}}
27
27
  <br />
28
28
  <a href="" data-test-radio-reset {{on "click" this.reset}}>
29
29
  {{t "caluma.form.power-select.reset"}}
@@ -21,6 +21,15 @@
21
21
  @onClick={{fn this.download file.id}}
22
22
  />
23
23
  {{/each}}
24
+ {{else if
25
+ (and
26
+ @field.answer.value
27
+ (eq
28
+ @field.question.raw.meta.widgetOverride "cf-field/input/number-separator"
29
+ )
30
+ )
31
+ }}
32
+ {{format-number @field.answer.value maximumFractionDigits=20}}
24
33
  {{else}}
25
34
  {{@field.answer.value}}
26
35
  {{/if}}
@@ -23,7 +23,7 @@
23
23
  }}
24
24
  <FieldComponent
25
25
  @field={{@field}}
26
- @disabled={{@disabled}}
26
+ @disabled={{or @disabled @field.refreshAnswer.isRunning}}
27
27
  @context={{@context}}
28
28
  @onSave={{perform this.save}}
29
29
  />
@@ -38,7 +38,7 @@
38
38
  <div
39
39
  class="cf-field__icon uk-padding-remove-vertical uk-flex uk-flex-middle uk-flex-center"
40
40
  >
41
- {{#if this.save.isRunning}}
41
+ {{#if (or this.save.isRunning @field.refreshAnswer.isRunning)}}
42
42
  <UkSpinner class="uk-animation-fade" />
43
43
  {{else if (or this.save.last.isError @field.isInvalid)}}
44
44
  <div class="uk-flex-inline">
@@ -214,6 +214,7 @@ fragment FieldQuestion on Question {
214
214
 
215
215
  fragment SimpleAnswer on Answer {
216
216
  id
217
+ meta
217
218
  question {
218
219
  id
219
220
  slug
@@ -0,0 +1,18 @@
1
+ #import * from '../fragments/field.graphql'
2
+
3
+ query RefreshAnswer($document: ID!, $question: ID!) {
4
+ allDocuments(filter: [{ id: $document }]) {
5
+ edges {
6
+ node {
7
+ id
8
+ answers(filter: [{ questions: [$question] }]) {
9
+ edges {
10
+ node {
11
+ ...FieldAnswer
12
+ }
13
+ }
14
+ }
15
+ }
16
+ }
17
+ }
18
+ }
@@ -2,6 +2,7 @@ import { setOwner } from "@ember/application";
2
2
  import { inject as service } from "@ember/service";
3
3
 
4
4
  import HiddenComponent from "@projectcaluma/ember-form/components/cf-field/input/hidden";
5
+ import NumberSeparatorComponent from "@projectcaluma/ember-form/components/cf-field/input/number-separator";
5
6
  import PowerSelectComponent from "@projectcaluma/ember-form/components/cf-field/input/powerselect";
6
7
 
7
8
  class HiddenOverride {
@@ -34,17 +35,30 @@ class PowerSelectOverride {
34
35
  ];
35
36
  }
36
37
 
37
- export function initialize(appInstance) {
38
- const options = appInstance.lookup("service:caluma-options");
38
+ class NumberSeparatorOverride {
39
+ @service intl;
39
40
 
40
- const hiddenOverride = new HiddenOverride();
41
- const powerSelectOverride = new PowerSelectOverride();
41
+ get label() {
42
+ return this.intl.t(
43
+ "caluma.form-builder.question.widgetOverrides.number-separator",
44
+ );
45
+ }
46
+
47
+ component = "cf-field/input/number-separator";
48
+ componentClass = NumberSeparatorComponent;
49
+ types = ["IntegerQuestion", "FloatQuestion", "CalculatedFloatQuestion"];
50
+ }
42
51
 
43
- setOwner(hiddenOverride, appInstance);
44
- setOwner(powerSelectOverride, appInstance);
52
+ export function initialize(appInstance) {
53
+ const options = appInstance.lookup("service:caluma-options");
45
54
 
46
- options.registerComponentOverride(hiddenOverride);
47
- options.registerComponentOverride(powerSelectOverride);
55
+ [HiddenOverride, PowerSelectOverride, NumberSeparatorOverride].forEach(
56
+ (cls) => {
57
+ const override = new cls();
58
+ setOwner(override, appInstance);
59
+ options.registerComponentOverride(override);
60
+ },
61
+ );
48
62
  }
49
63
 
50
64
  export default {
@@ -20,6 +20,7 @@ import saveDocumentListAnswerMutation from "@projectcaluma/ember-form/gql/mutati
20
20
  import saveDocumentStringAnswerMutation from "@projectcaluma/ember-form/gql/mutations/save-document-string-answer.graphql";
21
21
  import saveDocumentTableAnswerMutation from "@projectcaluma/ember-form/gql/mutations/save-document-table-answer.graphql";
22
22
  import getDocumentUsedDynamicOptionsQuery from "@projectcaluma/ember-form/gql/queries/document-used-dynamic-options.graphql";
23
+ import refreshAnswerQuery from "@projectcaluma/ember-form/gql/queries/refresh-answer.graphql";
23
24
  import Base from "@projectcaluma/ember-form/lib/base";
24
25
  import dependencies from "@projectcaluma/ember-form/lib/dependencies";
25
26
 
@@ -634,6 +635,29 @@ export default class Field extends Base {
634
635
  this._errors = errors;
635
636
  }
636
637
 
638
+ @dropTask
639
+ *refreshAnswer() {
640
+ const response = yield this.apollo.query(
641
+ {
642
+ query: refreshAnswerQuery,
643
+ fetchPolicy: "network-only",
644
+ variables: {
645
+ document: this.document.uuid,
646
+ question: this.question.slug,
647
+ },
648
+ },
649
+ "allDocuments.edges",
650
+ );
651
+
652
+ const rawAnswer = response[0].node.answers.edges[0]?.node;
653
+
654
+ if (rawAnswer) {
655
+ Object.entries(rawAnswer).forEach(([key, value]) => {
656
+ this.answer.raw[key] = value;
657
+ });
658
+ }
659
+ }
660
+
637
661
  /**
638
662
  * Validate the value against the regexes of the given format validators.
639
663
  *
@@ -0,0 +1 @@
1
+ export { default } from "@projectcaluma/ember-form/components/cf-field/input/number-separator";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-form",
3
- "version": "12.9.0",
3
+ "version": "12.10.0",
4
4
  "description": "Ember addon for rendering Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -9,7 +9,7 @@
9
9
  "homepage": "https://docs.caluma.io/ember-caluma",
10
10
  "repository": "github:projectcaluma/ember-caluma",
11
11
  "dependencies": {
12
- "@babel/core": "^7.23.7",
12
+ "@babel/core": "^7.23.9",
13
13
  "@ember/string": "^3.1.1",
14
14
  "@embroider/macros": "^1.13.4",
15
15
  "@embroider/util": "^1.12.1",
@@ -39,13 +39,13 @@
39
39
  "lodash.isequal": "^4.5.0",
40
40
  "luxon": "^3.4.4",
41
41
  "tracked-toolbox": "^2.0.0",
42
- "@projectcaluma/ember-core": "^12.9.0"
42
+ "@projectcaluma/ember-core": "^12.10.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@ember/optional-features": "2.0.0",
45
+ "@ember/optional-features": "2.1.0",
46
46
  "@ember/test-helpers": "3.2.1",
47
47
  "@embroider/test-setup": "3.0.3",
48
- "@faker-js/faker": "8.3.1",
48
+ "@faker-js/faker": "8.4.1",
49
49
  "broccoli-asset-rev": "3.0.0",
50
50
  "ember-cli": "5.5.0",
51
51
  "ember-cli-clean-css": "3.0.0",
@@ -67,13 +67,13 @@
67
67
  "qunit-dom": "3.0.0",
68
68
  "uikit": "3.17.11",
69
69
  "uuid": "9.0.1",
70
- "webpack": "5.89.0",
71
- "@projectcaluma/ember-testing": "12.9.0",
72
- "@projectcaluma/ember-workflow": "12.9.0"
70
+ "webpack": "5.90.0",
71
+ "@projectcaluma/ember-testing": "12.10.0",
72
+ "@projectcaluma/ember-workflow": "12.10.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "ember-source": "^4.0.0",
76
- "@projectcaluma/ember-workflow": "^12.9.0"
76
+ "@projectcaluma/ember-workflow": "^12.10.0"
77
77
  },
78
78
  "dependenciesMeta": {
79
79
  "@projectcaluma/ember-core": {