@glowgreen/gg-questionnaire-v2 0.0.70 → 0.0.72

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.
@@ -1011,34 +1011,78 @@
1011
1011
  var newArray = this.fb.array([], convertedValidators);
1012
1012
  /** @type {?} */
1013
1013
  var currentArray = currentQuestionnaireForm ? ((/** @type {?} */ (currentQuestionnaireForm.get([section.name, question.name])))) : false;
1014
- if (currentArray) {
1015
- console.log('Has current array');
1016
- /** @type {?} */
1017
- var controlsSnapshot = lodash.clone(currentArray.controls);
1018
- try {
1019
- for (var controlsSnapshot_1 = __values(controlsSnapshot), controlsSnapshot_1_1 = controlsSnapshot_1.next(); !controlsSnapshot_1_1.done; controlsSnapshot_1_1 = controlsSnapshot_1.next()) {
1020
- var item = controlsSnapshot_1_1.value;
1021
- console.log('Got item', item);
1022
- /** @type {?} */
1023
- var index = currentArray.controls.indexOf(item);
1024
- /** @type {?} */
1025
- var group = this.generateFormsForRepeater(question, index);
1026
- console.log('Filtered to', group);
1027
- // Gross comparison below. Could be optimised however it's here to avoid inf loop.
1028
- /** @type {?} */
1029
- var currentItemStrinify = JSON.stringify(Object.keys(item.controls));
1030
- /** @type {?} */
1031
- var newItemStringify = JSON.stringify(Object.keys(group.controls));
1032
- if (currentItemStrinify !== newItemStringify) {
1033
- group.patchValue(item.value);
1034
- currentArray.setControl(index, group);
1014
+ if (currentArray && question.filteredRepeaterQuestions) {
1015
+ var _loop_1 = function (control) {
1016
+ var e_4, _a, e_5, _b;
1017
+ /** @type {?} */
1018
+ var index = currentArray.controls.indexOf(control);
1019
+ if (!index) {
1020
+ return "continue";
1021
+ }
1022
+ /** @type {?} */
1023
+ var filteredQuestions = question.filteredRepeaterQuestions[index];
1024
+ if (!filteredQuestions) {
1025
+ return "continue";
1026
+ }
1027
+ /** @type {?} */
1028
+ var filteredQuestionNames = filteredQuestions.map((/**
1029
+ * @param {?} x
1030
+ * @return {?}
1031
+ */
1032
+ function (x) { return x.name; }));
1033
+ /** @type {?} */
1034
+ var filteredOutQuestions = question.repeaterQuestions.filter((/**
1035
+ * @param {?} x
1036
+ * @return {?}
1037
+ */
1038
+ function (x) { return !filteredQuestionNames.includes(x.name); }));
1039
+ console.log('Triggering filtering for item', index);
1040
+ try {
1041
+ for (var filteredOutQuestions_1 = (e_4 = void 0, __values(filteredOutQuestions)), filteredOutQuestions_1_1 = filteredOutQuestions_1.next(); !filteredOutQuestions_1_1.done; filteredOutQuestions_1_1 = filteredOutQuestions_1.next()) {
1042
+ var filteredOutQuestion = filteredOutQuestions_1_1.value;
1043
+ /** @type {?} */
1044
+ var childControl = control.get(filteredOutQuestion.name);
1045
+ childControl.setValidators([]);
1046
+ childControl.updateValueAndValidity({ onlySelf: true, emitEvent: false });
1035
1047
  }
1036
1048
  }
1049
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1050
+ finally {
1051
+ try {
1052
+ if (filteredOutQuestions_1_1 && !filteredOutQuestions_1_1.done && (_a = filteredOutQuestions_1.return)) _a.call(filteredOutQuestions_1);
1053
+ }
1054
+ finally { if (e_4) throw e_4.error; }
1055
+ }
1056
+ try {
1057
+ for (var filteredQuestions_1 = (e_5 = void 0, __values(filteredQuestions)), filteredQuestions_1_1 = filteredQuestions_1.next(); !filteredQuestions_1_1.done; filteredQuestions_1_1 = filteredQuestions_1.next()) {
1058
+ var filteredQuestion = filteredQuestions_1_1.value;
1059
+ /** @type {?} */
1060
+ var childControl = control.get(filteredQuestion.name);
1061
+ /** @type {?} */
1062
+ var convertedValidators_1 = this_1.convertValidators(filteredQuestion.validators);
1063
+ childControl.setValidators(convertedValidators_1);
1064
+ childControl.updateValueAndValidity({ onlySelf: true, emitEvent: false });
1065
+ }
1066
+ }
1067
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1068
+ finally {
1069
+ try {
1070
+ if (filteredQuestions_1_1 && !filteredQuestions_1_1.done && (_b = filteredQuestions_1.return)) _b.call(filteredQuestions_1);
1071
+ }
1072
+ finally { if (e_5) throw e_5.error; }
1073
+ }
1074
+ };
1075
+ var this_1 = this;
1076
+ try {
1077
+ for (var _b = __values(currentArray.controls), _c = _b.next(); !_c.done; _c = _b.next()) {
1078
+ var control = _c.value;
1079
+ _loop_1(control);
1080
+ }
1037
1081
  }
1038
1082
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
1039
1083
  finally {
1040
1084
  try {
1041
- if (controlsSnapshot_1_1 && !controlsSnapshot_1_1.done && (_a = controlsSnapshot_1.return)) _a.call(controlsSnapshot_1);
1085
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1042
1086
  }
1043
1087
  finally { if (e_3) throw e_3.error; }
1044
1088
  }
@@ -1075,7 +1119,7 @@
1075
1119
  * @return {?} A form group.
1076
1120
  */
1077
1121
  function (question, convertedValidators) {
1078
- var e_4, _a;
1122
+ var e_6, _a;
1079
1123
  if (question.type !== QuestionType.Checklist || question.checklistItems.length === 0) {
1080
1124
  return null;
1081
1125
  }
@@ -1089,12 +1133,12 @@
1089
1133
  checklistForms.addControl(checklistItem.name, checklistItemControl);
1090
1134
  }
1091
1135
  }
1092
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1136
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1093
1137
  finally {
1094
1138
  try {
1095
1139
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1096
1140
  }
1097
- finally { if (e_4) throw e_4.error; }
1141
+ finally { if (e_6) throw e_6.error; }
1098
1142
  }
1099
1143
  return checklistForms;
1100
1144
  };
@@ -1119,39 +1163,27 @@
1119
1163
  * @return {?} A form group.
1120
1164
  */
1121
1165
  function (question, index) {
1122
- var e_5, _a;
1166
+ var e_7, _a;
1123
1167
  if (question.type !== QuestionType.Repeater || question.repeaterQuestions.length === 0) {
1124
1168
  console.log('Question isnt a repeater or has no questions, returning null');
1125
1169
  return null;
1126
1170
  }
1127
1171
  /** @type {?} */
1128
- var repeaterQuestions = question.repeaterQuestions;
1129
- if (question.filteredRepeaterQuestions && question.filteredRepeaterQuestions[index]) {
1130
- repeaterQuestions = question.filteredRepeaterQuestions[index];
1131
- }
1132
- console.log('Index passed', index);
1133
- console.log('All filtered questions', question.filteredRepeaterQuestions);
1134
- console.log('Got the following repeater questions', repeaterQuestions.map((/**
1135
- * @param {?} x
1136
- * @return {?}
1137
- */
1138
- function (x) { return x.name; })));
1139
- /** @type {?} */
1140
1172
  var repeaterForms = this.fb.group({});
1141
1173
  try {
1142
- for (var repeaterQuestions_1 = __values(repeaterQuestions), repeaterQuestions_1_1 = repeaterQuestions_1.next(); !repeaterQuestions_1_1.done; repeaterQuestions_1_1 = repeaterQuestions_1.next()) {
1143
- var repeaterQuestion = repeaterQuestions_1_1.value;
1174
+ for (var _b = __values(question.repeaterQuestions), _c = _b.next(); !_c.done; _c = _b.next()) {
1175
+ var repeaterQuestion = _c.value;
1144
1176
  /** @type {?} */
1145
1177
  var repeaterQuestionControl = this.generateControlForRepeaterQuestion(repeaterQuestion);
1146
1178
  repeaterForms.addControl(repeaterQuestion.name, repeaterQuestionControl);
1147
1179
  }
1148
1180
  }
1149
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1181
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1150
1182
  finally {
1151
1183
  try {
1152
- if (repeaterQuestions_1_1 && !repeaterQuestions_1_1.done && (_a = repeaterQuestions_1.return)) _a.call(repeaterQuestions_1);
1184
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1153
1185
  }
1154
- finally { if (e_5) throw e_5.error; }
1186
+ finally { if (e_7) throw e_7.error; }
1155
1187
  }
1156
1188
  return repeaterForms;
1157
1189
  };
@@ -1201,7 +1233,7 @@
1201
1233
  * @return {?} A convered array of form validators.
1202
1234
  */
1203
1235
  function (validators) {
1204
- var e_6, _a;
1236
+ var e_8, _a;
1205
1237
  if (!validators || validators.length === 0) {
1206
1238
  return [];
1207
1239
  }
@@ -1217,12 +1249,12 @@
1217
1249
  }
1218
1250
  }
1219
1251
  }
1220
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1252
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
1221
1253
  finally {
1222
1254
  try {
1223
1255
  if (validators_1_1 && !validators_1_1.done && (_a = validators_1.return)) _a.call(validators_1);
1224
1256
  }
1225
- finally { if (e_6) throw e_6.error; }
1257
+ finally { if (e_8) throw e_8.error; }
1226
1258
  }
1227
1259
  return convertedValidators;
1228
1260
  };
@@ -1274,12 +1306,12 @@
1274
1306
  * @return {?}
1275
1307
  */
1276
1308
  function (savedState, sections, currentQuestionnaireForm) {
1277
- var e_7, _a, e_8, _b, e_9, _c;
1309
+ var e_9, _a, e_10, _b, e_11, _c;
1278
1310
  try {
1279
1311
  for (var sections_2 = __values(sections), sections_2_1 = sections_2.next(); !sections_2_1.done; sections_2_1 = sections_2.next()) {
1280
1312
  var section = sections_2_1.value;
1281
1313
  try {
1282
- for (var _d = (e_8 = void 0, __values(section.questions)), _e = _d.next(); !_e.done; _e = _d.next()) {
1314
+ for (var _d = (e_10 = void 0, __values(section.questions)), _e = _d.next(); !_e.done; _e = _d.next()) {
1283
1315
  var question = _e.value;
1284
1316
  if (question.type !== QuestionType.Repeater) {
1285
1317
  continue;
@@ -1296,7 +1328,7 @@
1296
1328
  }
1297
1329
  try {
1298
1330
  // For each item that used to be there push a new empty template there to be populated.
1299
- for (var repeaterArray_1 = (e_9 = void 0, __values(repeaterArray)), repeaterArray_1_1 = repeaterArray_1.next(); !repeaterArray_1_1.done; repeaterArray_1_1 = repeaterArray_1.next()) {
1331
+ for (var repeaterArray_1 = (e_11 = void 0, __values(repeaterArray)), repeaterArray_1_1 = repeaterArray_1.next(); !repeaterArray_1_1.done; repeaterArray_1_1 = repeaterArray_1.next()) {
1300
1332
  var repeaterItem = repeaterArray_1_1.value;
1301
1333
  /** @type {?} */
1302
1334
  var index = repeaterArray.indexOf(repeaterItem);
@@ -1305,30 +1337,30 @@
1305
1337
  repeaterFormArray.push(repeaterItemTemplate);
1306
1338
  }
1307
1339
  }
1308
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1340
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1309
1341
  finally {
1310
1342
  try {
1311
1343
  if (repeaterArray_1_1 && !repeaterArray_1_1.done && (_c = repeaterArray_1.return)) _c.call(repeaterArray_1);
1312
1344
  }
1313
- finally { if (e_9) throw e_9.error; }
1345
+ finally { if (e_11) throw e_11.error; }
1314
1346
  }
1315
1347
  }
1316
1348
  }
1317
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1349
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
1318
1350
  finally {
1319
1351
  try {
1320
1352
  if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
1321
1353
  }
1322
- finally { if (e_8) throw e_8.error; }
1354
+ finally { if (e_10) throw e_10.error; }
1323
1355
  }
1324
1356
  }
1325
1357
  }
1326
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1358
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1327
1359
  finally {
1328
1360
  try {
1329
1361
  if (sections_2_1 && !sections_2_1.done && (_a = sections_2.return)) _a.call(sections_2);
1330
1362
  }
1331
- finally { if (e_7) throw e_7.error; }
1363
+ finally { if (e_9) throw e_9.error; }
1332
1364
  }
1333
1365
  };
1334
1366
  FormConstructorService.decorators = [