@glowgreen/gg-questionnaire-v2 0.0.42 → 0.0.44

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.
@@ -264,7 +264,7 @@
264
264
  * @return {?} An array of filtered sections with their filtered questions.
265
265
  */
266
266
  function (sections, currentQuestionnaireForm, additionalData) {
267
- var e_1, _a, e_2, _b, e_3, _c;
267
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
268
268
  /** @type {?} */
269
269
  var filteredSections = [];
270
270
  try {
@@ -276,51 +276,78 @@
276
276
  /** @type {?} */
277
277
  var filteredQuestions = [];
278
278
  try {
279
- for (var _d = (e_2 = void 0, __values(section.questions)), _e = _d.next(); !_e.done; _e = _d.next()) {
280
- var question = _e.value;
279
+ for (var _f = (e_2 = void 0, __values(section.questions)), _g = _f.next(); !_g.done; _g = _f.next()) {
280
+ var question = _g.value;
281
281
  if (!this.meetsConditionGroups(question.conditionGroups, currentQuestionnaireForm, additionalData)) {
282
282
  continue;
283
283
  }
284
- if (question.repeaterQuestions) {
284
+ // If it's a repeater we need to do a lot of extra filtering due to per item conditions.
285
+ if (question.type === 'repeater') {
285
286
  /** @type {?} */
286
- var filteredRepeaterQuestions = [];
287
+ var items = (/** @type {?} */ (currentQuestionnaireForm.get([section.name, question.name])));
287
288
  try {
288
- for (var _f = (e_3 = void 0, __values(question.repeaterQuestions)), _g = _f.next(); !_g.done; _g = _f.next()) {
289
- var repeaterQuestion = _g.value;
290
- if (this.meetsConditionGroups(repeaterQuestion.conditionGroups, currentQuestionnaireForm, additionalData)) {
291
- filteredRepeaterQuestions.push(repeaterQuestion);
289
+ for (var _h = (e_3 = void 0, __values(items.controls)), _j = _h.next(); !_j.done; _j = _h.next()) {
290
+ var repeaterItem = _j.value;
291
+ /** @type {?} */
292
+ var filteredRepeaterItemQuestions = [];
293
+ try {
294
+ for (var _k = (e_4 = void 0, __values(question.repeaterQuestions)), _l = _k.next(); !_l.done; _l = _k.next()) {
295
+ var repeaterQuestion = _l.value;
296
+ /** @type {?} */
297
+ var meetsConditions = this.meetsConditionGroups(repeaterQuestion.conditionGroups, currentQuestionnaireForm, additionalData, (/** @type {?} */ (repeaterItem)));
298
+ if (meetsConditions) {
299
+ this.setFetchForQuestion(repeaterQuestion, additionalData, currentQuestionnaireForm, (/** @type {?} */ (repeaterItem)));
300
+ filteredRepeaterItemQuestions.push(repeaterQuestion);
301
+ }
302
+ }
303
+ }
304
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
305
+ finally {
306
+ try {
307
+ if (_l && !_l.done && (_d = _k.return)) _d.call(_k);
308
+ }
309
+ finally { if (e_4) throw e_4.error; }
310
+ }
311
+ try {
312
+ for (var filteredRepeaterItemQuestions_1 = (e_5 = void 0, __values(filteredRepeaterItemQuestions)), filteredRepeaterItemQuestions_1_1 = filteredRepeaterItemQuestions_1.next(); !filteredRepeaterItemQuestions_1_1.done; filteredRepeaterItemQuestions_1_1 = filteredRepeaterItemQuestions_1.next()) {
313
+ var filteredRepeaterItemQuestion = filteredRepeaterItemQuestions_1_1.value;
314
+ if (filteredRepeaterItemQuestion.type !== 'select') {
315
+ continue;
316
+ }
317
+ this.setFetchForQuestion(filteredRepeaterItemQuestion, additionalData, currentQuestionnaireForm);
318
+ }
292
319
  }
320
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
321
+ finally {
322
+ try {
323
+ if (filteredRepeaterItemQuestions_1_1 && !filteredRepeaterItemQuestions_1_1.done && (_e = filteredRepeaterItemQuestions_1.return)) _e.call(filteredRepeaterItemQuestions_1);
324
+ }
325
+ finally { if (e_5) throw e_5.error; }
326
+ }
327
+ /** @type {?} */
328
+ var index = items.controls.indexOf(repeaterItem);
329
+ if (!question.filteredRepeaterQuestions) {
330
+ question.filteredRepeaterQuestions = [];
331
+ }
332
+ question.filteredRepeaterQuestions[index] = filteredRepeaterItemQuestions;
293
333
  }
294
334
  }
295
335
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
296
336
  finally {
297
337
  try {
298
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
338
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
299
339
  }
300
340
  finally { if (e_3) throw e_3.error; }
301
341
  }
302
342
  }
303
- if (question.fetchPath) {
304
- /** @type {?} */
305
- var options = additionalData[question.fetchPath];
306
- if (question.fetchSelectors && question.fetchSelectors.length > 0) {
307
- /** @type {?} */
308
- var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData);
309
- options = lodash.get(additionalData[question.fetchPath], values);
310
- }
311
- options = this.getFinalFetchArray(options);
312
- if (!question.selectOptions) {
313
- question.selectOptions = [];
314
- }
315
- question.selectOptions = question.selectOptions.concat(options);
316
- }
343
+ this.setFetchForQuestion(question, additionalData, currentQuestionnaireForm);
317
344
  filteredQuestions.push(question);
318
345
  }
319
346
  }
320
347
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
321
348
  finally {
322
349
  try {
323
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
350
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
324
351
  }
325
352
  finally { if (e_2) throw e_2.error; }
326
353
  }
@@ -340,6 +367,39 @@
340
367
  }
341
368
  return filteredSections;
342
369
  };
370
+ /**
371
+ * @private
372
+ * @param {?} question
373
+ * @param {?} additionalData
374
+ * @param {?} currentQuestionnaireForm
375
+ * @param {?=} repeaterItem
376
+ * @return {?}
377
+ */
378
+ FilterService.prototype.setFetchForQuestion = /**
379
+ * @private
380
+ * @param {?} question
381
+ * @param {?} additionalData
382
+ * @param {?} currentQuestionnaireForm
383
+ * @param {?=} repeaterItem
384
+ * @return {?}
385
+ */
386
+ function (question, additionalData, currentQuestionnaireForm, repeaterItem) {
387
+ if (question.fetchPath) {
388
+ return;
389
+ }
390
+ /** @type {?} */
391
+ var options = additionalData[question.fetchPath];
392
+ if (question.fetchSelectors && question.fetchSelectors.length > 0) {
393
+ /** @type {?} */
394
+ var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData, repeaterItem);
395
+ options = lodash.get(additionalData[question.fetchPath], values);
396
+ }
397
+ options = this.getFinalFetchArray(options);
398
+ if (!question.selectOptions) {
399
+ question.selectOptions = [];
400
+ }
401
+ question.selectOptions = question.selectOptions.concat(options);
402
+ };
343
403
  /**
344
404
  * @private
345
405
  * @param {?} items
@@ -351,7 +411,7 @@
351
411
  * @return {?}
352
412
  */
353
413
  function (items) {
354
- var e_4, _a;
414
+ var e_6, _a;
355
415
  if (!items) {
356
416
  return null;
357
417
  }
@@ -376,12 +436,12 @@
376
436
  }
377
437
  }
378
438
  }
379
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
439
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
380
440
  finally {
381
441
  try {
382
442
  if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
383
443
  }
384
- finally { if (e_4) throw e_4.error; }
444
+ finally { if (e_6) throw e_6.error; }
385
445
  }
386
446
  return convertedArray;
387
447
  };
@@ -412,6 +472,7 @@
412
472
  * @param {?} conditionGroups The array of condition groups.
413
473
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
414
474
  * @param {?=} additionalData
475
+ * @param {?=} repeaterItem
415
476
  * @return {?} A boolean stating if the condition groups conditions has been met.
416
477
  */
417
478
  FilterService.prototype.meetsConditionGroups = /**
@@ -421,9 +482,10 @@
421
482
  * @param {?} conditionGroups The array of condition groups.
422
483
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
423
484
  * @param {?=} additionalData
485
+ * @param {?=} repeaterItem
424
486
  * @return {?} A boolean stating if the condition groups conditions has been met.
425
487
  */
426
- function (conditionGroups, currentQuestionnaireForm, additionalData) {
488
+ function (conditionGroups, currentQuestionnaireForm, additionalData, repeaterItem) {
427
489
  var _this = this;
428
490
  if (!conditionGroups || conditionGroups.length === 0) {
429
491
  return true;
@@ -433,7 +495,7 @@
433
495
  * @return {?}
434
496
  */
435
497
  function (x) {
436
- return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData) === true;
498
+ return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData, repeaterItem) === true;
437
499
  }));
438
500
  };
439
501
  /**
@@ -450,6 +512,7 @@
450
512
  * @param {?} conditionGroup The condition group to check.
451
513
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
452
514
  * @param {?=} additionalData
515
+ * @param {?=} repeaterItem
453
516
  * @return {?} A boolean stating if the condition group conditions has been met.
454
517
  */
455
518
  FilterService.prototype.meetsConditionGroup = /**
@@ -459,10 +522,11 @@
459
522
  * @param {?} conditionGroup The condition group to check.
460
523
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
461
524
  * @param {?=} additionalData
525
+ * @param {?=} repeaterItem
462
526
  * @return {?} A boolean stating if the condition group conditions has been met.
463
527
  */
464
- function (conditionGroup, currentQuestionnaireForm, additionalData) {
465
- var e_5, _a;
528
+ function (conditionGroup, currentQuestionnaireForm, additionalData, repeaterItem) {
529
+ var e_7, _a;
466
530
  if (!conditionGroup.conditions || conditionGroup.conditions.length === 0) {
467
531
  return true;
468
532
  }
@@ -471,15 +535,15 @@
471
535
  try {
472
536
  for (var _b = __values(conditionGroup.conditions), _c = _b.next(); !_c.done; _c = _b.next()) {
473
537
  var condition = _c.value;
474
- results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData));
538
+ results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData, repeaterItem));
475
539
  }
476
540
  }
477
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
541
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
478
542
  finally {
479
543
  try {
480
544
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
481
545
  }
482
- finally { if (e_5) throw e_5.error; }
546
+ finally { if (e_7) throw e_7.error; }
483
547
  }
484
548
  switch (conditionGroup.relationship) {
485
549
  case ConditionRelationship.Every:
@@ -516,6 +580,7 @@
516
580
  * @param {?} condition The condition to check.
517
581
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
518
582
  * @param {?=} additionalData
583
+ * @param {?=} repeaterItem
519
584
  * @return {?} A boolean stating if the condition group conditions has been met.
520
585
  */
521
586
  FilterService.prototype.meetsCondition = /**
@@ -525,14 +590,15 @@
525
590
  * @param {?} condition The condition to check.
526
591
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
527
592
  * @param {?=} additionalData
593
+ * @param {?=} repeaterItem
528
594
  * @return {?} A boolean stating if the condition group conditions has been met.
529
595
  */
530
- function (condition, currentQuestionnaireForm, additionalData) {
531
- var e_6, _a, e_7, _b;
596
+ function (condition, currentQuestionnaireForm, additionalData, repeaterItem) {
597
+ var e_8, _a, e_9, _b;
532
598
  /** @type {?} */
533
- var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData);
599
+ var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData, repeaterItem);
534
600
  /** @type {?} */
535
- var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData);
601
+ var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData, repeaterItem);
536
602
  /** @type {?} */
537
603
  var result = false;
538
604
  switch (condition.type) {
@@ -558,7 +624,7 @@
558
624
  for (var v2s_1 = __values(v2s), v2s_1_1 = v2s_1.next(); !v2s_1_1.done; v2s_1_1 = v2s_1.next()) {
559
625
  var v2 = v2s_1_1.value;
560
626
  try {
561
- for (var v1s_1 = (e_7 = void 0, __values(v1s)), v1s_1_1 = v1s_1.next(); !v1s_1_1.done; v1s_1_1 = v1s_1.next()) {
627
+ for (var v1s_1 = (e_9 = void 0, __values(v1s)), v1s_1_1 = v1s_1.next(); !v1s_1_1.done; v1s_1_1 = v1s_1.next()) {
562
628
  var v1 = v1s_1_1.value;
563
629
  switch (condition.type) {
564
630
  case ConditionType.EqualTo:
@@ -592,21 +658,21 @@
592
658
  }
593
659
  }
594
660
  }
595
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
661
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
596
662
  finally {
597
663
  try {
598
664
  if (v1s_1_1 && !v1s_1_1.done && (_b = v1s_1.return)) _b.call(v1s_1);
599
665
  }
600
- finally { if (e_7) throw e_7.error; }
666
+ finally { if (e_9) throw e_9.error; }
601
667
  }
602
668
  }
603
669
  }
604
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
670
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
605
671
  finally {
606
672
  try {
607
673
  if (v2s_1_1 && !v2s_1_1.done && (_a = v2s_1.return)) _a.call(v2s_1);
608
674
  }
609
- finally { if (e_6) throw e_6.error; }
675
+ finally { if (e_8) throw e_8.error; }
610
676
  }
611
677
  }
612
678
  return result;
@@ -643,6 +709,7 @@
643
709
  * @param {?} paths The array of strings to check.
644
710
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
645
711
  * @param {?=} additionalData
712
+ * @param {?=} repeaterItem
646
713
  * @return {?} An array of strings/values
647
714
  */
648
715
  FilterService.prototype.getValuesForArray = /**
@@ -652,10 +719,11 @@
652
719
  * @param {?} paths The array of strings to check.
653
720
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
654
721
  * @param {?=} additionalData
722
+ * @param {?=} repeaterItem
655
723
  * @return {?} An array of strings/values
656
724
  */
657
- function (paths, currentQuestionnaireForm, additionalData) {
658
- var e_8, _a;
725
+ function (paths, currentQuestionnaireForm, additionalData, repeaterItem) {
726
+ var e_10, _a;
659
727
  if (currentQuestionnaireForm) {
660
728
  /** @type {?} */
661
729
  var values = [];
@@ -663,16 +731,16 @@
663
731
  for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
664
732
  var path = paths_1_1.value;
665
733
  /** @type {?} */
666
- var value = this.getValueForString(path, currentQuestionnaireForm, additionalData);
734
+ var value = this.getValueForString(path, currentQuestionnaireForm, additionalData, repeaterItem);
667
735
  values.push(value);
668
736
  }
669
737
  }
670
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
738
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
671
739
  finally {
672
740
  try {
673
741
  if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
674
742
  }
675
- finally { if (e_8) throw e_8.error; }
743
+ finally { if (e_10) throw e_10.error; }
676
744
  }
677
745
  return values;
678
746
  }
@@ -694,6 +762,7 @@
694
762
  * @param {?} path The string value to check.
695
763
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
696
764
  * @param {?=} additionalData
765
+ * @param {?=} repeaterItem
697
766
  * @return {?} A string/value.
698
767
  */
699
768
  FilterService.prototype.getValueForString = /**
@@ -703,15 +772,19 @@
703
772
  * @param {?} path The string value to check.
704
773
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
705
774
  * @param {?=} additionalData
775
+ * @param {?=} repeaterItem
706
776
  * @return {?} A string/value.
707
777
  */
708
- function (path, currentQuestionnaireForm, additionalData) {
778
+ function (path, currentQuestionnaireForm, additionalData, repeaterItem) {
709
779
  if (currentQuestionnaireForm) {
710
780
  if (!additionalData) {
711
781
  additionalData = {};
712
782
  }
713
783
  /** @type {?} */
714
784
  var control = currentQuestionnaireForm.get(path.toString());
785
+ if ((!control || !control.value) && repeaterItem) {
786
+ control = repeaterItem.get(path.toString());
787
+ }
715
788
  /** @type {?} */
716
789
  var value = control ? control.value : this.convertStringToValue(path);
717
790
  return lodash.get(additionalData, path, value);
@@ -1012,25 +1085,29 @@
1012
1085
  * Generates the form template for a repeater question.
1013
1086
  * @author Will Poulson
1014
1087
  * @param {?} question The question. Must be of type repeater or else null is returned.
1088
+ * @param {?=} index
1015
1089
  * @return {?} A form group.
1016
1090
  */
1017
1091
  FormConstructorService.prototype.generateFormsForRepeater = /**
1018
1092
  * Generates the form template for a repeater question.
1019
1093
  * @author Will Poulson
1020
1094
  * @param {?} question The question. Must be of type repeater or else null is returned.
1095
+ * @param {?=} index
1021
1096
  * @return {?} A form group.
1022
1097
  */
1023
- function (question) {
1098
+ function (question, index) {
1024
1099
  var e_4, _a;
1025
1100
  if (question.type !== QuestionType.Repeater || question.repeaterQuestions.length === 0) {
1026
1101
  console.log('Question isnt a repeater or has no questions, returning null');
1027
1102
  return null;
1028
1103
  }
1029
1104
  /** @type {?} */
1105
+ var repeaterQuestions = index ? question.filteredRepeaterQuestions[index] : question.repeaterQuestions;
1106
+ /** @type {?} */
1030
1107
  var repeaterForms = this.fb.group({});
1031
1108
  try {
1032
- for (var _b = __values(question.repeaterQuestions), _c = _b.next(); !_c.done; _c = _b.next()) {
1033
- var repeaterQuestion = _c.value;
1109
+ for (var repeaterQuestions_1 = __values(repeaterQuestions), repeaterQuestions_1_1 = repeaterQuestions_1.next(); !repeaterQuestions_1_1.done; repeaterQuestions_1_1 = repeaterQuestions_1.next()) {
1110
+ var repeaterQuestion = repeaterQuestions_1_1.value;
1034
1111
  /** @type {?} */
1035
1112
  var repeaterQuestionControl = this.generateControlForRepeaterQuestion(repeaterQuestion);
1036
1113
  repeaterForms.addControl(repeaterQuestion.name, repeaterQuestionControl);
@@ -1039,7 +1116,7 @@
1039
1116
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
1040
1117
  finally {
1041
1118
  try {
1042
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1119
+ if (repeaterQuestions_1_1 && !repeaterQuestions_1_1.done && (_a = repeaterQuestions_1.return)) _a.call(repeaterQuestions_1);
1043
1120
  }
1044
1121
  finally { if (e_4) throw e_4.error; }
1045
1122
  }
@@ -1189,7 +1266,9 @@
1189
1266
  for (var repeaterArray_1 = (e_8 = void 0, __values(repeaterArray)), repeaterArray_1_1 = repeaterArray_1.next(); !repeaterArray_1_1.done; repeaterArray_1_1 = repeaterArray_1.next()) {
1190
1267
  var repeaterItem = repeaterArray_1_1.value;
1191
1268
  /** @type {?} */
1192
- var repeaterItemTemplate = this.generateFormsForRepeater(question);
1269
+ var index = repeaterArray.indexOf(repeaterItem);
1270
+ /** @type {?} */
1271
+ var repeaterItemTemplate = this.generateFormsForRepeater(question, index);
1193
1272
  repeaterFormArray.push(repeaterItemTemplate);
1194
1273
  }
1195
1274
  }