@glowgreen/gg-questionnaire-v2 0.0.43 → 0.0.45

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;
268
268
  /** @type {?} */
269
269
  var filteredSections = [];
270
270
  try {
@@ -276,39 +276,63 @@
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 _e = (e_2 = void 0, __values(section.questions)), _f = _e.next(); !_f.done; _f = _e.next()) {
280
+ var question = _f.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 _g = (e_3 = void 0, __values(items.controls)), _h = _g.next(); !_h.done; _h = _g.next()) {
290
+ var repeaterItem = _h.value;
291
+ /** @type {?} */
292
+ var filteredRepeaterItemQuestions = [];
293
+ console.log('Filtering repeater item questions');
294
+ try {
295
+ for (var _j = (e_4 = void 0, __values(question.repeaterQuestions)), _k = _j.next(); !_k.done; _k = _j.next()) {
296
+ var repeaterQuestion = _k.value;
297
+ /** @type {?} */
298
+ var meetsConditions = this.meetsConditionGroups(repeaterQuestion.conditionGroups, currentQuestionnaireForm, additionalData, (/** @type {?} */ (repeaterItem)));
299
+ if (meetsConditions) {
300
+ repeaterQuestion.selectOptions = this.getFetchOptionsForQuestion(repeaterQuestion, additionalData, currentQuestionnaireForm, (/** @type {?} */ (repeaterItem)));
301
+ filteredRepeaterItemQuestions.push(repeaterQuestion);
302
+ }
303
+ }
304
+ }
305
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
306
+ finally {
307
+ try {
308
+ if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
309
+ }
310
+ finally { if (e_4) throw e_4.error; }
311
+ }
312
+ /** @type {?} */
313
+ var index = items.controls.indexOf(repeaterItem);
314
+ if (!question.filteredRepeaterQuestions) {
315
+ question.filteredRepeaterQuestions = [];
293
316
  }
317
+ question.filteredRepeaterQuestions[index] = filteredRepeaterItemQuestions;
294
318
  }
295
319
  }
296
320
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
297
321
  finally {
298
322
  try {
299
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
323
+ if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
300
324
  }
301
325
  finally { if (e_3) throw e_3.error; }
302
326
  }
303
327
  }
304
- this.setFetchForQuestion(question, additionalData, currentQuestionnaireForm);
328
+ question.selectOptions = this.getFetchOptionsForQuestion(question, additionalData, currentQuestionnaireForm);
305
329
  filteredQuestions.push(question);
306
330
  }
307
331
  }
308
332
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
309
333
  finally {
310
334
  try {
311
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
335
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
312
336
  }
313
337
  finally { if (e_2) throw e_2.error; }
314
338
  }
@@ -333,31 +357,34 @@
333
357
  * @param {?} question
334
358
  * @param {?} additionalData
335
359
  * @param {?} currentQuestionnaireForm
360
+ * @param {?=} repeaterItem
336
361
  * @return {?}
337
362
  */
338
- FilterService.prototype.setFetchForQuestion = /**
363
+ FilterService.prototype.getFetchOptionsForQuestion = /**
339
364
  * @private
340
365
  * @param {?} question
341
366
  * @param {?} additionalData
342
367
  * @param {?} currentQuestionnaireForm
368
+ * @param {?=} repeaterItem
343
369
  * @return {?}
344
370
  */
345
- function (question, additionalData, currentQuestionnaireForm) {
346
- if (question.fetchPath) {
347
- return;
371
+ function (question, additionalData, currentQuestionnaireForm, repeaterItem) {
372
+ if (!question.fetchPath) {
373
+ return question.selectOptions;
348
374
  }
375
+ console.log('Getting fetch data for', question.name);
349
376
  /** @type {?} */
350
377
  var options = additionalData[question.fetchPath];
351
378
  if (question.fetchSelectors && question.fetchSelectors.length > 0) {
352
379
  /** @type {?} */
353
- var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData);
380
+ var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData, repeaterItem);
354
381
  options = lodash.get(additionalData[question.fetchPath], values);
355
382
  }
356
383
  options = this.getFinalFetchArray(options);
357
384
  if (!question.selectOptions) {
358
385
  question.selectOptions = [];
359
386
  }
360
- question.selectOptions = question.selectOptions.concat(options);
387
+ return question.selectOptions.concat(options);
361
388
  };
362
389
  /**
363
390
  * @private
@@ -370,7 +397,7 @@
370
397
  * @return {?}
371
398
  */
372
399
  function (items) {
373
- var e_4, _a;
400
+ var e_5, _a;
374
401
  if (!items) {
375
402
  return null;
376
403
  }
@@ -395,12 +422,12 @@
395
422
  }
396
423
  }
397
424
  }
398
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
425
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
399
426
  finally {
400
427
  try {
401
428
  if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
402
429
  }
403
- finally { if (e_4) throw e_4.error; }
430
+ finally { if (e_5) throw e_5.error; }
404
431
  }
405
432
  return convertedArray;
406
433
  };
@@ -431,6 +458,7 @@
431
458
  * @param {?} conditionGroups The array of condition groups.
432
459
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
433
460
  * @param {?=} additionalData
461
+ * @param {?=} repeaterItem
434
462
  * @return {?} A boolean stating if the condition groups conditions has been met.
435
463
  */
436
464
  FilterService.prototype.meetsConditionGroups = /**
@@ -440,9 +468,10 @@
440
468
  * @param {?} conditionGroups The array of condition groups.
441
469
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
442
470
  * @param {?=} additionalData
471
+ * @param {?=} repeaterItem
443
472
  * @return {?} A boolean stating if the condition groups conditions has been met.
444
473
  */
445
- function (conditionGroups, currentQuestionnaireForm, additionalData) {
474
+ function (conditionGroups, currentQuestionnaireForm, additionalData, repeaterItem) {
446
475
  var _this = this;
447
476
  if (!conditionGroups || conditionGroups.length === 0) {
448
477
  return true;
@@ -452,7 +481,7 @@
452
481
  * @return {?}
453
482
  */
454
483
  function (x) {
455
- return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData) === true;
484
+ return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData, repeaterItem) === true;
456
485
  }));
457
486
  };
458
487
  /**
@@ -469,6 +498,7 @@
469
498
  * @param {?} conditionGroup The condition group to check.
470
499
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
471
500
  * @param {?=} additionalData
501
+ * @param {?=} repeaterItem
472
502
  * @return {?} A boolean stating if the condition group conditions has been met.
473
503
  */
474
504
  FilterService.prototype.meetsConditionGroup = /**
@@ -478,10 +508,11 @@
478
508
  * @param {?} conditionGroup The condition group to check.
479
509
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
480
510
  * @param {?=} additionalData
511
+ * @param {?=} repeaterItem
481
512
  * @return {?} A boolean stating if the condition group conditions has been met.
482
513
  */
483
- function (conditionGroup, currentQuestionnaireForm, additionalData) {
484
- var e_5, _a;
514
+ function (conditionGroup, currentQuestionnaireForm, additionalData, repeaterItem) {
515
+ var e_6, _a;
485
516
  if (!conditionGroup.conditions || conditionGroup.conditions.length === 0) {
486
517
  return true;
487
518
  }
@@ -490,15 +521,15 @@
490
521
  try {
491
522
  for (var _b = __values(conditionGroup.conditions), _c = _b.next(); !_c.done; _c = _b.next()) {
492
523
  var condition = _c.value;
493
- results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData));
524
+ results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData, repeaterItem));
494
525
  }
495
526
  }
496
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
527
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
497
528
  finally {
498
529
  try {
499
530
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
500
531
  }
501
- finally { if (e_5) throw e_5.error; }
532
+ finally { if (e_6) throw e_6.error; }
502
533
  }
503
534
  switch (conditionGroup.relationship) {
504
535
  case ConditionRelationship.Every:
@@ -535,6 +566,7 @@
535
566
  * @param {?} condition The condition to check.
536
567
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
537
568
  * @param {?=} additionalData
569
+ * @param {?=} repeaterItem
538
570
  * @return {?} A boolean stating if the condition group conditions has been met.
539
571
  */
540
572
  FilterService.prototype.meetsCondition = /**
@@ -544,14 +576,15 @@
544
576
  * @param {?} condition The condition to check.
545
577
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
546
578
  * @param {?=} additionalData
579
+ * @param {?=} repeaterItem
547
580
  * @return {?} A boolean stating if the condition group conditions has been met.
548
581
  */
549
- function (condition, currentQuestionnaireForm, additionalData) {
550
- var e_6, _a, e_7, _b;
582
+ function (condition, currentQuestionnaireForm, additionalData, repeaterItem) {
583
+ var e_7, _a, e_8, _b;
551
584
  /** @type {?} */
552
- var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData);
585
+ var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData, repeaterItem);
553
586
  /** @type {?} */
554
- var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData);
587
+ var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData, repeaterItem);
555
588
  /** @type {?} */
556
589
  var result = false;
557
590
  switch (condition.type) {
@@ -577,7 +610,7 @@
577
610
  for (var v2s_1 = __values(v2s), v2s_1_1 = v2s_1.next(); !v2s_1_1.done; v2s_1_1 = v2s_1.next()) {
578
611
  var v2 = v2s_1_1.value;
579
612
  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()) {
613
+ for (var v1s_1 = (e_8 = void 0, __values(v1s)), v1s_1_1 = v1s_1.next(); !v1s_1_1.done; v1s_1_1 = v1s_1.next()) {
581
614
  var v1 = v1s_1_1.value;
582
615
  switch (condition.type) {
583
616
  case ConditionType.EqualTo:
@@ -611,21 +644,21 @@
611
644
  }
612
645
  }
613
646
  }
614
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
647
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
615
648
  finally {
616
649
  try {
617
650
  if (v1s_1_1 && !v1s_1_1.done && (_b = v1s_1.return)) _b.call(v1s_1);
618
651
  }
619
- finally { if (e_7) throw e_7.error; }
652
+ finally { if (e_8) throw e_8.error; }
620
653
  }
621
654
  }
622
655
  }
623
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
656
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
624
657
  finally {
625
658
  try {
626
659
  if (v2s_1_1 && !v2s_1_1.done && (_a = v2s_1.return)) _a.call(v2s_1);
627
660
  }
628
- finally { if (e_6) throw e_6.error; }
661
+ finally { if (e_7) throw e_7.error; }
629
662
  }
630
663
  }
631
664
  return result;
@@ -662,6 +695,7 @@
662
695
  * @param {?} paths The array of strings to check.
663
696
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
664
697
  * @param {?=} additionalData
698
+ * @param {?=} repeaterItem
665
699
  * @return {?} An array of strings/values
666
700
  */
667
701
  FilterService.prototype.getValuesForArray = /**
@@ -671,10 +705,11 @@
671
705
  * @param {?} paths The array of strings to check.
672
706
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
673
707
  * @param {?=} additionalData
708
+ * @param {?=} repeaterItem
674
709
  * @return {?} An array of strings/values
675
710
  */
676
- function (paths, currentQuestionnaireForm, additionalData) {
677
- var e_8, _a;
711
+ function (paths, currentQuestionnaireForm, additionalData, repeaterItem) {
712
+ var e_9, _a;
678
713
  if (currentQuestionnaireForm) {
679
714
  /** @type {?} */
680
715
  var values = [];
@@ -682,16 +717,16 @@
682
717
  for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
683
718
  var path = paths_1_1.value;
684
719
  /** @type {?} */
685
- var value = this.getValueForString(path, currentQuestionnaireForm, additionalData);
720
+ var value = this.getValueForString(path, currentQuestionnaireForm, additionalData, repeaterItem);
686
721
  values.push(value);
687
722
  }
688
723
  }
689
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
724
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
690
725
  finally {
691
726
  try {
692
727
  if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
693
728
  }
694
- finally { if (e_8) throw e_8.error; }
729
+ finally { if (e_9) throw e_9.error; }
695
730
  }
696
731
  return values;
697
732
  }
@@ -713,6 +748,7 @@
713
748
  * @param {?} path The string value to check.
714
749
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
715
750
  * @param {?=} additionalData
751
+ * @param {?=} repeaterItem
716
752
  * @return {?} A string/value.
717
753
  */
718
754
  FilterService.prototype.getValueForString = /**
@@ -722,15 +758,19 @@
722
758
  * @param {?} path The string value to check.
723
759
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
724
760
  * @param {?=} additionalData
761
+ * @param {?=} repeaterItem
725
762
  * @return {?} A string/value.
726
763
  */
727
- function (path, currentQuestionnaireForm, additionalData) {
764
+ function (path, currentQuestionnaireForm, additionalData, repeaterItem) {
728
765
  if (currentQuestionnaireForm) {
729
766
  if (!additionalData) {
730
767
  additionalData = {};
731
768
  }
732
769
  /** @type {?} */
733
770
  var control = currentQuestionnaireForm.get(path.toString());
771
+ if ((!control || !control.value) && repeaterItem) {
772
+ control = repeaterItem.get(path.toString());
773
+ }
734
774
  /** @type {?} */
735
775
  var value = control ? control.value : this.convertStringToValue(path);
736
776
  return lodash.get(additionalData, path, value);
@@ -1031,25 +1071,29 @@
1031
1071
  * Generates the form template for a repeater question.
1032
1072
  * @author Will Poulson
1033
1073
  * @param {?} question The question. Must be of type repeater or else null is returned.
1074
+ * @param {?=} index
1034
1075
  * @return {?} A form group.
1035
1076
  */
1036
1077
  FormConstructorService.prototype.generateFormsForRepeater = /**
1037
1078
  * Generates the form template for a repeater question.
1038
1079
  * @author Will Poulson
1039
1080
  * @param {?} question The question. Must be of type repeater or else null is returned.
1081
+ * @param {?=} index
1040
1082
  * @return {?} A form group.
1041
1083
  */
1042
- function (question) {
1084
+ function (question, index) {
1043
1085
  var e_4, _a;
1044
1086
  if (question.type !== QuestionType.Repeater || question.repeaterQuestions.length === 0) {
1045
1087
  console.log('Question isnt a repeater or has no questions, returning null');
1046
1088
  return null;
1047
1089
  }
1048
1090
  /** @type {?} */
1091
+ var repeaterQuestions = index ? question.filteredRepeaterQuestions[index] : question.repeaterQuestions;
1092
+ /** @type {?} */
1049
1093
  var repeaterForms = this.fb.group({});
1050
1094
  try {
1051
- for (var _b = __values(question.repeaterQuestions), _c = _b.next(); !_c.done; _c = _b.next()) {
1052
- var repeaterQuestion = _c.value;
1095
+ for (var repeaterQuestions_1 = __values(repeaterQuestions), repeaterQuestions_1_1 = repeaterQuestions_1.next(); !repeaterQuestions_1_1.done; repeaterQuestions_1_1 = repeaterQuestions_1.next()) {
1096
+ var repeaterQuestion = repeaterQuestions_1_1.value;
1053
1097
  /** @type {?} */
1054
1098
  var repeaterQuestionControl = this.generateControlForRepeaterQuestion(repeaterQuestion);
1055
1099
  repeaterForms.addControl(repeaterQuestion.name, repeaterQuestionControl);
@@ -1058,7 +1102,7 @@
1058
1102
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
1059
1103
  finally {
1060
1104
  try {
1061
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1105
+ if (repeaterQuestions_1_1 && !repeaterQuestions_1_1.done && (_a = repeaterQuestions_1.return)) _a.call(repeaterQuestions_1);
1062
1106
  }
1063
1107
  finally { if (e_4) throw e_4.error; }
1064
1108
  }
@@ -1208,7 +1252,9 @@
1208
1252
  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
1253
  var repeaterItem = repeaterArray_1_1.value;
1210
1254
  /** @type {?} */
1211
- var repeaterItemTemplate = this.generateFormsForRepeater(question);
1255
+ var index = repeaterArray.indexOf(repeaterItem);
1256
+ /** @type {?} */
1257
+ var repeaterItemTemplate = this.generateFormsForRepeater(question, index);
1212
1258
  repeaterFormArray.push(repeaterItemTemplate);
1213
1259
  }
1214
1260
  }