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