@projectcaluma/ember-form-builder 11.1.5 → 11.2.1

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.
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This module holds the application instance which is needed in the validations
3
+ * to allow context of the ember container in order to allow injections of
4
+ * services. The `instance` property will be set in an instance initializer.
5
+ */
6
+ export default { instance: null };
@@ -16,40 +16,17 @@
16
16
  @on-update={{this.updateName}}
17
17
  />
18
18
 
19
- {{#if (or @slug (not this.prefix))}}
20
- <f.input
21
- @type="text"
22
- @name="slug"
23
- @label={{t "caluma.form-builder.form.slug"}}
24
- @required={{true}}
25
- @disabled={{@slug}}
26
- @on-update={{this.updateSlug}}
27
- />
28
- {{else}}
29
- <f.input
30
- @name="slug"
31
- @required={{true}}
32
- @disabled={{@slug}}
33
- @label={{t "caluma.form-builder.question.slug"}}
34
- @on-update={{this.updateSlug value="target.value"}}
35
- as |fi|
36
- >
37
- <div class="cfb-prefixed">
38
- <span class="cfb-prefixed-slug">{{this.prefix}}</span>
39
- <f.input
40
- @type="text"
41
- @model={{fi.model}}
42
- @name={{fi.name}}
43
- @value={{fi.value}}
44
- @update={{fi.update}}
45
- @setDirty={{fi.setDirty}}
46
- @inputId={{fi.inputId}}
47
- @isValid={{fi.isValid}}
48
- @isInvalid={{fi.isInvalid}}
49
- />
50
- </div>
51
- </f.input>
52
- {{/if}}
19
+ <f.input
20
+ @type="text"
21
+ @name="slug"
22
+ @label={{t "caluma.form-builder.form.slug"}}
23
+ @required={{true}}
24
+ @disabled={{not (is-empty @slug)}}
25
+ @renderComponent={{component
26
+ "cfb-slug-input"
27
+ onUnlink=(fn (mut this.slugUnlinked) true)
28
+ }}
29
+ />
53
30
 
54
31
  <f.input
55
32
  @name="description"
@@ -74,7 +51,7 @@
74
51
 
75
52
  <div class="uk-text-right">
76
53
  <f.submit
77
- @disabled={{or f.loading f.model.isInvalid}}
54
+ @disabled={{f.loading}}
78
55
  @label={{t "caluma.form-builder.global.save"}}
79
56
  />
80
57
  </div>
@@ -1,16 +1,14 @@
1
1
  import { action } from "@ember/object";
2
2
  import { inject as service } from "@ember/service";
3
- import { macroCondition, isTesting } from "@embroider/macros";
4
3
  import Component from "@glimmer/component";
5
4
  import { queryManager } from "ember-apollo-client";
6
- import { timeout, restartableTask, dropTask } from "ember-concurrency";
5
+ import { restartableTask, dropTask } from "ember-concurrency";
7
6
  import { trackedTask } from "ember-resources/util/ember-concurrency";
8
7
 
9
8
  import FormValidations from "../../validations/form";
10
9
 
11
10
  import slugify from "@projectcaluma/ember-core/utils/slugify";
12
11
  import saveFormMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-form.graphql";
13
- import checkFormSlugQuery from "@projectcaluma/ember-form-builder/gql/queries/check-form-slug.graphql";
14
12
  import formEditorGeneralQuery from "@projectcaluma/ember-form-builder/gql/queries/form-editor-general.graphql";
15
13
 
16
14
  export default class CfbFormEditorGeneral extends Component {
@@ -61,16 +59,13 @@ export default class CfbFormEditorGeneral extends Component {
61
59
  @dropTask
62
60
  *submit(changeset) {
63
61
  try {
64
- const slug =
65
- ((!this.args.slug && this.prefix) || "") + changeset.get("slug");
66
-
67
62
  const form = yield this.apollo.mutate(
68
63
  {
69
64
  mutation: saveFormMutation,
70
65
  variables: {
71
66
  input: {
72
67
  name: changeset.get("name"),
73
- slug,
68
+ slug: changeset.get("slug"),
74
69
  description: changeset.get("description"),
75
70
  isArchived: changeset.get("isArchived"),
76
71
  isPublished: changeset.get("isPublished"),
@@ -100,47 +95,15 @@ export default class CfbFormEditorGeneral extends Component {
100
95
  }
101
96
  }
102
97
 
103
- @restartableTask
104
- *validateSlug(slug, changeset) {
105
- /* istanbul ignore next */
106
- if (macroCondition(isTesting())) {
107
- // no timeout
108
- } else {
109
- yield timeout(500);
110
- }
111
-
112
- const res = yield this.apollo.query(
113
- {
114
- query: checkFormSlugQuery,
115
- variables: { slug },
116
- },
117
- "allForms.edges"
118
- );
119
-
120
- if (res && res.length) {
121
- changeset.pushErrors(
122
- "slug",
123
- this.intl.t("caluma.form-builder.validations.form.slug")
124
- );
125
- }
126
- }
127
-
128
98
  @action
129
99
  updateName(value, changeset) {
130
100
  changeset.set("name", value);
131
101
 
132
- if (!this.args.slug) {
133
- const slug = slugify(value, { locale: this.intl.primaryLocale });
134
- changeset.set("slug", slug);
102
+ if (!this.args.slug && !this.slugUnlinked) {
103
+ const slugifiedName = slugify(value, { locale: this.intl.primaryLocale });
104
+ const slug = slugifiedName ? this.prefix + slugifiedName : "";
135
105
 
136
- this.validateSlug.perform(this.prefix + slug, changeset);
106
+ changeset.set("slug", slug);
137
107
  }
138
108
  }
139
-
140
- @action
141
- updateSlug(value, changeset) {
142
- changeset.set("slug", value);
143
-
144
- this.validateSlug.perform(this.prefix + value, changeset);
145
- }
146
109
  }
@@ -5,26 +5,26 @@
5
5
  @handle=".uk-sortable-handle"
6
6
  @onMoved={{this._handleMoved}}
7
7
  @tagName="ul"
8
- class="uk-list uk-list-divider uk-margin-remove-bottom uk-margin-small-top"
8
+ class="uk-list uk-list-divider uk-form-controls uk-margin-small-top"
9
9
  >
10
- {{#each this.optionRows as |row i|}}
11
- <li data-test-row={{concat "option-" (add i 1)}}>
10
+ {{#each @value as |row i|}}
11
+ <li class="cfb-option-row" data-test-row={{concat "option-" (add i 1)}}>
12
12
  <ValidatedForm @model={{row}} as |f|>
13
13
  <div
14
14
  uk-grid
15
- class="uk-grid-small uk-flex uk-flex-middle"
15
+ class="uk-grid-small uk-flex uk-flex-top"
16
16
  id={{row.slug}}
17
17
  >
18
- {{#if (not (and row.isNew (gt this.optionRows.length 1)))}}
19
- <span
20
- data-test-sort-handle
21
- uk-icon="menu"
22
- class="uk-sortable-handle"
23
- role="button"
24
- ></span>
25
- {{/if}}
26
- <div class="uk-width-auto">
27
- {{#if (and row.isNew (gt this.optionRows.length 1))}}
18
+ <div class="uk-width-auto uk-flex uk-flex-middle">
19
+ {{#if this.canReorder}}
20
+ <span
21
+ data-test-sort-handle
22
+ uk-icon="menu"
23
+ class="uk-sortable-handle uk-margin-small-right"
24
+ role="button"
25
+ ></span>
26
+ {{/if}}
27
+ {{#if (is-empty row.id)}}
28
28
  <button
29
29
  data-test-delete-row
30
30
  type="button"
@@ -34,21 +34,25 @@
34
34
  {{on "click" (fn this.deleteRow row)}}
35
35
  >
36
36
  </button>
37
+ {{else}}
38
+ <button
39
+ data-test-archive-row
40
+ type="button"
41
+ class="uk-icon-button"
42
+ uk-icon={{if row.isArchived "refresh" "close"}}
43
+ title={{t
44
+ (concat
45
+ "caluma.form-builder.options."
46
+ (if row.isArchived "restore" "archive")
47
+ )
48
+ }}
49
+ {{on
50
+ "click"
51
+ (fn (changeset-set row "isArchived") (not row.isArchived))
52
+ }}
53
+ >
54
+ </button>
37
55
  {{/if}}
38
- <button
39
- data-test-archive-row
40
- type="button"
41
- class="uk-icon-button"
42
- uk-icon={{if row.isArchived "plus" "close"}}
43
- title={{t
44
- (concat
45
- "caluma.form-builder.options."
46
- (if row.isArchived "restore" "archive")
47
- )
48
- }}
49
- {{on "click" (fn this.toggleRowArchived row)}}
50
- >
51
- </button>
52
56
  </div>
53
57
  <div class="uk-width-expand">
54
58
  <f.input
@@ -56,6 +60,7 @@
56
60
  @inputName={{concat "option-" (add i 1) "-label"}}
57
61
  @required={{true}}
58
62
  @disabled={{row.isArchived}}
63
+ @submitted={{@submitted}}
59
64
  @on-update={{this.updateLabel}}
60
65
  />
61
66
  </div>
@@ -64,8 +69,14 @@
64
69
  @name="slug"
65
70
  @inputName={{concat "option-" (add i 1) "-slug"}}
66
71
  @required={{true}}
67
- @disabled={{not row.isNew}}
68
- @on-update={{this.updateSlug}}
72
+ @disabled={{not (is-empty row.id)}}
73
+ @submitted={{@submitted}}
74
+ @renderComponent={{component
75
+ "cfb-slug-input"
76
+ hidePrefix=true
77
+ prefix=@model.slug
78
+ onUnlink=(fn (mut row.slugUnlinked) true)
79
+ }}
69
80
  />
70
81
  </div>
71
82
  </div>
@@ -1,11 +1,10 @@
1
1
  import { action } from "@ember/object";
2
2
  import { inject as service } from "@ember/service";
3
3
  import Component from "@glimmer/component";
4
- import { tracked } from "@glimmer/tracking";
5
4
  import { queryManager } from "ember-apollo-client";
6
5
  import { Changeset } from "ember-changeset";
7
6
  import lookupValidator from "ember-changeset-validations";
8
- import { task } from "ember-concurrency";
7
+ import { dropTask } from "ember-concurrency";
9
8
 
10
9
  import slugify from "@projectcaluma/ember-core/utils/slugify";
11
10
  import saveChoiceQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-choice-question.graphql";
@@ -17,90 +16,24 @@ const TYPES = {
17
16
  ChoiceQuestion: saveChoiceQuestionMutation,
18
17
  };
19
18
 
20
- const removeQuestionPrefix = (slug, questionSlug) => {
21
- return slug.replace(new RegExp(`^${questionSlug}-`), "");
22
- };
23
-
24
- const addQuestionPrefix = (slug, questionSlug) => {
25
- return `${questionSlug}-${slug}`;
26
- };
27
-
28
19
  export default class CfbFormEditorQuestionOptions extends Component {
29
- @tracked _optionRows;
30
-
31
20
  @service intl;
32
21
  @service notification;
33
- @queryManager apollo;
34
-
35
- constructor(...args) {
36
- super(...args);
37
-
38
- this._optionRows = this.args.value?.edges?.length
39
- ? this.args.value.edges.map(
40
- (edge) =>
41
- new Changeset(
42
- {
43
- slug: removeQuestionPrefix(edge.node.slug, this.questionSlug),
44
- label: edge.node.label,
45
- isArchived: edge.node.isArchived,
46
- isNew: false,
47
- },
48
- lookupValidator(OptionValidations),
49
- OptionValidations
50
- )
51
- )
52
- : [
53
- new Changeset(
54
- { slug: "", label: "", isNew: true, linkSlug: true },
55
- lookupValidator(OptionValidations),
56
- OptionValidations
57
- ),
58
- ];
59
- }
60
-
61
- get questionSlug() {
62
- return this.args.model.slug;
63
- }
64
-
65
- get optionRows() {
66
- return this._optionRows;
67
- }
68
22
 
69
- _update() {
70
- this.args.update({
71
- edges: this.optionRows
72
- .filter((row) => !row.isNew || row.isDirty)
73
- .map((row) => {
74
- const { label, slug, isArchived } = Object.assign(
75
- {},
76
- row.get("data"),
77
- row.get("change")
78
- );
79
-
80
- return {
81
- node: {
82
- label,
83
- slug: addQuestionPrefix(
84
- removeQuestionPrefix(slug, this.questionSlug),
85
- this.questionSlug
86
- ),
87
- isArchived: Boolean(isArchived),
88
- },
89
- };
90
- }),
91
- });
23
+ @queryManager apollo;
92
24
 
93
- this.args.setDirty();
25
+ get canReorder() {
26
+ return this.args.value.every((row) => row.get("id") !== undefined);
94
27
  }
95
28
 
96
- @task
29
+ @dropTask
97
30
  *reorderOptions(slugs) {
98
31
  try {
99
32
  yield this.apollo.mutate({
100
33
  mutation: TYPES[this.args.model.__typename],
101
34
  variables: {
102
35
  input: {
103
- slug: this.questionSlug,
36
+ slug: this.args.model.slug,
104
37
  label: this.args.model.label,
105
38
  options: slugs,
106
39
  },
@@ -123,55 +56,45 @@ export default class CfbFormEditorQuestionOptions extends Component {
123
56
 
124
57
  @action
125
58
  addRow() {
126
- this._optionRows = [
127
- ...this.optionRows,
59
+ this.args.update([
60
+ ...this.args.value,
128
61
  new Changeset(
129
- { slug: "", label: "", isNew: true, linkSlug: true },
62
+ {
63
+ id: undefined,
64
+ slug: "",
65
+ label: "",
66
+ isArchived: false,
67
+ slugUnlinked: false,
68
+ question: this.args.model.slug,
69
+ },
130
70
  lookupValidator(OptionValidations),
131
71
  OptionValidations
132
72
  ),
133
- ];
73
+ ]);
134
74
 
135
- this._update();
75
+ this.args.setDirty();
136
76
  }
137
77
 
138
78
  @action
139
79
  deleteRow(row) {
140
- this._optionRows = this.optionRows.filter((r) => r !== row);
141
-
142
- this._update();
143
- }
144
-
145
- @action
146
- toggleRowArchived(row) {
147
- row.set("isArchived", !row.get("isArchived"));
148
-
149
- this._update();
80
+ this.args.update(this.args.value.filter((r) => r !== row));
81
+ this.args.setDirty();
150
82
  }
151
83
 
152
84
  @action
153
85
  updateLabel(value, changeset) {
154
86
  changeset.set("label", value);
155
87
 
156
- if (changeset.get("isNew") && changeset.get("linkSlug")) {
157
- changeset.set(
158
- "slug",
159
- slugify(value, { locale: this.intl.primaryLocale })
160
- );
161
- }
162
- this._update();
163
- }
164
-
165
- @action
166
- updateSlug(value, changeset) {
167
- changeset.set("slug", value);
168
- changeset.set("linkSlug", false);
169
- this._update();
170
- }
88
+ if (!changeset.get("id") && !changeset.get("slugUnlinked")) {
89
+ const slugifiedLabel = slugify(value, {
90
+ locale: this.intl.primaryLocale,
91
+ });
92
+ const slug = slugifiedLabel
93
+ ? `${this.args.model.slug}-${slugifiedLabel}`
94
+ : "";
171
95
 
172
- @action
173
- update() {
174
- this._update();
96
+ changeset.set("slug", slug);
97
+ }
175
98
  }
176
99
 
177
100
  @action
@@ -180,12 +103,7 @@ export default class CfbFormEditorQuestionOptions extends Component {
180
103
  const options = [...sortable.$el.children].slice(0, -1);
181
104
 
182
105
  this.reorderOptions.perform(
183
- options.map((option) =>
184
- addQuestionPrefix(
185
- option.firstElementChild.firstElementChild.id,
186
- this.questionSlug
187
- )
188
- )
106
+ options.map((option) => option.firstElementChild.firstElementChild.id)
189
107
  );
190
108
  }
191
109
  }