@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.
@@ -76,7 +76,7 @@ var FilterService = /** @class */ (function () {
76
76
  * @return {?} An array of filtered sections with their filtered questions.
77
77
  */
78
78
  function (sections, currentQuestionnaireForm, additionalData) {
79
- var e_1, _a, e_2, _b, e_3, _c;
79
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
80
80
  /** @type {?} */
81
81
  var filteredSections = [];
82
82
  try {
@@ -88,39 +88,63 @@ var FilterService = /** @class */ (function () {
88
88
  /** @type {?} */
89
89
  var filteredQuestions = [];
90
90
  try {
91
- for (var _d = (e_2 = void 0, __values(section.questions)), _e = _d.next(); !_e.done; _e = _d.next()) {
92
- var question = _e.value;
91
+ for (var _e = (e_2 = void 0, __values(section.questions)), _f = _e.next(); !_f.done; _f = _e.next()) {
92
+ var question = _f.value;
93
93
  if (!this.meetsConditionGroups(question.conditionGroups, currentQuestionnaireForm, additionalData)) {
94
94
  continue;
95
95
  }
96
- if (question.repeaterQuestions) {
96
+ // If it's a repeater we need to do a lot of extra filtering due to per item conditions.
97
+ if (question.type === 'repeater') {
97
98
  /** @type {?} */
98
- var filteredRepeaterQuestions = [];
99
+ var items = (/** @type {?} */ (currentQuestionnaireForm.get([section.name, question.name])));
99
100
  try {
100
- for (var _f = (e_3 = void 0, __values(question.repeaterQuestions)), _g = _f.next(); !_g.done; _g = _f.next()) {
101
- var repeaterQuestion = _g.value;
102
- if (this.meetsConditionGroups(repeaterQuestion.conditionGroups, currentQuestionnaireForm, additionalData)) {
103
- this.setFetchForQuestion(question, additionalData, currentQuestionnaireForm);
104
- filteredRepeaterQuestions.push(repeaterQuestion);
101
+ for (var _g = (e_3 = void 0, __values(items.controls)), _h = _g.next(); !_h.done; _h = _g.next()) {
102
+ var repeaterItem = _h.value;
103
+ /** @type {?} */
104
+ var filteredRepeaterItemQuestions = [];
105
+ console.log('Filtering repeater item questions');
106
+ try {
107
+ for (var _j = (e_4 = void 0, __values(question.repeaterQuestions)), _k = _j.next(); !_k.done; _k = _j.next()) {
108
+ var repeaterQuestion = _k.value;
109
+ /** @type {?} */
110
+ var meetsConditions = this.meetsConditionGroups(repeaterQuestion.conditionGroups, currentQuestionnaireForm, additionalData, (/** @type {?} */ (repeaterItem)));
111
+ if (meetsConditions) {
112
+ repeaterQuestion.selectOptions = this.getFetchOptionsForQuestion(repeaterQuestion, additionalData, currentQuestionnaireForm, (/** @type {?} */ (repeaterItem)));
113
+ filteredRepeaterItemQuestions.push(repeaterQuestion);
114
+ }
115
+ }
116
+ }
117
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
118
+ finally {
119
+ try {
120
+ if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
121
+ }
122
+ finally { if (e_4) throw e_4.error; }
123
+ }
124
+ /** @type {?} */
125
+ var index = items.controls.indexOf(repeaterItem);
126
+ if (!question.filteredRepeaterQuestions) {
127
+ question.filteredRepeaterQuestions = [];
105
128
  }
129
+ question.filteredRepeaterQuestions[index] = filteredRepeaterItemQuestions;
106
130
  }
107
131
  }
108
132
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
109
133
  finally {
110
134
  try {
111
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
135
+ if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
112
136
  }
113
137
  finally { if (e_3) throw e_3.error; }
114
138
  }
115
139
  }
116
- this.setFetchForQuestion(question, additionalData, currentQuestionnaireForm);
140
+ question.selectOptions = this.getFetchOptionsForQuestion(question, additionalData, currentQuestionnaireForm);
117
141
  filteredQuestions.push(question);
118
142
  }
119
143
  }
120
144
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
121
145
  finally {
122
146
  try {
123
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
147
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
124
148
  }
125
149
  finally { if (e_2) throw e_2.error; }
126
150
  }
@@ -145,31 +169,34 @@ var FilterService = /** @class */ (function () {
145
169
  * @param {?} question
146
170
  * @param {?} additionalData
147
171
  * @param {?} currentQuestionnaireForm
172
+ * @param {?=} repeaterItem
148
173
  * @return {?}
149
174
  */
150
- FilterService.prototype.setFetchForQuestion = /**
175
+ FilterService.prototype.getFetchOptionsForQuestion = /**
151
176
  * @private
152
177
  * @param {?} question
153
178
  * @param {?} additionalData
154
179
  * @param {?} currentQuestionnaireForm
180
+ * @param {?=} repeaterItem
155
181
  * @return {?}
156
182
  */
157
- function (question, additionalData, currentQuestionnaireForm) {
158
- if (question.fetchPath) {
159
- return;
183
+ function (question, additionalData, currentQuestionnaireForm, repeaterItem) {
184
+ if (!question.fetchPath) {
185
+ return question.selectOptions;
160
186
  }
187
+ console.log('Getting fetch data for', question.name);
161
188
  /** @type {?} */
162
189
  var options = additionalData[question.fetchPath];
163
190
  if (question.fetchSelectors && question.fetchSelectors.length > 0) {
164
191
  /** @type {?} */
165
- var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData);
192
+ var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData, repeaterItem);
166
193
  options = get(additionalData[question.fetchPath], values);
167
194
  }
168
195
  options = this.getFinalFetchArray(options);
169
196
  if (!question.selectOptions) {
170
197
  question.selectOptions = [];
171
198
  }
172
- question.selectOptions = question.selectOptions.concat(options);
199
+ return question.selectOptions.concat(options);
173
200
  };
174
201
  /**
175
202
  * @private
@@ -182,7 +209,7 @@ var FilterService = /** @class */ (function () {
182
209
  * @return {?}
183
210
  */
184
211
  function (items) {
185
- var e_4, _a;
212
+ var e_5, _a;
186
213
  if (!items) {
187
214
  return null;
188
215
  }
@@ -207,12 +234,12 @@ var FilterService = /** @class */ (function () {
207
234
  }
208
235
  }
209
236
  }
210
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
237
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
211
238
  finally {
212
239
  try {
213
240
  if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
214
241
  }
215
- finally { if (e_4) throw e_4.error; }
242
+ finally { if (e_5) throw e_5.error; }
216
243
  }
217
244
  return convertedArray;
218
245
  };
@@ -243,6 +270,7 @@ var FilterService = /** @class */ (function () {
243
270
  * @param {?} conditionGroups The array of condition groups.
244
271
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
245
272
  * @param {?=} additionalData
273
+ * @param {?=} repeaterItem
246
274
  * @return {?} A boolean stating if the condition groups conditions has been met.
247
275
  */
248
276
  FilterService.prototype.meetsConditionGroups = /**
@@ -252,9 +280,10 @@ var FilterService = /** @class */ (function () {
252
280
  * @param {?} conditionGroups The array of condition groups.
253
281
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
254
282
  * @param {?=} additionalData
283
+ * @param {?=} repeaterItem
255
284
  * @return {?} A boolean stating if the condition groups conditions has been met.
256
285
  */
257
- function (conditionGroups, currentQuestionnaireForm, additionalData) {
286
+ function (conditionGroups, currentQuestionnaireForm, additionalData, repeaterItem) {
258
287
  var _this = this;
259
288
  if (!conditionGroups || conditionGroups.length === 0) {
260
289
  return true;
@@ -264,7 +293,7 @@ var FilterService = /** @class */ (function () {
264
293
  * @return {?}
265
294
  */
266
295
  function (x) {
267
- return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData) === true;
296
+ return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData, repeaterItem) === true;
268
297
  }));
269
298
  };
270
299
  /**
@@ -281,6 +310,7 @@ var FilterService = /** @class */ (function () {
281
310
  * @param {?} conditionGroup The condition group to check.
282
311
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
283
312
  * @param {?=} additionalData
313
+ * @param {?=} repeaterItem
284
314
  * @return {?} A boolean stating if the condition group conditions has been met.
285
315
  */
286
316
  FilterService.prototype.meetsConditionGroup = /**
@@ -290,10 +320,11 @@ var FilterService = /** @class */ (function () {
290
320
  * @param {?} conditionGroup The condition group to check.
291
321
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
292
322
  * @param {?=} additionalData
323
+ * @param {?=} repeaterItem
293
324
  * @return {?} A boolean stating if the condition group conditions has been met.
294
325
  */
295
- function (conditionGroup, currentQuestionnaireForm, additionalData) {
296
- var e_5, _a;
326
+ function (conditionGroup, currentQuestionnaireForm, additionalData, repeaterItem) {
327
+ var e_6, _a;
297
328
  if (!conditionGroup.conditions || conditionGroup.conditions.length === 0) {
298
329
  return true;
299
330
  }
@@ -302,15 +333,15 @@ var FilterService = /** @class */ (function () {
302
333
  try {
303
334
  for (var _b = __values(conditionGroup.conditions), _c = _b.next(); !_c.done; _c = _b.next()) {
304
335
  var condition = _c.value;
305
- results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData));
336
+ results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData, repeaterItem));
306
337
  }
307
338
  }
308
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
339
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
309
340
  finally {
310
341
  try {
311
342
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
312
343
  }
313
- finally { if (e_5) throw e_5.error; }
344
+ finally { if (e_6) throw e_6.error; }
314
345
  }
315
346
  switch (conditionGroup.relationship) {
316
347
  case ConditionRelationship.Every:
@@ -347,6 +378,7 @@ var FilterService = /** @class */ (function () {
347
378
  * @param {?} condition The condition to check.
348
379
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
349
380
  * @param {?=} additionalData
381
+ * @param {?=} repeaterItem
350
382
  * @return {?} A boolean stating if the condition group conditions has been met.
351
383
  */
352
384
  FilterService.prototype.meetsCondition = /**
@@ -356,14 +388,15 @@ var FilterService = /** @class */ (function () {
356
388
  * @param {?} condition The condition to check.
357
389
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
358
390
  * @param {?=} additionalData
391
+ * @param {?=} repeaterItem
359
392
  * @return {?} A boolean stating if the condition group conditions has been met.
360
393
  */
361
- function (condition, currentQuestionnaireForm, additionalData) {
362
- var e_6, _a, e_7, _b;
394
+ function (condition, currentQuestionnaireForm, additionalData, repeaterItem) {
395
+ var e_7, _a, e_8, _b;
363
396
  /** @type {?} */
364
- var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData);
397
+ var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData, repeaterItem);
365
398
  /** @type {?} */
366
- var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData);
399
+ var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData, repeaterItem);
367
400
  /** @type {?} */
368
401
  var result = false;
369
402
  switch (condition.type) {
@@ -389,7 +422,7 @@ var FilterService = /** @class */ (function () {
389
422
  for (var v2s_1 = __values(v2s), v2s_1_1 = v2s_1.next(); !v2s_1_1.done; v2s_1_1 = v2s_1.next()) {
390
423
  var v2 = v2s_1_1.value;
391
424
  try {
392
- 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()) {
425
+ 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()) {
393
426
  var v1 = v1s_1_1.value;
394
427
  switch (condition.type) {
395
428
  case ConditionType.EqualTo:
@@ -423,21 +456,21 @@ var FilterService = /** @class */ (function () {
423
456
  }
424
457
  }
425
458
  }
426
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
459
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
427
460
  finally {
428
461
  try {
429
462
  if (v1s_1_1 && !v1s_1_1.done && (_b = v1s_1.return)) _b.call(v1s_1);
430
463
  }
431
- finally { if (e_7) throw e_7.error; }
464
+ finally { if (e_8) throw e_8.error; }
432
465
  }
433
466
  }
434
467
  }
435
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
468
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
436
469
  finally {
437
470
  try {
438
471
  if (v2s_1_1 && !v2s_1_1.done && (_a = v2s_1.return)) _a.call(v2s_1);
439
472
  }
440
- finally { if (e_6) throw e_6.error; }
473
+ finally { if (e_7) throw e_7.error; }
441
474
  }
442
475
  }
443
476
  return result;
@@ -474,6 +507,7 @@ var FilterService = /** @class */ (function () {
474
507
  * @param {?} paths The array of strings to check.
475
508
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
476
509
  * @param {?=} additionalData
510
+ * @param {?=} repeaterItem
477
511
  * @return {?} An array of strings/values
478
512
  */
479
513
  FilterService.prototype.getValuesForArray = /**
@@ -483,10 +517,11 @@ var FilterService = /** @class */ (function () {
483
517
  * @param {?} paths The array of strings to check.
484
518
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
485
519
  * @param {?=} additionalData
520
+ * @param {?=} repeaterItem
486
521
  * @return {?} An array of strings/values
487
522
  */
488
- function (paths, currentQuestionnaireForm, additionalData) {
489
- var e_8, _a;
523
+ function (paths, currentQuestionnaireForm, additionalData, repeaterItem) {
524
+ var e_9, _a;
490
525
  if (currentQuestionnaireForm) {
491
526
  /** @type {?} */
492
527
  var values = [];
@@ -494,16 +529,16 @@ var FilterService = /** @class */ (function () {
494
529
  for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
495
530
  var path = paths_1_1.value;
496
531
  /** @type {?} */
497
- var value = this.getValueForString(path, currentQuestionnaireForm, additionalData);
532
+ var value = this.getValueForString(path, currentQuestionnaireForm, additionalData, repeaterItem);
498
533
  values.push(value);
499
534
  }
500
535
  }
501
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
536
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
502
537
  finally {
503
538
  try {
504
539
  if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
505
540
  }
506
- finally { if (e_8) throw e_8.error; }
541
+ finally { if (e_9) throw e_9.error; }
507
542
  }
508
543
  return values;
509
544
  }
@@ -525,6 +560,7 @@ var FilterService = /** @class */ (function () {
525
560
  * @param {?} path The string value to check.
526
561
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
527
562
  * @param {?=} additionalData
563
+ * @param {?=} repeaterItem
528
564
  * @return {?} A string/value.
529
565
  */
530
566
  FilterService.prototype.getValueForString = /**
@@ -534,15 +570,19 @@ var FilterService = /** @class */ (function () {
534
570
  * @param {?} path The string value to check.
535
571
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
536
572
  * @param {?=} additionalData
573
+ * @param {?=} repeaterItem
537
574
  * @return {?} A string/value.
538
575
  */
539
- function (path, currentQuestionnaireForm, additionalData) {
576
+ function (path, currentQuestionnaireForm, additionalData, repeaterItem) {
540
577
  if (currentQuestionnaireForm) {
541
578
  if (!additionalData) {
542
579
  additionalData = {};
543
580
  }
544
581
  /** @type {?} */
545
582
  var control = currentQuestionnaireForm.get(path.toString());
583
+ if ((!control || !control.value) && repeaterItem) {
584
+ control = repeaterItem.get(path.toString());
585
+ }
546
586
  /** @type {?} */
547
587
  var value = control ? control.value : this.convertStringToValue(path);
548
588
  return get(additionalData, path, value);
@@ -843,25 +883,29 @@ var FormConstructorService = /** @class */ (function () {
843
883
  * Generates the form template for a repeater question.
844
884
  * @author Will Poulson
845
885
  * @param {?} question The question. Must be of type repeater or else null is returned.
886
+ * @param {?=} index
846
887
  * @return {?} A form group.
847
888
  */
848
889
  FormConstructorService.prototype.generateFormsForRepeater = /**
849
890
  * Generates the form template for a repeater question.
850
891
  * @author Will Poulson
851
892
  * @param {?} question The question. Must be of type repeater or else null is returned.
893
+ * @param {?=} index
852
894
  * @return {?} A form group.
853
895
  */
854
- function (question) {
896
+ function (question, index) {
855
897
  var e_4, _a;
856
898
  if (question.type !== QuestionType.Repeater || question.repeaterQuestions.length === 0) {
857
899
  console.log('Question isnt a repeater or has no questions, returning null');
858
900
  return null;
859
901
  }
860
902
  /** @type {?} */
903
+ var repeaterQuestions = index ? question.filteredRepeaterQuestions[index] : question.repeaterQuestions;
904
+ /** @type {?} */
861
905
  var repeaterForms = this.fb.group({});
862
906
  try {
863
- for (var _b = __values(question.repeaterQuestions), _c = _b.next(); !_c.done; _c = _b.next()) {
864
- var repeaterQuestion = _c.value;
907
+ for (var repeaterQuestions_1 = __values(repeaterQuestions), repeaterQuestions_1_1 = repeaterQuestions_1.next(); !repeaterQuestions_1_1.done; repeaterQuestions_1_1 = repeaterQuestions_1.next()) {
908
+ var repeaterQuestion = repeaterQuestions_1_1.value;
865
909
  /** @type {?} */
866
910
  var repeaterQuestionControl = this.generateControlForRepeaterQuestion(repeaterQuestion);
867
911
  repeaterForms.addControl(repeaterQuestion.name, repeaterQuestionControl);
@@ -870,7 +914,7 @@ var FormConstructorService = /** @class */ (function () {
870
914
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
871
915
  finally {
872
916
  try {
873
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
917
+ if (repeaterQuestions_1_1 && !repeaterQuestions_1_1.done && (_a = repeaterQuestions_1.return)) _a.call(repeaterQuestions_1);
874
918
  }
875
919
  finally { if (e_4) throw e_4.error; }
876
920
  }
@@ -1020,7 +1064,9 @@ var FormConstructorService = /** @class */ (function () {
1020
1064
  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()) {
1021
1065
  var repeaterItem = repeaterArray_1_1.value;
1022
1066
  /** @type {?} */
1023
- var repeaterItemTemplate = this.generateFormsForRepeater(question);
1067
+ var index = repeaterArray.indexOf(repeaterItem);
1068
+ /** @type {?} */
1069
+ var repeaterItemTemplate = this.generateFormsForRepeater(question, index);
1024
1070
  repeaterFormArray.push(repeaterItemTemplate);
1025
1071
  }
1026
1072
  }