@glowgreen/gg-questionnaire-v2 0.0.43 → 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,27 +276,66 @@
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
- this.setFetchForQuestion(question, additionalData, currentQuestionnaireForm);
292
- 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
+ }
293
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;
294
333
  }
295
334
  }
296
335
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
297
336
  finally {
298
337
  try {
299
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
338
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
300
339
  }
301
340
  finally { if (e_3) throw e_3.error; }
302
341
  }
@@ -308,7 +347,7 @@
308
347
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
309
348
  finally {
310
349
  try {
311
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
350
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
312
351
  }
313
352
  finally { if (e_2) throw e_2.error; }
314
353
  }
@@ -333,6 +372,7 @@
333
372
  * @param {?} question
334
373
  * @param {?} additionalData
335
374
  * @param {?} currentQuestionnaireForm
375
+ * @param {?=} repeaterItem
336
376
  * @return {?}
337
377
  */
338
378
  FilterService.prototype.setFetchForQuestion = /**
@@ -340,9 +380,10 @@
340
380
  * @param {?} question
341
381
  * @param {?} additionalData
342
382
  * @param {?} currentQuestionnaireForm
383
+ * @param {?=} repeaterItem
343
384
  * @return {?}
344
385
  */
345
- function (question, additionalData, currentQuestionnaireForm) {
386
+ function (question, additionalData, currentQuestionnaireForm, repeaterItem) {
346
387
  if (question.fetchPath) {
347
388
  return;
348
389
  }
@@ -350,7 +391,7 @@
350
391
  var options = additionalData[question.fetchPath];
351
392
  if (question.fetchSelectors && question.fetchSelectors.length > 0) {
352
393
  /** @type {?} */
353
- var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData);
394
+ var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData, repeaterItem);
354
395
  options = lodash.get(additionalData[question.fetchPath], values);
355
396
  }
356
397
  options = this.getFinalFetchArray(options);
@@ -370,7 +411,7 @@
370
411
  * @return {?}
371
412
  */
372
413
  function (items) {
373
- var e_4, _a;
414
+ var e_6, _a;
374
415
  if (!items) {
375
416
  return null;
376
417
  }
@@ -395,12 +436,12 @@
395
436
  }
396
437
  }
397
438
  }
398
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
439
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
399
440
  finally {
400
441
  try {
401
442
  if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
402
443
  }
403
- finally { if (e_4) throw e_4.error; }
444
+ finally { if (e_6) throw e_6.error; }
404
445
  }
405
446
  return convertedArray;
406
447
  };
@@ -431,6 +472,7 @@
431
472
  * @param {?} conditionGroups The array of condition groups.
432
473
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
433
474
  * @param {?=} additionalData
475
+ * @param {?=} repeaterItem
434
476
  * @return {?} A boolean stating if the condition groups conditions has been met.
435
477
  */
436
478
  FilterService.prototype.meetsConditionGroups = /**
@@ -440,9 +482,10 @@
440
482
  * @param {?} conditionGroups The array of condition groups.
441
483
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
442
484
  * @param {?=} additionalData
485
+ * @param {?=} repeaterItem
443
486
  * @return {?} A boolean stating if the condition groups conditions has been met.
444
487
  */
445
- function (conditionGroups, currentQuestionnaireForm, additionalData) {
488
+ function (conditionGroups, currentQuestionnaireForm, additionalData, repeaterItem) {
446
489
  var _this = this;
447
490
  if (!conditionGroups || conditionGroups.length === 0) {
448
491
  return true;
@@ -452,7 +495,7 @@
452
495
  * @return {?}
453
496
  */
454
497
  function (x) {
455
- return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData) === true;
498
+ return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData, repeaterItem) === true;
456
499
  }));
457
500
  };
458
501
  /**
@@ -469,6 +512,7 @@
469
512
  * @param {?} conditionGroup The condition group to check.
470
513
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
471
514
  * @param {?=} additionalData
515
+ * @param {?=} repeaterItem
472
516
  * @return {?} A boolean stating if the condition group conditions has been met.
473
517
  */
474
518
  FilterService.prototype.meetsConditionGroup = /**
@@ -478,10 +522,11 @@
478
522
  * @param {?} conditionGroup The condition group to check.
479
523
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
480
524
  * @param {?=} additionalData
525
+ * @param {?=} repeaterItem
481
526
  * @return {?} A boolean stating if the condition group conditions has been met.
482
527
  */
483
- function (conditionGroup, currentQuestionnaireForm, additionalData) {
484
- var e_5, _a;
528
+ function (conditionGroup, currentQuestionnaireForm, additionalData, repeaterItem) {
529
+ var e_7, _a;
485
530
  if (!conditionGroup.conditions || conditionGroup.conditions.length === 0) {
486
531
  return true;
487
532
  }
@@ -490,15 +535,15 @@
490
535
  try {
491
536
  for (var _b = __values(conditionGroup.conditions), _c = _b.next(); !_c.done; _c = _b.next()) {
492
537
  var condition = _c.value;
493
- results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData));
538
+ results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData, repeaterItem));
494
539
  }
495
540
  }
496
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
541
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
497
542
  finally {
498
543
  try {
499
544
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
500
545
  }
501
- finally { if (e_5) throw e_5.error; }
546
+ finally { if (e_7) throw e_7.error; }
502
547
  }
503
548
  switch (conditionGroup.relationship) {
504
549
  case ConditionRelationship.Every:
@@ -535,6 +580,7 @@
535
580
  * @param {?} condition The condition to check.
536
581
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
537
582
  * @param {?=} additionalData
583
+ * @param {?=} repeaterItem
538
584
  * @return {?} A boolean stating if the condition group conditions has been met.
539
585
  */
540
586
  FilterService.prototype.meetsCondition = /**
@@ -544,14 +590,15 @@
544
590
  * @param {?} condition The condition to check.
545
591
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
546
592
  * @param {?=} additionalData
593
+ * @param {?=} repeaterItem
547
594
  * @return {?} A boolean stating if the condition group conditions has been met.
548
595
  */
549
- function (condition, currentQuestionnaireForm, additionalData) {
550
- var e_6, _a, e_7, _b;
596
+ function (condition, currentQuestionnaireForm, additionalData, repeaterItem) {
597
+ var e_8, _a, e_9, _b;
551
598
  /** @type {?} */
552
- var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData);
599
+ var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData, repeaterItem);
553
600
  /** @type {?} */
554
- var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData);
601
+ var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData, repeaterItem);
555
602
  /** @type {?} */
556
603
  var result = false;
557
604
  switch (condition.type) {
@@ -577,7 +624,7 @@
577
624
  for (var v2s_1 = __values(v2s), v2s_1_1 = v2s_1.next(); !v2s_1_1.done; v2s_1_1 = v2s_1.next()) {
578
625
  var v2 = v2s_1_1.value;
579
626
  try {
580
- 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()) {
581
628
  var v1 = v1s_1_1.value;
582
629
  switch (condition.type) {
583
630
  case ConditionType.EqualTo:
@@ -611,21 +658,21 @@
611
658
  }
612
659
  }
613
660
  }
614
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
661
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
615
662
  finally {
616
663
  try {
617
664
  if (v1s_1_1 && !v1s_1_1.done && (_b = v1s_1.return)) _b.call(v1s_1);
618
665
  }
619
- finally { if (e_7) throw e_7.error; }
666
+ finally { if (e_9) throw e_9.error; }
620
667
  }
621
668
  }
622
669
  }
623
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
670
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
624
671
  finally {
625
672
  try {
626
673
  if (v2s_1_1 && !v2s_1_1.done && (_a = v2s_1.return)) _a.call(v2s_1);
627
674
  }
628
- finally { if (e_6) throw e_6.error; }
675
+ finally { if (e_8) throw e_8.error; }
629
676
  }
630
677
  }
631
678
  return result;
@@ -662,6 +709,7 @@
662
709
  * @param {?} paths The array of strings to check.
663
710
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
664
711
  * @param {?=} additionalData
712
+ * @param {?=} repeaterItem
665
713
  * @return {?} An array of strings/values
666
714
  */
667
715
  FilterService.prototype.getValuesForArray = /**
@@ -671,10 +719,11 @@
671
719
  * @param {?} paths The array of strings to check.
672
720
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
673
721
  * @param {?=} additionalData
722
+ * @param {?=} repeaterItem
674
723
  * @return {?} An array of strings/values
675
724
  */
676
- function (paths, currentQuestionnaireForm, additionalData) {
677
- var e_8, _a;
725
+ function (paths, currentQuestionnaireForm, additionalData, repeaterItem) {
726
+ var e_10, _a;
678
727
  if (currentQuestionnaireForm) {
679
728
  /** @type {?} */
680
729
  var values = [];
@@ -682,16 +731,16 @@
682
731
  for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
683
732
  var path = paths_1_1.value;
684
733
  /** @type {?} */
685
- var value = this.getValueForString(path, currentQuestionnaireForm, additionalData);
734
+ var value = this.getValueForString(path, currentQuestionnaireForm, additionalData, repeaterItem);
686
735
  values.push(value);
687
736
  }
688
737
  }
689
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
738
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
690
739
  finally {
691
740
  try {
692
741
  if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
693
742
  }
694
- finally { if (e_8) throw e_8.error; }
743
+ finally { if (e_10) throw e_10.error; }
695
744
  }
696
745
  return values;
697
746
  }
@@ -713,6 +762,7 @@
713
762
  * @param {?} path The string value to check.
714
763
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
715
764
  * @param {?=} additionalData
765
+ * @param {?=} repeaterItem
716
766
  * @return {?} A string/value.
717
767
  */
718
768
  FilterService.prototype.getValueForString = /**
@@ -722,15 +772,19 @@
722
772
  * @param {?} path The string value to check.
723
773
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
724
774
  * @param {?=} additionalData
775
+ * @param {?=} repeaterItem
725
776
  * @return {?} A string/value.
726
777
  */
727
- function (path, currentQuestionnaireForm, additionalData) {
778
+ function (path, currentQuestionnaireForm, additionalData, repeaterItem) {
728
779
  if (currentQuestionnaireForm) {
729
780
  if (!additionalData) {
730
781
  additionalData = {};
731
782
  }
732
783
  /** @type {?} */
733
784
  var control = currentQuestionnaireForm.get(path.toString());
785
+ if ((!control || !control.value) && repeaterItem) {
786
+ control = repeaterItem.get(path.toString());
787
+ }
734
788
  /** @type {?} */
735
789
  var value = control ? control.value : this.convertStringToValue(path);
736
790
  return lodash.get(additionalData, path, value);
@@ -1031,25 +1085,29 @@
1031
1085
  * Generates the form template for a repeater question.
1032
1086
  * @author Will Poulson
1033
1087
  * @param {?} question The question. Must be of type repeater or else null is returned.
1088
+ * @param {?=} index
1034
1089
  * @return {?} A form group.
1035
1090
  */
1036
1091
  FormConstructorService.prototype.generateFormsForRepeater = /**
1037
1092
  * Generates the form template for a repeater question.
1038
1093
  * @author Will Poulson
1039
1094
  * @param {?} question The question. Must be of type repeater or else null is returned.
1095
+ * @param {?=} index
1040
1096
  * @return {?} A form group.
1041
1097
  */
1042
- function (question) {
1098
+ function (question, index) {
1043
1099
  var e_4, _a;
1044
1100
  if (question.type !== QuestionType.Repeater || question.repeaterQuestions.length === 0) {
1045
1101
  console.log('Question isnt a repeater or has no questions, returning null');
1046
1102
  return null;
1047
1103
  }
1048
1104
  /** @type {?} */
1105
+ var repeaterQuestions = index ? question.filteredRepeaterQuestions[index] : question.repeaterQuestions;
1106
+ /** @type {?} */
1049
1107
  var repeaterForms = this.fb.group({});
1050
1108
  try {
1051
- for (var _b = __values(question.repeaterQuestions), _c = _b.next(); !_c.done; _c = _b.next()) {
1052
- 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;
1053
1111
  /** @type {?} */
1054
1112
  var repeaterQuestionControl = this.generateControlForRepeaterQuestion(repeaterQuestion);
1055
1113
  repeaterForms.addControl(repeaterQuestion.name, repeaterQuestionControl);
@@ -1058,7 +1116,7 @@
1058
1116
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
1059
1117
  finally {
1060
1118
  try {
1061
- 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);
1062
1120
  }
1063
1121
  finally { if (e_4) throw e_4.error; }
1064
1122
  }
@@ -1208,7 +1266,9 @@
1208
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()) {
1209
1267
  var repeaterItem = repeaterArray_1_1.value;
1210
1268
  /** @type {?} */
1211
- var repeaterItemTemplate = this.generateFormsForRepeater(question);
1269
+ var index = repeaterArray.indexOf(repeaterItem);
1270
+ /** @type {?} */
1271
+ var repeaterItemTemplate = this.generateFormsForRepeater(question, index);
1212
1272
  repeaterFormArray.push(repeaterItemTemplate);
1213
1273
  }
1214
1274
  }