@projectcaluma/ember-form-builder 12.7.0 → 12.8.0

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.
@@ -4,11 +4,14 @@
4
4
  <div class="uk-form-controls">
5
5
  <div
6
6
  name={{@name}}
7
- class="uk-textarea cfb-code-editor {{concat 'language-' @language}}"
7
+ class="uk-textarea cfb-code-editor
8
+ {{concat 'language-' @language}}
9
+ {{if @isValid 'uk-form-success'}}
10
+ {{if @isInvalid 'uk-form-danger'}}"
8
11
  {{did-insert this.didInsertNode}}
9
12
  {{will-destroy this.willDestroyNode}}
10
13
  {{autoresize mode="height"}}
11
- {{on "blur" @setDirty}}
14
+ {{on "blur" this.onBlur}}
12
15
  ></div>
13
16
  </div>
14
17
 
@@ -6,6 +6,8 @@ import hljs from "highlight.js/lib/core";
6
6
  import json from "highlight.js/lib/languages/json";
7
7
  import markdown from "highlight.js/lib/languages/markdown";
8
8
  import jexl from "highlightjs-jexl/src/languages/jexl";
9
+ import isEqual from "lodash.isequal";
10
+ import "highlight.js/styles/github.css";
9
11
 
10
12
  hljs.configure({ ignoreUnescapedHTML: true });
11
13
 
@@ -15,14 +17,15 @@ hljs.registerLanguage("jexl", jexl);
15
17
 
16
18
  export default class CfbCodeEditorComponent extends Component {
17
19
  _editor = null;
18
- _cursor = null;
19
20
  _lastValue = this.args.value;
20
21
 
21
- get value() {
22
- const value = this.args.value;
23
-
24
- if (this.args.language === "json" && typeof value === "object") {
25
- return JSON.stringify(value?.unwrap?.() ?? value, null, 2);
22
+ get stringValue() {
23
+ if (this.args.language === "json" && typeof this.args.value === "object") {
24
+ return JSON.stringify(
25
+ this.args.value?.unwrap?.() ?? this.args.value,
26
+ null,
27
+ 2,
28
+ );
26
29
  }
27
30
 
28
31
  return this.args.value;
@@ -30,10 +33,6 @@ export default class CfbCodeEditorComponent extends Component {
30
33
 
31
34
  @action
32
35
  onUpdate(value) {
33
- if (this._lastValue === value) return;
34
-
35
- this._cursor = this._editor.save();
36
-
37
36
  if (this.args.language === "json") {
38
37
  try {
39
38
  value = JSON.parse(value);
@@ -42,20 +41,23 @@ export default class CfbCodeEditorComponent extends Component {
42
41
  }
43
42
  }
44
43
 
44
+ if (isEqual(this._lastValue, value)) return;
45
+
45
46
  this._lastValue = value;
46
47
  this.args.update(value);
47
48
  }
48
49
 
49
50
  @action
50
51
  updateCode() {
51
- if (this._lastValue === this.value) return;
52
+ if (isEqual(this._lastValue, this.args.value)) return;
52
53
 
53
- this._editor.updateCode(this.value, false);
54
+ this._editor.updateCode(this.stringValue, false);
55
+ }
54
56
 
55
- if (this._cursor) {
56
- this._editor.restore(this._cursor);
57
- this._cursor = null;
58
- }
57
+ @action
58
+ onBlur() {
59
+ this._editor.updateCode(this.stringValue);
60
+ this.args.setDirty();
59
61
  }
60
62
 
61
63
  @action
@@ -66,7 +68,7 @@ export default class CfbCodeEditorComponent extends Component {
66
68
  });
67
69
 
68
70
  // set initial value
69
- this._editor.updateCode(this.value);
71
+ this._editor.updateCode(this.stringValue);
70
72
 
71
73
  // register update method
72
74
  this._editor.onUpdate(this.onUpdate);
@@ -0,0 +1,50 @@
1
+ {{#if this.otherForms}}
2
+ <a
3
+ ...attributes
4
+ href="#"
5
+ {{on "click" (fn (mut this.modalVisible) true)}}
6
+ data-test-show-question-usage-modal-link
7
+ >
8
+ {{this.title}}
9
+ </a>
10
+ {{/if}}
11
+
12
+ <UkModal
13
+ @visible={{this.modalVisible}}
14
+ @stack={{true}}
15
+ @onHide={{fn (mut this.modalVisible) false}}
16
+ data-test-question-usage-modal
17
+ as |modal|
18
+ >
19
+ <modal.header>
20
+ {{t "caluma.form-builder.question.usage.references-heading"}}
21
+ </modal.header>
22
+ <modal.body>
23
+ <ul class="uk-list uk-list-divider">
24
+ {{#each this.forms.value as |form|}}
25
+ <li data-test-question-form-item={{form.node.slug}}>
26
+ <div class="uk-flex uk-flex-middle">
27
+ <span class="uk-width-expand">
28
+ <LinkTo @route="edit" @model={{form.node.slug}}>
29
+ {{form.node.name}}
30
+ </LinkTo>
31
+ </span>
32
+
33
+ {{#if form.node.isArchived}}
34
+ <UkBadge>
35
+ {{t "caluma.form-builder.form.isArchived"}}
36
+ </UkBadge>
37
+ {{/if}}
38
+
39
+ {{#unless form.node.isPublished}}
40
+ <UkBadge class="uk-margin-small-left">
41
+ {{t "caluma.form-builder.question.usage.not-published"}}
42
+ </UkBadge>
43
+ {{/unless}}
44
+ </div>
45
+ <div class="uk-text-muted uk-text-small">{{form.node.slug}}</div>
46
+ </li>
47
+ {{/each}}
48
+ </ul>
49
+ </modal.body>
50
+ </UkModal>
@@ -0,0 +1,46 @@
1
+ import { inject as service } from "@ember/service";
2
+ import Component from "@glimmer/component";
3
+ import { tracked } from "@glimmer/tracking";
4
+ import { queryManager } from "ember-apollo-client";
5
+ import { trackedFunction } from "ember-resources/util/function";
6
+
7
+ import allFormsForQuestionQuery from "@projectcaluma/ember-form-builder/gql/queries/all-forms-for-question.graphql";
8
+
9
+ export default class CfbFormEditorQuestionUsage extends Component {
10
+ @service intl;
11
+ @queryManager apollo;
12
+
13
+ @tracked modalVisible = false;
14
+
15
+ get title() {
16
+ return this.intl.t("caluma.form-builder.question.usage.title", {
17
+ n: this.otherForms,
18
+ // for highlighting the number we use the <b> tag
19
+ htmlSafe: true,
20
+ });
21
+ }
22
+
23
+ get otherForms() {
24
+ return this.forms.value?.length - 1 ?? 0;
25
+ }
26
+
27
+ forms = trackedFunction(this, async () => {
28
+ try {
29
+ const forms = await this.apollo.query(
30
+ {
31
+ query: allFormsForQuestionQuery,
32
+ variables: {
33
+ slug: this.args.model.slug,
34
+ },
35
+ fetchPolicy: "no-cache",
36
+ },
37
+ "allForms.edges",
38
+ );
39
+
40
+ return forms;
41
+ } catch (error) {
42
+ console.error(error);
43
+ return { value: [] };
44
+ }
45
+ });
46
+ }
@@ -440,7 +440,9 @@
440
440
  />
441
441
  {{/if}}
442
442
 
443
- <div class="uk-text-right">
443
+ <div class="uk-flex uk-flex-between uk-flex-middle uk-flex-row-reverse">
444
+ <CfbFormEditor::QuestionUsage @model={{f.model}} class="uk-flex-last" />
445
+
444
446
  <f.submit
445
447
  @disabled={{f.loading}}
446
448
  @label={{t "caluma.form-builder.global.save"}}
@@ -0,0 +1,13 @@
1
+ query AllFormsForQuestion($slug: String!) {
2
+ allForms(filter: [{ questions: [$slug] }]) {
3
+ edges {
4
+ node {
5
+ id
6
+ slug
7
+ name
8
+ isArchived
9
+ isPublished
10
+ }
11
+ }
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ export { default } from "@projectcaluma/ember-form-builder/components/cfb-form-editor/question-usage";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-form-builder",
3
- "version": "12.7.0",
3
+ "version": "12.8.0",
4
4
  "description": "Ember engine for building Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -14,12 +14,12 @@
14
14
  "@ember/legacy-built-in-components": "^0.5.0",
15
15
  "@ember/render-modifiers": "^2.1.0",
16
16
  "@ember/string": "^3.1.1",
17
- "@embroider/macros": "^1.13.3",
17
+ "@embroider/macros": "^1.13.4",
18
18
  "@glimmer/component": "^1.1.2",
19
19
  "@glimmer/tracking": "^1.1.2",
20
20
  "codejar": "^4.2.0",
21
21
  "ember-apollo-client": "~4.0.2",
22
- "ember-auto-import": "^2.7.0",
22
+ "ember-auto-import": "^2.7.1",
23
23
  "ember-changeset": "^4.1.2",
24
24
  "ember-changeset-validations": "^4.1.1",
25
25
  "ember-cli-babel": "^8.2.0",
@@ -41,9 +41,10 @@
41
41
  "highlight.js": "^11.9.0",
42
42
  "highlightjs-jexl": "^0.0.5",
43
43
  "jexl": "^2.3.0",
44
+ "lodash.isequal": "^4.5.0",
44
45
  "uikit": "^3.17.11",
45
- "@projectcaluma/ember-core": "^12.7.0",
46
- "@projectcaluma/ember-form": "^12.7.0"
46
+ "@projectcaluma/ember-form": "^12.8.0",
47
+ "@projectcaluma/ember-core": "^12.8.0"
47
48
  },
48
49
  "//": [
49
50
  "TODO: remove obsolete dependency to `ember-data` which is only necessary",
@@ -79,7 +80,7 @@
79
80
  "qunit": "2.20.0",
80
81
  "qunit-dom": "3.0.0",
81
82
  "webpack": "5.89.0",
82
- "@projectcaluma/ember-testing": "12.7.0"
83
+ "@projectcaluma/ember-testing": "12.8.0"
83
84
  },
84
85
  "peerDependencies": {
85
86
  "ember-engines": "^0.9.0",
@@ -134,6 +134,11 @@ caluma:
134
134
 
135
135
  hideLabel: "Label verstecken"
136
136
 
137
+ usage:
138
+ title: "Diese Frage wird in {n,plural, =1 {<b>einem</b> Formular} other {<b>#</b> Formularen}} verwendet."
139
+ references-heading: "Alle Verweise auf diese Frage"
140
+ not-published: "nicht publiziert"
141
+
137
142
  options:
138
143
  delete: "Option löschen"
139
144
  archive: "Option archivieren (verstecken)"
@@ -134,6 +134,11 @@ caluma:
134
134
 
135
135
  hideLabel: "Hide label"
136
136
 
137
+ usage:
138
+ title: "This question is used in {n,plural, =1 {<b>another</b> form} other {<b>#</b> other forms}}"
139
+ references-heading: "All references of this question"
140
+ not-published: "not published"
141
+
137
142
  options:
138
143
  delete: "Delete option"
139
144
  archive: "Archive (hide) option"
@@ -134,6 +134,11 @@ caluma:
134
134
 
135
135
  hideLabel: "Cacher l'étiquette"
136
136
 
137
+ usage:
138
+ title: "Cette question est {n,plural, =1 {utilisé sous <b>une</b> forme} other {utilisé sous <b>#</b> formes}}."
139
+ references-heading: "Toutes les références à cette question"
140
+ not-published: "non publié"
141
+
137
142
  options:
138
143
  delete: "Supprimer l'option"
139
144
  archive: "Archiver (masquer) l'option"