@projectcaluma/ember-form-builder 11.0.0-beta.3 → 11.0.0-beta.30

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +138 -0
  2. package/addon/components/cfb-code-editor.hbs +25 -9
  3. package/addon/components/cfb-code-editor.js +59 -11
  4. package/addon/components/cfb-form-editor/general.hbs +1 -3
  5. package/addon/components/cfb-form-editor/general.js +6 -7
  6. package/addon/components/cfb-form-editor/question/default.hbs +11 -9
  7. package/addon/components/cfb-form-editor/question/options.hbs +3 -3
  8. package/addon/components/cfb-form-editor/question/validation.hbs +16 -14
  9. package/addon/components/cfb-form-editor/question/validation.js +17 -13
  10. package/addon/components/cfb-form-editor/question-list/item.hbs +44 -38
  11. package/addon/components/cfb-form-editor/question-list.hbs +2 -2
  12. package/addon/components/cfb-form-editor/question-list.js +9 -3
  13. package/addon/components/cfb-form-editor/question.hbs +55 -96
  14. package/addon/components/cfb-form-editor/question.js +56 -35
  15. package/addon/components/cfb-form-list.hbs +7 -7
  16. package/addon/components/cfb-form-list.js +44 -11
  17. package/addon/controllers/index.js +6 -0
  18. package/addon/engine.js +1 -1
  19. package/addon/gql/fragments/field.graphql +14 -2
  20. package/addon/gql/mutations/add-form-question.graphql +1 -1
  21. package/addon/gql/mutations/remove-form-question.graphql +1 -1
  22. package/addon/gql/mutations/reorder-form-questions.graphql +1 -1
  23. package/addon/gql/mutations/save-calculated-float-question.graphql +1 -0
  24. package/addon/gql/mutations/save-choice-question.graphql +1 -0
  25. package/addon/gql/mutations/save-date-question.graphql +3 -0
  26. package/addon/gql/mutations/save-dynamic-choice-question.graphql +1 -0
  27. package/addon/gql/mutations/save-dynamic-multiple-choice-question.graphql +1 -0
  28. package/addon/gql/mutations/save-files-question.graphql +14 -0
  29. package/addon/gql/mutations/save-float-question.graphql +1 -0
  30. package/addon/gql/mutations/save-integer-question.graphql +1 -0
  31. package/addon/gql/mutations/save-multiple-choice-question.graphql +1 -0
  32. package/addon/gql/mutations/save-table-question.graphql +1 -0
  33. package/addon/gql/mutations/save-text-question.graphql +1 -0
  34. package/addon/gql/mutations/save-textarea-question.graphql +1 -0
  35. package/addon/gql/queries/all-format-validators.graphql +10 -0
  36. package/addon/gql/queries/check-form-slug.graphql +1 -1
  37. package/addon/gql/queries/check-question-slug.graphql +1 -1
  38. package/addon/gql/queries/form-editor-general.graphql +1 -1
  39. package/addon/gql/queries/form-editor-question.graphql +29 -1
  40. package/addon/gql/queries/search-form-question.graphql +3 -3
  41. package/addon/instance-initializers/form-builder-widget-overrides.js +15 -0
  42. package/addon/modifiers/pikaday.js +2 -0
  43. package/addon/routes/edit/questions/edit.js +2 -1
  44. package/addon/routes/edit.js +1 -1
  45. package/addon/templates/index.hbs +8 -1
  46. package/addon/validations/question.js +6 -0
  47. package/addon/validators/gt-lt.js +17 -38
  48. package/app/instance-initializers/form-builder-widget-overrides.js +4 -0
  49. package/app/styles/@projectcaluma/ember-form-builder.scss +2 -2
  50. package/app/styles/_cfb-uikit-powerselect.scss +2 -0
  51. package/config/environment.js +0 -7
  52. package/index.js +4 -2
  53. package/package.json +53 -40
  54. package/translations/de.yaml +7 -6
  55. package/translations/en.yaml +4 -3
  56. package/translations/fr.yaml +154 -1
  57. package/addon/components/cfb-float-input.hbs +0 -14
  58. package/addon/components/cfb-label.hbs +0 -12
  59. package/addon/gql/mutations/save-file-question.graphql +0 -11
  60. package/app/components/cfb-float-input.js +0 -1
  61. package/app/components/cfb-label.js +0 -1
  62. package/app/styles/_cfb-powerselect.scss +0 -31
@@ -113,26 +113,11 @@
113
113
  {{/if}}
114
114
 
115
115
  {{#if (has-question-type f.model "static")}}
116
- <div class="uk-margin">
117
- <f.input
118
- @label={{t "caluma.form-builder.question.staticContent"}}
119
- @name="staticContent"
120
- @renderComponent={{component
121
- "cfb-code-editor"
122
- language="markdown"
123
- className="uk-margin-remove-bottom"
124
- }}
125
- class="uk-margin-remove-bottom"
126
- />
127
- <small class="uk-text-muted">
128
- {{t "caluma.form-builder.question.supportsMarkdownPrefix"}}
129
- <a
130
- target="_blank"
131
- rel="noopener noreferrer"
132
- href="https://www.markdownguide.org/basic-syntax"
133
- >{{t "caluma.form-builder.question.markdown"}}</a>
134
- </small>
135
- </div>
116
+ <f.input
117
+ @label={{t "caluma.form-builder.question.staticContent"}}
118
+ @name="staticContent"
119
+ @renderComponent={{component "cfb-code-editor" language="markdown"}}
120
+ />
136
121
  {{/if}}
137
122
 
138
123
  {{#if (has-question-type f.model "action-button")}}
@@ -140,27 +125,21 @@
140
125
  @label={{t "caluma.form-builder.question.confirmationText"}}
141
126
  @name="infoText"
142
127
  @type="textarea"
128
+ {{autoresize mode="height"}}
143
129
  />
144
130
  {{else}}
145
- <div class="uk-margin">
146
- <f.input
147
- @label={{t "caluma.form-builder.question.infoText"}}
148
- @name="infoText"
149
- @renderComponent={{component
150
- "cfb-code-editor"
151
- language="markdown"
152
- className="uk-margin-remove-bottom"
153
- }}
154
- />
155
- <small class="uk-text-muted">
156
- {{t "caluma.form-builder.question.supportsMarkdownPrefix"}}
157
- <a
158
- target="_blank"
159
- rel="noopener noreferrer"
160
- href="https://www.markdownguide.org/basic-syntax"
161
- >{{t "caluma.form-builder.question.markdown"}}</a>
162
- </small>
163
- </div>
131
+ <f.input
132
+ @label={{t "caluma.form-builder.question.infoText"}}
133
+ @name="infoText"
134
+ @renderComponent={{component "cfb-code-editor" language="markdown"}}
135
+ />
136
+ {{/if}}
137
+
138
+ {{#if (not (has-question-type f.model "action-button" "static" "form"))}}
139
+ <f.input
140
+ @name="hintText"
141
+ @label={{t "caluma.form-builder.question.hintText"}}
142
+ />
164
143
  {{/if}}
165
144
 
166
145
  {{#if (has-question-type f.model "text" "textarea" "integer" "float")}}
@@ -207,13 +186,13 @@
207
186
  />
208
187
 
209
188
  <f.input
210
- @name="meta.formatValidators"
189
+ @name="formatValidators"
211
190
  @label={{t "caluma.form-builder.question.formatValidators"}}
212
- @placeholder={{t "caluma.form-builder.question.choose"}}
191
+ @placeholder={{t "caluma.form-builder.question.no-selection"}}
213
192
  @required={{false}}
214
193
  @renderComponent={{component "cfb-form-editor/question/validation"}}
215
- @on-update={{changeset-set f.model "meta.formatValidators"}}
216
- @value={{changeset-get f.model "meta.formatValidators"}}
194
+ @on-update={{changeset-set f.model "formatValidators"}}
195
+ @value={{changeset-get f.model "formatValidators"}}
217
196
  />
218
197
  {{/if}}
219
198
 
@@ -242,17 +221,18 @@
242
221
  <div uk-grid class="uk-grid-small uk-child-width-1-2 uk-margin">
243
222
  <div>
244
223
  <f.input
224
+ @type="number"
245
225
  @name="floatMinValue"
246
226
  @label={{t "caluma.form-builder.question.min-value"}}
247
- @renderComponent={{component "cfb-float-input"}}
227
+ step="any"
248
228
  />
249
229
  </div>
250
-
251
230
  <div>
252
231
  <f.input
232
+ @type="number"
253
233
  @name="floatMaxValue"
254
234
  @label={{t "caluma.form-builder.question.max-value"}}
255
- @renderComponent={{component "cfb-float-input"}}
235
+ step="any"
256
236
  />
257
237
  </div>
258
238
  </div>
@@ -295,10 +275,10 @@
295
275
  @type="select"
296
276
  @required={{true}}
297
277
  @label={{t "caluma.form-builder.question.dataSource"}}
298
- @options={{or this.availableDataSources.lastSuccessful.value array}}
278
+ @options={{or this.availableDataSources.lastSuccessful.value (array)}}
299
279
  @optionTargetPath="name"
300
280
  @optionLabelPath="info"
301
- @includeBlank={{t "caluma.form-builder.question.choose"}}
281
+ @prompt={{t "caluma.form-builder.question.no-selection"}}
302
282
  />
303
283
  {{/if}}
304
284
 
@@ -328,9 +308,9 @@
328
308
  as |fi|
329
309
  >
330
310
  <PowerSelect
331
- @options={{or this.availableForms.lastSuccessful.value array}}
311
+ @options={{or this.availableForms.lastSuccessful.value (array)}}
332
312
  @selected={{fi.value}}
333
- @placeholder={{t "caluma.form-builder.question.choose"}}
313
+ @placeholder={{t "caluma.form-builder.question.no-selection"}}
334
314
  @onBlur={{fi.setDirty}}
335
315
  @onChange={{fi.update}}
336
316
  @searchField="slug"
@@ -359,33 +339,12 @@
359
339
  </div>
360
340
 
361
341
  {{#if @slug}}
362
- <div class="uk-margin">
363
- <f.input
364
- @name="meta.columnsToDisplay"
365
- @label={{t "caluma.form-builder.question.columnsToDisplay"}}
366
- >
367
- {{#each this.model.rowForm.questions.edges as |rowEdge|}}
368
- {{#let rowEdge.node as |row|}}
369
- <label class="cf-checkbox_label">
370
- <input
371
- type="checkbox"
372
- value={{row.slug}}
373
- checked={{includes
374
- row.slug
375
- this.model.meta.columnsToDisplay
376
- }}
377
- class="uk-checkbox uk-margin-small-right"
378
- {{on
379
- "change"
380
- (fn this.toggleColumnToDisplay row.slug f.model)
381
- }}
382
- />
383
- {{row.label}}
384
- </label>
385
- {{/let}}
386
- {{/each}}
387
- </f.input>
388
- </div>
342
+ <f.input
343
+ @type="checkbox-group"
344
+ @name="meta.columnsToDisplay"
345
+ @label={{t "caluma.form-builder.question.columnsToDisplay"}}
346
+ @options={{this.columnsToDisplayOptions}}
347
+ />
389
348
  {{/if}}
390
349
  {{/if}}
391
350
 
@@ -403,9 +362,9 @@
403
362
  as |fi|
404
363
  >
405
364
  <PowerSelect
406
- @options={{or this.availableForms.lastSuccessful.value array}}
365
+ @options={{or this.availableForms.lastSuccessful.value (array)}}
407
366
  @selected={{fi.value}}
408
- @placeholder={{t "caluma.form-builder.question.choose"}}
367
+ @placeholder={{t "caluma.form-builder.question.no-selection"}}
409
368
  @onBlur={{fi.setDirty}}
410
369
  @onChange={{fi.update}}
411
370
  @searchField="slug"
@@ -437,7 +396,7 @@
437
396
  @optionTargetPath="component"
438
397
  @optionLabelPath="label"
439
398
  @options={{this.availableOverrides}}
440
- class="uk-flex uk-flex-between uk-flex-column"
399
+ @prompt={{t "caluma.form-builder.question.no-selection"}}
441
400
  />
442
401
 
443
402
  <f.input
@@ -445,7 +404,6 @@
445
404
  @label={{t "caluma.form-builder.question.isArchived"}}
446
405
  @required={{true}}
447
406
  @renderComponent={{component "cfb-toggle-switch" size="small"}}
448
- class="uk-flex uk-flex-between uk-flex-column"
449
407
  />
450
408
 
451
409
  <UkButton
@@ -468,17 +426,14 @@
468
426
  @required={{true}}
469
427
  @label={{t "caluma.form-builder.question.validateOnEnter"}}
470
428
  @renderComponent={{component "cfb-toggle-switch" size="small"}}
471
- class="uk-flex uk-flex-between uk-flex-column"
472
429
  />
473
430
  {{/if}}
474
431
 
475
- <div class="uk-margin">
476
- <f.input
477
- @label={{t "caluma.form-builder.question.isHidden"}}
478
- @name="isHidden"
479
- @renderComponent={{component "cfb-code-editor" language="jexl"}}
480
- />
481
- </div>
432
+ <f.input
433
+ @label={{t "caluma.form-builder.question.isHidden"}}
434
+ @name="isHidden"
435
+ @renderComponent={{component "cfb-code-editor" language="jexl"}}
436
+ />
482
437
 
483
438
  {{#if
484
439
  (not
@@ -487,14 +442,18 @@
487
442
  )
488
443
  )
489
444
  }}
490
- <div class="uk-margin">
491
- <f.input
492
- @label={{t "caluma.form-builder.question.isRequired"}}
493
- @name="isRequired"
494
- @renderComponent={{component "cfb-code-editor" language="jexl"}}
495
- />
496
- </div>
445
+ <f.input
446
+ @label={{t "caluma.form-builder.question.isRequired"}}
447
+ @name="isRequired"
448
+ @renderComponent={{component "cfb-code-editor" language="jexl"}}
449
+ />
497
450
  {{/if}}
451
+
452
+ <f.input
453
+ @label={{t "caluma.form-builder.question.meta"}}
454
+ @name="meta"
455
+ @renderComponent={{component "cfb-code-editor" language="json"}}
456
+ />
498
457
  {{/if}}
499
458
 
500
459
  <div class="uk-text-right">
@@ -1,15 +1,14 @@
1
- import { getOwner } from "@ember/application";
2
1
  import { A } from "@ember/array";
3
2
  import { action } from "@ember/object";
4
3
  import { inject as service } from "@ember/service";
5
4
  import { camelize } from "@ember/string";
5
+ import { macroCondition, isTesting } from "@embroider/macros";
6
6
  import Component from "@glimmer/component";
7
7
  import { tracked } from "@glimmer/tracking";
8
8
  import { queryManager } from "ember-apollo-client";
9
9
  import Changeset from "ember-changeset";
10
10
  import lookupValidator from "ember-changeset-validations";
11
11
  import { dropTask, restartableTask, task, timeout } from "ember-concurrency";
12
- import { all } from "rsvp";
13
12
 
14
13
  import { hasQuestionType } from "@projectcaluma/ember-core/helpers/has-question-type";
15
14
  import slugify from "@projectcaluma/ember-core/utils/slugify";
@@ -27,7 +26,7 @@ import saveDefaultStringAnswerMutation from "@projectcaluma/ember-form-builder/g
27
26
  import saveDefaultTableAnswerMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-default-table-answer.graphql";
28
27
  import saveDynamicChoiceQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-dynamic-choice-question.graphql";
29
28
  import saveDynamicMultipleChoiceQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-dynamic-multiple-choice-question.graphql";
30
- import saveFileQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-file-question.graphql";
29
+ import saveFilesQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-files-question.graphql";
31
30
  import saveFloatQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-float-question.graphql";
32
31
  import saveFormQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-form-question.graphql";
33
32
  import saveIntegerQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-integer-question.graphql";
@@ -54,7 +53,7 @@ export const TYPES = {
54
53
  DynamicChoiceQuestion: saveDynamicChoiceQuestionMutation,
55
54
  TableQuestion: saveTableQuestionMutation,
56
55
  FormQuestion: saveFormQuestionMutation,
57
- FileQuestion: saveFileQuestionMutation,
56
+ FilesQuestion: saveFilesQuestionMutation,
58
57
  StaticQuestion: saveStaticQuestionMutation,
59
58
  DateQuestion: saveDateQuestionMutation,
60
59
  CalculatedFloatQuestion: saveCalculatedFloatQuestionMutation,
@@ -106,6 +105,7 @@ export default class CfbFormEditorQuestion extends Component {
106
105
  subForm: {},
107
106
  meta: {},
108
107
  dataSource: "",
108
+ formatValidators: null,
109
109
  // action button
110
110
  action: ACTIONS[0],
111
111
  color: COLORS[0],
@@ -142,7 +142,9 @@ export default class CfbFormEditorQuestion extends Component {
142
142
  if (!forms.map) {
143
143
  return [];
144
144
  }
145
- return forms.mapBy("node").filter((form) => form.slug !== this.args.form);
145
+ return forms
146
+ .filter((edge) => edge.node.slug !== this.args.form)
147
+ .map((edge) => edge.node);
146
148
  }
147
149
 
148
150
  @restartableTask
@@ -182,20 +184,14 @@ export default class CfbFormEditorQuestion extends Component {
182
184
 
183
185
  get availableOverrides() {
184
186
  const type = this.changeset.get("__typename");
185
- const overrides = this.calumaOptions
186
- .getComponentOverrides()
187
- .filter((override) => {
188
- return !override.types || override.types.includes(type);
189
- });
190
187
 
191
- return [
192
- { label: this.intl.t("caluma.form.power-select.null"), component: "" },
193
- ...overrides,
194
- ];
188
+ return this.calumaOptions.getComponentOverrides().filter((override) => {
189
+ return !override.types || override.types.includes(type);
190
+ });
195
191
  }
196
192
 
197
193
  get model() {
198
- return this.data.lastSuccessful?.value?.firstObject?.node;
194
+ return this.data.lastSuccessful?.value?.[0]?.node;
199
195
  }
200
196
 
201
197
  get changeset() {
@@ -208,20 +204,31 @@ export default class CfbFormEditorQuestion extends Component {
208
204
  : "";
209
205
  }
210
206
 
207
+ get columnsToDisplayOptions() {
208
+ return this.model.rowForm?.questions.edges.map((edge) => ({
209
+ key: edge.node.slug,
210
+ label: edge.node.label,
211
+ }));
212
+ }
213
+
211
214
  getInput(changeset) {
212
215
  const slug =
213
216
  ((!this.args.slug && this.prefix) || "") + changeset.get("slug");
214
217
 
218
+ const rawMeta = changeset.get("meta");
219
+
215
220
  const input = {
216
221
  slug,
217
222
  label: changeset.get("label"),
218
223
  isHidden: changeset.get("isHidden"),
219
224
  infoText: changeset.get("infoText"),
220
- meta: JSON.stringify(changeset.get("meta").unwrap()),
225
+ meta: JSON.stringify(rawMeta?.unwrap?.() ?? rawMeta),
221
226
  isArchived: changeset.get("isArchived"),
222
227
  };
223
228
 
224
- if (!hasQuestionType(changeset, "static", "calculated-float")) {
229
+ if (
230
+ !hasQuestionType(changeset, "static", "calculated-float", "action-button")
231
+ ) {
225
232
  Object.assign(input, {
226
233
  isRequired: changeset.get("isRequired"),
227
234
  });
@@ -240,6 +247,7 @@ export default class CfbFormEditorQuestion extends Component {
240
247
  minValue: parseInt(changeset.get("integerMinValue")),
241
248
  maxValue: parseInt(changeset.get("integerMaxValue")),
242
249
  placeholder: changeset.get("placeholder"),
250
+ hintText: changeset.get("hintText"),
243
251
  };
244
252
  }
245
253
 
@@ -248,6 +256,7 @@ export default class CfbFormEditorQuestion extends Component {
248
256
  minValue: parseFloat(changeset.get("floatMinValue")),
249
257
  maxValue: parseFloat(changeset.get("floatMaxValue")),
250
258
  placeholder: changeset.get("placeholder"),
259
+ hintText: changeset.get("hintText"),
251
260
  };
252
261
  }
253
262
 
@@ -256,6 +265,10 @@ export default class CfbFormEditorQuestion extends Component {
256
265
  minLength: parseInt(changeset.get("minLength")),
257
266
  maxLength: parseInt(changeset.get("maxLength")),
258
267
  placeholder: changeset.get("placeholder"),
268
+ formatValidators: changeset
269
+ .get("formatValidators")
270
+ ?.edges.map((edge) => edge.node.slug),
271
+ hintText: changeset.get("hintText"),
259
272
  };
260
273
  }
261
274
 
@@ -264,36 +277,51 @@ export default class CfbFormEditorQuestion extends Component {
264
277
  minLength: parseInt(changeset.get("minLength")),
265
278
  maxLength: parseInt(changeset.get("maxLength")),
266
279
  placeholder: changeset.get("placeholder"),
280
+ formatValidators: changeset
281
+ .get("formatValidators")
282
+ ?.edges.map((edge) => edge.node.slug),
283
+ hintText: changeset.get("hintText"),
284
+ };
285
+ }
286
+
287
+ _getDateQuestionInput(changeset) {
288
+ return {
289
+ hintText: changeset.get("hintText"),
267
290
  };
268
291
  }
269
292
 
270
293
  _getMultipleChoiceQuestionInput(changeset) {
271
294
  return {
272
295
  options: changeset.get("options.edges").map(({ node: { slug } }) => slug),
296
+ hintText: changeset.get("hintText"),
273
297
  };
274
298
  }
275
299
 
276
300
  _getChoiceQuestionInput(changeset) {
277
301
  return {
278
302
  options: changeset.get("options.edges").map(({ node: { slug } }) => slug),
303
+ hintText: changeset.get("hintText"),
279
304
  };
280
305
  }
281
306
 
282
307
  _getDynamicMultipleChoiceQuestionInput(changeset) {
283
308
  return {
284
309
  dataSource: changeset.get("dataSource"),
310
+ hintText: changeset.get("hintText"),
285
311
  };
286
312
  }
287
313
 
288
314
  _getDynamicChoiceQuestionInput(changeset) {
289
315
  return {
290
316
  dataSource: changeset.get("dataSource"),
317
+ hintText: changeset.get("hintText"),
291
318
  };
292
319
  }
293
320
 
294
321
  _getTableQuestionInput(changeset) {
295
322
  return {
296
323
  rowForm: changeset.get("rowForm.slug"),
324
+ hintText: changeset.get("hintText"),
297
325
  };
298
326
  }
299
327
 
@@ -312,6 +340,13 @@ export default class CfbFormEditorQuestion extends Component {
312
340
  _getCalculatedFloatQuestionInput(changeset) {
313
341
  return {
314
342
  calcExpression: changeset.get("calcExpression"),
343
+ hintText: changeset.get("hintText"),
344
+ };
345
+ }
346
+
347
+ _getFilesQuestionInput(changeset) {
348
+ return {
349
+ hintText: changeset.get("hintText"),
315
350
  };
316
351
  }
317
352
 
@@ -325,7 +360,7 @@ export default class CfbFormEditorQuestion extends Component {
325
360
 
326
361
  @task
327
362
  *saveOptions(changeset) {
328
- yield all(
363
+ yield Promise.all(
329
364
  (changeset.get("options.edges") || []).map(async ({ node: option }) => {
330
365
  const { label, slug, isArchived } = option;
331
366
 
@@ -418,10 +453,9 @@ export default class CfbFormEditorQuestion extends Component {
418
453
  @restartableTask
419
454
  *validateSlug(slug, changeset) {
420
455
  /* istanbul ignore next */
421
- if (
422
- getOwner(this).resolveRegistration("config:environment").environment !==
423
- "test"
424
- ) {
456
+ if (macroCondition(isTesting())) {
457
+ // no timeout
458
+ } else {
425
459
  yield timeout(500);
426
460
  }
427
461
 
@@ -469,19 +503,6 @@ export default class CfbFormEditorQuestion extends Component {
469
503
  this.validateSlug.perform(this.prefix + value, changeset);
470
504
  }
471
505
 
472
- /*
473
- * This function adds the selected slugs to the columns to display
474
- * list if it isnt present, otherwise it will remove the slug.
475
- */
476
- @action
477
- toggleColumnToDisplay(value, changeset) {
478
- const displayed = new Set(changeset.get("meta.columnsToDisplay"));
479
-
480
- displayed.delete(value) || displayed.add(value);
481
-
482
- changeset.set("meta.columnsToDisplay", [...displayed]);
483
- }
484
-
485
506
  @action
486
507
  updateSubForm(value, changeset) {
487
508
  changeset.set("subForm.slug", value.slug);
@@ -1,11 +1,11 @@
1
1
  <div class="uk-flex uk-flex-between">
2
2
  <div class="uk-button-group">
3
- {{#each (array "active" "archived" "all") as |category|}}
3
+ {{#each this.categories as |category|}}
4
4
  <UkButton
5
- data-test-filter={{category}}
6
- @onClick={{fn (perform this.setFilter) "category" category}}
7
- @label={{t (concat "caluma.form-builder.form." category)}}
8
- @class={{if (eq this.category category) "uk-button-primary" ""}}
5
+ data-test-filter={{category.value}}
6
+ @onClick={{fn @onUpdateCategory category.value}}
7
+ @label={{category.label}}
8
+ @color={{if (eq @category category.value) "primary"}}
9
9
  />
10
10
  {{/each}}
11
11
  </div>
@@ -26,8 +26,8 @@
26
26
  type="search"
27
27
  placeholder="{{t 'caluma.form-builder.global.search'}}..."
28
28
  aria-label="{{t 'caluma.form-builder.global.search'}}"
29
- value={{this.search}}
30
- {{on "input" (fn (perform this.setFilter) "search")}}
29
+ value={{@search}}
30
+ {{on "input" (perform this.search)}}
31
31
  />
32
32
  </div>
33
33
 
@@ -1,38 +1,71 @@
1
+ import { inject as service } from "@ember/service";
2
+ import { macroCondition, isTesting } from "@embroider/macros";
1
3
  import Component from "@glimmer/component";
2
- import { tracked } from "@glimmer/tracking";
3
4
  import { timeout, restartableTask } from "ember-concurrency";
4
5
 
5
6
  import { useCalumaQuery } from "@projectcaluma/ember-core/caluma-query";
6
7
  import { allForms } from "@projectcaluma/ember-core/caluma-query/queries";
7
8
 
8
9
  export default class ComponentsCfbFormListComponent extends Component {
10
+ @service intl;
11
+
9
12
  formsQuery = useCalumaQuery(this, allForms, () => ({
10
13
  options: { pageSize: 20 },
11
14
  filter: this.filter,
12
15
  order: [{ attribute: "NAME", direction: "ASC" }],
13
16
  }));
14
17
 
15
- @tracked category = "active";
16
- @tracked search = "";
18
+ get categories() {
19
+ return [
20
+ {
21
+ value: "active",
22
+ label: this.intl.t("caluma.form-builder.form.active"),
23
+ },
24
+ {
25
+ value: "archived",
26
+ label: this.intl.t("caluma.form-builder.form.isArchived"),
27
+ },
28
+ {
29
+ value: "published",
30
+ label: this.intl.t("caluma.form-builder.form.isPublished"),
31
+ },
32
+ {
33
+ value: "unpublished",
34
+ label: this.intl.t("caluma.form-builder.form.draft"),
35
+ },
36
+ { value: "all", label: this.intl.t("caluma.form-builder.form.all") },
37
+ ];
38
+ }
17
39
 
18
40
  get filter() {
19
41
  const isArchived =
20
- this.category === "active"
42
+ this.args.category === "active"
21
43
  ? { isArchived: false }
22
- : this.category === "archived"
44
+ : this.args.category === "archived"
23
45
  ? { isArchived: true }
24
46
  : null;
25
47
 
26
- const search = this.search ? { search: this.search } : null;
48
+ const search = this.args.search ? { search: this.args.search } : null;
49
+
50
+ const isPublished =
51
+ this.args.category === "unpublished"
52
+ ? { isPublished: false }
53
+ : this.args.category === "published"
54
+ ? { isPublished: true }
55
+ : null;
27
56
 
28
- return [isArchived, search].filter(Boolean) || null;
57
+ return [isArchived, isPublished, search].filter(Boolean) || null;
29
58
  }
30
59
 
31
60
  @restartableTask
32
- *setFilter(name, eventOrValue) {
33
- yield timeout(500);
61
+ *search(event) {
62
+ /* istanbul ignore next */
63
+ if (macroCondition(isTesting())) {
64
+ // no timeout
65
+ } else {
66
+ yield timeout(500);
67
+ }
34
68
 
35
- this[name] =
36
- eventOrValue instanceof Event ? eventOrValue.target.value : eventOrValue;
69
+ this.args.onUpdateSearch(event.target.value);
37
70
  }
38
71
  }
@@ -1,10 +1,16 @@
1
1
  import Controller from "@ember/controller";
2
2
  import { action } from "@ember/object";
3
3
  import { inject as service } from "@ember/service";
4
+ import { tracked } from "@glimmer/tracking";
4
5
 
5
6
  export default class IndexController extends Controller {
6
7
  @service router;
7
8
 
9
+ queryParams = ["search", "category"];
10
+
11
+ @tracked search = "";
12
+ @tracked category = "active";
13
+
8
14
  @action
9
15
  newForm() {
10
16
  this.router.transitionTo("new");
package/addon/engine.js CHANGED
@@ -11,7 +11,7 @@ export default class FormBuilderEngine extends Engine {
11
11
  Resolver = Resolver;
12
12
 
13
13
  dependencies = {
14
- services: ["apollo", "notification", "intl", "caluma-options", "validator"],
14
+ services: ["apollo", "notification", "intl", "caluma-options"],
15
15
  };
16
16
  }
17
17