@glowgreen/gg-questionnaire-v2 0.0.69 → 0.0.71

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,42 +1011,77 @@
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(item.controls.map((/**
1030
- * @param {?} x
1031
- * @return {?}
1032
- */
1033
- function (x) { return name; })));
1034
- /** @type {?} */
1035
- var newItemStringify = JSON.stringify(((/** @type {?} */ (group))).controls.map((/**
1036
- * @param {?} x
1037
- * @return {?}
1038
- */
1039
- function (x) { return name; })));
1040
- if (currentItemStrinify !== newItemStringify) {
1041
- group.patchValue(item.value);
1042
- 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
+ try {
1040
+ 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()) {
1041
+ var filteredOutQuestion = filteredOutQuestions_1_1.value;
1042
+ /** @type {?} */
1043
+ var childControl = control.get(filteredOutQuestion.name);
1044
+ childControl.setValidators([]);
1045
+ childControl.updateValueAndValidity();
1043
1046
  }
1044
1047
  }
1048
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1049
+ finally {
1050
+ try {
1051
+ if (filteredOutQuestions_1_1 && !filteredOutQuestions_1_1.done && (_a = filteredOutQuestions_1.return)) _a.call(filteredOutQuestions_1);
1052
+ }
1053
+ finally { if (e_4) throw e_4.error; }
1054
+ }
1055
+ try {
1056
+ 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()) {
1057
+ var filteredQuestion = filteredQuestions_1_1.value;
1058
+ /** @type {?} */
1059
+ var childControl = control.get(filteredQuestion.name);
1060
+ /** @type {?} */
1061
+ var convertedValidators_1 = this_1.convertValidators(filteredQuestion.validators);
1062
+ childControl.setValidators(convertedValidators_1);
1063
+ childControl.updateValueAndValidity();
1064
+ }
1065
+ }
1066
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1067
+ finally {
1068
+ try {
1069
+ if (filteredQuestions_1_1 && !filteredQuestions_1_1.done && (_b = filteredQuestions_1.return)) _b.call(filteredQuestions_1);
1070
+ }
1071
+ finally { if (e_5) throw e_5.error; }
1072
+ }
1073
+ };
1074
+ var this_1 = this;
1075
+ try {
1076
+ for (var _b = __values(currentArray.controls), _c = _b.next(); !_c.done; _c = _b.next()) {
1077
+ var control = _c.value;
1078
+ _loop_1(control);
1079
+ }
1045
1080
  }
1046
1081
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
1047
1082
  finally {
1048
1083
  try {
1049
- if (controlsSnapshot_1_1 && !controlsSnapshot_1_1.done && (_a = controlsSnapshot_1.return)) _a.call(controlsSnapshot_1);
1084
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1050
1085
  }
1051
1086
  finally { if (e_3) throw e_3.error; }
1052
1087
  }
@@ -1083,7 +1118,7 @@
1083
1118
  * @return {?} A form group.
1084
1119
  */
1085
1120
  function (question, convertedValidators) {
1086
- var e_4, _a;
1121
+ var e_6, _a;
1087
1122
  if (question.type !== QuestionType.Checklist || question.checklistItems.length === 0) {
1088
1123
  return null;
1089
1124
  }
@@ -1097,12 +1132,12 @@
1097
1132
  checklistForms.addControl(checklistItem.name, checklistItemControl);
1098
1133
  }
1099
1134
  }
1100
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1135
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1101
1136
  finally {
1102
1137
  try {
1103
1138
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1104
1139
  }
1105
- finally { if (e_4) throw e_4.error; }
1140
+ finally { if (e_6) throw e_6.error; }
1106
1141
  }
1107
1142
  return checklistForms;
1108
1143
  };
@@ -1127,39 +1162,27 @@
1127
1162
  * @return {?} A form group.
1128
1163
  */
1129
1164
  function (question, index) {
1130
- var e_5, _a;
1165
+ var e_7, _a;
1131
1166
  if (question.type !== QuestionType.Repeater || question.repeaterQuestions.length === 0) {
1132
1167
  console.log('Question isnt a repeater or has no questions, returning null');
1133
1168
  return null;
1134
1169
  }
1135
1170
  /** @type {?} */
1136
- var repeaterQuestions = question.repeaterQuestions;
1137
- if (question.filteredRepeaterQuestions && question.filteredRepeaterQuestions[index]) {
1138
- repeaterQuestions = question.filteredRepeaterQuestions[index];
1139
- }
1140
- console.log('Index passed', index);
1141
- console.log('All filtered questions', question.filteredRepeaterQuestions);
1142
- console.log('Got the following repeater questions', repeaterQuestions.map((/**
1143
- * @param {?} x
1144
- * @return {?}
1145
- */
1146
- function (x) { return x.name; })));
1147
- /** @type {?} */
1148
1171
  var repeaterForms = this.fb.group({});
1149
1172
  try {
1150
- for (var repeaterQuestions_1 = __values(repeaterQuestions), repeaterQuestions_1_1 = repeaterQuestions_1.next(); !repeaterQuestions_1_1.done; repeaterQuestions_1_1 = repeaterQuestions_1.next()) {
1151
- var repeaterQuestion = repeaterQuestions_1_1.value;
1173
+ for (var _b = __values(question.repeaterQuestions), _c = _b.next(); !_c.done; _c = _b.next()) {
1174
+ var repeaterQuestion = _c.value;
1152
1175
  /** @type {?} */
1153
1176
  var repeaterQuestionControl = this.generateControlForRepeaterQuestion(repeaterQuestion);
1154
1177
  repeaterForms.addControl(repeaterQuestion.name, repeaterQuestionControl);
1155
1178
  }
1156
1179
  }
1157
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1180
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1158
1181
  finally {
1159
1182
  try {
1160
- if (repeaterQuestions_1_1 && !repeaterQuestions_1_1.done && (_a = repeaterQuestions_1.return)) _a.call(repeaterQuestions_1);
1183
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1161
1184
  }
1162
- finally { if (e_5) throw e_5.error; }
1185
+ finally { if (e_7) throw e_7.error; }
1163
1186
  }
1164
1187
  return repeaterForms;
1165
1188
  };
@@ -1209,7 +1232,7 @@
1209
1232
  * @return {?} A convered array of form validators.
1210
1233
  */
1211
1234
  function (validators) {
1212
- var e_6, _a;
1235
+ var e_8, _a;
1213
1236
  if (!validators || validators.length === 0) {
1214
1237
  return [];
1215
1238
  }
@@ -1225,12 +1248,12 @@
1225
1248
  }
1226
1249
  }
1227
1250
  }
1228
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1251
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
1229
1252
  finally {
1230
1253
  try {
1231
1254
  if (validators_1_1 && !validators_1_1.done && (_a = validators_1.return)) _a.call(validators_1);
1232
1255
  }
1233
- finally { if (e_6) throw e_6.error; }
1256
+ finally { if (e_8) throw e_8.error; }
1234
1257
  }
1235
1258
  return convertedValidators;
1236
1259
  };
@@ -1282,12 +1305,12 @@
1282
1305
  * @return {?}
1283
1306
  */
1284
1307
  function (savedState, sections, currentQuestionnaireForm) {
1285
- var e_7, _a, e_8, _b, e_9, _c;
1308
+ var e_9, _a, e_10, _b, e_11, _c;
1286
1309
  try {
1287
1310
  for (var sections_2 = __values(sections), sections_2_1 = sections_2.next(); !sections_2_1.done; sections_2_1 = sections_2.next()) {
1288
1311
  var section = sections_2_1.value;
1289
1312
  try {
1290
- for (var _d = (e_8 = void 0, __values(section.questions)), _e = _d.next(); !_e.done; _e = _d.next()) {
1313
+ for (var _d = (e_10 = void 0, __values(section.questions)), _e = _d.next(); !_e.done; _e = _d.next()) {
1291
1314
  var question = _e.value;
1292
1315
  if (question.type !== QuestionType.Repeater) {
1293
1316
  continue;
@@ -1304,7 +1327,7 @@
1304
1327
  }
1305
1328
  try {
1306
1329
  // For each item that used to be there push a new empty template there to be populated.
1307
- 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()) {
1330
+ 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()) {
1308
1331
  var repeaterItem = repeaterArray_1_1.value;
1309
1332
  /** @type {?} */
1310
1333
  var index = repeaterArray.indexOf(repeaterItem);
@@ -1313,30 +1336,30 @@
1313
1336
  repeaterFormArray.push(repeaterItemTemplate);
1314
1337
  }
1315
1338
  }
1316
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1339
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1317
1340
  finally {
1318
1341
  try {
1319
1342
  if (repeaterArray_1_1 && !repeaterArray_1_1.done && (_c = repeaterArray_1.return)) _c.call(repeaterArray_1);
1320
1343
  }
1321
- finally { if (e_9) throw e_9.error; }
1344
+ finally { if (e_11) throw e_11.error; }
1322
1345
  }
1323
1346
  }
1324
1347
  }
1325
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1348
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
1326
1349
  finally {
1327
1350
  try {
1328
1351
  if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
1329
1352
  }
1330
- finally { if (e_8) throw e_8.error; }
1353
+ finally { if (e_10) throw e_10.error; }
1331
1354
  }
1332
1355
  }
1333
1356
  }
1334
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1357
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1335
1358
  finally {
1336
1359
  try {
1337
1360
  if (sections_2_1 && !sections_2_1.done && (_a = sections_2.return)) _a.call(sections_2);
1338
1361
  }
1339
- finally { if (e_7) throw e_7.error; }
1362
+ finally { if (e_9) throw e_9.error; }
1340
1363
  }
1341
1364
  };
1342
1365
  FormConstructorService.decorators = [