@glowgreen/gg-questionnaire-v2 0.0.1

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.
Files changed (79) hide show
  1. package/bundles/glowgreen-gg-questionnaire-v2.umd.js +2102 -0
  2. package/bundles/glowgreen-gg-questionnaire-v2.umd.js.map +1 -0
  3. package/bundles/glowgreen-gg-questionnaire-v2.umd.min.js +2 -0
  4. package/bundles/glowgreen-gg-questionnaire-v2.umd.min.js.map +1 -0
  5. package/esm2015/glowgreen-gg-questionnaire-v2.js +11 -0
  6. package/esm2015/lib/enums/condition-relationship.enum.js +11 -0
  7. package/esm2015/lib/enums/condition-type.enum.js +15 -0
  8. package/esm2015/lib/enums/input-type.enum.js +20 -0
  9. package/esm2015/lib/enums/question-type.enum.js +17 -0
  10. package/esm2015/lib/enums/repeater-question-type.enum.js +11 -0
  11. package/esm2015/lib/enums/validation-type.enum.js +15 -0
  12. package/esm2015/lib/gg-questionnaire-v2.module.js +41 -0
  13. package/esm2015/lib/interfaces/attachment.js +15 -0
  14. package/esm2015/lib/interfaces/checklist-item.js +15 -0
  15. package/esm2015/lib/interfaces/condition-group.js +15 -0
  16. package/esm2015/lib/interfaces/condition.js +17 -0
  17. package/esm2015/lib/interfaces/question.js +41 -0
  18. package/esm2015/lib/interfaces/questionnaire-options.js +21 -0
  19. package/esm2015/lib/interfaces/questionnaire.js +15 -0
  20. package/esm2015/lib/interfaces/repeater-question.js +27 -0
  21. package/esm2015/lib/interfaces/section.js +19 -0
  22. package/esm2015/lib/interfaces/select-option.js +15 -0
  23. package/esm2015/lib/interfaces/validator.js +15 -0
  24. package/esm2015/lib/services/filter.service.js +258 -0
  25. package/esm2015/lib/services/form-constructor.service.js +245 -0
  26. package/esm2015/lib/services/questionnaire.service.js +644 -0
  27. package/esm2015/public_api.js +16 -0
  28. package/esm5/glowgreen-gg-questionnaire-v2.js +11 -0
  29. package/esm5/lib/enums/condition-relationship.enum.js +11 -0
  30. package/esm5/lib/enums/condition-type.enum.js +15 -0
  31. package/esm5/lib/enums/input-type.enum.js +20 -0
  32. package/esm5/lib/enums/question-type.enum.js +17 -0
  33. package/esm5/lib/enums/repeater-question-type.enum.js +11 -0
  34. package/esm5/lib/enums/validation-type.enum.js +15 -0
  35. package/esm5/lib/gg-questionnaire-v2.module.js +49 -0
  36. package/esm5/lib/interfaces/attachment.js +15 -0
  37. package/esm5/lib/interfaces/checklist-item.js +15 -0
  38. package/esm5/lib/interfaces/condition-group.js +15 -0
  39. package/esm5/lib/interfaces/condition.js +17 -0
  40. package/esm5/lib/interfaces/question.js +41 -0
  41. package/esm5/lib/interfaces/questionnaire-options.js +21 -0
  42. package/esm5/lib/interfaces/questionnaire.js +15 -0
  43. package/esm5/lib/interfaces/repeater-question.js +27 -0
  44. package/esm5/lib/interfaces/section.js +19 -0
  45. package/esm5/lib/interfaces/select-option.js +15 -0
  46. package/esm5/lib/interfaces/validator.js +15 -0
  47. package/esm5/lib/services/filter.service.js +445 -0
  48. package/esm5/lib/services/form-constructor.service.js +460 -0
  49. package/esm5/lib/services/questionnaire.service.js +943 -0
  50. package/esm5/public_api.js +16 -0
  51. package/fesm2015/glowgreen-gg-questionnaire-v2.js +1194 -0
  52. package/fesm2015/glowgreen-gg-questionnaire-v2.js.map +1 -0
  53. package/fesm5/glowgreen-gg-questionnaire-v2.js +1897 -0
  54. package/fesm5/glowgreen-gg-questionnaire-v2.js.map +1 -0
  55. package/glowgreen-gg-questionnaire-v2.d.ts +6 -0
  56. package/glowgreen-gg-questionnaire-v2.metadata.json +1 -0
  57. package/lib/enums/condition-relationship.enum.d.ts +4 -0
  58. package/lib/enums/condition-type.enum.d.ts +8 -0
  59. package/lib/enums/input-type.enum.d.ts +13 -0
  60. package/lib/enums/question-type.enum.d.ts +10 -0
  61. package/lib/enums/repeater-question-type.enum.d.ts +4 -0
  62. package/lib/enums/validation-type.enum.d.ts +8 -0
  63. package/lib/gg-questionnaire-v2.module.d.ts +5 -0
  64. package/lib/interfaces/attachment.d.ts +4 -0
  65. package/lib/interfaces/checklist-item.d.ts +4 -0
  66. package/lib/interfaces/condition-group.d.ts +6 -0
  67. package/lib/interfaces/condition.d.ts +6 -0
  68. package/lib/interfaces/question.d.ts +24 -0
  69. package/lib/interfaces/questionnaire-options.d.ts +7 -0
  70. package/lib/interfaces/questionnaire.d.ts +5 -0
  71. package/lib/interfaces/repeater-question.d.ts +15 -0
  72. package/lib/interfaces/section.d.ts +8 -0
  73. package/lib/interfaces/select-option.d.ts +4 -0
  74. package/lib/interfaces/validator.d.ts +5 -0
  75. package/lib/services/filter.service.d.ts +62 -0
  76. package/lib/services/form-constructor.service.d.ts +78 -0
  77. package/lib/services/questionnaire.service.d.ts +163 -0
  78. package/package.json +21 -0
  79. package/public_api.d.ts +17 -0
@@ -0,0 +1,1897 @@
1
+ import { __values, __awaiter, __generator } from 'tslib';
2
+ import { cloneDeep } from 'lodash';
3
+ import { Injectable, NgModule, defineInjectable, inject, EventEmitter, Inject } from '@angular/core';
4
+ import { FormBuilder, Validators, FormsModule, ReactiveFormsModule, FormArray } from '@angular/forms';
5
+
6
+ /**
7
+ * @fileoverview added by tsickle
8
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
9
+ */
10
+ /** @enum {string} */
11
+ var QuestionType = {
12
+ Input: 'input',
13
+ Select: 'select',
14
+ Textarea: 'textarea',
15
+ Repeater: 'repeater',
16
+ Checklist: 'checklist',
17
+ Attachment: 'attachment',
18
+ Upload: 'upload',
19
+ Signature: 'signature',
20
+ };
21
+
22
+ /**
23
+ * @fileoverview added by tsickle
24
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
25
+ */
26
+ /** @enum {string} */
27
+ var ConditionType = {
28
+ EqualTo: 'equalTo',
29
+ NotEqualTo: 'notEqualTo',
30
+ LessThan: 'lessThan',
31
+ GreaterThan: 'greaterThan',
32
+ Includes: 'includes',
33
+ Excludes: 'excludes',
34
+ };
35
+
36
+ /**
37
+ * @fileoverview added by tsickle
38
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
39
+ */
40
+ /** @enum {string} */
41
+ var ConditionRelationship = {
42
+ Every: 'every',
43
+ Any: 'any',
44
+ };
45
+
46
+ /**
47
+ * @fileoverview added by tsickle
48
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
49
+ */
50
+ var FilterService = /** @class */ (function () {
51
+ function FilterService() {
52
+ }
53
+ /**
54
+ * Filters an array of sections based on their condition groups.
55
+ * @param sections The array of sections to filter.
56
+ * @param currentQuestionnaireForm The current form data, can be null/undefined.
57
+ * @returns An array of filtered sections with their filtered questions.
58
+ * @author Will Poulson
59
+ */
60
+ /**
61
+ * Filters an array of sections based on their condition groups.
62
+ * @author Will Poulson
63
+ * @param {?} sections The array of sections to filter.
64
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
65
+ * @return {?} An array of filtered sections with their filtered questions.
66
+ */
67
+ FilterService.prototype.filterSections = /**
68
+ * Filters an array of sections based on their condition groups.
69
+ * @author Will Poulson
70
+ * @param {?} sections The array of sections to filter.
71
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
72
+ * @return {?} An array of filtered sections with their filtered questions.
73
+ */
74
+ function (sections, currentQuestionnaireForm) {
75
+ var e_1, _a, e_2, _b, e_3, _c;
76
+ /** @type {?} */
77
+ var filteredSections = [];
78
+ try {
79
+ for (var sections_1 = __values(sections), sections_1_1 = sections_1.next(); !sections_1_1.done; sections_1_1 = sections_1.next()) {
80
+ var section = sections_1_1.value;
81
+ if (this.meetsConditionGroups(section.conditionGroups, currentQuestionnaireForm)) {
82
+ /** @type {?} */
83
+ var filteredQuestions = [];
84
+ try {
85
+ for (var _d = __values(section.questions), _e = _d.next(); !_e.done; _e = _d.next()) {
86
+ var question = _e.value;
87
+ if (this.meetsConditionGroups(question.conditionGroups, currentQuestionnaireForm)) {
88
+ if (question.repeaterQuestions) {
89
+ try {
90
+ for (var _f = __values(question.repeaterQuestions), _g = _f.next(); !_g.done; _g = _f.next()) {
91
+ var repeaterQuestion = _g.value;
92
+ if (this.meetsConditionGroups(repeaterQuestion.conditionGroups, currentQuestionnaireForm)) ;
93
+ }
94
+ }
95
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
96
+ finally {
97
+ try {
98
+ if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
99
+ }
100
+ finally { if (e_3) throw e_3.error; }
101
+ }
102
+ }
103
+ filteredQuestions.push(question);
104
+ }
105
+ }
106
+ }
107
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
108
+ finally {
109
+ try {
110
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
111
+ }
112
+ finally { if (e_2) throw e_2.error; }
113
+ }
114
+ section.questions = filteredQuestions;
115
+ filteredSections.push(section);
116
+ }
117
+ }
118
+ }
119
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
120
+ finally {
121
+ try {
122
+ if (sections_1_1 && !sections_1_1.done && (_a = sections_1.return)) _a.call(sections_1);
123
+ }
124
+ finally { if (e_1) throw e_1.error; }
125
+ }
126
+ return filteredSections;
127
+ };
128
+ /**
129
+ * Checks if each condition groups conditions have been met.
130
+ * @param conditionGroups The array of condition groups.
131
+ * @param currentQuestionnaireForm The current form data, can be null/undefined.
132
+ * @returns A boolean stating if the condition groups conditions has been met.
133
+ * @author Will Poulson
134
+ */
135
+ /**
136
+ * Checks if each condition groups conditions have been met.
137
+ * @author Will Poulson
138
+ * @private
139
+ * @param {?} conditionGroups The array of condition groups.
140
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
141
+ * @return {?} A boolean stating if the condition groups conditions has been met.
142
+ */
143
+ FilterService.prototype.meetsConditionGroups = /**
144
+ * Checks if each condition groups conditions have been met.
145
+ * @author Will Poulson
146
+ * @private
147
+ * @param {?} conditionGroups The array of condition groups.
148
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
149
+ * @return {?} A boolean stating if the condition groups conditions has been met.
150
+ */
151
+ function (conditionGroups, currentQuestionnaireForm) {
152
+ var _this = this;
153
+ if (!conditionGroups || conditionGroups.length === 0) {
154
+ return true;
155
+ }
156
+ return conditionGroups.every((/**
157
+ * @param {?} x
158
+ * @return {?}
159
+ */
160
+ function (x) {
161
+ return _this.meetsConditionGroup(x, currentQuestionnaireForm) === true;
162
+ }));
163
+ };
164
+ /**
165
+ * Checks if a condition groups conditions have been met.
166
+ * @param conditionGroup The condition group to check.
167
+ * @param currentQuestionnaireForm The current form data, can be null/undefined.
168
+ * @returns A boolean stating if the condition group conditions has been met.
169
+ * @author Will Poulson
170
+ */
171
+ /**
172
+ * Checks if a condition groups conditions have been met.
173
+ * @author Will Poulson
174
+ * @private
175
+ * @param {?} conditionGroup The condition group to check.
176
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
177
+ * @return {?} A boolean stating if the condition group conditions has been met.
178
+ */
179
+ FilterService.prototype.meetsConditionGroup = /**
180
+ * Checks if a condition groups conditions have been met.
181
+ * @author Will Poulson
182
+ * @private
183
+ * @param {?} conditionGroup The condition group to check.
184
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
185
+ * @return {?} A boolean stating if the condition group conditions has been met.
186
+ */
187
+ function (conditionGroup, currentQuestionnaireForm) {
188
+ var e_4, _a;
189
+ if (!conditionGroup.conditions || conditionGroup.conditions.length === 0) {
190
+ return true;
191
+ }
192
+ /** @type {?} */
193
+ var results = [];
194
+ try {
195
+ for (var _b = __values(conditionGroup.conditions), _c = _b.next(); !_c.done; _c = _b.next()) {
196
+ var condition = _c.value;
197
+ results.push(this.meetsCondition(condition, currentQuestionnaireForm));
198
+ }
199
+ }
200
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
201
+ finally {
202
+ try {
203
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
204
+ }
205
+ finally { if (e_4) throw e_4.error; }
206
+ }
207
+ switch (conditionGroup.relationship) {
208
+ case ConditionRelationship.Every:
209
+ return results.every((/**
210
+ * @param {?} x
211
+ * @return {?}
212
+ */
213
+ function (x) {
214
+ return x === true;
215
+ }));
216
+ case ConditionRelationship.Any:
217
+ return !!results.find((/**
218
+ * @param {?} x
219
+ * @return {?}
220
+ */
221
+ function (x) {
222
+ return x === true;
223
+ }));
224
+ default:
225
+ return true;
226
+ }
227
+ };
228
+ /**
229
+ * Checks if a condition has been met.
230
+ * @param condition The condition to check.
231
+ * @param currentQuestionnaireForm The current form data, can be null/undefined.
232
+ * @returns A boolean stating if the condition group conditions has been met.
233
+ * @author Will Poulson
234
+ */
235
+ /**
236
+ * Checks if a condition has been met.
237
+ * @author Will Poulson
238
+ * @private
239
+ * @param {?} condition The condition to check.
240
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
241
+ * @return {?} A boolean stating if the condition group conditions has been met.
242
+ */
243
+ FilterService.prototype.meetsCondition = /**
244
+ * Checks if a condition has been met.
245
+ * @author Will Poulson
246
+ * @private
247
+ * @param {?} condition The condition to check.
248
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
249
+ * @return {?} A boolean stating if the condition group conditions has been met.
250
+ */
251
+ function (condition, currentQuestionnaireForm) {
252
+ var e_5, _a, e_6, _b;
253
+ /** @type {?} */
254
+ var v1s = this.getValuesForArray(condition.v1s, currentQuestionnaireForm);
255
+ /** @type {?} */
256
+ var v2s = this.getValuesForArray(condition.v2s, currentQuestionnaireForm);
257
+ /** @type {?} */
258
+ var result = false;
259
+ switch (condition.type) {
260
+ case ConditionType.Excludes:
261
+ result = v1s.filter((/**
262
+ * @param {?} v1
263
+ * @return {?}
264
+ */
265
+ function (v1) {
266
+ return v2s.indexOf(v1) > -1;
267
+ })).length === 0;
268
+ break;
269
+ case ConditionType.Includes:
270
+ result = v1s.filter((/**
271
+ * @param {?} v1
272
+ * @return {?}
273
+ */
274
+ function (v1) {
275
+ return v2s.indexOf(v1) > -1;
276
+ })).length !== 0;
277
+ break;
278
+ default: try {
279
+ for (var v2s_1 = __values(v2s), v2s_1_1 = v2s_1.next(); !v2s_1_1.done; v2s_1_1 = v2s_1.next()) {
280
+ var v2 = v2s_1_1.value;
281
+ try {
282
+ for (var v1s_1 = __values(v1s), v1s_1_1 = v1s_1.next(); !v1s_1_1.done; v1s_1_1 = v1s_1.next()) {
283
+ var v1 = v1s_1_1.value;
284
+ switch (condition.type) {
285
+ case ConditionType.EqualTo:
286
+ v1 = this.getStringForValue(v1);
287
+ v2 = this.getStringForValue(v2);
288
+ if (v1 === v2) {
289
+ result = true;
290
+ }
291
+ break;
292
+ case ConditionType.NotEqualTo:
293
+ v1 = this.getStringForValue(v1);
294
+ v2 = this.getStringForValue(v2);
295
+ if (v1 !== v2) {
296
+ result = true;
297
+ }
298
+ break;
299
+ case ConditionType.GreaterThan:
300
+ v1 = parseFloat(v1);
301
+ v2 = parseFloat(v2);
302
+ if (v1 >= v2) {
303
+ result = true;
304
+ }
305
+ break;
306
+ case ConditionType.LessThan:
307
+ v1 = parseFloat(v1);
308
+ v2 = parseFloat(v2);
309
+ if (v1 <= v2) {
310
+ result = true;
311
+ }
312
+ break;
313
+ }
314
+ }
315
+ }
316
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
317
+ finally {
318
+ try {
319
+ if (v1s_1_1 && !v1s_1_1.done && (_b = v1s_1.return)) _b.call(v1s_1);
320
+ }
321
+ finally { if (e_6) throw e_6.error; }
322
+ }
323
+ }
324
+ }
325
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
326
+ finally {
327
+ try {
328
+ if (v2s_1_1 && !v2s_1_1.done && (_a = v2s_1.return)) _a.call(v2s_1);
329
+ }
330
+ finally { if (e_5) throw e_5.error; }
331
+ }
332
+ }
333
+ return result;
334
+ };
335
+ /**
336
+ * @private
337
+ * @param {?} value
338
+ * @return {?}
339
+ */
340
+ FilterService.prototype.getStringForValue = /**
341
+ * @private
342
+ * @param {?} value
343
+ * @return {?}
344
+ */
345
+ function (value) {
346
+ switch (value) {
347
+ case null:
348
+ return 'null';
349
+ default:
350
+ return value.toString();
351
+ }
352
+ };
353
+ /**
354
+ * Gets the current values for an array of strings.
355
+ * @param paths The array of strings to check.
356
+ * @param currentQuestionnaireForm The current form data, can be null/undefined.
357
+ * @returns An array of strings/values
358
+ * @author Will Poulson
359
+ */
360
+ /**
361
+ * Gets the current values for an array of strings.
362
+ * @author Will Poulson
363
+ * @private
364
+ * @param {?} paths The array of strings to check.
365
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
366
+ * @return {?} An array of strings/values
367
+ */
368
+ FilterService.prototype.getValuesForArray = /**
369
+ * Gets the current values for an array of strings.
370
+ * @author Will Poulson
371
+ * @private
372
+ * @param {?} paths The array of strings to check.
373
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
374
+ * @return {?} An array of strings/values
375
+ */
376
+ function (paths, currentQuestionnaireForm) {
377
+ var e_7, _a;
378
+ if (currentQuestionnaireForm) {
379
+ /** @type {?} */
380
+ var values = [];
381
+ try {
382
+ for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
383
+ var path = paths_1_1.value;
384
+ /** @type {?} */
385
+ var value = this.getValueForString(path, currentQuestionnaireForm);
386
+ values.push(value);
387
+ }
388
+ }
389
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
390
+ finally {
391
+ try {
392
+ if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
393
+ }
394
+ finally { if (e_7) throw e_7.error; }
395
+ }
396
+ return values;
397
+ }
398
+ else {
399
+ return paths;
400
+ }
401
+ };
402
+ /**
403
+ * Gets a current value for a string.
404
+ * @param path The string value to check.
405
+ * @param currentQuestionnaireForm The current form data, can be null/undefined.
406
+ * @returns A string/value.
407
+ * @author Will Poulson
408
+ */
409
+ /**
410
+ * Gets a current value for a string.
411
+ * @author Will Poulson
412
+ * @private
413
+ * @param {?} path The string value to check.
414
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
415
+ * @return {?} A string/value.
416
+ */
417
+ FilterService.prototype.getValueForString = /**
418
+ * Gets a current value for a string.
419
+ * @author Will Poulson
420
+ * @private
421
+ * @param {?} path The string value to check.
422
+ * @param {?} currentQuestionnaireForm The current form data, can be null/undefined.
423
+ * @return {?} A string/value.
424
+ */
425
+ function (path, currentQuestionnaireForm) {
426
+ if (currentQuestionnaireForm) {
427
+ /** @type {?} */
428
+ var control = currentQuestionnaireForm.get(path);
429
+ return control ? control.value : this.convertStringToValue(path);
430
+ }
431
+ else {
432
+ return this.convertStringToValue(path);
433
+ }
434
+ };
435
+ /**
436
+ * Converts a string to a value.
437
+ * Eg. true/false.
438
+ * @param path The string value to check for conversion;
439
+ * @returns Either a string or the converted value.
440
+ * @author Will Poulson
441
+ */
442
+ /**
443
+ * Converts a string to a value.
444
+ * Eg. true/false.
445
+ * @author Will Poulson
446
+ * @private
447
+ * @param {?} path The string value to check for conversion;
448
+ * @return {?} Either a string or the converted value.
449
+ */
450
+ FilterService.prototype.convertStringToValue = /**
451
+ * Converts a string to a value.
452
+ * Eg. true/false.
453
+ * @author Will Poulson
454
+ * @private
455
+ * @param {?} path The string value to check for conversion;
456
+ * @return {?} Either a string or the converted value.
457
+ */
458
+ function (path) {
459
+ switch (path) {
460
+ case 'true':
461
+ return true;
462
+ case 'false':
463
+ return false;
464
+ case 'null':
465
+ return null;
466
+ default:
467
+ return path;
468
+ }
469
+ };
470
+ FilterService.decorators = [
471
+ { type: Injectable, args: [{
472
+ providedIn: 'root'
473
+ },] }
474
+ ];
475
+ /** @nocollapse */
476
+ FilterService.ctorParameters = function () { return []; };
477
+ /** @nocollapse */ FilterService.ngInjectableDef = defineInjectable({ factory: function FilterService_Factory() { return new FilterService(); }, token: FilterService, providedIn: "root" });
478
+ return FilterService;
479
+ }());
480
+
481
+ /**
482
+ * @fileoverview added by tsickle
483
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
484
+ */
485
+ /** @enum {string} */
486
+ var ValidationType = {
487
+ Required: 'required',
488
+ Boolean: 'boolean',
489
+ Number: 'number',
490
+ String: 'string',
491
+ Email: 'email',
492
+ Telephone: 'telephone',
493
+ };
494
+
495
+ /**
496
+ * @fileoverview added by tsickle
497
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
498
+ */
499
+ var FormConstructorService = /** @class */ (function () {
500
+ function FormConstructorService(fb, filterService) {
501
+ this.fb = fb;
502
+ this.filterService = filterService;
503
+ }
504
+ /**
505
+ * Constructs a form group based on the questionnaire data.
506
+ * This form group has been filtered down based on the conditions of the sections and questions.
507
+ * @param questionnaire The questionnaire data to build the form group on.
508
+ * @returns A filted form group.
509
+ * @author Will Poulson
510
+ */
511
+ /**
512
+ * Constructs a form group based on the questionnaire data.
513
+ * This form group has been filtered down based on the conditions of the sections and questions.
514
+ * @author Will Poulson
515
+ * @param {?} questionnaire The questionnaire data to build the form group on.
516
+ * @param {?} currentQuestionnaireForm
517
+ * @param {?=} skipFilter
518
+ * @return {?} A filted form group.
519
+ */
520
+ FormConstructorService.prototype.generateFormsForQuestionnaire = /**
521
+ * Constructs a form group based on the questionnaire data.
522
+ * This form group has been filtered down based on the conditions of the sections and questions.
523
+ * @author Will Poulson
524
+ * @param {?} questionnaire The questionnaire data to build the form group on.
525
+ * @param {?} currentQuestionnaireForm
526
+ * @param {?=} skipFilter
527
+ * @return {?} A filted form group.
528
+ */
529
+ function (questionnaire, currentQuestionnaireForm, skipFilter) {
530
+ /** @type {?} */
531
+ var sections = skipFilter ?
532
+ questionnaire.sections :
533
+ this.filterService.filterSections(questionnaire.sections, currentQuestionnaireForm);
534
+ /** @type {?} */
535
+ var questionnaireForms = this.generateFormsForSections(sections, currentQuestionnaireForm);
536
+ return { sections: sections, forms: questionnaireForms };
537
+ };
538
+ /**
539
+ * @private
540
+ * @param {?} sections
541
+ * @param {?} currentQuestionnaireForm
542
+ * @return {?}
543
+ */
544
+ FormConstructorService.prototype.generateFormsForSections = /**
545
+ * @private
546
+ * @param {?} sections
547
+ * @param {?} currentQuestionnaireForm
548
+ * @return {?}
549
+ */
550
+ function (sections, currentQuestionnaireForm) {
551
+ var e_1, _a;
552
+ /** @type {?} */
553
+ var questionnaireForms = this.fb.group({});
554
+ try {
555
+ for (var sections_1 = __values(sections), sections_1_1 = sections_1.next(); !sections_1_1.done; sections_1_1 = sections_1.next()) {
556
+ var section = sections_1_1.value;
557
+ /** @type {?} */
558
+ var sectionForms = this.generateFormsForSection(section, currentQuestionnaireForm);
559
+ questionnaireForms.addControl(section.name, sectionForms);
560
+ }
561
+ }
562
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
563
+ finally {
564
+ try {
565
+ if (sections_1_1 && !sections_1_1.done && (_a = sections_1.return)) _a.call(sections_1);
566
+ }
567
+ finally { if (e_1) throw e_1.error; }
568
+ }
569
+ return questionnaireForms;
570
+ };
571
+ /**
572
+ * Constructs a form group based on the section data.
573
+ * This form group has been filtered down based on the conditions of the questions.
574
+ * @param section The section data to build the form group on.
575
+ * @returns A filtered form group.
576
+ * @author Will Poulson
577
+ */
578
+ /**
579
+ * Constructs a form group based on the section data.
580
+ * This form group has been filtered down based on the conditions of the questions.
581
+ * @author Will Poulson
582
+ * @private
583
+ * @param {?} section The section data to build the form group on.
584
+ * @param {?} currentQuestionnaireForm
585
+ * @return {?} A filtered form group.
586
+ */
587
+ FormConstructorService.prototype.generateFormsForSection = /**
588
+ * Constructs a form group based on the section data.
589
+ * This form group has been filtered down based on the conditions of the questions.
590
+ * @author Will Poulson
591
+ * @private
592
+ * @param {?} section The section data to build the form group on.
593
+ * @param {?} currentQuestionnaireForm
594
+ * @return {?} A filtered form group.
595
+ */
596
+ function (section, currentQuestionnaireForm) {
597
+ var e_2, _a;
598
+ /** @type {?} */
599
+ var sectionForms = this.fb.group({});
600
+ try {
601
+ for (var _b = __values(section.questions), _c = _b.next(); !_c.done; _c = _b.next()) {
602
+ var question = _c.value;
603
+ /** @type {?} */
604
+ var questionControl = this.generateControlForQuestion(question, section, currentQuestionnaireForm);
605
+ sectionForms.addControl(question.name, questionControl);
606
+ }
607
+ }
608
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
609
+ finally {
610
+ try {
611
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
612
+ }
613
+ finally { if (e_2) throw e_2.error; }
614
+ }
615
+ return sectionForms;
616
+ };
617
+ /**
618
+ * Constructs an astract form control based on the question data.
619
+ * @param question The question data to build the abstract control on.
620
+ * @returns An abstract control.
621
+ * @author Will Poulson
622
+ */
623
+ /**
624
+ * Constructs an astract form control based on the question data.
625
+ * @author Will Poulson
626
+ * @private
627
+ * @param {?} question The question data to build the abstract control on.
628
+ * @param {?} section
629
+ * @param {?} currentQuestionnaireForm
630
+ * @return {?} An abstract control.
631
+ */
632
+ FormConstructorService.prototype.generateControlForQuestion = /**
633
+ * Constructs an astract form control based on the question data.
634
+ * @author Will Poulson
635
+ * @private
636
+ * @param {?} question The question data to build the abstract control on.
637
+ * @param {?} section
638
+ * @param {?} currentQuestionnaireForm
639
+ * @return {?} An abstract control.
640
+ */
641
+ function (question, section, currentQuestionnaireForm) {
642
+ /** @type {?} */
643
+ var convertedValidators = this.convertValidators(question.validators);
644
+ switch (question.type) {
645
+ case QuestionType.Repeater:
646
+ /** @type {?} */
647
+ var currentArray = currentQuestionnaireForm ? ((/** @type {?} */ (currentQuestionnaireForm.get([section.name, question.name])))) : false;
648
+ /** @type {?} */
649
+ var newArray = currentArray ? currentArray.controls : [];
650
+ return this.fb.array(newArray, convertedValidators);
651
+ case QuestionType.Checklist:
652
+ return this.generateGroupForChecklist(question, convertedValidators);
653
+ default:
654
+ return this.fb.control(null, { validators: convertedValidators, updateOn: 'blur' });
655
+ }
656
+ };
657
+ /**
658
+ * Generates the form group for a checklist question.
659
+ * @param question The question. Must be of type checklist or else null is returned.
660
+ * @returns A form group.
661
+ * @author Will Poulson
662
+ */
663
+ /**
664
+ * Generates the form group for a checklist question.
665
+ * @author Will Poulson
666
+ * @private
667
+ * @param {?} question The question. Must be of type checklist or else null is returned.
668
+ * @param {?} convertedValidators
669
+ * @return {?} A form group.
670
+ */
671
+ FormConstructorService.prototype.generateGroupForChecklist = /**
672
+ * Generates the form group for a checklist question.
673
+ * @author Will Poulson
674
+ * @private
675
+ * @param {?} question The question. Must be of type checklist or else null is returned.
676
+ * @param {?} convertedValidators
677
+ * @return {?} A form group.
678
+ */
679
+ function (question, convertedValidators) {
680
+ var e_3, _a;
681
+ if (question.type !== QuestionType.Checklist || question.checklistItems.length === 0) {
682
+ return null;
683
+ }
684
+ /** @type {?} */
685
+ var checklistForms = this.fb.group({}, convertedValidators);
686
+ try {
687
+ for (var _b = __values(question.checklistItems), _c = _b.next(); !_c.done; _c = _b.next()) {
688
+ var checklistItem = _c.value;
689
+ /** @type {?} */
690
+ var checklistItemControl = this.fb.control(false, { updateOn: 'blur' });
691
+ checklistForms.addControl(checklistItem.name, checklistItemControl);
692
+ }
693
+ }
694
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
695
+ finally {
696
+ try {
697
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
698
+ }
699
+ finally { if (e_3) throw e_3.error; }
700
+ }
701
+ return checklistForms;
702
+ };
703
+ /**
704
+ * Generates the form template for a repeater question.
705
+ * @param question The question. Must be of type repeater or else null is returned.
706
+ * @returns A form group.
707
+ * @author Will Poulson
708
+ */
709
+ /**
710
+ * Generates the form template for a repeater question.
711
+ * @author Will Poulson
712
+ * @param {?} question The question. Must be of type repeater or else null is returned.
713
+ * @return {?} A form group.
714
+ */
715
+ FormConstructorService.prototype.generateFormsForRepeater = /**
716
+ * Generates the form template for a repeater question.
717
+ * @author Will Poulson
718
+ * @param {?} question The question. Must be of type repeater or else null is returned.
719
+ * @return {?} A form group.
720
+ */
721
+ function (question) {
722
+ var e_4, _a;
723
+ if (question.type !== QuestionType.Repeater || question.repeaterQuestions.length === 0) {
724
+ console.log('Question isnt a repeater or has no questions, returning null');
725
+ return null;
726
+ }
727
+ /** @type {?} */
728
+ var repeaterForms = this.fb.group({});
729
+ try {
730
+ for (var _b = __values(question.repeaterQuestions), _c = _b.next(); !_c.done; _c = _b.next()) {
731
+ var repeaterQuestion = _c.value;
732
+ /** @type {?} */
733
+ var repeaterQuestionControl = this.generateControlForRepeaterQuestion(repeaterQuestion);
734
+ repeaterForms.addControl(repeaterQuestion.name, repeaterQuestionControl);
735
+ }
736
+ }
737
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
738
+ finally {
739
+ try {
740
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
741
+ }
742
+ finally { if (e_4) throw e_4.error; }
743
+ }
744
+ return repeaterForms;
745
+ };
746
+ /**
747
+ * Generates a control for a repeaters question.
748
+ * @param repeaterQuestion A repeater question.
749
+ * @returns An abstract control.
750
+ * @author Will Poulson
751
+ */
752
+ /**
753
+ * Generates a control for a repeaters question.
754
+ * @author Will Poulson
755
+ * @private
756
+ * @param {?} repeaterQuestion A repeater question.
757
+ * @return {?} An abstract control.
758
+ */
759
+ FormConstructorService.prototype.generateControlForRepeaterQuestion = /**
760
+ * Generates a control for a repeaters question.
761
+ * @author Will Poulson
762
+ * @private
763
+ * @param {?} repeaterQuestion A repeater question.
764
+ * @return {?} An abstract control.
765
+ */
766
+ function (repeaterQuestion) {
767
+ /** @type {?} */
768
+ var convertedValidators = this.convertValidators(repeaterQuestion.validators);
769
+ return this.fb.control(null, { validators: convertedValidators, updateOn: 'blur' });
770
+ };
771
+ /**
772
+ * Converts an array of validators into form validators.
773
+ * @param validators The uncoverted array of validators.
774
+ * @returns A convered array of form validators.
775
+ * @author Will Poulson
776
+ */
777
+ /**
778
+ * Converts an array of validators into form validators.
779
+ * @author Will Poulson
780
+ * @private
781
+ * @param {?} validators The uncoverted array of validators.
782
+ * @return {?} A convered array of form validators.
783
+ */
784
+ FormConstructorService.prototype.convertValidators = /**
785
+ * Converts an array of validators into form validators.
786
+ * @author Will Poulson
787
+ * @private
788
+ * @param {?} validators The uncoverted array of validators.
789
+ * @return {?} A convered array of form validators.
790
+ */
791
+ function (validators) {
792
+ var e_5, _a;
793
+ if (!validators || validators.length === 0) {
794
+ return [];
795
+ }
796
+ /** @type {?} */
797
+ var convertedValidators = [];
798
+ try {
799
+ for (var validators_1 = __values(validators), validators_1_1 = validators_1.next(); !validators_1_1.done; validators_1_1 = validators_1.next()) {
800
+ var validator = validators_1_1.value;
801
+ /** @type {?} */
802
+ var convertedValidator = this.convertValidator(validator);
803
+ if (convertedValidator) {
804
+ convertedValidators.push(convertedValidator);
805
+ }
806
+ }
807
+ }
808
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
809
+ finally {
810
+ try {
811
+ if (validators_1_1 && !validators_1_1.done && (_a = validators_1.return)) _a.call(validators_1);
812
+ }
813
+ finally { if (e_5) throw e_5.error; }
814
+ }
815
+ return convertedValidators;
816
+ };
817
+ /**
818
+ * Converts a single validator into a form validator.
819
+ * @param validator The unconverted validator.
820
+ * @returns A converted form validator.
821
+ * @author Will Poulson
822
+ */
823
+ /**
824
+ * Converts a single validator into a form validator.
825
+ * @author Will Poulson
826
+ * @private
827
+ * @param {?} validator The unconverted validator.
828
+ * @return {?} A converted form validator.
829
+ */
830
+ FormConstructorService.prototype.convertValidator = /**
831
+ * Converts a single validator into a form validator.
832
+ * @author Will Poulson
833
+ * @private
834
+ * @param {?} validator The unconverted validator.
835
+ * @return {?} A converted form validator.
836
+ */
837
+ function (validator) {
838
+ switch (validator.type) {
839
+ case ValidationType.Required:
840
+ return Validators.required;
841
+ default:
842
+ return null;
843
+ }
844
+ };
845
+ /**
846
+ * Constructs the forms for repeaters from saved state.
847
+ * @param savedState The saved state to load.
848
+ * @param sections The sections already generated by the form constructor.
849
+ */
850
+ /**
851
+ * Constructs the forms for repeaters from saved state.
852
+ * @param {?} savedState The saved state to load.
853
+ * @param {?} sections The sections already generated by the form constructor.
854
+ * @param {?} currentQuestionnaireForm
855
+ * @return {?}
856
+ */
857
+ FormConstructorService.prototype.constructRepeaterFromsFromState = /**
858
+ * Constructs the forms for repeaters from saved state.
859
+ * @param {?} savedState The saved state to load.
860
+ * @param {?} sections The sections already generated by the form constructor.
861
+ * @param {?} currentQuestionnaireForm
862
+ * @return {?}
863
+ */
864
+ function (savedState, sections, currentQuestionnaireForm) {
865
+ var e_6, _a, e_7, _b, e_8, _c;
866
+ try {
867
+ for (var sections_2 = __values(sections), sections_2_1 = sections_2.next(); !sections_2_1.done; sections_2_1 = sections_2.next()) {
868
+ var section = sections_2_1.value;
869
+ try {
870
+ for (var _d = __values(section.questions), _e = _d.next(); !_e.done; _e = _d.next()) {
871
+ var question = _e.value;
872
+ if (question.type !== QuestionType.Repeater) {
873
+ continue;
874
+ }
875
+ /** @type {?} */
876
+ var repeaterArray = savedState[section.name][question.name];
877
+ if (!repeaterArray || repeaterArray.length === 0) {
878
+ continue;
879
+ }
880
+ /** @type {?} */
881
+ var repeaterFormArray = (/** @type {?} */ (currentQuestionnaireForm.get([section.name, question.name])));
882
+ if (repeaterFormArray.controls.length === repeaterArray.length) {
883
+ continue;
884
+ }
885
+ try {
886
+ for (var repeaterArray_1 = __values(repeaterArray), repeaterArray_1_1 = repeaterArray_1.next(); !repeaterArray_1_1.done; repeaterArray_1_1 = repeaterArray_1.next()) {
887
+ var repeaterItem = repeaterArray_1_1.value;
888
+ /** @type {?} */
889
+ var repeaterItemTemplate = this.generateFormsForRepeater(question);
890
+ repeaterFormArray.push(repeaterItemTemplate);
891
+ }
892
+ }
893
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
894
+ finally {
895
+ try {
896
+ if (repeaterArray_1_1 && !repeaterArray_1_1.done && (_c = repeaterArray_1.return)) _c.call(repeaterArray_1);
897
+ }
898
+ finally { if (e_8) throw e_8.error; }
899
+ }
900
+ }
901
+ }
902
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
903
+ finally {
904
+ try {
905
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
906
+ }
907
+ finally { if (e_7) throw e_7.error; }
908
+ }
909
+ }
910
+ }
911
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
912
+ finally {
913
+ try {
914
+ if (sections_2_1 && !sections_2_1.done && (_a = sections_2.return)) _a.call(sections_2);
915
+ }
916
+ finally { if (e_6) throw e_6.error; }
917
+ }
918
+ };
919
+ FormConstructorService.decorators = [
920
+ { type: Injectable, args: [{
921
+ providedIn: 'root'
922
+ },] }
923
+ ];
924
+ /** @nocollapse */
925
+ FormConstructorService.ctorParameters = function () { return [
926
+ { type: FormBuilder },
927
+ { type: FilterService }
928
+ ]; };
929
+ /** @nocollapse */ FormConstructorService.ngInjectableDef = defineInjectable({ factory: function FormConstructorService_Factory() { return new FormConstructorService(inject(FormBuilder), inject(FilterService)); }, token: FormConstructorService, providedIn: "root" });
930
+ return FormConstructorService;
931
+ }());
932
+
933
+ /**
934
+ * @fileoverview added by tsickle
935
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
936
+ */
937
+ var QuestionnaireService = /** @class */ (function () {
938
+ function QuestionnaireService(formConstuctor, options) {
939
+ this.formConstuctor = formConstuctor;
940
+ this.options = options;
941
+ this.dataChangedEvent = new EventEmitter();
942
+ this.skippable = false;
943
+ }
944
+ /**
945
+ * Loads a questionnaire from data.
946
+ * @param questionnaire The questionnaire data to load, often parsed JSON from the editor.
947
+ * @param savedState The saved state of the questionnaire, often from localstorage.
948
+ * @returns null
949
+ * @author Will Poulson
950
+ */
951
+ /**
952
+ * Loads a questionnaire from data.
953
+ * @author Will Poulson
954
+ * @param {?} questionnaire The questionnaire data to load, often parsed JSON from the editor.
955
+ * @param {?=} savedState The saved state of the questionnaire, often from localstorage.
956
+ * @return {?} null
957
+ */
958
+ QuestionnaireService.prototype.loadQuestionnaire = /**
959
+ * Loads a questionnaire from data.
960
+ * @author Will Poulson
961
+ * @param {?} questionnaire The questionnaire data to load, often parsed JSON from the editor.
962
+ * @param {?=} savedState The saved state of the questionnaire, often from localstorage.
963
+ * @return {?} null
964
+ */
965
+ function (questionnaire, savedState) {
966
+ return __awaiter(this, void 0, void 0, function () {
967
+ var e_1, _a, e_2, _b, newData, _c, _d, section, _e, _f, question, control;
968
+ return __generator(this, function (_g) {
969
+ switch (_g.label) {
970
+ case 0:
971
+ this.originalQuestionnaire = cloneDeep(questionnaire);
972
+ this.currentQuestionnaire = cloneDeep(questionnaire);
973
+ if (savedState && Object.keys(savedState).length > 0) {
974
+ newData = this.formConstuctor.generateFormsForQuestionnaire(cloneDeep(this.originalQuestionnaire), this.currentQuestionnaireForm, true);
975
+ this.formConstuctor.constructRepeaterFromsFromState(savedState, newData.sections, newData.forms);
976
+ this.currentQuestionnaireForm = newData.forms;
977
+ this.currentQuestionnaireForm.patchValue(savedState);
978
+ }
979
+ return [4 /*yield*/, this.updateQuestionnaire(savedState)];
980
+ case 1:
981
+ _g.sent();
982
+ try {
983
+ for (_c = __values(this.currentQuestionnaire.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
984
+ section = _d.value;
985
+ try {
986
+ for (_e = __values(section.questions), _f = _e.next(); !_f.done; _f = _e.next()) {
987
+ question = _f.value;
988
+ control = this.currentQuestionnaireForm.get([section.name, question.name]);
989
+ if (!control.value && question.defaultValue) {
990
+ control.setValue(question.defaultValue);
991
+ }
992
+ }
993
+ }
994
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
995
+ finally {
996
+ try {
997
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
998
+ }
999
+ finally { if (e_2) throw e_2.error; }
1000
+ }
1001
+ }
1002
+ }
1003
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1004
+ finally {
1005
+ try {
1006
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1007
+ }
1008
+ finally { if (e_1) throw e_1.error; }
1009
+ }
1010
+ if (this.options.skipToFirstSection) {
1011
+ this.currentSectionName = Object.keys(this.currentQuestionnaireForm.controls)[0];
1012
+ }
1013
+ if (this.options.skipToFirstQuestion) {
1014
+ this.currentQuestionName = Object.keys(this.currentSection.formGroup.controls)[0];
1015
+ }
1016
+ return [2 /*return*/];
1017
+ }
1018
+ });
1019
+ });
1020
+ };
1021
+ /**
1022
+ * Updates the current questionnaire, used when a value is updated to check conditions.
1023
+ * @param savedState The saved state of the questionnaire, often from localstorage.
1024
+ * @returns null
1025
+ * @author Will Poulson
1026
+ */
1027
+ /**
1028
+ * Updates the current questionnaire, used when a value is updated to check conditions.
1029
+ * @author Will Poulson
1030
+ * @param {?=} savedState The saved state of the questionnaire, often from localstorage.
1031
+ * @return {?} null
1032
+ */
1033
+ QuestionnaireService.prototype.updateQuestionnaire = /**
1034
+ * Updates the current questionnaire, used when a value is updated to check conditions.
1035
+ * @author Will Poulson
1036
+ * @param {?=} savedState The saved state of the questionnaire, often from localstorage.
1037
+ * @return {?} null
1038
+ */
1039
+ function (savedState) {
1040
+ var _this = this;
1041
+ /** @type {?} */
1042
+ var newData = this.formConstuctor.generateFormsForQuestionnaire(cloneDeep(this.originalQuestionnaire), this.currentQuestionnaireForm);
1043
+ this.currentQuestionnaireForm = newData.forms;
1044
+ this.currentQuestionnaire.sections = newData.sections;
1045
+ if (savedState && Object.keys(savedState).length > 0) {
1046
+ this.currentQuestionnaireForm.patchValue(savedState);
1047
+ }
1048
+ if (this.questionnaireValueChangeSubscription) {
1049
+ this.questionnaireValueChangeSubscription.unsubscribe();
1050
+ }
1051
+ if (this.questionValueChangeSubscription) {
1052
+ this.questionValueChangeSubscription.unsubscribe();
1053
+ }
1054
+ this.questionnaireValueChangeSubscription = this.currentQuestionnaireForm.valueChanges.subscribe((/**
1055
+ * @return {?}
1056
+ */
1057
+ function () {
1058
+ _this.dataChangedEvent.emit();
1059
+ _this.updateQuestionnaire(_this.currentQuestionnaireForm.getRawValue());
1060
+ }));
1061
+ if (this.currentQuestion) {
1062
+ this.questionValueChangeSubscription = this.currentQuestion.formControl.valueChanges.subscribe((/**
1063
+ * @return {?}
1064
+ */
1065
+ function () {
1066
+ _this.clearFields(_this.currentQuestion.data.clearfields);
1067
+ }));
1068
+ }
1069
+ return;
1070
+ };
1071
+ Object.defineProperty(QuestionnaireService.prototype, "isValid", {
1072
+ get: /**
1073
+ * @return {?}
1074
+ */
1075
+ function () {
1076
+ return this.currentQuestionnaireForm.valid;
1077
+ },
1078
+ enumerable: true,
1079
+ configurable: true
1080
+ });
1081
+ /**
1082
+ * @param {?} name
1083
+ * @return {?}
1084
+ */
1085
+ QuestionnaireService.prototype.sectionValid = /**
1086
+ * @param {?} name
1087
+ * @return {?}
1088
+ */
1089
+ function (name) {
1090
+ return this.currentQuestionnaireForm.get(name).valid;
1091
+ };
1092
+ /**
1093
+ * Clears all the fields parsed
1094
+ * @param clearfields An array of strings, paths to clear.
1095
+ * @author Will Poulson
1096
+ */
1097
+ /**
1098
+ * Clears all the fields parsed
1099
+ * @author Will Poulson
1100
+ * @private
1101
+ * @param {?} clearfields An array of strings, paths to clear.
1102
+ * @return {?}
1103
+ */
1104
+ QuestionnaireService.prototype.clearFields = /**
1105
+ * Clears all the fields parsed
1106
+ * @author Will Poulson
1107
+ * @private
1108
+ * @param {?} clearfields An array of strings, paths to clear.
1109
+ * @return {?}
1110
+ */
1111
+ function (clearfields) {
1112
+ var e_3, _a;
1113
+ if (!clearfields || clearfields.length === 0) {
1114
+ return;
1115
+ }
1116
+ try {
1117
+ for (var clearfields_1 = __values(clearfields), clearfields_1_1 = clearfields_1.next(); !clearfields_1_1.done; clearfields_1_1 = clearfields_1.next()) {
1118
+ var clearfield = clearfields_1_1.value;
1119
+ /** @type {?} */
1120
+ var control = this.currentQuestionnaireForm.get(clearfield);
1121
+ if (control) {
1122
+ control.reset(undefined);
1123
+ }
1124
+ }
1125
+ }
1126
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1127
+ finally {
1128
+ try {
1129
+ if (clearfields_1_1 && !clearfields_1_1.done && (_a = clearfields_1.return)) _a.call(clearfields_1);
1130
+ }
1131
+ finally { if (e_3) throw e_3.error; }
1132
+ }
1133
+ };
1134
+ /**
1135
+ * Unloads the current questionnaire.
1136
+ * Useful when exiting a questionnaire page or completing a questionnaire.
1137
+ * @author Will Poulson
1138
+ */
1139
+ /**
1140
+ * Unloads the current questionnaire.
1141
+ * Useful when exiting a questionnaire page or completing a questionnaire.
1142
+ * @author Will Poulson
1143
+ * @return {?}
1144
+ */
1145
+ QuestionnaireService.prototype.unloadQuestionnaire = /**
1146
+ * Unloads the current questionnaire.
1147
+ * Useful when exiting a questionnaire page or completing a questionnaire.
1148
+ * @author Will Poulson
1149
+ * @return {?}
1150
+ */
1151
+ function () {
1152
+ this.originalQuestionnaire = undefined;
1153
+ this.currentQuestionnaireForm = undefined;
1154
+ this.currentQuestionnaire = undefined;
1155
+ this.currentSectionName = undefined;
1156
+ this.currentQuestionName = undefined;
1157
+ };
1158
+ Object.defineProperty(QuestionnaireService.prototype, "currentSection", {
1159
+ /**
1160
+ * Gets the current selected section.
1161
+ * @returns An object containing the section data and the related form group.
1162
+ * @author Will Poulson
1163
+ */
1164
+ get: /**
1165
+ * Gets the current selected section.
1166
+ * @author Will Poulson
1167
+ * @return {?} An object containing the section data and the related form group.
1168
+ */
1169
+ function () {
1170
+ var _this = this;
1171
+ if (!this.currentSectionName) {
1172
+ return null;
1173
+ }
1174
+ /** @type {?} */
1175
+ var data = this.currentQuestionnaire.sections.find((/**
1176
+ * @param {?} x
1177
+ * @return {?}
1178
+ */
1179
+ function (x) {
1180
+ return x.name === _this.currentSectionName;
1181
+ }));
1182
+ if (!data) {
1183
+ return null;
1184
+ }
1185
+ return {
1186
+ data: data,
1187
+ formGroup: (/** @type {?} */ (this.currentQuestionnaireForm.get(data.name)))
1188
+ };
1189
+ },
1190
+ enumerable: true,
1191
+ configurable: true
1192
+ });
1193
+ Object.defineProperty(QuestionnaireService.prototype, "availableSections", {
1194
+ /**
1195
+ * Gets all the avaialble sections.
1196
+ * @returns An array of all avaialble sections.
1197
+ * @author Will Poulson
1198
+ */
1199
+ get: /**
1200
+ * Gets all the avaialble sections.
1201
+ * @author Will Poulson
1202
+ * @return {?} An array of all avaialble sections.
1203
+ */
1204
+ function () {
1205
+ if (!this.currentQuestionnaire || !this.currentQuestionnaire.sections) {
1206
+ return [];
1207
+ }
1208
+ return this.currentQuestionnaire.sections;
1209
+ },
1210
+ enumerable: true,
1211
+ configurable: true
1212
+ });
1213
+ Object.defineProperty(QuestionnaireService.prototype, "currentData", {
1214
+ /**
1215
+ * Gets the current data for the entire questionnaire.
1216
+ * @returns An object of data.
1217
+ * @author Will Poulson
1218
+ */
1219
+ get: /**
1220
+ * Gets the current data for the entire questionnaire.
1221
+ * @author Will Poulson
1222
+ * @return {?} An object of data.
1223
+ */
1224
+ function () {
1225
+ return this.currentQuestionnaireForm.getRawValue();
1226
+ },
1227
+ enumerable: true,
1228
+ configurable: true
1229
+ });
1230
+ Object.defineProperty(QuestionnaireService.prototype, "currentQuestion", {
1231
+ /**
1232
+ * Gets the current selected question.
1233
+ * @returns An object containing the question data and the related form control.
1234
+ * @author Will Poulson
1235
+ */
1236
+ get: /**
1237
+ * Gets the current selected question.
1238
+ * @author Will Poulson
1239
+ * @return {?} An object containing the question data and the related form control.
1240
+ */
1241
+ function () {
1242
+ var _this = this;
1243
+ if (!this.currentQuestionName) {
1244
+ return null;
1245
+ }
1246
+ /** @type {?} */
1247
+ var data = this.currentSection.data.questions.find((/**
1248
+ * @param {?} x
1249
+ * @return {?}
1250
+ */
1251
+ function (x) {
1252
+ return x.name === _this.currentQuestionName;
1253
+ }));
1254
+ if (!data) {
1255
+ return null;
1256
+ }
1257
+ return {
1258
+ data: data,
1259
+ formControl: (/** @type {?} */ (this.currentSection.formGroup.get(data.name)))
1260
+ };
1261
+ },
1262
+ enumerable: true,
1263
+ configurable: true
1264
+ });
1265
+ /**
1266
+ * Navigates to the next question.
1267
+ * If there is no question to navigate to it will reject with a out of bounds exception.
1268
+ * If allowSkipRequiredField is false then it will reject if the current question is invalid.
1269
+ * If emitSectionFinishEvent is true then it will emit an event if it's navigating past the length of questions.
1270
+ * @returns A promise which will resolve when the question has been navigated to.
1271
+ * @author Will Poulson
1272
+ */
1273
+ /**
1274
+ * Navigates to the next question.
1275
+ * If there is no question to navigate to it will reject with a out of bounds exception.
1276
+ * If allowSkipRequiredField is false then it will reject if the current question is invalid.
1277
+ * If emitSectionFinishEvent is true then it will emit an event if it's navigating past the length of questions.
1278
+ * @author Will Poulson
1279
+ * @return {?} A promise which will resolve when the question has been navigated to.
1280
+ */
1281
+ QuestionnaireService.prototype.nextQuestion = /**
1282
+ * Navigates to the next question.
1283
+ * If there is no question to navigate to it will reject with a out of bounds exception.
1284
+ * If allowSkipRequiredField is false then it will reject if the current question is invalid.
1285
+ * If emitSectionFinishEvent is true then it will emit an event if it's navigating past the length of questions.
1286
+ * @author Will Poulson
1287
+ * @return {?} A promise which will resolve when the question has been navigated to.
1288
+ */
1289
+ function () {
1290
+ var _this = this;
1291
+ return new Promise((/**
1292
+ * @param {?} resolve
1293
+ * @param {?} reject
1294
+ * @return {?}
1295
+ */
1296
+ function (resolve, reject) {
1297
+ if (!_this.options.allowSkipRequiredField) {
1298
+ if (!_this.currentQuestion.formControl.valid) {
1299
+ return reject('Current question is invalid');
1300
+ }
1301
+ }
1302
+ _this.getCurrentQuestionIndex().then((/**
1303
+ * @param {?} currentIndex
1304
+ * @return {?}
1305
+ */
1306
+ function (currentIndex) {
1307
+ /** @type {?} */
1308
+ var newIndex = currentIndex + 1;
1309
+ _this.navigateToQuestion(newIndex).then((/**
1310
+ * @return {?}
1311
+ */
1312
+ function () {
1313
+ return resolve();
1314
+ })).catch((/**
1315
+ * @param {?} error
1316
+ * @return {?}
1317
+ */
1318
+ function (error) {
1319
+ return reject(error);
1320
+ }));
1321
+ })).catch((/**
1322
+ * @param {?} error
1323
+ * @return {?}
1324
+ */
1325
+ function (error) {
1326
+ return reject(error);
1327
+ }));
1328
+ }));
1329
+ };
1330
+ /**
1331
+ * Navigates to the previous question.
1332
+ * If there is no question to navigate to it will reject with a out of bounds exception.
1333
+ * If allowNavigateBackwards is false then it will reject.
1334
+ * @returns A promise which will resolve when the question has been navigated to.
1335
+ * @author Will Poulson
1336
+ */
1337
+ /**
1338
+ * Navigates to the previous question.
1339
+ * If there is no question to navigate to it will reject with a out of bounds exception.
1340
+ * If allowNavigateBackwards is false then it will reject.
1341
+ * @author Will Poulson
1342
+ * @return {?} A promise which will resolve when the question has been navigated to.
1343
+ */
1344
+ QuestionnaireService.prototype.prevQuestion = /**
1345
+ * Navigates to the previous question.
1346
+ * If there is no question to navigate to it will reject with a out of bounds exception.
1347
+ * If allowNavigateBackwards is false then it will reject.
1348
+ * @author Will Poulson
1349
+ * @return {?} A promise which will resolve when the question has been navigated to.
1350
+ */
1351
+ function () {
1352
+ var _this = this;
1353
+ return new Promise((/**
1354
+ * @param {?} resolve
1355
+ * @param {?} reject
1356
+ * @return {?}
1357
+ */
1358
+ function (resolve, reject) {
1359
+ if (!_this.options.allowNavigateBackwards) {
1360
+ return reject('This questionnaire does not allow for backwards navigation');
1361
+ }
1362
+ _this.getCurrentQuestionIndex().then((/**
1363
+ * @param {?} currentIndex
1364
+ * @return {?}
1365
+ */
1366
+ function (currentIndex) {
1367
+ /** @type {?} */
1368
+ var newIndex = currentIndex - 1;
1369
+ _this.navigateToQuestion(newIndex).then((/**
1370
+ * @return {?}
1371
+ */
1372
+ function () {
1373
+ return resolve();
1374
+ })).catch((/**
1375
+ * @param {?} error
1376
+ * @return {?}
1377
+ */
1378
+ function (error) {
1379
+ return reject(error);
1380
+ }));
1381
+ })).catch((/**
1382
+ * @param {?} error
1383
+ * @return {?}
1384
+ */
1385
+ function (error) {
1386
+ return reject(error);
1387
+ }));
1388
+ }));
1389
+ };
1390
+ /**
1391
+ * Gets the current questions index.
1392
+ * @returns A promise which resolves a number.
1393
+ * @author Will Poulson
1394
+ */
1395
+ /**
1396
+ * Gets the current questions index.
1397
+ * @author Will Poulson
1398
+ * @private
1399
+ * @return {?} A promise which resolves a number.
1400
+ */
1401
+ QuestionnaireService.prototype.getCurrentQuestionIndex = /**
1402
+ * Gets the current questions index.
1403
+ * @author Will Poulson
1404
+ * @private
1405
+ * @return {?} A promise which resolves a number.
1406
+ */
1407
+ function () {
1408
+ var _this = this;
1409
+ return new Promise((/**
1410
+ * @param {?} resolve
1411
+ * @param {?} reject
1412
+ * @return {?}
1413
+ */
1414
+ function (resolve, reject) {
1415
+ /** @type {?} */
1416
+ var currentIndex = _this.currentSection.data.questions.indexOf(_this.currentQuestion.data);
1417
+ if (currentIndex === -1) {
1418
+ return reject('Could not find current question');
1419
+ }
1420
+ return resolve(currentIndex);
1421
+ }));
1422
+ };
1423
+ /**
1424
+ * Checks a question is in bounds then navigates to it.
1425
+ * @param index The index to navigate to.
1426
+ * @returns A promise which will resolve when the question has been navigated to.
1427
+ * @author Will Poulson
1428
+ */
1429
+ /**
1430
+ * Checks a question is in bounds then navigates to it.
1431
+ * @author Will Poulson
1432
+ * @param {?} index The index to navigate to.
1433
+ * @return {?} A promise which will resolve when the question has been navigated to.
1434
+ */
1435
+ QuestionnaireService.prototype.navigateToQuestion = /**
1436
+ * Checks a question is in bounds then navigates to it.
1437
+ * @author Will Poulson
1438
+ * @param {?} index The index to navigate to.
1439
+ * @return {?} A promise which will resolve when the question has been navigated to.
1440
+ */
1441
+ function (index) {
1442
+ var _this = this;
1443
+ return new Promise((/**
1444
+ * @param {?} resolve
1445
+ * @param {?} reject
1446
+ * @return {?}
1447
+ */
1448
+ function (resolve, reject) {
1449
+ if (_this.currentSection.data.questions.length - 1 < index || index < 0) {
1450
+ return reject('Out of bounds exception');
1451
+ }
1452
+ _this.currentQuestionName = _this.currentSection.data.questions[index].name;
1453
+ return resolve();
1454
+ }));
1455
+ };
1456
+ /**
1457
+ * Navigates to the next section.
1458
+ * @returns A promise which will resolve when the section has been navigated to.
1459
+ * @author Will Poulson
1460
+ */
1461
+ /**
1462
+ * Navigates to the next section.
1463
+ * @author Will Poulson
1464
+ * @return {?} A promise which will resolve when the section has been navigated to.
1465
+ */
1466
+ QuestionnaireService.prototype.nextSection = /**
1467
+ * Navigates to the next section.
1468
+ * @author Will Poulson
1469
+ * @return {?} A promise which will resolve when the section has been navigated to.
1470
+ */
1471
+ function () {
1472
+ var _this = this;
1473
+ return new Promise((/**
1474
+ * @param {?} resolve
1475
+ * @param {?} reject
1476
+ * @return {?}
1477
+ */
1478
+ function (resolve, reject) {
1479
+ _this.getCurrentSectionIndex().then((/**
1480
+ * @param {?} currentIndex
1481
+ * @return {?}
1482
+ */
1483
+ function (currentIndex) {
1484
+ /** @type {?} */
1485
+ var newIndex = currentIndex + 1;
1486
+ _this.navigateToSection(newIndex).then((/**
1487
+ * @return {?}
1488
+ */
1489
+ function () {
1490
+ return resolve();
1491
+ })).catch((/**
1492
+ * @param {?} error
1493
+ * @return {?}
1494
+ */
1495
+ function (error) {
1496
+ return reject(error);
1497
+ }));
1498
+ })).catch((/**
1499
+ * @param {?} error
1500
+ * @return {?}
1501
+ */
1502
+ function (error) {
1503
+ return reject(error);
1504
+ }));
1505
+ }));
1506
+ };
1507
+ /**
1508
+ * Navigates to the previous section.
1509
+ * @returns A promise which will resolve when the section has been navigated to.
1510
+ * @author Will Poulson
1511
+ */
1512
+ /**
1513
+ * Navigates to the previous section.
1514
+ * @author Will Poulson
1515
+ * @return {?} A promise which will resolve when the section has been navigated to.
1516
+ */
1517
+ QuestionnaireService.prototype.prevSection = /**
1518
+ * Navigates to the previous section.
1519
+ * @author Will Poulson
1520
+ * @return {?} A promise which will resolve when the section has been navigated to.
1521
+ */
1522
+ function () {
1523
+ var _this = this;
1524
+ return new Promise((/**
1525
+ * @param {?} resolve
1526
+ * @param {?} reject
1527
+ * @return {?}
1528
+ */
1529
+ function (resolve, reject) {
1530
+ _this.getCurrentSectionIndex().then((/**
1531
+ * @param {?} currentIndex
1532
+ * @return {?}
1533
+ */
1534
+ function (currentIndex) {
1535
+ /** @type {?} */
1536
+ var newIndex = currentIndex - 1;
1537
+ _this.navigateToQuestion(newIndex).then((/**
1538
+ * @return {?}
1539
+ */
1540
+ function () {
1541
+ return resolve();
1542
+ })).catch((/**
1543
+ * @param {?} error
1544
+ * @return {?}
1545
+ */
1546
+ function (error) {
1547
+ return reject(error);
1548
+ }));
1549
+ })).catch((/**
1550
+ * @param {?} error
1551
+ * @return {?}
1552
+ */
1553
+ function (error) {
1554
+ return reject(error);
1555
+ }));
1556
+ }));
1557
+ };
1558
+ /**
1559
+ * Gets the current section index.
1560
+ * @returns A promise which resolves a number.
1561
+ * @author Will Poulson
1562
+ */
1563
+ /**
1564
+ * Gets the current section index.
1565
+ * @author Will Poulson
1566
+ * @private
1567
+ * @return {?} A promise which resolves a number.
1568
+ */
1569
+ QuestionnaireService.prototype.getCurrentSectionIndex = /**
1570
+ * Gets the current section index.
1571
+ * @author Will Poulson
1572
+ * @private
1573
+ * @return {?} A promise which resolves a number.
1574
+ */
1575
+ function () {
1576
+ var _this = this;
1577
+ return new Promise((/**
1578
+ * @param {?} resolve
1579
+ * @param {?} reject
1580
+ * @return {?}
1581
+ */
1582
+ function (resolve, reject) {
1583
+ /** @type {?} */
1584
+ var currentIndex = _this.currentQuestionnaire.sections.indexOf(_this.currentSection.data);
1585
+ if (currentIndex === -1) {
1586
+ return reject('Could not find current section');
1587
+ }
1588
+ return resolve(currentIndex);
1589
+ }));
1590
+ };
1591
+ /**
1592
+ * Checks a section is in bounds then navigates to it.
1593
+ * @param index The index to navigate to.
1594
+ * @returns A promise which will resolve when the section has been navigated to.
1595
+ * @author Will Poulson
1596
+ */
1597
+ /**
1598
+ * Checks a section is in bounds then navigates to it.
1599
+ * @author Will Poulson
1600
+ * @param {?} index The index to navigate to.
1601
+ * @return {?} A promise which will resolve when the section has been navigated to.
1602
+ */
1603
+ QuestionnaireService.prototype.navigateToSection = /**
1604
+ * Checks a section is in bounds then navigates to it.
1605
+ * @author Will Poulson
1606
+ * @param {?} index The index to navigate to.
1607
+ * @return {?} A promise which will resolve when the section has been navigated to.
1608
+ */
1609
+ function (index) {
1610
+ var _this = this;
1611
+ return new Promise((/**
1612
+ * @param {?} resolve
1613
+ * @param {?} reject
1614
+ * @return {?}
1615
+ */
1616
+ function (resolve, reject) {
1617
+ if (_this.currentQuestionnaire.sections.length - 1 < index || index < 0) {
1618
+ return reject('Out of bounds exception');
1619
+ }
1620
+ _this.currentSectionName = _this.currentQuestionnaire.sections[index].name;
1621
+ return resolve();
1622
+ }));
1623
+ };
1624
+ /**
1625
+ * Answers the current question with the parsed value.
1626
+ * @param answer The value to answer the question with.
1627
+ * @author Will Poulson
1628
+ */
1629
+ /**
1630
+ * Answers the current question with the parsed value.
1631
+ * @author Will Poulson
1632
+ * @param {?} answer The value to answer the question with.
1633
+ * @param {?=} sendToNextQuestion
1634
+ * @return {?}
1635
+ */
1636
+ QuestionnaireService.prototype.answerCurrentQuestion = /**
1637
+ * Answers the current question with the parsed value.
1638
+ * @author Will Poulson
1639
+ * @param {?} answer The value to answer the question with.
1640
+ * @param {?=} sendToNextQuestion
1641
+ * @return {?}
1642
+ */
1643
+ function (answer, sendToNextQuestion) {
1644
+ var _this = this;
1645
+ this.currentQuestion.formControl.setValue(answer);
1646
+ if (sendToNextQuestion && this.skippable) { // Timeout to prevent skipping glitch.
1647
+ this.skippable = false;
1648
+ setTimeout((/**
1649
+ * @return {?}
1650
+ */
1651
+ function () {
1652
+ _this.nextQuestion();
1653
+ _this.skippable = true;
1654
+ }), 150);
1655
+ }
1656
+ };
1657
+ /**
1658
+ * Adds a repeater item to the current question.
1659
+ * Current question must be of type Repeater.
1660
+ * @returns A promise which resolves when the repeater item has been added.
1661
+ * @author Will Poulson
1662
+ */
1663
+ /**
1664
+ * Adds a repeater item to the current question.
1665
+ * Current question must be of type Repeater.
1666
+ * @author Will Poulson
1667
+ * @return {?} A promise which resolves when the repeater item has been added.
1668
+ */
1669
+ QuestionnaireService.prototype.addRepeaterItem = /**
1670
+ * Adds a repeater item to the current question.
1671
+ * Current question must be of type Repeater.
1672
+ * @author Will Poulson
1673
+ * @return {?} A promise which resolves when the repeater item has been added.
1674
+ */
1675
+ function () {
1676
+ var _this = this;
1677
+ return new Promise((/**
1678
+ * @param {?} resolve
1679
+ * @param {?} reject
1680
+ * @return {?}
1681
+ */
1682
+ function (resolve, reject) {
1683
+ if (_this.currentQuestion.data.type !== QuestionType.Repeater) {
1684
+ return reject("Current question isn't a repeater");
1685
+ }
1686
+ /** @type {?} */
1687
+ var repeaterForm = _this.formConstuctor.generateFormsForRepeater(_this.currentQuestion.data);
1688
+ if (!repeaterForm) {
1689
+ return reject("Repeater template failed to generate. May be due to the repeater having no items in the editor.");
1690
+ }
1691
+ if (!(_this.currentQuestion.formControl instanceof FormArray)) {
1692
+ return reject("The current questions control isn't of type FormArray");
1693
+ }
1694
+ _this.currentQuestion.formControl.push(repeaterForm);
1695
+ return resolve();
1696
+ }));
1697
+ };
1698
+ /**
1699
+ * Removes a repeater item on the current question.
1700
+ * Current question must be of type Repeater.
1701
+ * @param index The index at which to remove.
1702
+ * @returns A promise which resolves when the repeater item has been removed.
1703
+ * @author Will Poulson
1704
+ */
1705
+ /**
1706
+ * Removes a repeater item on the current question.
1707
+ * Current question must be of type Repeater.
1708
+ * @author Will Poulson
1709
+ * @param {?} index The index at which to remove.
1710
+ * @return {?} A promise which resolves when the repeater item has been removed.
1711
+ */
1712
+ QuestionnaireService.prototype.removeRepeaterItem = /**
1713
+ * Removes a repeater item on the current question.
1714
+ * Current question must be of type Repeater.
1715
+ * @author Will Poulson
1716
+ * @param {?} index The index at which to remove.
1717
+ * @return {?} A promise which resolves when the repeater item has been removed.
1718
+ */
1719
+ function (index) {
1720
+ var _this = this;
1721
+ return new Promise((/**
1722
+ * @param {?} resolve
1723
+ * @param {?} reject
1724
+ * @return {?}
1725
+ */
1726
+ function (resolve, reject) {
1727
+ if (_this.currentQuestion.data.type !== QuestionType.Repeater) {
1728
+ return reject("Current question isn't a repeater");
1729
+ }
1730
+ if (!(_this.currentQuestion.formControl instanceof FormArray)) {
1731
+ return reject("The current questions control isn't of type FormArray");
1732
+ }
1733
+ _this.currentQuestion.formControl.removeAt(index);
1734
+ return resolve();
1735
+ }));
1736
+ };
1737
+ /**
1738
+ * Returns the display text for a given repeater item
1739
+ * @param index The index at which to get the label for.
1740
+ * @returns A string which is the display text.
1741
+ * @author Will Poulson
1742
+ */
1743
+ /**
1744
+ * Returns the display text for a given repeater item
1745
+ * @author Will Poulson
1746
+ * @param {?} index The index at which to get the label for.
1747
+ * @return {?} A string which is the display text.
1748
+ */
1749
+ QuestionnaireService.prototype.getRepeaterItemLabel = /**
1750
+ * Returns the display text for a given repeater item
1751
+ * @author Will Poulson
1752
+ * @param {?} index The index at which to get the label for.
1753
+ * @return {?} A string which is the display text.
1754
+ */
1755
+ function (index) {
1756
+ var e_4, _a;
1757
+ if (!this.currentQuestion.formControl || !(this.currentQuestion.formControl instanceof FormArray)) {
1758
+ return '';
1759
+ }
1760
+ /** @type {?} */
1761
+ var repeaterItem = this.currentQuestion.formControl.controls[index];
1762
+ if (!repeaterItem) {
1763
+ return '';
1764
+ }
1765
+ /** @type {?} */
1766
+ var template = this.currentQuestion.data.repeaterDisplayName;
1767
+ /** @type {?} */
1768
+ var splitTemplate = template.split(' ');
1769
+ /** @type {?} */
1770
+ var displayArray = [];
1771
+ try {
1772
+ for (var splitTemplate_1 = __values(splitTemplate), splitTemplate_1_1 = splitTemplate_1.next(); !splitTemplate_1_1.done; splitTemplate_1_1 = splitTemplate_1.next()) {
1773
+ var templateItem = splitTemplate_1_1.value;
1774
+ if (templateItem.match(/\[.*?\]/)) {
1775
+ /** @type {?} */
1776
+ var path = templateItem.replace(/[\[\]']+/g, '');
1777
+ /** @type {?} */
1778
+ var item = repeaterItem.get(path);
1779
+ /** @type {?} */
1780
+ var value = item.value ? item.value : '?';
1781
+ displayArray.push(value);
1782
+ }
1783
+ else {
1784
+ displayArray.push(templateItem);
1785
+ }
1786
+ }
1787
+ }
1788
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1789
+ finally {
1790
+ try {
1791
+ if (splitTemplate_1_1 && !splitTemplate_1_1.done && (_a = splitTemplate_1.return)) _a.call(splitTemplate_1);
1792
+ }
1793
+ finally { if (e_4) throw e_4.error; }
1794
+ }
1795
+ /** @type {?} */
1796
+ var display = displayArray.join(' ');
1797
+ return display;
1798
+ };
1799
+ QuestionnaireService.decorators = [
1800
+ { type: Injectable, args: [{
1801
+ providedIn: 'root'
1802
+ },] }
1803
+ ];
1804
+ /** @nocollapse */
1805
+ QuestionnaireService.ctorParameters = function () { return [
1806
+ { type: FormConstructorService },
1807
+ { type: undefined, decorators: [{ type: Inject, args: ['options',] }] }
1808
+ ]; };
1809
+ /** @nocollapse */ QuestionnaireService.ngInjectableDef = defineInjectable({ factory: function QuestionnaireService_Factory() { return new QuestionnaireService(inject(FormConstructorService), inject("options")); }, token: QuestionnaireService, providedIn: "root" });
1810
+ return QuestionnaireService;
1811
+ }());
1812
+
1813
+ /**
1814
+ * @fileoverview added by tsickle
1815
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1816
+ */
1817
+ var GgQuestionnaireV2Module = /** @class */ (function () {
1818
+ function GgQuestionnaireV2Module() {
1819
+ }
1820
+ /**
1821
+ * @param {?} options
1822
+ * @return {?}
1823
+ */
1824
+ GgQuestionnaireV2Module.forRoot = /**
1825
+ * @param {?} options
1826
+ * @return {?}
1827
+ */
1828
+ function (options) {
1829
+ return {
1830
+ ngModule: GgQuestionnaireV2Module,
1831
+ providers: [
1832
+ QuestionnaireService,
1833
+ {
1834
+ provide: 'options',
1835
+ useValue: options
1836
+ }
1837
+ ]
1838
+ };
1839
+ };
1840
+ GgQuestionnaireV2Module.decorators = [
1841
+ { type: NgModule, args: [{
1842
+ declarations: [],
1843
+ providers: [
1844
+ FormConstructorService,
1845
+ FilterService
1846
+ ],
1847
+ imports: [
1848
+ FormsModule,
1849
+ ReactiveFormsModule
1850
+ ],
1851
+ },] }
1852
+ ];
1853
+ return GgQuestionnaireV2Module;
1854
+ }());
1855
+
1856
+ /**
1857
+ * @fileoverview added by tsickle
1858
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1859
+ */
1860
+ /** @enum {string} */
1861
+ var InputType = {
1862
+ Text: 'text',
1863
+ Number: 'number',
1864
+ Email: 'email',
1865
+ Telephone: 'tel',
1866
+ Password: 'password',
1867
+ Color: 'color',
1868
+ Date: 'date',
1869
+ DateTimeLocal: 'datetime-local',
1870
+ Time: 'time',
1871
+ Month: 'month',
1872
+ Week: 'week',
1873
+ };
1874
+
1875
+ /**
1876
+ * @fileoverview added by tsickle
1877
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1878
+ */
1879
+ /** @enum {string} */
1880
+ var RepeaterQuestionType = {
1881
+ Input: 'input',
1882
+ Select: 'select',
1883
+ };
1884
+
1885
+ /**
1886
+ * @fileoverview added by tsickle
1887
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1888
+ */
1889
+
1890
+ /**
1891
+ * @fileoverview added by tsickle
1892
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1893
+ */
1894
+
1895
+ export { QuestionnaireService, GgQuestionnaireV2Module, ConditionRelationship, ConditionType, QuestionType, ValidationType, InputType, RepeaterQuestionType, FilterService as ɵb, FormConstructorService as ɵa };
1896
+
1897
+ //# sourceMappingURL=glowgreen-gg-questionnaire-v2.js.map