@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.
@@ -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, e_5, _e;
80
80
  /** @type {?} */
81
81
  var filteredSections = [];
82
82
  try {
@@ -88,51 +88,78 @@ 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 _f = (e_2 = void 0, __values(section.questions)), _g = _f.next(); !_g.done; _g = _f.next()) {
92
+ var question = _g.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
- filteredRepeaterQuestions.push(repeaterQuestion);
101
+ for (var _h = (e_3 = void 0, __values(items.controls)), _j = _h.next(); !_j.done; _j = _h.next()) {
102
+ var repeaterItem = _j.value;
103
+ /** @type {?} */
104
+ var filteredRepeaterItemQuestions = [];
105
+ try {
106
+ for (var _k = (e_4 = void 0, __values(question.repeaterQuestions)), _l = _k.next(); !_l.done; _l = _k.next()) {
107
+ var repeaterQuestion = _l.value;
108
+ /** @type {?} */
109
+ var meetsConditions = this.meetsConditionGroups(repeaterQuestion.conditionGroups, currentQuestionnaireForm, additionalData, (/** @type {?} */ (repeaterItem)));
110
+ if (meetsConditions) {
111
+ this.setFetchForQuestion(repeaterQuestion, additionalData, currentQuestionnaireForm, (/** @type {?} */ (repeaterItem)));
112
+ filteredRepeaterItemQuestions.push(repeaterQuestion);
113
+ }
114
+ }
115
+ }
116
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
117
+ finally {
118
+ try {
119
+ if (_l && !_l.done && (_d = _k.return)) _d.call(_k);
120
+ }
121
+ finally { if (e_4) throw e_4.error; }
122
+ }
123
+ try {
124
+ 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()) {
125
+ var filteredRepeaterItemQuestion = filteredRepeaterItemQuestions_1_1.value;
126
+ if (filteredRepeaterItemQuestion.type !== 'select') {
127
+ continue;
128
+ }
129
+ this.setFetchForQuestion(filteredRepeaterItemQuestion, additionalData, currentQuestionnaireForm);
130
+ }
104
131
  }
132
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
133
+ finally {
134
+ try {
135
+ if (filteredRepeaterItemQuestions_1_1 && !filteredRepeaterItemQuestions_1_1.done && (_e = filteredRepeaterItemQuestions_1.return)) _e.call(filteredRepeaterItemQuestions_1);
136
+ }
137
+ finally { if (e_5) throw e_5.error; }
138
+ }
139
+ /** @type {?} */
140
+ var index = items.controls.indexOf(repeaterItem);
141
+ if (!question.filteredRepeaterQuestions) {
142
+ question.filteredRepeaterQuestions = [];
143
+ }
144
+ question.filteredRepeaterQuestions[index] = filteredRepeaterItemQuestions;
105
145
  }
106
146
  }
107
147
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
108
148
  finally {
109
149
  try {
110
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
150
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
111
151
  }
112
152
  finally { if (e_3) throw e_3.error; }
113
153
  }
114
154
  }
115
- if (question.fetchPath) {
116
- /** @type {?} */
117
- var options = additionalData[question.fetchPath];
118
- if (question.fetchSelectors && question.fetchSelectors.length > 0) {
119
- /** @type {?} */
120
- var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData);
121
- options = get(additionalData[question.fetchPath], values);
122
- }
123
- options = this.getFinalFetchArray(options);
124
- if (!question.selectOptions) {
125
- question.selectOptions = [];
126
- }
127
- question.selectOptions = question.selectOptions.concat(options);
128
- }
155
+ this.setFetchForQuestion(question, additionalData, currentQuestionnaireForm);
129
156
  filteredQuestions.push(question);
130
157
  }
131
158
  }
132
159
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
133
160
  finally {
134
161
  try {
135
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
162
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
136
163
  }
137
164
  finally { if (e_2) throw e_2.error; }
138
165
  }
@@ -152,6 +179,39 @@ var FilterService = /** @class */ (function () {
152
179
  }
153
180
  return filteredSections;
154
181
  };
182
+ /**
183
+ * @private
184
+ * @param {?} question
185
+ * @param {?} additionalData
186
+ * @param {?} currentQuestionnaireForm
187
+ * @param {?=} repeaterItem
188
+ * @return {?}
189
+ */
190
+ FilterService.prototype.setFetchForQuestion = /**
191
+ * @private
192
+ * @param {?} question
193
+ * @param {?} additionalData
194
+ * @param {?} currentQuestionnaireForm
195
+ * @param {?=} repeaterItem
196
+ * @return {?}
197
+ */
198
+ function (question, additionalData, currentQuestionnaireForm, repeaterItem) {
199
+ if (question.fetchPath) {
200
+ return;
201
+ }
202
+ /** @type {?} */
203
+ var options = additionalData[question.fetchPath];
204
+ if (question.fetchSelectors && question.fetchSelectors.length > 0) {
205
+ /** @type {?} */
206
+ var values = this.getValuesForArray(question.fetchSelectors, currentQuestionnaireForm, additionalData, repeaterItem);
207
+ options = get(additionalData[question.fetchPath], values);
208
+ }
209
+ options = this.getFinalFetchArray(options);
210
+ if (!question.selectOptions) {
211
+ question.selectOptions = [];
212
+ }
213
+ question.selectOptions = question.selectOptions.concat(options);
214
+ };
155
215
  /**
156
216
  * @private
157
217
  * @param {?} items
@@ -163,7 +223,7 @@ var FilterService = /** @class */ (function () {
163
223
  * @return {?}
164
224
  */
165
225
  function (items) {
166
- var e_4, _a;
226
+ var e_6, _a;
167
227
  if (!items) {
168
228
  return null;
169
229
  }
@@ -188,12 +248,12 @@ var FilterService = /** @class */ (function () {
188
248
  }
189
249
  }
190
250
  }
191
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
251
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
192
252
  finally {
193
253
  try {
194
254
  if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
195
255
  }
196
- finally { if (e_4) throw e_4.error; }
256
+ finally { if (e_6) throw e_6.error; }
197
257
  }
198
258
  return convertedArray;
199
259
  };
@@ -224,6 +284,7 @@ var FilterService = /** @class */ (function () {
224
284
  * @param {?} conditionGroups The array of condition groups.
225
285
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
226
286
  * @param {?=} additionalData
287
+ * @param {?=} repeaterItem
227
288
  * @return {?} A boolean stating if the condition groups conditions has been met.
228
289
  */
229
290
  FilterService.prototype.meetsConditionGroups = /**
@@ -233,9 +294,10 @@ var FilterService = /** @class */ (function () {
233
294
  * @param {?} conditionGroups The array of condition groups.
234
295
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
235
296
  * @param {?=} additionalData
297
+ * @param {?=} repeaterItem
236
298
  * @return {?} A boolean stating if the condition groups conditions has been met.
237
299
  */
238
- function (conditionGroups, currentQuestionnaireForm, additionalData) {
300
+ function (conditionGroups, currentQuestionnaireForm, additionalData, repeaterItem) {
239
301
  var _this = this;
240
302
  if (!conditionGroups || conditionGroups.length === 0) {
241
303
  return true;
@@ -245,7 +307,7 @@ var FilterService = /** @class */ (function () {
245
307
  * @return {?}
246
308
  */
247
309
  function (x) {
248
- return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData) === true;
310
+ return _this.meetsConditionGroup(x, currentQuestionnaireForm, additionalData, repeaterItem) === true;
249
311
  }));
250
312
  };
251
313
  /**
@@ -262,6 +324,7 @@ var FilterService = /** @class */ (function () {
262
324
  * @param {?} conditionGroup The condition group to check.
263
325
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
264
326
  * @param {?=} additionalData
327
+ * @param {?=} repeaterItem
265
328
  * @return {?} A boolean stating if the condition group conditions has been met.
266
329
  */
267
330
  FilterService.prototype.meetsConditionGroup = /**
@@ -271,10 +334,11 @@ var FilterService = /** @class */ (function () {
271
334
  * @param {?} conditionGroup The condition group to check.
272
335
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
273
336
  * @param {?=} additionalData
337
+ * @param {?=} repeaterItem
274
338
  * @return {?} A boolean stating if the condition group conditions has been met.
275
339
  */
276
- function (conditionGroup, currentQuestionnaireForm, additionalData) {
277
- var e_5, _a;
340
+ function (conditionGroup, currentQuestionnaireForm, additionalData, repeaterItem) {
341
+ var e_7, _a;
278
342
  if (!conditionGroup.conditions || conditionGroup.conditions.length === 0) {
279
343
  return true;
280
344
  }
@@ -283,15 +347,15 @@ var FilterService = /** @class */ (function () {
283
347
  try {
284
348
  for (var _b = __values(conditionGroup.conditions), _c = _b.next(); !_c.done; _c = _b.next()) {
285
349
  var condition = _c.value;
286
- results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData));
350
+ results.push(this.meetsCondition(condition, currentQuestionnaireForm, additionalData, repeaterItem));
287
351
  }
288
352
  }
289
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
353
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
290
354
  finally {
291
355
  try {
292
356
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
293
357
  }
294
- finally { if (e_5) throw e_5.error; }
358
+ finally { if (e_7) throw e_7.error; }
295
359
  }
296
360
  switch (conditionGroup.relationship) {
297
361
  case ConditionRelationship.Every:
@@ -328,6 +392,7 @@ var FilterService = /** @class */ (function () {
328
392
  * @param {?} condition The condition to check.
329
393
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
330
394
  * @param {?=} additionalData
395
+ * @param {?=} repeaterItem
331
396
  * @return {?} A boolean stating if the condition group conditions has been met.
332
397
  */
333
398
  FilterService.prototype.meetsCondition = /**
@@ -337,14 +402,15 @@ var FilterService = /** @class */ (function () {
337
402
  * @param {?} condition The condition to check.
338
403
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
339
404
  * @param {?=} additionalData
405
+ * @param {?=} repeaterItem
340
406
  * @return {?} A boolean stating if the condition group conditions has been met.
341
407
  */
342
- function (condition, currentQuestionnaireForm, additionalData) {
343
- var e_6, _a, e_7, _b;
408
+ function (condition, currentQuestionnaireForm, additionalData, repeaterItem) {
409
+ var e_8, _a, e_9, _b;
344
410
  /** @type {?} */
345
- var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData);
411
+ var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm, additionalData, repeaterItem);
346
412
  /** @type {?} */
347
- var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData);
413
+ var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm, additionalData, repeaterItem);
348
414
  /** @type {?} */
349
415
  var result = false;
350
416
  switch (condition.type) {
@@ -370,7 +436,7 @@ var FilterService = /** @class */ (function () {
370
436
  for (var v2s_1 = __values(v2s), v2s_1_1 = v2s_1.next(); !v2s_1_1.done; v2s_1_1 = v2s_1.next()) {
371
437
  var v2 = v2s_1_1.value;
372
438
  try {
373
- 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()) {
439
+ 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()) {
374
440
  var v1 = v1s_1_1.value;
375
441
  switch (condition.type) {
376
442
  case ConditionType.EqualTo:
@@ -404,21 +470,21 @@ var FilterService = /** @class */ (function () {
404
470
  }
405
471
  }
406
472
  }
407
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
473
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
408
474
  finally {
409
475
  try {
410
476
  if (v1s_1_1 && !v1s_1_1.done && (_b = v1s_1.return)) _b.call(v1s_1);
411
477
  }
412
- finally { if (e_7) throw e_7.error; }
478
+ finally { if (e_9) throw e_9.error; }
413
479
  }
414
480
  }
415
481
  }
416
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
482
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
417
483
  finally {
418
484
  try {
419
485
  if (v2s_1_1 && !v2s_1_1.done && (_a = v2s_1.return)) _a.call(v2s_1);
420
486
  }
421
- finally { if (e_6) throw e_6.error; }
487
+ finally { if (e_8) throw e_8.error; }
422
488
  }
423
489
  }
424
490
  return result;
@@ -455,6 +521,7 @@ var FilterService = /** @class */ (function () {
455
521
  * @param {?} paths The array of strings to check.
456
522
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
457
523
  * @param {?=} additionalData
524
+ * @param {?=} repeaterItem
458
525
  * @return {?} An array of strings/values
459
526
  */
460
527
  FilterService.prototype.getValuesForArray = /**
@@ -464,10 +531,11 @@ var FilterService = /** @class */ (function () {
464
531
  * @param {?} paths The array of strings to check.
465
532
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
466
533
  * @param {?=} additionalData
534
+ * @param {?=} repeaterItem
467
535
  * @return {?} An array of strings/values
468
536
  */
469
- function (paths, currentQuestionnaireForm, additionalData) {
470
- var e_8, _a;
537
+ function (paths, currentQuestionnaireForm, additionalData, repeaterItem) {
538
+ var e_10, _a;
471
539
  if (currentQuestionnaireForm) {
472
540
  /** @type {?} */
473
541
  var values = [];
@@ -475,16 +543,16 @@ var FilterService = /** @class */ (function () {
475
543
  for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
476
544
  var path = paths_1_1.value;
477
545
  /** @type {?} */
478
- var value = this.getValueForString(path, currentQuestionnaireForm, additionalData);
546
+ var value = this.getValueForString(path, currentQuestionnaireForm, additionalData, repeaterItem);
479
547
  values.push(value);
480
548
  }
481
549
  }
482
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
550
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
483
551
  finally {
484
552
  try {
485
553
  if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
486
554
  }
487
- finally { if (e_8) throw e_8.error; }
555
+ finally { if (e_10) throw e_10.error; }
488
556
  }
489
557
  return values;
490
558
  }
@@ -506,6 +574,7 @@ var FilterService = /** @class */ (function () {
506
574
  * @param {?} path The string value to check.
507
575
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
508
576
  * @param {?=} additionalData
577
+ * @param {?=} repeaterItem
509
578
  * @return {?} A string/value.
510
579
  */
511
580
  FilterService.prototype.getValueForString = /**
@@ -515,15 +584,19 @@ var FilterService = /** @class */ (function () {
515
584
  * @param {?} path The string value to check.
516
585
  * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
517
586
  * @param {?=} additionalData
587
+ * @param {?=} repeaterItem
518
588
  * @return {?} A string/value.
519
589
  */
520
- function (path, currentQuestionnaireForm, additionalData) {
590
+ function (path, currentQuestionnaireForm, additionalData, repeaterItem) {
521
591
  if (currentQuestionnaireForm) {
522
592
  if (!additionalData) {
523
593
  additionalData = {};
524
594
  }
525
595
  /** @type {?} */
526
596
  var control = currentQuestionnaireForm.get(path.toString());
597
+ if ((!control || !control.value) && repeaterItem) {
598
+ control = repeaterItem.get(path.toString());
599
+ }
527
600
  /** @type {?} */
528
601
  var value = control ? control.value : this.convertStringToValue(path);
529
602
  return get(additionalData, path, value);
@@ -824,25 +897,29 @@ var FormConstructorService = /** @class */ (function () {
824
897
  * Generates the form template for a repeater question.
825
898
  * @author Will Poulson
826
899
  * @param {?} question The question. Must be of type repeater or else null is returned.
900
+ * @param {?=} index
827
901
  * @return {?} A form group.
828
902
  */
829
903
  FormConstructorService.prototype.generateFormsForRepeater = /**
830
904
  * Generates the form template for a repeater question.
831
905
  * @author Will Poulson
832
906
  * @param {?} question The question. Must be of type repeater or else null is returned.
907
+ * @param {?=} index
833
908
  * @return {?} A form group.
834
909
  */
835
- function (question) {
910
+ function (question, index) {
836
911
  var e_4, _a;
837
912
  if (question.type !== QuestionType.Repeater || question.repeaterQuestions.length === 0) {
838
913
  console.log('Question isnt a repeater or has no questions, returning null');
839
914
  return null;
840
915
  }
841
916
  /** @type {?} */
917
+ var repeaterQuestions = index ? question.filteredRepeaterQuestions[index] : question.repeaterQuestions;
918
+ /** @type {?} */
842
919
  var repeaterForms = this.fb.group({});
843
920
  try {
844
- for (var _b = __values(question.repeaterQuestions), _c = _b.next(); !_c.done; _c = _b.next()) {
845
- var repeaterQuestion = _c.value;
921
+ for (var repeaterQuestions_1 = __values(repeaterQuestions), repeaterQuestions_1_1 = repeaterQuestions_1.next(); !repeaterQuestions_1_1.done; repeaterQuestions_1_1 = repeaterQuestions_1.next()) {
922
+ var repeaterQuestion = repeaterQuestions_1_1.value;
846
923
  /** @type {?} */
847
924
  var repeaterQuestionControl = this.generateControlForRepeaterQuestion(repeaterQuestion);
848
925
  repeaterForms.addControl(repeaterQuestion.name, repeaterQuestionControl);
@@ -851,7 +928,7 @@ var FormConstructorService = /** @class */ (function () {
851
928
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
852
929
  finally {
853
930
  try {
854
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
931
+ if (repeaterQuestions_1_1 && !repeaterQuestions_1_1.done && (_a = repeaterQuestions_1.return)) _a.call(repeaterQuestions_1);
855
932
  }
856
933
  finally { if (e_4) throw e_4.error; }
857
934
  }
@@ -1001,7 +1078,9 @@ var FormConstructorService = /** @class */ (function () {
1001
1078
  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()) {
1002
1079
  var repeaterItem = repeaterArray_1_1.value;
1003
1080
  /** @type {?} */
1004
- var repeaterItemTemplate = this.generateFormsForRepeater(question);
1081
+ var index = repeaterArray.indexOf(repeaterItem);
1082
+ /** @type {?} */
1083
+ var repeaterItemTemplate = this.generateFormsForRepeater(question, index);
1005
1084
  repeaterFormArray.push(repeaterItemTemplate);
1006
1085
  }
1007
1086
  }