survery-lib 0.1.60 → 0.2.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 (49) hide show
  1. package/esm2022/lib/components/question-boolean-template/question-boolean-template.component.mjs +57 -55
  2. package/esm2022/lib/components/question-cascade-template/question-cascade-template.component.mjs +46 -20
  3. package/esm2022/lib/components/question-check-box-template/question-check-box-template.component.mjs +63 -56
  4. package/esm2022/lib/components/question-dropdown-multi-template/question-dropdown-multi-template.component.mjs +60 -53
  5. package/esm2022/lib/components/question-dropdown-template/question-dropdown-template.component.mjs +53 -38
  6. package/esm2022/lib/components/question-matrix-template/question-matrix-template.component.mjs +66 -54
  7. package/esm2022/lib/components/question-radio-button-template/question-radio-button-template.component.mjs +60 -52
  8. package/esm2022/lib/components/question-text-template/question-text-template.component.mjs +75 -70
  9. package/esm2022/lib/core/states/entites/question-group.entity.mjs +8 -0
  10. package/esm2022/lib/core/states/entites/question.entity.mjs +8 -0
  11. package/esm2022/lib/core/states/entites/rule.entity.mjs +8 -0
  12. package/esm2022/lib/core/states/survey-store/question-group.selector.mjs +9 -0
  13. package/esm2022/lib/core/states/survey-store/question.selector.mjs +22 -0
  14. package/esm2022/lib/core/states/survey-store/survey.action.mjs +18 -0
  15. package/esm2022/lib/core/states/survey-store/survey.reducer.mjs +102 -0
  16. package/esm2022/lib/core/states/survey-store/survey.selector.mjs +33 -0
  17. package/esm2022/lib/pipes/filter-question.pipe.mjs +3 -3
  18. package/esm2022/lib/pipes/find-question.pipe.mjs +19 -0
  19. package/esm2022/lib/services/survey-lib.service.mjs +100 -51
  20. package/esm2022/lib/survery-lib.component.mjs +80 -285
  21. package/esm2022/lib/survery-lib.module.mjs +21 -7
  22. package/esm2022/lib/usecases/check-rule-exps.usecase.mjs +1 -1
  23. package/esm2022/shared/form-interfaces/survery-lib.form-interface.mjs +1 -1
  24. package/fesm2022/survery-lib.mjs +820 -714
  25. package/fesm2022/survery-lib.mjs.map +1 -1
  26. package/lib/components/question-boolean-template/question-boolean-template.component.d.ts +7 -6
  27. package/lib/components/question-cascade-template/question-cascade-template.component.d.ts +9 -6
  28. package/lib/components/question-check-box-template/question-check-box-template.component.d.ts +7 -6
  29. package/lib/components/question-dropdown-multi-template/question-dropdown-multi-template.component.d.ts +6 -6
  30. package/lib/components/question-dropdown-template/question-dropdown-template.component.d.ts +5 -2
  31. package/lib/components/question-matrix-template/question-matrix-template.component.d.ts +7 -6
  32. package/lib/components/question-radio-button-template/question-radio-button-template.component.d.ts +7 -6
  33. package/lib/components/question-text-template/question-text-template.component.d.ts +8 -7
  34. package/lib/core/states/entites/question-group.entity.d.ts +11 -0
  35. package/lib/core/states/entites/question.entity.d.ts +27 -0
  36. package/lib/core/states/entites/rule.entity.d.ts +8 -0
  37. package/lib/core/states/survey-store/question-group.selector.d.ts +4 -0
  38. package/lib/core/states/survey-store/question.selector.d.ts +7 -0
  39. package/lib/core/states/survey-store/survey.action.d.ts +54 -0
  40. package/lib/core/states/survey-store/survey.reducer.d.ts +12 -0
  41. package/lib/core/states/survey-store/survey.selector.d.ts +9 -0
  42. package/lib/pipes/filter-question.pipe.d.ts +2 -3
  43. package/lib/pipes/find-question.pipe.d.ts +8 -0
  44. package/lib/services/survey-lib.service.d.ts +4 -32
  45. package/lib/survery-lib.component.d.ts +15 -23
  46. package/lib/survery-lib.module.d.ts +9 -6
  47. package/lib/usecases/check-rule-exps.usecase.d.ts +2 -3
  48. package/package.json +1 -1
  49. package/shared/form-interfaces/survery-lib.form-interface.d.ts +3 -3
@@ -1,17 +1,22 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, Directive, HostListener, Pipe, EventEmitter, Component, Output, Input, InjectionToken, Inject, NgModule } from '@angular/core';
2
+ import { Injectable, Directive, HostListener, Pipe, Component, Input, EventEmitter, Output, InjectionToken, Inject, NgModule } from '@angular/core';
3
3
  import { v4 } from 'uuid';
4
- import { Subject, of, debounceTime, map, filter, distinctUntilChanged } from 'rxjs';
4
+ import { of, debounceTime, distinctUntilChanged, map, filter, pairwise, take } from 'rxjs';
5
+ import * as i5 from '@angular/forms';
6
+ import { Validators, FormControl, ReactiveFormsModule, FormsModule } from '@angular/forms';
7
+ import * as i3 from '@ngrx/store';
8
+ import { createFeatureSelector, createSelector, createAction, props, createReducer, on, StoreModule } from '@ngrx/store';
9
+ import { createEntityAdapter } from '@ngrx/entity';
10
+ import * as i4 from '@angular/common';
11
+ import { CommonModule } from '@angular/common';
5
12
  import * as i1 from '@ng-stack/forms';
6
13
  import { Validators as Validators$1, NgsFormsModule } from '@ng-stack/forms';
7
- import * as i3 from '@angular/common';
8
- import { CommonModule } from '@angular/common';
9
- import * as i4 from '@angular/forms';
10
- import { Validators, ReactiveFormsModule, FormsModule } from '@angular/forms';
11
- import * as i5 from '@ng-select/ng-select';
14
+ import * as i6 from '@ng-select/ng-select';
12
15
  import { NgSelectModule } from '@ng-select/ng-select';
13
16
  import * as i1$1 from '@angular/common/http';
14
17
  import { HttpHeaders, HttpClientModule } from '@angular/common/http';
18
+ import * as i2 from '@ngrx/effects';
19
+ import { EffectsModule } from '@ngrx/effects';
15
20
 
16
21
  var QuestionTypeEnum;
17
22
  (function (QuestionTypeEnum) {
@@ -25,15 +30,6 @@ var QuestionTypeEnum;
25
30
  QuestionTypeEnum[QuestionTypeEnum["Cascade"] = 8] = "Cascade";
26
31
  })(QuestionTypeEnum || (QuestionTypeEnum = {}));
27
32
 
28
- var LogicActionEnum;
29
- (function (LogicActionEnum) {
30
- LogicActionEnum[LogicActionEnum["Show"] = 1] = "Show";
31
- LogicActionEnum[LogicActionEnum["Hide"] = 2] = "Hide";
32
- LogicActionEnum[LogicActionEnum["Enable"] = 3] = "Enable";
33
- LogicActionEnum[LogicActionEnum["Disable"] = 4] = "Disable";
34
- LogicActionEnum[LogicActionEnum["SetAnswer"] = 5] = "SetAnswer";
35
- })(LogicActionEnum || (LogicActionEnum = {}));
36
-
37
33
  var InputTypeEnum;
38
34
  (function (InputTypeEnum) {
39
35
  InputTypeEnum[InputTypeEnum["Color"] = 1] = "Color";
@@ -46,59 +42,202 @@ var InputTypeEnum;
46
42
  InputTypeEnum[InputTypeEnum["Phone"] = 8] = "Phone";
47
43
  })(InputTypeEnum || (InputTypeEnum = {}));
48
44
 
45
+ function selectQuestionId(a) {
46
+ return a.questionId;
47
+ }
48
+ const questionAdapter = createEntityAdapter({
49
+ selectId: selectQuestionId
50
+ });
51
+
52
+ function selectRuleId(a) {
53
+ return a.ruleId;
54
+ }
55
+ const ruleAdapter = createEntityAdapter({
56
+ selectId: selectRuleId
57
+ });
58
+
59
+ const { selectAll: selectAll$3, selectIds: selectIds$3 } = questionAdapter.getSelectors();
60
+ const selectSurveyData$2 = createFeatureSelector('survey-lib');
61
+ const selectedPageId = createSelector(selectSurveyData$2, (state) => state.selectedPageId);
62
+ const showedSurveyPages = createSelector(selectSurveyData$2, (state) => {
63
+ var pageArr = selectAll$3(state.questionArr).filter(x => x.isShow == true).map(x => x.surveyPageId);
64
+ const distinctArray = pageArr.filter((n, i) => pageArr.indexOf(n) === i);
65
+ return distinctArray.sort((a, b) => a - b);
66
+ });
67
+ const selectedPageIndex = createSelector(showedSurveyPages, selectSurveyData$2, (pageArr, state) => {
68
+ return pageArr.findIndex(x => x == state.selectedPageId);
69
+ });
70
+ const isFirstPage = createSelector(showedSurveyPages, selectSurveyData$2, (pageArr, state) => {
71
+ if (pageArr.length > 0) {
72
+ return pageArr.findIndex(x => x == state.selectedPageId) == 0;
73
+ }
74
+ return true;
75
+ });
76
+ const isLastPage = createSelector(showedSurveyPages, selectSurveyData$2, (pageArr, state) => {
77
+ return pageArr.findIndex(x => x == state.selectedPageId) == (pageArr.length - 1);
78
+ });
79
+ const ruleArr = createSelector(selectSurveyData$2, (state) => ruleAdapter.getSelectors().selectAll(state.ruleArr));
80
+ const surveySelectors = {
81
+ selectedPageId,
82
+ selectedPageIndex,
83
+ showedSurveyPages,
84
+ isFirstPage,
85
+ isLastPage,
86
+ ruleArr
87
+ };
88
+
89
+ function selectQuestionGroupId(a) {
90
+ return a.questionGroupId;
91
+ }
92
+ const questionGroupAdapter = createEntityAdapter({
93
+ selectId: selectQuestionGroupId
94
+ });
95
+
96
+ const { selectAll: selectAll$2, selectIds: selectIds$2 } = questionGroupAdapter.getSelectors();
97
+ const selectSurveyData$1 = createFeatureSelector('survey-lib');
98
+ const pageQuestionGroups = createSelector(selectSurveyData$1, (state) => selectAll$2(state.questionGroupArr).filter(x => x.surveyPageId == state.selectedPageId));
99
+ const questionGroupSelectors = {
100
+ pageQuestionGroups
101
+ };
102
+
103
+ const { selectAll: selectAll$1, selectIds: selectIds$1 } = questionAdapter.getSelectors();
104
+ const selectSurveyData = createFeatureSelector('survey-lib');
105
+ const allQuestions = createSelector(selectSurveyData, (state) => selectAll$1(state.questionArr));
106
+ const pageQuestions = createSelector(selectSurveyData, (state) => selectAll$1(state.questionArr).filter(x => x.surveyPageId == state.selectedPageId));
107
+ const questionAnswers = createSelector(selectSurveyData, (state) => selectAll$1(state.questionArr).filter(x => x.isMatrixGroup != true).map(x => {
108
+ return {
109
+ SurveyPageIndex: x.surveyPageId,
110
+ QuestionId: x.questionId,
111
+ QuestionType: x.questionType,
112
+ AnswerId: x.answerId,
113
+ AnswerText: x.answerText,
114
+ AnswerIdArr: x.answerIdArr
115
+ };
116
+ }));
117
+ const questionSelectors = {
118
+ allQuestions,
119
+ pageQuestions,
120
+ questionAnswers
121
+ };
122
+
123
+ const loadSurvey = createAction('[Survey library] Load Survey', props());
124
+ const addQuestion = createAction('[Survey library] Add Question', props());
125
+ const updateQuestionAnswer = createAction('[Survey library] Update Question Answer', props());
126
+ const updateQuestionShow = createAction('[Survey library] Update Question Show', props());
127
+ const updateQuestionDisable = createAction('[Survey library] Update Question Disable', props());
128
+ const removeQuestion = createAction('[Survey library] Remove Question', props());
129
+ const updatePageId = createAction('[Survey library] Update Page Id', props());
130
+ const surveyActions = {
131
+ loadSurvey,
132
+ addQuestion,
133
+ updateQuestionAnswer,
134
+ updateQuestionShow,
135
+ updateQuestionDisable,
136
+ removeQuestion,
137
+ updatePageId,
138
+ };
139
+
49
140
  class SurveyLibService {
50
- get surveyDataObsrv() {
51
- return this.surveyDataSubject.asObservable();
52
- }
53
- get surveyAnswersObsrv() {
54
- return this.surveyAnswersSubject.asObservable();
55
- }
56
- get reloadSurveyObsrv() {
57
- return this.reloadSurveySubject.asObservable();
58
- }
59
- get questionIsShowObsrv() {
60
- return this.questionIsShowSubject.asObservable();
61
- }
62
- get questionIsDisabledObsrv() {
63
- return this.questionIsDisabledSubject.asObservable();
64
- }
65
- get addQuestionObsrv() {
66
- return this.addQuestionSubject.asObservable();
67
- }
68
- get removeQuestionObsrv() {
69
- return this.removeQuestionSubject.asObservable();
70
- }
71
- constructor() {
72
- this.surveyDataSubject = new Subject();
73
- this.surveyAnswersSubject = new Subject();
74
- this.reloadSurveySubject = new Subject();
75
- this.questionIsShowSubject = new Subject();
76
- this.questionIsDisabledSubject = new Subject();
77
- this.addQuestionSubject = new Subject();
78
- this.removeQuestionSubject = new Subject();
141
+ constructor(_Store) {
142
+ this._Store = _Store;
79
143
  }
80
144
  setSurveyData(survey) {
81
- this.surveyDataSubject.next(survey);
145
+ var questionArr = [];
146
+ var questionGroupArr = [];
147
+ survey.surveyPages.forEach((page, pageIndex) => {
148
+ page.surveyQuestionGroups.forEach(group => {
149
+ questionGroupArr.push({
150
+ questionGroupId: group.questionGroupId,
151
+ questionGroupName: group.questionGroupName,
152
+ questionGroupDescription: group.questionGroupDescription,
153
+ surveyPageId: page.pageId
154
+ });
155
+ group.surveyQuestions.forEach(question => {
156
+ var newQuestions = this.addQuestion(question, page.pageId, group.questionGroupId);
157
+ questionArr.push(...newQuestions);
158
+ });
159
+ });
160
+ });
161
+ var pageIdArr = survey.surveyPages.map(x => x.pageId);
162
+ this._Store.dispatch(surveyActions.loadSurvey({
163
+ questionArr: questionArr,
164
+ ruleArr: survey.surveyRules,
165
+ questionGroupArr: questionGroupArr,
166
+ selectedPageId: Math.min(...pageIdArr)
167
+ }));
168
+ }
169
+ addQuestion(question, pageIndex, questionGroupId) {
170
+ var questionArr = [{
171
+ surveyPageId: pageIndex,
172
+ questionId: question.questionId,
173
+ questionType: question.questionTypeId,
174
+ inputTypeId: question.surveyAnswers[0].inputTypeId,
175
+ isMatrixGroup: question.questionTypeId == QuestionTypeEnum.Matrix,
176
+ answerId: null,
177
+ answerIdArr: null,
178
+ answerText: null,
179
+ isRequired: question.isRequired,
180
+ isValid: null,
181
+ isDisabled: question.isReadOnly,
182
+ isShow: question.isVisable,
183
+ isDisabled_default: question.isReadOnly,
184
+ isShow_default: question.isVisable,
185
+ questionGroupId: questionGroupId,
186
+ parentQuestionId: null,
187
+ questionAllInfo: question
188
+ }];
189
+ if (question.questionTypeId == QuestionTypeEnum.Matrix) {
190
+ question.surveySubQuestions.forEach(subQuestion => {
191
+ questionArr.push({
192
+ surveyPageId: pageIndex,
193
+ questionId: subQuestion.questionId,
194
+ questionType: question.questionTypeId,
195
+ inputTypeId: question.surveyAnswers[0].inputTypeId,
196
+ isMatrixGroup: false,
197
+ answerId: null,
198
+ answerIdArr: null,
199
+ answerText: null,
200
+ isRequired: question.isRequired,
201
+ isValid: null,
202
+ isDisabled: question.isReadOnly,
203
+ isShow: question.isVisable,
204
+ isDisabled_default: question.isReadOnly,
205
+ isShow_default: question.isVisable,
206
+ parentQuestionId: question.questionId,
207
+ questionGroupId: questionGroupId,
208
+ questionAllInfo: question
209
+ });
210
+ });
211
+ }
212
+ return questionArr;
82
213
  }
83
214
  setsurveyAnswers(model) {
84
- this.surveyAnswersSubject.next(model);
85
- }
86
- setQuestionIsShow(questionId, isShow) {
87
- this.questionIsShowSubject.next({ questionId, isShow });
88
- }
89
- setQuestionIsDisabled(questionId, isDisabled) {
90
- this.questionIsDisabledSubject.next({ questionId, isDisabled });
91
- }
92
- setReloadSurvey() {
93
- this.reloadSurveySubject.next(v4());
94
- }
95
- setAddQuestion(question, pageIndex) {
96
- this.addQuestionSubject.next({ question, pageIndex });
97
- }
98
- setRemoveQuestion(questionId) {
99
- this.removeQuestionSubject.next({ questionId });
215
+ model.defaultAnswers.forEach(answer => {
216
+ if (answer.QuestionType == QuestionTypeEnum.TextInput) {
217
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
218
+ questionId: answer.QuestionId,
219
+ answer: answer.AnswerText,
220
+ isValid: true
221
+ }));
222
+ }
223
+ else if (answer.QuestionType == QuestionTypeEnum.CheckBox
224
+ || answer.QuestionType == QuestionTypeEnum.DropDownMulti) {
225
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
226
+ questionId: answer.QuestionId,
227
+ answer: answer.AnswerIdArr,
228
+ isValid: true
229
+ }));
230
+ }
231
+ else {
232
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
233
+ questionId: answer.QuestionId,
234
+ answer: answer.AnswerId,
235
+ isValid: true
236
+ }));
237
+ }
238
+ });
100
239
  }
101
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveyLibService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
240
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveyLibService, deps: [{ token: i3.Store }], target: i0.ɵɵFactoryTarget.Injectable }); }
102
241
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveyLibService, providedIn: 'root' }); }
103
242
  }
104
243
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveyLibService, decorators: [{
@@ -106,7 +245,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
106
245
  args: [{
107
246
  providedIn: 'root'
108
247
  }]
109
- }], ctorParameters: function () { return []; } });
248
+ }], ctorParameters: function () { return [{ type: i3.Store }]; } });
110
249
 
111
250
  var LogicPropertyEnum;
112
251
  (function (LogicPropertyEnum) {
@@ -405,54 +544,56 @@ class QuestionTextTemplateComponent {
405
544
  return null;
406
545
  }
407
546
  set setQuestion(value) {
408
- this.surveyQuestion = value;
409
- this.rForm.patchValue({
410
- id: value.questionId,
411
- name: value.questionName,
412
- title: value.questionTitle,
413
- typeId: value.questionTypeId,
414
- description: value.questionDescription,
415
- isDisabled: value.isReadOnly,
416
- isShow: value.isVisable
417
- });
418
- if (value.surveyAnswers[0]?.answerId != null && value.surveyAnswers[0]?.answerId != undefined) {
419
- this.fCtrls.surveyAnswerId.setValue(value.surveyAnswers[0].answerId);
420
- this.fCtrls.inputTypeId.setValue(value.surveyAnswers[0].inputTypeId);
421
- }
422
- if (value.isRequired == true) {
423
- this.fCtrls.answer.addValidators([Validators.required]);
424
- if (value.surveyAnswers[0].inputTypeId == InputTypeEnum.Number) {
425
- if (value.surveyAnswers[0].inputMin != null) {
426
- this.fCtrls.inputMin.setValue(value.surveyAnswers[0].inputMin);
427
- this.fCtrls.answer.addValidators([Validators.min(value.surveyAnswers[0].inputMin)]);
547
+ if (!this.surveyQuestion) {
548
+ this.surveyQuestion = value.questionAllInfo;
549
+ this.isTextArea = value.questionAllInfo.isAdvanceTextArea;
550
+ this.rForm.patchValue({
551
+ id: value.questionId,
552
+ name: value.questionAllInfo.questionName,
553
+ title: value.questionAllInfo.questionTitle,
554
+ typeId: value.questionAllInfo.questionTypeId,
555
+ description: value.questionAllInfo.questionDescription,
556
+ isDisabled: value.questionAllInfo.isReadOnly,
557
+ isShow: value.questionAllInfo.isVisable
558
+ });
559
+ if (value.questionAllInfo.surveyAnswers[0]?.answerId != null && value.questionAllInfo.surveyAnswers[0]?.answerId != undefined) {
560
+ this.fCtrls.surveyAnswerId.setValue(value.questionAllInfo.surveyAnswers[0].answerId);
561
+ this.fCtrls.inputTypeId.setValue(value.questionAllInfo.surveyAnswers[0].inputTypeId);
562
+ }
563
+ if (value.isRequired == true) {
564
+ this.fCtrls.answer.addValidators([Validators.required]);
565
+ if (value.questionAllInfo.surveyAnswers[0].inputTypeId == InputTypeEnum.Number) {
566
+ if (value.questionAllInfo.surveyAnswers[0].inputMin != null) {
567
+ this.fCtrls.inputMin.setValue(value.questionAllInfo.surveyAnswers[0].inputMin);
568
+ this.fCtrls.answer.addValidators([Validators.min(value.questionAllInfo.surveyAnswers[0].inputMin)]);
569
+ }
570
+ if (value.questionAllInfo.surveyAnswers[0].inputMax != null) {
571
+ this.fCtrls.inputMax.setValue(value.questionAllInfo.surveyAnswers[0].inputMax);
572
+ this.fCtrls.answer.addValidators([Validators.max(value.questionAllInfo.surveyAnswers[0].inputMax)]);
573
+ }
574
+ if (value.questionAllInfo.surveyAnswers[0].inputMin != null || value.questionAllInfo.surveyAnswers[0].inputMax != null) {
575
+ this.fCtrls.inputTypeId.setValue(InputTypeEnum.Text);
576
+ }
428
577
  }
429
- if (value.surveyAnswers[0].inputMax != null) {
430
- this.fCtrls.inputMax.setValue(value.surveyAnswers[0].inputMax);
431
- this.fCtrls.answer.addValidators([Validators.max(value.surveyAnswers[0].inputMax)]);
578
+ else if (value.questionAllInfo.surveyAnswers[0].inputTypeId == InputTypeEnum.Email) {
579
+ this.fCtrls.answer.addValidators([Validators.email]);
432
580
  }
433
- if (value.surveyAnswers[0].inputMin != null || value.surveyAnswers[0].inputMax != null) {
434
- this.fCtrls.inputTypeId.setValue(InputTypeEnum.Text);
581
+ else if (value.questionAllInfo.surveyAnswers[0].inputTypeId == InputTypeEnum.Phone) {
582
+ this.fCtrls.answer.addValidators([PhoneValidator]);
435
583
  }
584
+ this.fCtrls.answer.updateValueAndValidity();
436
585
  }
437
- else if (value.surveyAnswers[0].inputTypeId == InputTypeEnum.Email) {
438
- this.fCtrls.answer.addValidators([Validators.email]);
439
- }
440
- else if (value.surveyAnswers[0].inputTypeId == InputTypeEnum.Phone) {
441
- this.fCtrls.answer.addValidators([PhoneValidator]);
442
- }
443
- this.fCtrls.answer.updateValueAndValidity();
586
+ this.toggleEnableAnswer(value.questionAllInfo.isReadOnly);
444
587
  }
445
- this.toggleEnableAnswer(value.isReadOnly);
446
588
  }
447
589
  set isDisabled(value) {
448
590
  this.toggleEnableAnswer(value);
449
591
  }
450
- constructor(_formBuilder, _surveyLibService) {
592
+ constructor(_formBuilder, _surveyLibService, _Store) {
451
593
  this._formBuilder = _formBuilder;
452
594
  this._surveyLibService = _surveyLibService;
453
- this.emitter = new EventEmitter();
595
+ this._Store = _Store;
454
596
  this.isArabicLang = false;
455
- this.isTextArea = false;
456
597
  this.rForm = this._formBuilder.group({
457
598
  id: [null],
458
599
  name: [null],
@@ -469,7 +610,7 @@ class QuestionTextTemplateComponent {
469
610
  });
470
611
  }
471
612
  ngOnInit() {
472
- this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
613
+ this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200), distinctUntilChanged()).subscribe(value => {
473
614
  const formValue = this.rForm.value;
474
615
  if (formValue.inputTypeId == InputTypeEnum.Email) {
475
616
  const isRequired = this.fCtrls.answer.hasValidator(Validators.required);
@@ -485,27 +626,31 @@ class QuestionTextTemplateComponent {
485
626
  }
486
627
  setTimeout(() => {
487
628
  const formValue = this.rForm.value;
488
- this.emitter.emit({
489
- QuestionId: formValue.id,
490
- IsValid: this.fCtrls.answer.valid,
491
- Answer: value,
492
- SurveyAnswerId: formValue.surveyAnswerId
493
- });
629
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
630
+ questionId: formValue.id,
631
+ answer: value,
632
+ isValid: this.fCtrls.answer.valid
633
+ }));
494
634
  }, 100);
495
635
  });
496
- this.fCtrls.answer.setValue(null);
497
- this._surveyLibService.surveyAnswersObsrv.pipe(map(x => x.defaultAnswers.filter(x => x.QuestionId == this.fCtrls.id.value)))
498
- .pipe(filter(x => x.length > 0)).pipe(map(x => x.at(0)))
499
- .subscribe(answer => {
500
- this.fCtrls.answer.setValue(answer.AnswerText);
501
- });
502
- this._surveyLibService.questionIsDisabledObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
503
- this.fCtrls.isDisabled.setValue(x.isDisabled);
504
- });
505
- this._surveyLibService.questionIsShowObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
506
- this.fCtrls.isShow.setValue(x.isShow);
507
- if (x.isShow == false) {
508
- this.fCtrls.answer.setValue(null);
636
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
637
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
638
+ const oldValue = value[0];
639
+ const newValue = value[1];
640
+ //updated answer
641
+ if (oldValue?.answerText != newValue?.answerText) {
642
+ this.fCtrls.answer.setValue(newValue?.answerText, { emitEvent: false });
643
+ }
644
+ //updated isDisabled
645
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
646
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
647
+ }
648
+ //updated isShow
649
+ if (oldValue?.isShow != newValue?.isShow) {
650
+ this.fCtrls.isShow.setValue(newValue?.isShow);
651
+ if (newValue?.isShow == false) {
652
+ this.fCtrls.answer.setValue(null);
653
+ }
509
654
  }
510
655
  });
511
656
  }
@@ -521,17 +666,13 @@ class QuestionTextTemplateComponent {
521
666
  }
522
667
  this.fCtrls.answer.updateValueAndValidity();
523
668
  }
524
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionTextTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }], target: i0.ɵɵFactoryTarget.Component }); }
525
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionTextTemplateComponent, selector: "lib-question-text-template", inputs: { isArabicLang: "isArabicLang", isTextArea: "isTextArea", setQuestion: "setQuestion", isDisabled: "isDisabled" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<div class=\"quastion\" [formGroup]=\"rForm\" [attr.id]=\"'question_'+fCtrls.id.value\"\r\n [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n <p *ngIf=\"questionMinMaxIndicator\" class=\"text-danger\">\r\n <small >{{questionMinMaxIndicator}}</small>\r\n </p> \r\n </h3>\r\n <div class=\"text-quastion\">\r\n <ng-container *ngIf=\"isTextArea == false else textAreaTemplate\">\r\n <input class=\"form-control\" libMaskedForMinMax [attr.min]=\"fCtrls.inputMin.value\"\r\n [attr.max]=\"fCtrls.inputMax.value\" [formControl]=\"convertToFormControl(fCtrls.answer)\"\r\n [disabled]=\"isDisabled\" [attr.type]=\"fCtrls.inputTypeId.value | textBoxTypeAttr\">\r\n </ng-container>\r\n <ng-template #textAreaTemplate>\r\n <textarea class=\"form-control\" rows=\"2\" [formControl]=\"convertToFormControl(fCtrls.answer)\"\r\n [disabled]=\"isDisabled\"></textarea>\r\n </ng-template>\r\n </div>", styles: [""], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i4.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i4.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: MaskedForMinMaxDirective, selector: "[libMaskedForMinMax]" }, { kind: "pipe", type: TextBoxTypeAttrPipe, name: "textBoxTypeAttr" }] }); }
669
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionTextTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: i3.Store }], target: i0.ɵɵFactoryTarget.Component }); }
670
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionTextTemplateComponent, selector: "lib-question-text-template", inputs: { isArabicLang: "isArabicLang", setQuestion: "setQuestion", isDisabled: "isDisabled" }, ngImport: i0, template: "<div class=\"quastion\" [formGroup]=\"rForm\" [attr.id]=\"'question_'+fCtrls.id.value\"\r\n [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n <p *ngIf=\"questionMinMaxIndicator\" class=\"text-danger\">\r\n <small >{{questionMinMaxIndicator}}</small>\r\n </p> \r\n </h3>\r\n <div class=\"text-quastion\">\r\n <ng-container *ngIf=\"isTextArea == false else textAreaTemplate\">\r\n <input class=\"form-control\" libMaskedForMinMax [attr.min]=\"fCtrls.inputMin.value\"\r\n [attr.max]=\"fCtrls.inputMax.value\" [formControl]=\"convertToFormControl(fCtrls.answer)\"\r\n [disabled]=\"isDisabled\" [attr.type]=\"fCtrls.inputTypeId.value | textBoxTypeAttr\">\r\n </ng-container>\r\n <ng-template #textAreaTemplate>\r\n <textarea class=\"form-control\" rows=\"2\" [formControl]=\"convertToFormControl(fCtrls.answer)\"\r\n [disabled]=\"isDisabled\"></textarea>\r\n </ng-template>\r\n </div>", styles: [""], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i5.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i5.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i5.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i5.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: MaskedForMinMaxDirective, selector: "[libMaskedForMinMax]" }, { kind: "pipe", type: TextBoxTypeAttrPipe, name: "textBoxTypeAttr" }] }); }
526
671
  }
527
672
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionTextTemplateComponent, decorators: [{
528
673
  type: Component,
529
674
  args: [{ selector: 'lib-question-text-template', template: "<div class=\"quastion\" [formGroup]=\"rForm\" [attr.id]=\"'question_'+fCtrls.id.value\"\r\n [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n <p *ngIf=\"questionMinMaxIndicator\" class=\"text-danger\">\r\n <small >{{questionMinMaxIndicator}}</small>\r\n </p> \r\n </h3>\r\n <div class=\"text-quastion\">\r\n <ng-container *ngIf=\"isTextArea == false else textAreaTemplate\">\r\n <input class=\"form-control\" libMaskedForMinMax [attr.min]=\"fCtrls.inputMin.value\"\r\n [attr.max]=\"fCtrls.inputMax.value\" [formControl]=\"convertToFormControl(fCtrls.answer)\"\r\n [disabled]=\"isDisabled\" [attr.type]=\"fCtrls.inputTypeId.value | textBoxTypeAttr\">\r\n </ng-container>\r\n <ng-template #textAreaTemplate>\r\n <textarea class=\"form-control\" rows=\"2\" [formControl]=\"convertToFormControl(fCtrls.answer)\"\r\n [disabled]=\"isDisabled\"></textarea>\r\n </ng-template>\r\n </div>" }]
530
- }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }]; }, propDecorators: { emitter: [{
531
- type: Output
532
- }], isArabicLang: [{
533
- type: Input
534
- }], isTextArea: [{
675
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { isArabicLang: [{
535
676
  type: Input
536
677
  }], setQuestion: [{
537
678
  type: Input
@@ -547,33 +688,35 @@ class QuestionRadioButtonTemplateComponent {
547
688
  return QuestionTypeEnum;
548
689
  }
549
690
  set setQuestion(value) {
550
- this.surveyQuestion = value;
551
- this.rForm.patchValue({
552
- id: value.questionId,
553
- name: value.questionName,
554
- title: value.questionTitle,
555
- typeId: value.questionTypeId,
556
- description: value.questionDescription,
557
- isDisabled: value.isReadOnly,
558
- isShow: value.isVisable
559
- });
560
- value.surveyAnswers.forEach(surveryAnswer => {
561
- this.fCtrls.answerArray.push(this._formBuilder.group({
562
- id: [surveryAnswer.answerId],
563
- title: [surveryAnswer.answerTitle],
564
- isSelected: [false]
565
- }));
566
- });
567
- if (value.isRequired == true) {
568
- this.fCtrls.answer.addValidators([Validators.required]);
569
- this.fCtrls.answer.updateValueAndValidity();
691
+ if (!this.surveyQuestion) {
692
+ this.surveyQuestion = value.questionAllInfo;
693
+ this.rForm.patchValue({
694
+ id: value.questionId,
695
+ name: value.questionAllInfo.questionName,
696
+ title: value.questionAllInfo.questionTitle,
697
+ typeId: value.questionAllInfo.questionTypeId,
698
+ description: value.questionAllInfo.questionDescription,
699
+ isDisabled: value.questionAllInfo.isReadOnly,
700
+ isShow: value.questionAllInfo.isVisable
701
+ });
702
+ value.questionAllInfo.surveyAnswers.forEach(surveryAnswer => {
703
+ this.fCtrls.answerArray.push(this._formBuilder.group({
704
+ id: [surveryAnswer.answerId],
705
+ title: [surveryAnswer.answerTitle],
706
+ isSelected: [false]
707
+ }));
708
+ });
709
+ if (value.isRequired == true) {
710
+ this.fCtrls.answer.addValidators([Validators.required]);
711
+ this.fCtrls.answer.updateValueAndValidity();
712
+ }
570
713
  }
571
714
  }
572
- constructor(_formBuilder, _surveyLibService) {
715
+ constructor(_formBuilder, _surveyLibService, _Store) {
573
716
  this._formBuilder = _formBuilder;
574
717
  this._surveyLibService = _surveyLibService;
718
+ this._Store = _Store;
575
719
  this.elemId = v4();
576
- this.emitter = new EventEmitter();
577
720
  this.rForm = this._formBuilder.group({
578
721
  id: [null],
579
722
  name: [null],
@@ -589,29 +732,34 @@ class QuestionRadioButtonTemplateComponent {
589
732
  ngOnInit() {
590
733
  this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
591
734
  const formValue = this.rForm.value;
592
- this.emitter.emit({
593
- QuestionId: formValue.id,
594
- IsValid: this.fCtrls.answer.valid,
595
- Answer: value
596
- });
735
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
736
+ questionId: formValue.id,
737
+ answer: value,
738
+ isValid: this.fCtrls.answer.valid
739
+ }));
597
740
  });
598
- this.fCtrls.answer.setValue(null);
599
- this._surveyLibService.surveyAnswersObsrv.pipe(map(x => x.defaultAnswers.filter(x => x.QuestionId == this.fCtrls.id.value)))
600
- .pipe(filter(x => x.length > 0)).pipe(map(x => x.at(0)))
601
- .subscribe(answer => {
602
- this.fCtrls.answer.setValue(answer.AnswerId);
603
- const groupIndex = this.fCtrls.answerArray.value.findIndex(x => x.id == answer.AnswerId);
604
- if (groupIndex > -1) {
605
- this.fCtrls.answerArray.at(groupIndex).controls.isSelected.setValue(true);
741
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
742
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
743
+ const oldValue = value[0];
744
+ const newValue = value[1];
745
+ //updated answer
746
+ if (oldValue?.answerId != newValue?.answerId) {
747
+ this.fCtrls.answer.setValue(newValue?.answerId, { emitEvent: false });
748
+ const groupIndex = this.fCtrls.answerArray.value.findIndex(x => x.id == newValue?.answerId);
749
+ if (groupIndex > -1) {
750
+ this.fCtrls.answerArray.at(groupIndex).controls.isSelected.setValue(true);
751
+ }
606
752
  }
607
- });
608
- this._surveyLibService.questionIsDisabledObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
609
- this.fCtrls.isDisabled.setValue(x.isDisabled);
610
- });
611
- this._surveyLibService.questionIsShowObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
612
- this.fCtrls.isShow.setValue(x.isShow);
613
- if (x.isShow == false) {
614
- this.fCtrls.answer.setValue(null);
753
+ //updated isDisabled
754
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
755
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
756
+ }
757
+ //updated isShow
758
+ if (oldValue?.isShow != newValue?.isShow) {
759
+ this.fCtrls.isShow.setValue(newValue?.isShow);
760
+ if (newValue?.isShow == false) {
761
+ this.fCtrls.answer.setValue(null);
762
+ }
615
763
  }
616
764
  });
617
765
  }
@@ -621,15 +769,13 @@ class QuestionRadioButtonTemplateComponent {
621
769
  convertToFormControl(element) {
622
770
  return element;
623
771
  }
624
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionRadioButtonTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }], target: i0.ɵɵFactoryTarget.Component }); }
625
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionRadioButtonTemplateComponent, selector: "lib-question-radio-button-template", inputs: { setQuestion: "setQuestion" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"radio-button-quastion\">\r\n <div class=\"form-check form-check-radio form-check-inline\" \r\n *ngFor=\"let item of fCtrls.answerArray.controls;let i = index\">\r\n <input class=\"form-check-input\" type=\"radio\" (change)=\"onChangeAnswer(item.value)\" [disabled]=\"fCtrls.isDisabled.value\"\r\n name=\"{{elemId}}__radio-btn-option\" id=\"{{elemId}}__radio-btn_{{i}}\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label\" for=\"{{elemId}}__radio-btn_{{i}}\" [innerHTML]=\"item.value.title\"></label>\r\n </div>\r\n </div>\r\n</div>\r\n", styles: [""], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
772
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionRadioButtonTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: i3.Store }], target: i0.ɵɵFactoryTarget.Component }); }
773
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionRadioButtonTemplateComponent, selector: "lib-question-radio-button-template", inputs: { setQuestion: "setQuestion" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"radio-button-quastion\">\r\n <div class=\"form-check form-check-radio form-check-inline\" \r\n *ngFor=\"let item of fCtrls.answerArray.controls;let i = index\">\r\n <input class=\"form-check-input\" type=\"radio\" (change)=\"onChangeAnswer(item.value)\" [disabled]=\"fCtrls.isDisabled.value\"\r\n name=\"{{elemId}}__radio-btn-option\" id=\"{{elemId}}__radio-btn_{{i}}\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label\" for=\"{{elemId}}__radio-btn_{{i}}\" [innerHTML]=\"item.value.title\"></label>\r\n </div>\r\n </div>\r\n</div>\r\n", styles: [""], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
626
774
  }
627
775
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionRadioButtonTemplateComponent, decorators: [{
628
776
  type: Component,
629
777
  args: [{ selector: 'lib-question-radio-button-template', template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"radio-button-quastion\">\r\n <div class=\"form-check form-check-radio form-check-inline\" \r\n *ngFor=\"let item of fCtrls.answerArray.controls;let i = index\">\r\n <input class=\"form-check-input\" type=\"radio\" (change)=\"onChangeAnswer(item.value)\" [disabled]=\"fCtrls.isDisabled.value\"\r\n name=\"{{elemId}}__radio-btn-option\" id=\"{{elemId}}__radio-btn_{{i}}\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label\" for=\"{{elemId}}__radio-btn_{{i}}\" [innerHTML]=\"item.value.title\"></label>\r\n </div>\r\n </div>\r\n</div>\r\n" }]
630
- }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }]; }, propDecorators: { emitter: [{
631
- type: Output
632
- }], setQuestion: [{
778
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
633
779
  type: Input
634
780
  }] } });
635
781
 
@@ -641,33 +787,35 @@ class QuestionCheckBoxTemplateComponent {
641
787
  return QuestionTypeEnum;
642
788
  }
643
789
  set setQuestion(value) {
644
- this.surveyQuestion = value;
645
- this.rForm.patchValue({
646
- id: value.questionId,
647
- name: value.questionName,
648
- title: value.questionTitle,
649
- typeId: value.questionTypeId,
650
- description: value.questionDescription,
651
- isDisabled: value.isReadOnly,
652
- isShow: value.isVisable
653
- });
654
- value.surveyAnswers.forEach(surveryAnswer => {
655
- this.fCtrls.answerArray.push(this._formBuilder.group({
656
- id: [surveryAnswer.answerId],
657
- title: [surveryAnswer.answerTitle],
658
- isSelected: [false]
659
- }));
660
- });
661
- if (value.isRequired == true) {
662
- this.fCtrls.answer.addValidators([Validators.required]);
663
- this.fCtrls.answer.updateValueAndValidity();
790
+ if (!this.surveyQuestion) {
791
+ this.surveyQuestion = value.questionAllInfo;
792
+ this.rForm.patchValue({
793
+ id: value.questionId,
794
+ name: value.questionAllInfo.questionName,
795
+ title: value.questionAllInfo.questionTitle,
796
+ typeId: value.questionAllInfo.questionTypeId,
797
+ description: value.questionAllInfo.questionDescription,
798
+ isDisabled: value.questionAllInfo.isReadOnly,
799
+ isShow: value.questionAllInfo.isVisable
800
+ });
801
+ value.questionAllInfo.surveyAnswers.forEach(surveryAnswer => {
802
+ this.fCtrls.answerArray.push(this._formBuilder.group({
803
+ id: [surveryAnswer.answerId],
804
+ title: [surveryAnswer.answerTitle],
805
+ isSelected: [false]
806
+ }));
807
+ });
808
+ if (value.isRequired == true) {
809
+ this.fCtrls.answer.addValidators([Validators.required]);
810
+ this.fCtrls.answer.updateValueAndValidity();
811
+ }
664
812
  }
665
813
  }
666
- constructor(_formBuilder, _surveyLibService) {
814
+ constructor(_formBuilder, _surveyLibService, _Store) {
667
815
  this._formBuilder = _formBuilder;
668
816
  this._surveyLibService = _surveyLibService;
817
+ this._Store = _Store;
669
818
  this.elemId = v4();
670
- this.emitter = new EventEmitter();
671
819
  this.rForm = this._formBuilder.group({
672
820
  id: [null],
673
821
  name: [null],
@@ -683,33 +831,37 @@ class QuestionCheckBoxTemplateComponent {
683
831
  ngOnInit() {
684
832
  this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
685
833
  const formValue = this.rForm.value;
686
- this.emitter.emit({
687
- QuestionId: formValue.id,
688
- IsValid: this.fCtrls.answer.valid,
689
- Answer: value
690
- });
834
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
835
+ questionId: formValue.id,
836
+ answer: value,
837
+ isValid: this.fCtrls.answer.valid
838
+ }));
691
839
  });
692
- this.fCtrls.answer.setValue(null);
693
- this._surveyLibService.surveyAnswersObsrv
694
- .pipe(map(x => x.defaultAnswers.filter(x => x.QuestionId == this.fCtrls.id.value)))
695
- .pipe(filter(x => x.length > 0)).pipe(map(x => x.at(0)))
696
- .subscribe(answer => {
697
- const distinctArray = answer.AnswerIdArr.filter((n, i) => answer.AnswerIdArr.indexOf(n) === i);
698
- this.fCtrls.answer.setValue(distinctArray);
699
- answer.AnswerIdArr.forEach(answerId => {
700
- const groupIndex = this.fCtrls.answerArray.value.findIndex(x => x.id == answerId);
701
- if (groupIndex > -1) {
702
- this.fCtrls.answerArray.at(groupIndex).controls.isSelected.setValue(true);
840
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
841
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
842
+ const oldValue = value[0];
843
+ const newValue = value[1];
844
+ //updated answer
845
+ if (oldValue?.answerIdArr != newValue?.answerIdArr) {
846
+ const distinctArray = newValue?.answerIdArr.filter((n, i) => newValue?.answerIdArr.indexOf(n) === i);
847
+ this.fCtrls.answer.setValue(distinctArray, { emitEvent: false });
848
+ newValue?.answerIdArr.forEach(answerId => {
849
+ const groupIndex = this.fCtrls.answerArray.value.findIndex(x => x.id == answerId);
850
+ if (groupIndex > -1) {
851
+ this.fCtrls.answerArray.at(groupIndex).controls.isSelected.setValue(true);
852
+ }
853
+ });
854
+ }
855
+ //updated isDisabled
856
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
857
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
858
+ }
859
+ //updated isShow
860
+ if (oldValue?.isShow != newValue?.isShow) {
861
+ this.fCtrls.isShow.setValue(newValue?.isShow);
862
+ if (newValue?.isShow == false) {
863
+ this.fCtrls.answer.setValue(null);
703
864
  }
704
- });
705
- });
706
- this._surveyLibService.questionIsDisabledObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
707
- this.fCtrls.isDisabled.setValue(x.isDisabled);
708
- });
709
- this._surveyLibService.questionIsShowObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
710
- this.fCtrls.isShow.setValue(x.isShow);
711
- if (x.isShow == false) {
712
- this.fCtrls.answer.setValue(null);
713
865
  }
714
866
  });
715
867
  }
@@ -727,15 +879,13 @@ class QuestionCheckBoxTemplateComponent {
727
879
  convertToFormControl(element) {
728
880
  return element;
729
881
  }
730
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionCheckBoxTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }], target: i0.ɵɵFactoryTarget.Component }); }
731
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionCheckBoxTemplateComponent, selector: "lib-question-check-box-template", inputs: { setQuestion: "setQuestion" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n\r\n <div class=\"checkbox-button-quastion\">\r\n <div class=\"form-check check-box-form-check\" *ngFor=\"let item of fCtrls.answerArray.controls ;let i = index\">\r\n <input type=\"checkbox\" class=\"form-check-input\" id=\"{{elemId}}__checkbox_{{i}}\" [disabled]=\"fCtrls.isDisabled.value\"\r\n (change)=\"onChangeAnswer(item.value ,$event)\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label \" for=\"{{elemId}}__checkbox_{{i}}\" [innerHTML]=\"item.value.title\"></label>\r\n </div>\r\n </div>\r\n</div>\r\n", styles: [""], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
882
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionCheckBoxTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: i3.Store }], target: i0.ɵɵFactoryTarget.Component }); }
883
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionCheckBoxTemplateComponent, selector: "lib-question-check-box-template", inputs: { setQuestion: "setQuestion" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n\r\n <div class=\"checkbox-button-quastion\">\r\n <div class=\"form-check check-box-form-check\" *ngFor=\"let item of fCtrls.answerArray.controls ;let i = index\">\r\n <input type=\"checkbox\" class=\"form-check-input\" id=\"{{elemId}}__checkbox_{{i}}\" [disabled]=\"fCtrls.isDisabled.value\"\r\n (change)=\"onChangeAnswer(item.value ,$event)\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label \" for=\"{{elemId}}__checkbox_{{i}}\" [innerHTML]=\"item.value.title\"></label>\r\n </div>\r\n </div>\r\n</div>\r\n", styles: [""], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
732
884
  }
733
885
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionCheckBoxTemplateComponent, decorators: [{
734
886
  type: Component,
735
887
  args: [{ selector: 'lib-question-check-box-template', template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n\r\n <div class=\"checkbox-button-quastion\">\r\n <div class=\"form-check check-box-form-check\" *ngFor=\"let item of fCtrls.answerArray.controls ;let i = index\">\r\n <input type=\"checkbox\" class=\"form-check-input\" id=\"{{elemId}}__checkbox_{{i}}\" [disabled]=\"fCtrls.isDisabled.value\"\r\n (change)=\"onChangeAnswer(item.value ,$event)\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label \" for=\"{{elemId}}__checkbox_{{i}}\" [innerHTML]=\"item.value.title\"></label>\r\n </div>\r\n </div>\r\n</div>\r\n" }]
736
- }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }]; }, propDecorators: { emitter: [{
737
- type: Output
738
- }], setQuestion: [{
888
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
739
889
  type: Input
740
890
  }] } });
741
891
 
@@ -747,24 +897,27 @@ class QuestionDropdownTemplateComponent {
747
897
  return QuestionTypeEnum;
748
898
  }
749
899
  set setQuestion(value) {
750
- this.surveyQuestion = value;
751
- this.rForm.patchValue({
752
- id: value.questionId,
753
- name: value.questionName,
754
- title: value.questionTitle,
755
- typeId: value.questionTypeId,
756
- description: value.questionDescription,
757
- isDisabled: value.isReadOnly,
758
- isShow: value.isVisable
759
- });
760
- if (value.isRequired == true) {
761
- this.fCtrls.answer.addValidators([Validators.required]);
762
- this.fCtrls.answer.updateValueAndValidity();
900
+ if (!this.surveyQuestion) {
901
+ this.surveyQuestion = value.questionAllInfo;
902
+ this.rForm.patchValue({
903
+ id: value.questionId,
904
+ name: value.questionAllInfo.questionName,
905
+ title: value.questionAllInfo.questionTitle,
906
+ typeId: value.questionAllInfo.questionTypeId,
907
+ description: value.questionAllInfo.questionDescription,
908
+ isDisabled: value.questionAllInfo.isReadOnly,
909
+ isShow: value.questionAllInfo.isVisable
910
+ });
911
+ if (value.isRequired == true) {
912
+ this.fCtrls.answer.addValidators([Validators.required]);
913
+ this.fCtrls.answer.updateValueAndValidity();
914
+ }
763
915
  }
764
916
  }
765
- constructor(_formBuilder, _surveyLibService) {
917
+ constructor(_formBuilder, _surveyLibService, _Store) {
766
918
  this._formBuilder = _formBuilder;
767
919
  this._surveyLibService = _surveyLibService;
920
+ this._Store = _Store;
768
921
  this.emitter = new EventEmitter();
769
922
  this.rForm = this._formBuilder.group({
770
923
  id: [null],
@@ -778,41 +931,50 @@ class QuestionDropdownTemplateComponent {
778
931
  });
779
932
  }
780
933
  ngOnInit() {
781
- this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
934
+ this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200), distinctUntilChanged()).subscribe(value => {
782
935
  const formValue = this.rForm.value;
936
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
937
+ questionId: formValue.id,
938
+ answer: value,
939
+ isValid: this.fCtrls.answer.valid
940
+ }));
783
941
  this.emitter.emit({
784
942
  QuestionId: formValue.id,
785
943
  IsValid: this.fCtrls.answer.valid,
786
944
  Answer: value
787
945
  });
788
946
  });
789
- this.fCtrls.answer.setValue(null);
790
- this._surveyLibService.surveyAnswersObsrv
791
- .pipe(map(x => x.defaultAnswers.filter(x => x.QuestionId == this.fCtrls.id.value)))
792
- .pipe(filter(x => x.length > 0)).pipe(map(x => x.at(0)))
793
- .subscribe(answer => {
794
- this.fCtrls.answer.setValue(answer.AnswerId);
795
- });
796
- this._surveyLibService.questionIsDisabledObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
797
- this.fCtrls.isDisabled.setValue(x.isDisabled);
798
- });
799
- this._surveyLibService.questionIsShowObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
800
- this.fCtrls.isShow.setValue(x.isShow);
801
- if (x.isShow == false) {
802
- this.fCtrls.answer.setValue(null);
947
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
948
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
949
+ const oldValue = value[0];
950
+ const newValue = value[1];
951
+ //updated answer
952
+ if (oldValue?.answerId != newValue?.answerId) {
953
+ this.fCtrls.answer.setValue(newValue?.answerId, { emitEvent: false });
954
+ }
955
+ //updated isDisabled
956
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
957
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
958
+ }
959
+ //updated isShow
960
+ if (oldValue?.isShow != newValue?.isShow) {
961
+ this.fCtrls.isShow.setValue(newValue?.isShow);
962
+ if (newValue?.isShow == false) {
963
+ this.fCtrls.answer.setValue(null);
964
+ }
803
965
  }
804
966
  });
805
967
  }
806
968
  convertToFormControl(element) {
807
969
  return element;
808
970
  }
809
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionDropdownTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }], target: i0.ɵɵFactoryTarget.Component }); }
810
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionDropdownTemplateComponent, selector: "lib-question-dropdown-template", inputs: { setQuestion: "setQuestion" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"text-quastion text-quastion__dropdown\">\r\n <ng-select [items]=\"surveyQuestion?.surveyAnswers\" bindValue=\"answerId\" bindLabel=\"answerTitle\" class=\"form-control\"\r\n [formControl]=\"convertToFormControl(fCtrls.answer)\" [disabled]=\"fCtrls.isDisabled.value\" [multiple]=\"false\">\r\n </ng-select>\r\n </div>\r\n</div>\r\n", styles: [".text-quastion .form-control{padding:10px}\n"], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i5.NgSelectComponent, selector: "ng-select", inputs: ["bindLabel", "bindValue", "markFirst", "placeholder", "notFoundText", "typeToSearchText", "addTagText", "loadingText", "clearAllText", "appearance", "dropdownPosition", "appendTo", "loading", "closeOnSelect", "hideSelected", "selectOnTab", "openOnEnter", "maxSelectedItems", "groupBy", "groupValue", "bufferAmount", "virtualScroll", "selectableGroup", "selectableGroupAsModel", "searchFn", "trackByFn", "clearOnBackspace", "labelForId", "inputAttrs", "tabIndex", "readonly", "searchWhileComposing", "minTermLength", "editableSearchTerm", "keyDownFn", "typeahead", "multiple", "addTag", "searchable", "clearable", "isOpen", "items", "compareWith", "clearSearchOnAdd", "deselectOnClick"], outputs: ["blur", "focus", "change", "open", "close", "search", "clear", "add", "remove", "scroll", "scrollToEnd"] }] }); }
971
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionDropdownTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: i3.Store }], target: i0.ɵɵFactoryTarget.Component }); }
972
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionDropdownTemplateComponent, selector: "lib-question-dropdown-template", inputs: { setQuestion: "setQuestion" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion?.isRequired\">*</span>\r\n </h3>\r\n <div class=\"text-quastion text-quastion__dropdown\">\r\n <ng-select [items]=\"surveyQuestion?.surveyAnswers\" bindValue=\"answerId\" bindLabel=\"answerTitle\" class=\"form-control\"\r\n [formControl]=\"convertToFormControl(fCtrls.answer)\" [disabled]=\"fCtrls.isDisabled.value\" [multiple]=\"false\">\r\n </ng-select>\r\n </div>\r\n</div>\r\n", styles: [".text-quastion .form-control{padding:10px}\n"], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i5.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i6.NgSelectComponent, selector: "ng-select", inputs: ["bindLabel", "bindValue", "markFirst", "placeholder", "notFoundText", "typeToSearchText", "addTagText", "loadingText", "clearAllText", "appearance", "dropdownPosition", "appendTo", "loading", "closeOnSelect", "hideSelected", "selectOnTab", "openOnEnter", "maxSelectedItems", "groupBy", "groupValue", "bufferAmount", "virtualScroll", "selectableGroup", "selectableGroupAsModel", "searchFn", "trackByFn", "clearOnBackspace", "labelForId", "inputAttrs", "tabIndex", "readonly", "searchWhileComposing", "minTermLength", "editableSearchTerm", "keyDownFn", "typeahead", "multiple", "addTag", "searchable", "clearable", "isOpen", "items", "compareWith", "clearSearchOnAdd", "deselectOnClick"], outputs: ["blur", "focus", "change", "open", "close", "search", "clear", "add", "remove", "scroll", "scrollToEnd"] }] }); }
811
973
  }
812
974
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionDropdownTemplateComponent, decorators: [{
813
975
  type: Component,
814
- args: [{ selector: 'lib-question-dropdown-template', template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"text-quastion text-quastion__dropdown\">\r\n <ng-select [items]=\"surveyQuestion?.surveyAnswers\" bindValue=\"answerId\" bindLabel=\"answerTitle\" class=\"form-control\"\r\n [formControl]=\"convertToFormControl(fCtrls.answer)\" [disabled]=\"fCtrls.isDisabled.value\" [multiple]=\"false\">\r\n </ng-select>\r\n </div>\r\n</div>\r\n", styles: [".text-quastion .form-control{padding:10px}\n"] }]
815
- }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }]; }, propDecorators: { emitter: [{
976
+ args: [{ selector: 'lib-question-dropdown-template', template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion?.isRequired\">*</span>\r\n </h3>\r\n <div class=\"text-quastion text-quastion__dropdown\">\r\n <ng-select [items]=\"surveyQuestion?.surveyAnswers\" bindValue=\"answerId\" bindLabel=\"answerTitle\" class=\"form-control\"\r\n [formControl]=\"convertToFormControl(fCtrls.answer)\" [disabled]=\"fCtrls.isDisabled.value\" [multiple]=\"false\">\r\n </ng-select>\r\n </div>\r\n</div>\r\n", styles: [".text-quastion .form-control{padding:10px}\n"] }]
977
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { emitter: [{
816
978
  type: Output
817
979
  }], setQuestion: [{
818
980
  type: Input
@@ -826,39 +988,41 @@ class QuestionMatrixTemplateComponent {
826
988
  return QuestionTypeEnum;
827
989
  }
828
990
  set setQuestion(value) {
829
- this.surveyQuestion = value;
830
- this.rForm.patchValue({
831
- id: value.questionId,
832
- typeId: value.questionTypeId,
833
- isDisabled: value.isReadOnly,
834
- isShow: value.isVisable
835
- });
836
- value.surveySubQuestions.forEach(x => {
837
- var group = this._formBuilder.group({
838
- subQuestionId: [x.questionId],
839
- questionTitle: [x.questionTitle],
840
- answer: [null],
991
+ if (!this.surveyQuestion) {
992
+ this.surveyQuestion = value.questionAllInfo;
993
+ this.rForm.patchValue({
994
+ id: value.questionId,
995
+ typeId: value.questionAllInfo.questionTypeId,
996
+ isDisabled: value.questionAllInfo.isReadOnly,
997
+ isShow: value.questionAllInfo.isVisable
841
998
  });
842
- if (value.isRequired == true) {
843
- group.controls.answer.addValidators([Validators.required]);
844
- group.controls.answer.updateValueAndValidity();
845
- }
846
- group.controls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
847
- const formValue = this.rForm.value;
848
- this.emitter.emit({
849
- QuestionId: group.value.subQuestionId,
850
- Answer: group.value.answer,
851
- IsValid: group.controls.answer.valid
999
+ value.questionAllInfo.surveySubQuestions.forEach(x => {
1000
+ var group = this._formBuilder.group({
1001
+ subQuestionId: [x.questionId],
1002
+ questionTitle: [x.questionTitle],
1003
+ answer: [null],
852
1004
  });
1005
+ if (value.isRequired == true) {
1006
+ group.controls.answer.addValidators([Validators.required]);
1007
+ group.controls.answer.updateValueAndValidity();
1008
+ }
1009
+ group.controls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
1010
+ const formValue = this.rForm.value;
1011
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
1012
+ questionId: group.value.subQuestionId,
1013
+ answer: group.value.answer,
1014
+ isValid: group.controls.answer.valid
1015
+ }));
1016
+ });
1017
+ this.fCtrls.subQuestionArray.push(group);
853
1018
  });
854
- this.fCtrls.subQuestionArray.push(group);
855
- });
1019
+ }
856
1020
  }
857
- constructor(_formBuilder, _surveyLibService) {
1021
+ constructor(_formBuilder, _surveyLibService, _Store) {
858
1022
  this._formBuilder = _formBuilder;
859
1023
  this._surveyLibService = _surveyLibService;
1024
+ this._Store = _Store;
860
1025
  this.elemId = v4();
861
- this.emitter = new EventEmitter();
862
1026
  this.rForm = this._formBuilder.group({
863
1027
  id: [null],
864
1028
  typeId: [null],
@@ -868,46 +1032,53 @@ class QuestionMatrixTemplateComponent {
868
1032
  });
869
1033
  }
870
1034
  ngOnInit() {
871
- this._surveyLibService.surveyAnswersObsrv
872
- .pipe(map(x => x.defaultAnswers.filter(x => x.ParentQuestionId == this.fCtrls.id.value)))
873
- .pipe(filter(x => x.length > 0))
874
- .subscribe(answers => {
1035
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
1036
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
1037
+ const oldValue = value[0];
1038
+ const newValue = value[1];
1039
+ //updated isDisabled
1040
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
1041
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
1042
+ }
1043
+ //updated isShow
1044
+ if (oldValue?.isShow != newValue?.isShow) {
1045
+ this.fCtrls.isShow.setValue(newValue?.isShow);
1046
+ // if (newValue?.isShow == false) {
1047
+ // this.fCtrls.answer.setValue(null);
1048
+ // }
1049
+ }
1050
+ });
1051
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.filter(x => x.parentQuestionId == this.fCtrls.id.value)))
1052
+ .pipe(filter(x => x.length > 0)).subscribe(questions => {
1053
+ //Update Answers
875
1054
  this.fCtrls.subQuestionArray.controls.forEach(group => {
876
- var answer = answers.find(x => x.QuestionId == group.value.subQuestionId);
877
- if (answer != null) {
878
- group.controls.answer.setValue(answer.AnswerId);
1055
+ var question = questions.find(x => x.questionId == group.value.subQuestionId);
1056
+ if (question != null) {
1057
+ group.controls.answer.setValue(question.answerId, { emitEvent: false });
879
1058
  }
880
1059
  });
881
1060
  });
882
- this._surveyLibService.questionIsDisabledObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
883
- this.fCtrls.isDisabled.setValue(x.isDisabled);
884
- });
885
- this._surveyLibService.questionIsShowObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
886
- this.fCtrls.isShow.setValue(x.isShow);
887
- });
888
1061
  }
889
1062
  onChangeAnswer(question, answer) {
890
1063
  const index = this.fCtrls.subQuestionArray.value.findIndex(x => x.subQuestionId == question.subQuestionId);
891
1064
  var subQuestionGroup = this.fCtrls.subQuestionArray.controls[index];
892
1065
  subQuestionGroup.controls.answer.setValue(answer.answerId);
893
- this.emitter.emit({
894
- QuestionId: subQuestionGroup.value.subQuestionId,
895
- Answer: subQuestionGroup.value.answer,
896
- IsValid: subQuestionGroup.controls.answer.valid
897
- });
1066
+ // this.emitter.emit({
1067
+ // QuestionId: subQuestionGroup.value.subQuestionId,
1068
+ // Answer: subQuestionGroup.value.answer,
1069
+ // IsValid: subQuestionGroup.controls.answer.valid
1070
+ // });
898
1071
  }
899
1072
  convertToFormControl(element) {
900
1073
  return element;
901
1074
  }
902
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionMatrixTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }], target: i0.ɵɵFactoryTarget.Component }); }
903
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionMatrixTemplateComponent, selector: "lib-question-matrix-template", inputs: { setQuestion: "setQuestion" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" style=\" border-collapse: collapse;\"\r\n[ngClass]=\"{'d-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"matrix-question\" [formGroup]=\"rForm\">\r\n <div class=\"matrix-table\" formArrayName=\"subQuestionArray\">\r\n <div class=\"matrix-head-row\">\r\n <div class=\"matrix-col\">\r\n </div>\r\n <div class=\"matrix-col\" *ngFor=\"let answers of surveyQuestion?.surveyAnswers\" >\r\n <span [innerHTML]=\"answers.answerTitle\"></span>\r\n </div>\r\n </div>\r\n\r\n <div class=\"matrix-row\" [attr.id]=\"'question_'+questionGroup.value.subQuestionId\"\r\n *ngFor=\"let questionGroup of fCtrls.subQuestionArray.controls ;let subQuestionIndex = index\"\r\n [ngClass]=\"{'invalid-question': questionGroup.controls.answer.invalid}\">\r\n <div class=\"matrix-col matrix-sub-quastion\" [innerHTML]=\"questionGroup.value.questionTitle\">\r\n </div>\r\n <div class=\"matrix-col answer__container\" *ngFor=\"let answer of surveyQuestion?.surveyAnswers;let answerIndex = index\">\r\n <div class=\"form-check form-check-radio form-check-inline\">\r\n <input class=\"form-check-input\" type=\"radio\" name=\"{{elemId}}__radio-btn-option_{{subQuestionIndex}}\"\r\n id=\"{{elemId}}__radio-btn_{{subQuestionIndex}}_{{answerIndex}}\" (change)=\"onChangeAnswer(questionGroup.value ,answer)\"\r\n value=\"{{answer.answerId}}\" [checked]=\"answer.answerId == questionGroup.value.answer\">\r\n <label class=\"form-check-label d-inline d-lg-none\" [innerHTML]=\"answer.answerTitle\"\r\n for=\"{{elemId}}__radio-btn_{{subQuestionIndex}}_{{answerIndex}}\"> </label>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n </div>\r\n\r\n </div>\r\n</div>", styles: ["@media (max-width: 767px){.quastion .quastion-title{position:sticky;top:150px;z-index:1000;padding:10px 20px;background-color:#4c3d8f;color:#fff;font-size:16px;box-shadow:4px 5px 5px #0000004d;border-radius:10px;-webkit-border-radius:10px;-moz-border-radius:10px;-ms-border-radius:10px;-o-border-radius:10px}.quastion .quastion-title:last-of-type(){position:static;z-index:initial}.quastion .matrix-question .matrix-table .matrix-row .matrix-col{width:100%!important}.matrix-table .matrix-row .matrix-col .form-check{flex-direction:row}.matrix-head-row{display:none!important}.answer__container.matrix-col{padding:5px 15px!important}.answer__container.matrix-col .form-check-radio .form-check-label{padding-right:15px!important}}\n"], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i4.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i4.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i4.FormArrayName, selector: "[formArrayName]", inputs: ["formArrayName"] }] }); }
1075
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionMatrixTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: i3.Store }], target: i0.ɵɵFactoryTarget.Component }); }
1076
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionMatrixTemplateComponent, selector: "lib-question-matrix-template", inputs: { setQuestion: "setQuestion" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" style=\" border-collapse: collapse;\"\r\n[ngClass]=\"{'d-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"matrix-question\" [formGroup]=\"rForm\">\r\n <div class=\"matrix-table\" formArrayName=\"subQuestionArray\">\r\n <div class=\"matrix-head-row\">\r\n <div class=\"matrix-col\">\r\n </div>\r\n <div class=\"matrix-col\" *ngFor=\"let answers of surveyQuestion?.surveyAnswers\" >\r\n <span [innerHTML]=\"answers.answerTitle\"></span>\r\n </div>\r\n </div>\r\n\r\n <div class=\"matrix-row\" [attr.id]=\"'question_'+questionGroup.value.subQuestionId\"\r\n *ngFor=\"let questionGroup of fCtrls.subQuestionArray.controls ;let subQuestionIndex = index\"\r\n [ngClass]=\"{'invalid-question': questionGroup.controls.answer.invalid}\">\r\n <div class=\"matrix-col matrix-sub-quastion\" [innerHTML]=\"questionGroup.value.questionTitle\">\r\n </div>\r\n <div class=\"matrix-col answer__container\" *ngFor=\"let answer of surveyQuestion?.surveyAnswers;let answerIndex = index\">\r\n <div class=\"form-check form-check-radio form-check-inline\">\r\n <input class=\"form-check-input\" type=\"radio\" name=\"{{elemId}}__radio-btn-option_{{subQuestionIndex}}\"\r\n id=\"{{elemId}}__radio-btn_{{subQuestionIndex}}_{{answerIndex}}\" (change)=\"onChangeAnswer(questionGroup.value ,answer)\"\r\n value=\"{{answer.answerId}}\" [checked]=\"answer.answerId == questionGroup.value.answer\">\r\n <label class=\"form-check-label d-inline d-lg-none\" [innerHTML]=\"answer.answerTitle\"\r\n for=\"{{elemId}}__radio-btn_{{subQuestionIndex}}_{{answerIndex}}\"> </label>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n </div>\r\n\r\n </div>\r\n</div>", styles: ["@media (max-width: 767px){.quastion .quastion-title{position:sticky;top:150px;z-index:1000;padding:10px 20px;background-color:#4c3d8f;color:#fff;font-size:16px;box-shadow:4px 5px 5px #0000004d;border-radius:10px;-webkit-border-radius:10px;-moz-border-radius:10px;-ms-border-radius:10px;-o-border-radius:10px}.quastion .quastion-title:last-of-type(){position:static;z-index:initial}.quastion .matrix-question .matrix-table .matrix-row .matrix-col{width:100%!important}.matrix-table .matrix-row .matrix-col .form-check{flex-direction:row}.matrix-head-row{display:none!important}.answer__container.matrix-col{padding:5px 15px!important}.answer__container.matrix-col .form-check-radio .form-check-label{padding-right:15px!important}}\n"], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i5.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i5.FormArrayName, selector: "[formArrayName]", inputs: ["formArrayName"] }] }); }
904
1077
  }
905
1078
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionMatrixTemplateComponent, decorators: [{
906
1079
  type: Component,
907
1080
  args: [{ selector: 'lib-question-matrix-template', template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" style=\" border-collapse: collapse;\"\r\n[ngClass]=\"{'d-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"surveyQuestion?.questionTitle\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"matrix-question\" [formGroup]=\"rForm\">\r\n <div class=\"matrix-table\" formArrayName=\"subQuestionArray\">\r\n <div class=\"matrix-head-row\">\r\n <div class=\"matrix-col\">\r\n </div>\r\n <div class=\"matrix-col\" *ngFor=\"let answers of surveyQuestion?.surveyAnswers\" >\r\n <span [innerHTML]=\"answers.answerTitle\"></span>\r\n </div>\r\n </div>\r\n\r\n <div class=\"matrix-row\" [attr.id]=\"'question_'+questionGroup.value.subQuestionId\"\r\n *ngFor=\"let questionGroup of fCtrls.subQuestionArray.controls ;let subQuestionIndex = index\"\r\n [ngClass]=\"{'invalid-question': questionGroup.controls.answer.invalid}\">\r\n <div class=\"matrix-col matrix-sub-quastion\" [innerHTML]=\"questionGroup.value.questionTitle\">\r\n </div>\r\n <div class=\"matrix-col answer__container\" *ngFor=\"let answer of surveyQuestion?.surveyAnswers;let answerIndex = index\">\r\n <div class=\"form-check form-check-radio form-check-inline\">\r\n <input class=\"form-check-input\" type=\"radio\" name=\"{{elemId}}__radio-btn-option_{{subQuestionIndex}}\"\r\n id=\"{{elemId}}__radio-btn_{{subQuestionIndex}}_{{answerIndex}}\" (change)=\"onChangeAnswer(questionGroup.value ,answer)\"\r\n value=\"{{answer.answerId}}\" [checked]=\"answer.answerId == questionGroup.value.answer\">\r\n <label class=\"form-check-label d-inline d-lg-none\" [innerHTML]=\"answer.answerTitle\"\r\n for=\"{{elemId}}__radio-btn_{{subQuestionIndex}}_{{answerIndex}}\"> </label>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n </div>\r\n\r\n </div>\r\n</div>", styles: ["@media (max-width: 767px){.quastion .quastion-title{position:sticky;top:150px;z-index:1000;padding:10px 20px;background-color:#4c3d8f;color:#fff;font-size:16px;box-shadow:4px 5px 5px #0000004d;border-radius:10px;-webkit-border-radius:10px;-moz-border-radius:10px;-ms-border-radius:10px;-o-border-radius:10px}.quastion .quastion-title:last-of-type(){position:static;z-index:initial}.quastion .matrix-question .matrix-table .matrix-row .matrix-col{width:100%!important}.matrix-table .matrix-row .matrix-col .form-check{flex-direction:row}.matrix-head-row{display:none!important}.answer__container.matrix-col{padding:5px 15px!important}.answer__container.matrix-col .form-check-radio .form-check-label{padding-right:15px!important}}\n"] }]
908
- }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }]; }, propDecorators: { emitter: [{
909
- type: Output
910
- }], setQuestion: [{
1081
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
911
1082
  type: Input
912
1083
  }] } });
913
1084
 
@@ -919,34 +1090,35 @@ class QuestionBooleanTemplateComponent {
919
1090
  return QuestionTypeEnum;
920
1091
  }
921
1092
  set setQuestion(value) {
922
- this.surveyQuestion = value;
923
- this.rForm.patchValue({
924
- id: value.questionId,
925
- name: value.questionName,
926
- title: value.questionTitle,
927
- typeId: value.questionTypeId,
928
- description: value.questionDescription,
929
- isDisabled: value.isReadOnly,
930
- isShow: value.isVisable
931
- });
932
- console.log(value.surveyAnswers);
933
- value.surveyAnswers.forEach(surveryAnswer => {
934
- this.fCtrls.answerArray.push(this._formBuilder.group({
935
- id: [surveryAnswer.answerId],
936
- title: [surveryAnswer.answerTitle],
937
- isSelected: [false]
938
- }));
939
- });
940
- if (value.isRequired == true) {
941
- this.fCtrls.answer.addValidators([Validators.required]);
942
- this.fCtrls.answer.updateValueAndValidity();
1093
+ if (!this.surveyQuestion) {
1094
+ this.surveyQuestion = value.questionAllInfo;
1095
+ this.rForm.patchValue({
1096
+ id: value.questionId,
1097
+ name: value.questionAllInfo.questionName,
1098
+ title: value.questionAllInfo.questionTitle,
1099
+ typeId: value.questionAllInfo.questionTypeId,
1100
+ description: value.questionAllInfo.questionDescription,
1101
+ isDisabled: value.questionAllInfo.isReadOnly,
1102
+ isShow: value.questionAllInfo.isVisable
1103
+ });
1104
+ value.questionAllInfo.surveyAnswers.forEach(surveryAnswer => {
1105
+ this.fCtrls.answerArray.push(this._formBuilder.group({
1106
+ id: [surveryAnswer.answerId],
1107
+ title: [surveryAnswer.answerTitle],
1108
+ isSelected: [false]
1109
+ }));
1110
+ });
1111
+ if (value.isRequired == true) {
1112
+ this.fCtrls.answer.addValidators([Validators.required]);
1113
+ this.fCtrls.answer.updateValueAndValidity();
1114
+ }
943
1115
  }
944
1116
  }
945
- constructor(_formBuilder, _surveyLibService) {
1117
+ constructor(_formBuilder, _surveyLibService, _Store) {
946
1118
  this._formBuilder = _formBuilder;
947
1119
  this._surveyLibService = _surveyLibService;
1120
+ this._Store = _Store;
948
1121
  this.elemId = v4();
949
- this.emitter = new EventEmitter();
950
1122
  this.rForm = this._formBuilder.group({
951
1123
  id: [null],
952
1124
  name: [null],
@@ -960,32 +1132,32 @@ class QuestionBooleanTemplateComponent {
960
1132
  });
961
1133
  }
962
1134
  ngOnInit() {
963
- this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
1135
+ this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200), distinctUntilChanged()).subscribe(value => {
964
1136
  const formValue = this.rForm.value;
965
- this.emitter.emit({
966
- QuestionId: formValue.id,
967
- IsValid: this.fCtrls.answer.valid,
968
- Answer: value
969
- });
1137
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
1138
+ questionId: formValue.id,
1139
+ answer: value,
1140
+ isValid: this.fCtrls.answer.valid
1141
+ }));
970
1142
  });
971
- this.fCtrls.answer.setValue(null);
972
- this._surveyLibService.surveyAnswersObsrv
973
- .pipe(map(x => x.defaultAnswers.filter(x => x.QuestionId == this.fCtrls.id.value)))
974
- .pipe(filter(x => x.length > 0)).pipe(map(x => x.at(0)))
975
- .subscribe(answer => {
976
- this.fCtrls.answer.setValue(answer.AnswerId);
977
- const groupIndex = this.fCtrls.answerArray.value.findIndex(x => x.id == answer.AnswerId);
978
- if (groupIndex > -1) {
979
- this.fCtrls.answerArray.at(groupIndex).controls.isSelected.setValue(true);
1143
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
1144
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
1145
+ const oldValue = value[0];
1146
+ const newValue = value[1];
1147
+ //updated answer
1148
+ if (oldValue?.answerId != newValue?.answerId) {
1149
+ this.fCtrls.answer.setValue(newValue?.answerId, { emitEvent: false });
980
1150
  }
981
- });
982
- this._surveyLibService.questionIsDisabledObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
983
- this.fCtrls.isDisabled.setValue(x.isDisabled);
984
- });
985
- this._surveyLibService.questionIsShowObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
986
- this.fCtrls.isShow.setValue(x.isShow);
987
- if (x.isShow == false) {
988
- this.fCtrls.answer.setValue(null);
1151
+ //updated isDisabled
1152
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
1153
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
1154
+ }
1155
+ //updated isShow
1156
+ if (oldValue?.isShow != newValue?.isShow) {
1157
+ this.fCtrls.isShow.setValue(newValue?.isShow);
1158
+ if (newValue?.isShow == false) {
1159
+ this.fCtrls.answer.setValue(null);
1160
+ }
989
1161
  }
990
1162
  });
991
1163
  }
@@ -995,15 +1167,13 @@ class QuestionBooleanTemplateComponent {
995
1167
  convertToFormControl(element) {
996
1168
  return element;
997
1169
  }
998
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionBooleanTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }], target: i0.ɵɵFactoryTarget.Component }); }
999
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionBooleanTemplateComponent, selector: "lib-question-boolean-template", inputs: { setQuestion: "setQuestion" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\"\r\n [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"radio-button-quastion\">\r\n <div class=\"form-check form-check-radio form-check-inline\"\r\n *ngFor=\"let item of fCtrls.answerArray.controls ;let i = index\">\r\n <input class=\"form-check-input\" type=\"radio\" (change)=\"onChangeAnswer(item.value)\"\r\n [disabled]=\"fCtrls.isDisabled.value\" name=\"{{elemId}}__radio-btn-option\"\r\n id=\"{{elemId}}__radio-btn_{{i}}\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label\" for=\"{{elemId}}__radio-btn_{{i}}\">{{item.value.title}}</label>\r\n </div>\r\n </div>\r\n</div>", styles: [""], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
1170
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionBooleanTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: i3.Store }], target: i0.ɵɵFactoryTarget.Component }); }
1171
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionBooleanTemplateComponent, selector: "lib-question-boolean-template", inputs: { setQuestion: "setQuestion" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\"\r\n [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"radio-button-quastion\">\r\n <div class=\"form-check form-check-radio form-check-inline\"\r\n *ngFor=\"let item of fCtrls.answerArray.controls ;let i = index\">\r\n <input class=\"form-check-input\" type=\"radio\" (change)=\"onChangeAnswer(item.value)\"\r\n [disabled]=\"fCtrls.isDisabled.value\" name=\"{{elemId}}__radio-btn-option\"\r\n id=\"{{elemId}}__radio-btn_{{i}}\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label\" for=\"{{elemId}}__radio-btn_{{i}}\">{{item.value.title}}</label>\r\n </div>\r\n </div>\r\n</div>", styles: [""], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
1000
1172
  }
1001
1173
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionBooleanTemplateComponent, decorators: [{
1002
1174
  type: Component,
1003
1175
  args: [{ selector: 'lib-question-boolean-template', template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\"\r\n [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"radio-button-quastion\">\r\n <div class=\"form-check form-check-radio form-check-inline\"\r\n *ngFor=\"let item of fCtrls.answerArray.controls ;let i = index\">\r\n <input class=\"form-check-input\" type=\"radio\" (change)=\"onChangeAnswer(item.value)\"\r\n [disabled]=\"fCtrls.isDisabled.value\" name=\"{{elemId}}__radio-btn-option\"\r\n id=\"{{elemId}}__radio-btn_{{i}}\" [checked]=\"item.value.isSelected == true? true : null\">\r\n <label class=\"form-check-label\" for=\"{{elemId}}__radio-btn_{{i}}\">{{item.value.title}}</label>\r\n </div>\r\n </div>\r\n</div>" }]
1004
- }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }]; }, propDecorators: { emitter: [{
1005
- type: Output
1006
- }], setQuestion: [{
1176
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
1007
1177
  type: Input
1008
1178
  }] } });
1009
1179
 
@@ -1015,33 +1185,35 @@ class QuestionDropdownMultiTemplateComponent {
1015
1185
  return QuestionTypeEnum;
1016
1186
  }
1017
1187
  set setQuestion(value) {
1018
- this.surveyQuestion = value;
1019
- this.rForm.patchValue({
1020
- id: value.questionId,
1021
- name: value.questionName,
1022
- title: value.questionTitle,
1023
- typeId: value.questionTypeId,
1024
- description: value.questionDescription,
1025
- isDisabled: value.isReadOnly,
1026
- isShow: value.isVisable
1027
- });
1028
- value.surveyAnswers.forEach(surveryAnswer => {
1029
- this.fCtrls.answerArray.push(this._formBuilder.group({
1030
- id: [surveryAnswer.answerId],
1031
- title: [surveryAnswer.answerTitle],
1032
- isSelected: [false]
1033
- }));
1034
- });
1035
- if (value.isRequired == true) {
1036
- this.fCtrls.answer.addValidators([Validators$1.required]);
1037
- this.fCtrls.answer.updateValueAndValidity();
1188
+ if (!this.surveyQuestion) {
1189
+ this.surveyQuestion = value.questionAllInfo;
1190
+ this.rForm.patchValue({
1191
+ id: value.questionId,
1192
+ name: value.questionAllInfo.questionName,
1193
+ title: value.questionAllInfo.questionTitle,
1194
+ typeId: value.questionAllInfo.questionTypeId,
1195
+ description: value.questionAllInfo.questionDescription,
1196
+ isDisabled: value.questionAllInfo.isReadOnly,
1197
+ isShow: value.questionAllInfo.isVisable
1198
+ });
1199
+ value.questionAllInfo.surveyAnswers.forEach(surveryAnswer => {
1200
+ this.fCtrls.answerArray.push(this._formBuilder.group({
1201
+ id: [surveryAnswer.answerId],
1202
+ title: [surveryAnswer.answerTitle],
1203
+ isSelected: [false]
1204
+ }));
1205
+ });
1206
+ if (value.isRequired == true) {
1207
+ this.fCtrls.answer.addValidators([Validators$1.required]);
1208
+ this.fCtrls.answer.updateValueAndValidity();
1209
+ }
1038
1210
  }
1039
1211
  }
1040
- constructor(_formBuilder, _surveyLibService) {
1212
+ constructor(_formBuilder, _surveyLibService, _Store) {
1041
1213
  this._formBuilder = _formBuilder;
1042
1214
  this._surveyLibService = _surveyLibService;
1215
+ this._Store = _Store;
1043
1216
  this.elemId = v4();
1044
- this.emitter = new EventEmitter();
1045
1217
  this.rForm = this._formBuilder.group({
1046
1218
  id: [null],
1047
1219
  name: [null],
@@ -1057,42 +1229,44 @@ class QuestionDropdownMultiTemplateComponent {
1057
1229
  ngOnInit() {
1058
1230
  this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
1059
1231
  const formValue = this.rForm.value;
1060
- this.emitter.emit({
1061
- QuestionId: formValue.id,
1062
- IsValid: this.fCtrls.answer.valid,
1063
- Answer: value
1064
- });
1065
- });
1066
- this.fCtrls.answer.setValue(null);
1067
- this._surveyLibService.surveyAnswersObsrv
1068
- .pipe(map(x => x.defaultAnswers.filter(x => x.QuestionId == this.fCtrls.id.value)))
1069
- .pipe(filter(x => x.length > 0)).pipe(map(x => x.at(0)))
1070
- .subscribe(answer => {
1071
- const distinctArray = answer.AnswerIdArr.filter((n, i) => answer.AnswerIdArr.indexOf(n) === i);
1072
- this.fCtrls.answer.setValue(distinctArray);
1073
- });
1074
- this._surveyLibService.questionIsDisabledObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
1075
- this.fCtrls.isDisabled.setValue(x.isDisabled);
1232
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
1233
+ questionId: formValue.id,
1234
+ answer: value,
1235
+ isValid: this.fCtrls.answer.valid
1236
+ }));
1076
1237
  });
1077
- this._surveyLibService.questionIsShowObsrv.pipe(filter(x => x.questionId == this.fCtrls.id.value)).subscribe(x => {
1078
- this.fCtrls.isShow.setValue(x.isShow);
1079
- if (x.isShow == false) {
1080
- this.fCtrls.answer.setValue(null);
1238
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
1239
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
1240
+ const oldValue = value[0];
1241
+ const newValue = value[1];
1242
+ //updated answer
1243
+ if (oldValue?.answerIdArr != newValue?.answerIdArr) {
1244
+ const distinctArray = newValue?.answerIdArr.filter((n, i) => newValue?.answerIdArr.indexOf(n) === i);
1245
+ this.fCtrls.answer.setValue(distinctArray, { emitEvent: false });
1246
+ }
1247
+ //updated isDisabled
1248
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
1249
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
1250
+ }
1251
+ //updated isShow
1252
+ if (oldValue?.isShow != newValue?.isShow) {
1253
+ this.fCtrls.isShow.setValue(newValue?.isShow);
1254
+ if (newValue?.isShow == false) {
1255
+ this.fCtrls.answer.setValue(null);
1256
+ }
1081
1257
  }
1082
1258
  });
1083
1259
  }
1084
1260
  convertToFormControl(element) {
1085
1261
  return element;
1086
1262
  }
1087
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionDropdownMultiTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }], target: i0.ɵɵFactoryTarget.Component }); }
1088
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionDropdownMultiTemplateComponent, selector: "lib-question-dropdown-multi-template", inputs: { setQuestion: "setQuestion" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"text-quastion text-quastion__dropdown\">\r\n <ng-select [items]=\"this.fCtrls.answerArray.value\" bindValue=\"id\" bindLabel=\"title\" class=\"form-control\"\r\n [formControl]=\"convertToFormControl(fCtrls.answer)\" [disabled]=\"fCtrls.isDisabled.value\" [multiple]=\"true\">\r\n </ng-select>\r\n </div>\r\n</div>\r\n", styles: [".text-quastion .form-control{padding:10px}\n"], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i5.NgSelectComponent, selector: "ng-select", inputs: ["bindLabel", "bindValue", "markFirst", "placeholder", "notFoundText", "typeToSearchText", "addTagText", "loadingText", "clearAllText", "appearance", "dropdownPosition", "appendTo", "loading", "closeOnSelect", "hideSelected", "selectOnTab", "openOnEnter", "maxSelectedItems", "groupBy", "groupValue", "bufferAmount", "virtualScroll", "selectableGroup", "selectableGroupAsModel", "searchFn", "trackByFn", "clearOnBackspace", "labelForId", "inputAttrs", "tabIndex", "readonly", "searchWhileComposing", "minTermLength", "editableSearchTerm", "keyDownFn", "typeahead", "multiple", "addTag", "searchable", "clearable", "isOpen", "items", "compareWith", "clearSearchOnAdd", "deselectOnClick"], outputs: ["blur", "focus", "change", "open", "close", "search", "clear", "add", "remove", "scroll", "scrollToEnd"] }] }); }
1263
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionDropdownMultiTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: i3.Store }], target: i0.ɵɵFactoryTarget.Component }); }
1264
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionDropdownMultiTemplateComponent, selector: "lib-question-dropdown-multi-template", inputs: { setQuestion: "setQuestion" }, ngImport: i0, template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"text-quastion text-quastion__dropdown\">\r\n <ng-select [items]=\"this.fCtrls.answerArray.value\" bindValue=\"id\" bindLabel=\"title\" class=\"form-control\"\r\n [formControl]=\"convertToFormControl(fCtrls.answer)\" [disabled]=\"fCtrls.isDisabled.value\" [multiple]=\"true\">\r\n </ng-select>\r\n </div>\r\n</div>\r\n", styles: [".text-quastion .form-control{padding:10px}\n"], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i5.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i6.NgSelectComponent, selector: "ng-select", inputs: ["bindLabel", "bindValue", "markFirst", "placeholder", "notFoundText", "typeToSearchText", "addTagText", "loadingText", "clearAllText", "appearance", "dropdownPosition", "appendTo", "loading", "closeOnSelect", "hideSelected", "selectOnTab", "openOnEnter", "maxSelectedItems", "groupBy", "groupValue", "bufferAmount", "virtualScroll", "selectableGroup", "selectableGroupAsModel", "searchFn", "trackByFn", "clearOnBackspace", "labelForId", "inputAttrs", "tabIndex", "readonly", "searchWhileComposing", "minTermLength", "editableSearchTerm", "keyDownFn", "typeahead", "multiple", "addTag", "searchable", "clearable", "isOpen", "items", "compareWith", "clearSearchOnAdd", "deselectOnClick"], outputs: ["blur", "focus", "change", "open", "close", "search", "clear", "add", "remove", "scroll", "scrollToEnd"] }] }); }
1089
1265
  }
1090
1266
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionDropdownMultiTemplateComponent, decorators: [{
1091
1267
  type: Component,
1092
1268
  args: [{ selector: 'lib-question-dropdown-multi-template', template: "<div class=\"quastion\" [attr.id]=\"'question_'+fCtrls.id.value\" [ngClass]=\"{'invalid-question': fCtrls.answer.invalid , 'd-none':fCtrls.isShow.value != true}\">\r\n <h3 class=\"quastion-title \">\r\n <span [innerHTML]=\"fCtrls.title.value\"></span>\r\n <span style=\"color: red;\" *ngIf=\"surveyQuestion.isRequired\">*</span>\r\n </h3>\r\n <div class=\"text-quastion text-quastion__dropdown\">\r\n <ng-select [items]=\"this.fCtrls.answerArray.value\" bindValue=\"id\" bindLabel=\"title\" class=\"form-control\"\r\n [formControl]=\"convertToFormControl(fCtrls.answer)\" [disabled]=\"fCtrls.isDisabled.value\" [multiple]=\"true\">\r\n </ng-select>\r\n </div>\r\n</div>\r\n", styles: [".text-quastion .form-control{padding:10px}\n"] }]
1093
- }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }]; }, propDecorators: { emitter: [{
1094
- type: Output
1095
- }], setQuestion: [{
1269
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
1096
1270
  type: Input
1097
1271
  }] } });
1098
1272
 
@@ -1121,6 +1295,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1121
1295
  args: [LibConfigService]
1122
1296
  }] }]; } });
1123
1297
 
1298
+ class FindQuestionPipe {
1299
+ transform(arr, questionId) {
1300
+ if (arr) {
1301
+ return arr.find(x => x.questionId == questionId);
1302
+ }
1303
+ return null;
1304
+ }
1305
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FindQuestionPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
1306
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: FindQuestionPipe, name: "findQuestion" }); }
1307
+ }
1308
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FindQuestionPipe, decorators: [{
1309
+ type: Pipe,
1310
+ args: [{
1311
+ name: 'findQuestion'
1312
+ }]
1313
+ }] });
1314
+
1124
1315
  class QuestionCascadeTemplateComponent {
1125
1316
  get fCtrls() {
1126
1317
  return this.rForm.controls;
@@ -1132,15 +1323,19 @@ class QuestionCascadeTemplateComponent {
1132
1323
  return this.fCtrls.questionArr;
1133
1324
  }
1134
1325
  set setQuestion(value) {
1135
- this.setQuestions(value);
1326
+ if (this.surveyQuestionArr?.length == 0) {
1327
+ this.setQuestions(value.questionAllInfo);
1328
+ }
1136
1329
  }
1137
- constructor(_formBuilder, _surveyLibService, _ApiService) {
1330
+ constructor(_formBuilder, _surveyLibService, _ApiService, _Store) {
1138
1331
  this._formBuilder = _formBuilder;
1139
1332
  this._surveyLibService = _surveyLibService;
1140
1333
  this._ApiService = _ApiService;
1334
+ this._Store = _Store;
1141
1335
  this.surveyQuestionArr = [];
1142
- this.emitter = new EventEmitter();
1143
- this.pageIndex = null;
1336
+ this.pageQuestions$ = this._Store.select(questionSelectors.pageQuestions);
1337
+ this.pageId = null;
1338
+ this.questionGroupId = null;
1144
1339
  this.isPre = false;
1145
1340
  this.surveyLanguageId = null;
1146
1341
  this.applicantKey = null;
@@ -1149,9 +1344,9 @@ class QuestionCascadeTemplateComponent {
1149
1344
  });
1150
1345
  }
1151
1346
  ngOnInit() {
1152
- this.fCtrls.questionArr.statusChanges.subscribe(v => {
1153
- console.log(v);
1154
- });
1347
+ // this.fCtrls.questionArr.statusChanges.subscribe(v => {
1348
+ // console.log(v);
1349
+ // })
1155
1350
  }
1156
1351
  onUpdateAnswer(model) {
1157
1352
  if (this.surveyQuestionArr.length > 1) {
@@ -1164,7 +1359,7 @@ class QuestionCascadeTemplateComponent {
1164
1359
  for (let index = 0; index < sortDeletedArr.length; index++) {
1165
1360
  const elementIndex = sortDeletedArr[index];
1166
1361
  const questionId = this.surveyQuestionArr[elementIndex].questionId;
1167
- this._surveyLibService.setRemoveQuestion(questionId);
1362
+ this._Store.dispatch(surveyActions.removeQuestion({ questionId: questionId }));
1168
1363
  this.surveyQuestionArr = this.surveyQuestionArr.filter(x => x.questionId != questionId);
1169
1364
  this.questionFormArray.removeAt(elementIndex);
1170
1365
  }
@@ -1177,12 +1372,29 @@ class QuestionCascadeTemplateComponent {
1177
1372
  surveyLanguageId: this.surveyLanguageId
1178
1373
  }).subscribe(res => {
1179
1374
  if (res.errors.filter(x => x.code == 17).length == 0) {
1375
+ this._Store.dispatch(surveyActions.addQuestion({ question: {
1376
+ surveyPageId: this.pageId,
1377
+ questionId: res.questionId,
1378
+ questionType: res.questionTypeId,
1379
+ inputTypeId: res.surveyAnswers[0].inputTypeId,
1380
+ isMatrixGroup: false,
1381
+ answerId: null,
1382
+ answerIdArr: null,
1383
+ answerText: null,
1384
+ isRequired: res.isRequired,
1385
+ isValid: null,
1386
+ isDisabled: res.isReadOnly,
1387
+ isShow: res.isVisable,
1388
+ isDisabled_default: res.isReadOnly,
1389
+ isShow_default: res.isVisable,
1390
+ questionGroupId: this.questionGroupId,
1391
+ parentQuestionId: model.QuestionId,
1392
+ questionAllInfo: res
1393
+ } }));
1180
1394
  this.setQuestions(res);
1181
- this._surveyLibService.setAddQuestion(res, this.pageIndex);
1182
1395
  }
1183
1396
  });
1184
1397
  }
1185
- this.emitter.emit(model);
1186
1398
  }
1187
1399
  identify(index, item) {
1188
1400
  return item.id;
@@ -1199,16 +1411,17 @@ class QuestionCascadeTemplateComponent {
1199
1411
  group.controls.answer.updateValueAndValidity();
1200
1412
  }
1201
1413
  this.fCtrls.questionArr.push(group);
1414
+ console.log(this.fCtrls.questionArr.value);
1202
1415
  }
1203
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionCascadeTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: ApiService }], target: i0.ɵɵFactoryTarget.Component }); }
1204
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionCascadeTemplateComponent, selector: "lib-question-cascade-template", inputs: { pageIndex: "pageIndex", isPre: "isPre", surveyLanguageId: "surveyLanguageId", applicantKey: "applicantKey", setQuestion: "setQuestion" }, outputs: { emitter: "emitter" }, ngImport: i0, template: "<ng-container *ngFor=\"let item of questionFormArray.value ; trackBy:identify ; let i = index\">\r\n <lib-question-dropdown-template #questionDropdownTemplate [setQuestion]=\"surveyQuestionArr[i]\"\r\n (emitter)=\"onUpdateAnswer($event)\" >\r\n </lib-question-dropdown-template>\r\n</ng-container>", styles: [""], dependencies: [{ kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: QuestionDropdownTemplateComponent, selector: "lib-question-dropdown-template", inputs: ["setQuestion"], outputs: ["emitter"] }] }); }
1416
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionCascadeTemplateComponent, deps: [{ token: i1.FormBuilder }, { token: SurveyLibService }, { token: ApiService }, { token: i3.Store }], target: i0.ɵɵFactoryTarget.Component }); }
1417
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: QuestionCascadeTemplateComponent, selector: "lib-question-cascade-template", inputs: { pageId: "pageId", questionGroupId: "questionGroupId", isPre: "isPre", surveyLanguageId: "surveyLanguageId", applicantKey: "applicantKey", setQuestion: "setQuestion" }, ngImport: i0, template: "<ng-container *ngFor=\"let item of questionFormArray.value ; trackBy:identify ; let i = index\">\r\n <lib-question-dropdown-template #questionDropdownTemplate [setQuestion]=\"(pageQuestions$ |async) |findQuestion :item.id \"\r\n (emitter)=\"onUpdateAnswer($event)\" >\r\n </lib-question-dropdown-template> \r\n</ng-container>", styles: [""], dependencies: [{ kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: QuestionDropdownTemplateComponent, selector: "lib-question-dropdown-template", inputs: ["setQuestion"], outputs: ["emitter"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }, { kind: "pipe", type: FindQuestionPipe, name: "findQuestion" }] }); }
1205
1418
  }
1206
1419
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionCascadeTemplateComponent, decorators: [{
1207
1420
  type: Component,
1208
- args: [{ selector: 'lib-question-cascade-template', template: "<ng-container *ngFor=\"let item of questionFormArray.value ; trackBy:identify ; let i = index\">\r\n <lib-question-dropdown-template #questionDropdownTemplate [setQuestion]=\"surveyQuestionArr[i]\"\r\n (emitter)=\"onUpdateAnswer($event)\" >\r\n </lib-question-dropdown-template>\r\n</ng-container>" }]
1209
- }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: ApiService }]; }, propDecorators: { emitter: [{
1210
- type: Output
1211
- }], pageIndex: [{
1421
+ args: [{ selector: 'lib-question-cascade-template', template: "<ng-container *ngFor=\"let item of questionFormArray.value ; trackBy:identify ; let i = index\">\r\n <lib-question-dropdown-template #questionDropdownTemplate [setQuestion]=\"(pageQuestions$ |async) |findQuestion :item.id \"\r\n (emitter)=\"onUpdateAnswer($event)\" >\r\n </lib-question-dropdown-template> \r\n</ng-container>" }]
1422
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: ApiService }, { type: i3.Store }]; }, propDecorators: { pageId: [{
1423
+ type: Input
1424
+ }], questionGroupId: [{
1212
1425
  type: Input
1213
1426
  }], isPre: [{
1214
1427
  type: Input
@@ -1220,6 +1433,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1220
1433
  type: Input
1221
1434
  }] } });
1222
1435
 
1436
+ class FilterQuestionPipe {
1437
+ transform(arr, questionGroupId) {
1438
+ return arr.filter(x => x.questionGroupId == questionGroupId && x.parentQuestionId == null);
1439
+ }
1440
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
1441
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, name: "filterQuestion" }); }
1442
+ }
1443
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, decorators: [{
1444
+ type: Pipe,
1445
+ args: [{
1446
+ name: 'filterQuestion'
1447
+ }]
1448
+ }] });
1449
+
1223
1450
  class SurveryLibComponent {
1224
1451
  get fCtrls() {
1225
1452
  return this.rForm.controls;
@@ -1227,55 +1454,25 @@ class SurveryLibComponent {
1227
1454
  get questionTypeEnum() {
1228
1455
  return QuestionTypeEnum;
1229
1456
  }
1230
- get isFirstPage() {
1231
- if (this.showedSurveyPages.length > 0) {
1232
- return this.showedSurveyPages.findIndex(x => x == this.fCtrls.currentPageIndex.value) == 0;
1233
- }
1234
- return true;
1235
- }
1236
- get isLastPage() {
1237
- return this.showedSurveyPages.findIndex(x => x == this.fCtrls.currentPageIndex.value) == (this.showedSurveyPages.length - 1);
1238
- }
1239
- get showedSurveyPages() {
1240
- var pageArr = [];
1241
- for (let index = 0; index < this.fCtrls.questionArray.value.length; index++) {
1242
- const question = this.fCtrls.questionArray.value[index];
1243
- if (question.isShow == true) {
1244
- if (question.questionType != this.questionTypeEnum.Matrix) {
1245
- pageArr.push(question.surveyPageIndex);
1246
- }
1247
- else if (question.questionType == this.questionTypeEnum.Matrix && question.isMatrixGroup == true) {
1248
- pageArr.push(question.surveyPageIndex);
1249
- }
1250
- }
1251
- }
1252
- const distinctArray = pageArr.filter((n, i) => pageArr.indexOf(n) === i);
1253
- return distinctArray.sort((a, b) => a - b);
1254
- }
1255
- get curruntShowedSurveyPages() {
1256
- return this.showedSurveyPages.findIndex(x => x == this.fCtrls.currentPageIndex.value) + 1;
1257
- }
1258
1457
  get surveyResult() {
1259
1458
  return {
1260
- currentPageIndex: this.fCtrls.currentPageIndex.value,
1261
- answers: this.fCtrls.questionArray.value.filter(x => x.isMatrixGroup != true).map(x => {
1262
- return {
1263
- SurveyPageIndex: x.surveyPageIndex,
1264
- QuestionId: x.questionId,
1265
- QuestionType: x.questionType,
1266
- AnswerId: x.answerId,
1267
- AnswerText: x.answerText,
1268
- AnswerIdArr: x.answerIdArr
1269
- };
1270
- })
1459
+ currentPageIndex: this.fCtrls.currentPageId.value,
1460
+ answers: this.questionAnswerArr
1271
1461
  };
1272
1462
  }
1273
- constructor(_surveyLibService, _formBuilder, _checkRuleExpsUsecase) {
1463
+ constructor(_surveyLibService, _Store, _formBuilder, _checkRuleExpsUsecase) {
1274
1464
  this._surveyLibService = _surveyLibService;
1465
+ this._Store = _Store;
1275
1466
  this._formBuilder = _formBuilder;
1276
1467
  this._checkRuleExpsUsecase = _checkRuleExpsUsecase;
1277
1468
  this.surveryLibraryDivId = v4();
1278
1469
  this.reloadDefaultAnswerId = v4();
1470
+ this.questionAnswerArr = [];
1471
+ this.pageQuestionGroups$ = this._Store.select(questionGroupSelectors.pageQuestionGroups);
1472
+ this.pageQuestions$ = this._Store.select(questionSelectors.pageQuestions);
1473
+ this.isFirstPage$ = this._Store.select(surveySelectors.isFirstPage);
1474
+ this.isLastPage$ = this._Store.select(surveySelectors.isLastPage);
1475
+ this.curruntShowedSurveyPages$ = this._Store.select(surveySelectors.selectedPageIndex).pipe(map(x => x + 1));
1279
1476
  this.isPre = false;
1280
1477
  this.surveyLanguageId = null;
1281
1478
  this.applicantKey = null;
@@ -1283,119 +1480,59 @@ class SurveryLibComponent {
1283
1480
  this.surveyResultEmit = new EventEmitter();
1284
1481
  this.selectLanguageEmit = new EventEmitter();
1285
1482
  this.rForm = this._formBuilder.group({
1286
- currentPageIndex: [0],
1287
- questionArray: this._formBuilder.array([]),
1288
- ruleQuestionArray: this._formBuilder.array([])
1483
+ currentPageId: new FormControl(0),
1484
+ showedSurveyPages: new FormControl([])
1485
+ });
1486
+ this._Store.select(questionSelectors.questionAnswers).subscribe(arr => {
1487
+ this.questionAnswerArr = arr;
1289
1488
  });
1290
1489
  }
1291
1490
  ngAfterViewInit() {
1292
1491
  }
1492
+ questionIdentify(index, item) {
1493
+ return item.questionId;
1494
+ }
1293
1495
  ngOnInit() {
1294
- this._surveyLibService.surveyDataObsrv.pipe(debounceTime(300), distinctUntilChanged()).subscribe(survey => {
1295
- this.fCtrls.questionArray.clear();
1296
- this.fCtrls.ruleQuestionArray.clear();
1297
- this.surveyData = null;
1298
- if (survey != null) {
1299
- this.surveyData = survey;
1300
- this.loadQuestions(survey);
1301
- }
1496
+ this._Store.select(surveySelectors.selectedPageId).subscribe(value => {
1497
+ this.fCtrls.currentPageId.setValue(value);
1302
1498
  });
1303
- this._surveyLibService.addQuestionObsrv.subscribe(res => {
1304
- this.addQuestionGroup(res.question, res.pageIndex);
1305
- });
1306
- this._surveyLibService.removeQuestionObsrv.subscribe(res => {
1307
- const index = this.fCtrls.questionArray.value.findIndex(x => x.questionId == res.questionId);
1308
- this.fCtrls.questionArray.removeAt(index);
1499
+ this._Store.select(surveySelectors.showedSurveyPages).subscribe(value => {
1500
+ this.fCtrls.showedSurveyPages.setValue(value);
1309
1501
  });
1310
1502
  }
1311
1503
  onPaggingNext() {
1312
- var invalidRecords = this.haveInValidateQuestions();
1313
- if (invalidRecords.length == 0) {
1314
- const nextPageIndex = this.getNextShowedPage();
1315
- if (nextPageIndex != null) {
1316
- this.fCtrls.currentPageIndex.setValue(nextPageIndex);
1317
- setTimeout(() => {
1318
- this.loadQuestionUpdates(nextPageIndex);
1319
- });
1320
- $('html, body').animate({
1321
- scrollTop: $(`#survery-card-${this.surveryLibraryDivId}`).offset().top - 120
1322
- }, 2000);
1504
+ this._Store.select(questionSelectors.pageQuestions).pipe(take(1)).subscribe(arr => {
1505
+ var invalidRecords = this.haveInValidateQuestions(arr);
1506
+ if (invalidRecords.length == 0) {
1507
+ const nextPageId = this.getNextShowedPage();
1508
+ if (nextPageId != null) {
1509
+ this._Store.dispatch(surveyActions.updatePageId({ pageId: nextPageId }));
1510
+ $('html, body').animate({
1511
+ scrollTop: $(`#survery-card-${this.surveryLibraryDivId}`).offset().top - 30
1512
+ }, 300);
1513
+ }
1514
+ else {
1515
+ this.surveyResultEmit.emit(this.questionAnswerArr);
1516
+ }
1323
1517
  }
1324
1518
  else {
1325
- var questionArr = this.fCtrls.questionArray.value.filter(x => x.isMatrixGroup != true).map(x => {
1326
- return {
1327
- SurveyPageIndex: x.surveyPageIndex,
1328
- QuestionId: x.questionId,
1329
- QuestionType: x.questionType,
1330
- AnswerId: x.answerId,
1331
- AnswerText: x.answerText,
1332
- AnswerIdArr: x.answerIdArr
1333
- };
1334
- });
1335
- this.surveyResultEmit.emit(questionArr);
1519
+ var firstQuestion = $('.invalid-question')[0];
1520
+ $('html, body').animate({
1521
+ scrollTop: $(firstQuestion).offset().top - 250
1522
+ }, 300);
1336
1523
  }
1337
- }
1338
- else {
1339
- var firstQuestion = invalidRecords[0];
1340
- $('html, body').animate({
1341
- scrollTop: $(`#question_${firstQuestion.questionId}`).offset().top - 120
1342
- }, 2000);
1343
- }
1344
- }
1345
- onPaggingBack() {
1346
- const prevPageIndex = this.getPrevShowedPage();
1347
- if (prevPageIndex != null) {
1348
- this.fCtrls.currentPageIndex.setValue(prevPageIndex);
1349
- }
1350
- }
1351
- onUpdateAnswers(model) {
1352
- model.forEach(elem => {
1353
- this.onUpdateAnswer(elem);
1354
1524
  });
1355
1525
  }
1356
- onUpdateAnswer(model) {
1357
- const index = this.fCtrls.questionArray.value.findIndex(x => x.questionId == model.QuestionId);
1358
- if (index > -1) {
1359
- var questionGroup = this.fCtrls.questionArray.controls[index];
1360
- questionGroup.controls.isValid.setValue(model.IsValid);
1361
- if (questionGroup.value.questionType == this.questionTypeEnum.TextInput) {
1362
- questionGroup.patchValue({
1363
- answerId: model.SurveyAnswerId,
1364
- answerText: model.Answer
1365
- });
1366
- }
1367
- else if (questionGroup.value.questionType == this.questionTypeEnum.CheckBox || questionGroup.value.questionType == this.questionTypeEnum.DropDownMulti) {
1368
- questionGroup.controls.answerIdArr.setValue(model.Answer);
1369
- }
1370
- else {
1371
- questionGroup.controls.answerId.setValue(model.Answer);
1372
- }
1373
- if (this.fCtrls.ruleQuestionArray.value.findIndex(x => x.questionId == model.QuestionId) > -1) {
1374
- this.checkRules(questionGroup.value.questionId);
1375
- }
1526
+ onPaggingBack() {
1527
+ const prevPageId = this.getPrevShowedPage();
1528
+ if (prevPageId != null) {
1529
+ this._Store.dispatch(surveyActions.updatePageId({ pageId: prevPageId }));
1376
1530
  }
1377
1531
  }
1378
- loadQuestions(survey) {
1379
- survey.surveyPages.forEach((page, pageIndex) => {
1380
- page.surveyQuestionGroups.forEach(group => {
1381
- group.surveyQuestions.forEach(question => {
1382
- this.addQuestionGroup(question, pageIndex);
1383
- });
1384
- });
1385
- });
1386
- survey.surveyRules.forEach(rule => {
1387
- rule.ruleExps.forEach(ruleExp => {
1388
- this.fCtrls.ruleQuestionArray.push(this._formBuilder.group({
1389
- questionId: ruleExp.questionId,
1390
- ruleId: rule.ruleId
1391
- }));
1392
- });
1393
- });
1394
- }
1395
- haveInValidateQuestions() {
1396
- const currentPageIndex = this.fCtrls.currentPageIndex.value;
1532
+ haveInValidateQuestions(questionArr) {
1533
+ const formValue = this.rForm.value;
1397
1534
  var invalidRecords = [];
1398
- var arr = this.fCtrls.questionArray.value.filter(x => x.surveyPageIndex == currentPageIndex && x.isDisabled == false && x.isShow == true);
1535
+ var arr = questionArr.filter(x => x.isDisabled == false && x.isShow == true);
1399
1536
  arr.map(x => {
1400
1537
  if (x.isRequired == true && x.isValid != true && x.isMatrixGroup != true) {
1401
1538
  invalidRecords.push(x);
@@ -1409,159 +1546,38 @@ class SurveryLibComponent {
1409
1546
  }
1410
1547
  });
1411
1548
  if (invalidRecords.length > 0) {
1412
- $(`#survey-page_${currentPageIndex}`).addClass('survey-page_submitted');
1549
+ $(`#survey-page_${formValue.currentPageId}`).addClass('survey-page_submitted');
1550
+ }
1551
+ else {
1552
+ $(`#survey-page_${formValue.currentPageId}`).removeClass('survey-page_submitted');
1413
1553
  }
1414
1554
  return invalidRecords;
1415
1555
  }
1416
- checkRules(questionId) {
1417
- var selectedRuleIdArr = this.rForm.value.ruleQuestionArray.filter(x => x.questionId == questionId).map(x => Number(x.ruleId));
1418
- var arr = this.surveyData.surveyRules.filter(x => selectedRuleIdArr.find(c => c == x.ruleId) != null);
1419
- arr.forEach(rule => {
1420
- this._checkRuleExpsUsecase.execute({
1421
- ruleExps: rule.ruleExps,
1422
- questions: this.fCtrls.questionArray.value,
1423
- currentPageIndex: this.fCtrls.currentPageIndex.value
1424
- }).subscribe(result => {
1425
- var isPassed = result.exprestionResultArr.filter(x => x == false).length == 0;
1426
- if (isPassed) {
1427
- rule.ruleResultQuestions.forEach(resultQuestion => {
1428
- const index = this.fCtrls.questionArray.value.findIndex(x => x.questionId == resultQuestion.questionId);
1429
- var questionGroup = this.fCtrls.questionArray.at(index);
1430
- if (rule.logicActionId == LogicActionEnum.Show) {
1431
- questionGroup.controls.isShow.setValue(true);
1432
- this._surveyLibService.setQuestionIsShow(questionGroup.value.questionId, true);
1433
- }
1434
- else if (rule.logicActionId == LogicActionEnum.Hide) {
1435
- questionGroup.controls.isShow.setValue(false);
1436
- this._surveyLibService.setQuestionIsShow(questionGroup.value.questionId, false);
1437
- }
1438
- else if (rule.logicActionId == LogicActionEnum.Enable) {
1439
- questionGroup.controls.isDisabled.setValue(false);
1440
- this._surveyLibService.setQuestionIsDisabled(questionGroup.value.questionId, false);
1441
- }
1442
- else if (rule.logicActionId == LogicActionEnum.Disable) {
1443
- questionGroup.controls.isDisabled.setValue(true);
1444
- this._surveyLibService.setQuestionIsDisabled(questionGroup.value.questionId, true);
1445
- }
1446
- else if (rule.logicActionId == LogicActionEnum.SetAnswer) {
1447
- }
1448
- if (questionGroup.value.questionType == QuestionTypeEnum.Matrix && questionGroup.value.isMatrixGroup == true) {
1449
- var subQuestions = this.fCtrls.questionArray.value.filter(x => x.surveyPageIndex == questionGroup.value.surveyPageIndex && x.isMatrixGroup == false);
1450
- subQuestions.forEach(subQuestion => {
1451
- const index = this.fCtrls.questionArray.value.findIndex(x => x.questionId == subQuestion.questionId);
1452
- var subQuestionGroup = this.fCtrls.questionArray.at(index);
1453
- subQuestionGroup.patchValue({
1454
- isShow: questionGroup.value.isShow,
1455
- isDisabled: questionGroup.value.isDisabled
1456
- });
1457
- this._surveyLibService.setQuestionIsDisabled(subQuestion.questionId, subQuestion.isDisabled);
1458
- this._surveyLibService.setQuestionIsShow(subQuestion.questionId, subQuestion.isShow);
1459
- });
1460
- }
1461
- });
1462
- }
1463
- else {
1464
- rule.ruleResultQuestions.forEach(resultQuestion => {
1465
- const index = this.fCtrls.questionArray.value.findIndex(x => x.questionId == resultQuestion.questionId);
1466
- var questionGroup = this.fCtrls.questionArray.at(index);
1467
- questionGroup.patchValue({
1468
- isShow: questionGroup.value.isShow_default,
1469
- isDisabled: questionGroup.value.isDisabled_default
1470
- });
1471
- this._surveyLibService.setQuestionIsDisabled(questionGroup.value.questionId, questionGroup.value.isDisabled_default);
1472
- this._surveyLibService.setQuestionIsShow(questionGroup.value.questionId, questionGroup.value.isShow_default);
1473
- });
1474
- }
1475
- });
1476
- });
1477
- }
1478
1556
  getNextShowedPage() {
1479
- var currentPageIndex = this.fCtrls.currentPageIndex.value;
1480
- var showedPages = this.showedSurveyPages;
1481
- var nextShowedPages = showedPages.filter(x => x > currentPageIndex);
1557
+ const formValue = this.rForm.value;
1558
+ var showedPages = formValue.showedSurveyPages;
1559
+ var nextShowedPages = showedPages.filter(x => x > formValue.currentPageId);
1482
1560
  if (nextShowedPages.length > 0) {
1483
1561
  return nextShowedPages[0];
1484
1562
  }
1485
1563
  return null;
1486
1564
  }
1487
1565
  getPrevShowedPage() {
1488
- var currentPageIndex = this.fCtrls.currentPageIndex.value;
1489
- var showedPages = this.showedSurveyPages;
1490
- var prevShowedPages = showedPages.filter(x => x < currentPageIndex);
1566
+ const formValue = this.rForm.value;
1567
+ var showedPages = formValue.showedSurveyPages;
1568
+ var prevShowedPages = showedPages.filter(x => x < formValue.currentPageId);
1491
1569
  if (prevShowedPages.length > 0) {
1492
1570
  return prevShowedPages[prevShowedPages.length - 1];
1493
1571
  }
1494
1572
  return null;
1495
1573
  }
1496
- addQuestionGroup(question, pageIndex) {
1497
- if (question.questionTypeId != 6) {
1498
- this.fCtrls.questionArray.push(this._formBuilder.group({
1499
- surveyPageIndex: pageIndex,
1500
- questionId: [question.questionId],
1501
- questionType: [question.questionTypeId],
1502
- inputTypeId: [question.surveyAnswers[0].inputTypeId],
1503
- isMatrixGroup: [false],
1504
- answerId: [null],
1505
- answerIdArr: [null],
1506
- answerText: [null],
1507
- isRequired: [question.isRequired],
1508
- isValid: [null],
1509
- isDisabled: [question.isReadOnly],
1510
- isShow: [question.isVisable],
1511
- isDisabled_default: [question.isReadOnly],
1512
- isShow_default: [question.isVisable]
1513
- }));
1514
- }
1515
- else {
1516
- this.fCtrls.questionArray.push(this._formBuilder.group({
1517
- surveyPageIndex: pageIndex,
1518
- questionId: [question.questionId],
1519
- questionType: [question.questionTypeId],
1520
- inputTypeId: [question.surveyAnswers[0].inputTypeId],
1521
- isMatrixGroup: [true],
1522
- answerId: [null],
1523
- answerIdArr: [null],
1524
- answerText: [null],
1525
- isRequired: [question.isRequired],
1526
- isValid: [null],
1527
- isDisabled: [question.isReadOnly],
1528
- isShow: [question.isVisable],
1529
- isDisabled_default: [question.isReadOnly],
1530
- isShow_default: [question.isVisable],
1531
- }));
1532
- question.surveySubQuestions.forEach(subQuestion => {
1533
- this.fCtrls.questionArray.push(this._formBuilder.group({
1534
- surveyPageIndex: pageIndex,
1535
- questionId: [subQuestion.questionId],
1536
- questionType: [question.questionTypeId],
1537
- inputTypeId: [question.surveyAnswers[0].inputTypeId],
1538
- isMatrixGroup: [false],
1539
- answerId: [null],
1540
- answerIdArr: [null],
1541
- answerText: [null],
1542
- isRequired: [question.isRequired],
1543
- isValid: [null],
1544
- isDisabled: [question.isReadOnly],
1545
- isShow: [question.isVisable],
1546
- isDisabled_default: [question.isReadOnly],
1547
- isShow_default: [question.isVisable]
1548
- }));
1549
- });
1550
- }
1551
- }
1552
- loadQuestionUpdates(pageIndex) {
1553
- this.fCtrls.questionArray.value.filter(x => x.surveyPageIndex == pageIndex).forEach(question => {
1554
- this._surveyLibService.setQuestionIsShow(question.questionId, question.isShow);
1555
- this._surveyLibService.setQuestionIsDisabled(question.questionId, question.isDisabled);
1556
- });
1557
- }
1558
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibComponent, deps: [{ token: SurveyLibService }, { token: i1.FormBuilder }, { token: CheckRuleExpsUsecase }], target: i0.ɵɵFactoryTarget.Component }); }
1559
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: SurveryLibComponent, selector: "lib-survery-lib", inputs: { isPre: "isPre", surveyLanguageId: "surveyLanguageId", applicantKey: "applicantKey", isArabicLang: "isArabicLang" }, outputs: { surveyResultEmit: "surveyResultEmit", selectLanguageEmit: "selectLanguageEmit" }, ngImport: i0, template: "<div id=\"survery-card-{{surveryLibraryDivId}}\" class=\"survay-card\">\r\n <div *ngFor=\"let surveyPage of surveyData?.surveyPages; let surveyPageIndex = index\"\r\n [attr.id]=\"'survey-page_'+surveyPageIndex\" [ngClass]=\"{'d-none': surveyPageIndex != fCtrls.currentPageIndex.value}\">\r\n <ng-container *ngFor=\"let item of surveyPage.surveyQuestionGroups\">\r\n <div class=\"survay-card\">\r\n <div class=\"survay-card-body\">\r\n <div class=\"survay-group\">\r\n <div class=\"title\">\r\n <h2 class=\"group-title\" [innerHTML]=\"item.questionGroupName\">\r\n </h2>\r\n <span class=\"group-sub-title \" [innerHTML]=\"item.questionGroupDescription\">\r\n </span>\r\n </div>\r\n <ng-container *ngFor=\"let question of item.surveyQuestions\">\r\n <lib-question-boolean-template #questionBooleanTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.Boolean\">\r\n </lib-question-boolean-template>\r\n\r\n <lib-question-text-template #questionTextTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.TextInput\"\r\n [isTextArea]=\"question.isAdvanceTextArea\" [isArabicLang]=\"isArabicLang\"></lib-question-text-template>\r\n\r\n <lib-question-radio-button-template #questionRadioButtonTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.RadioButton\">\r\n </lib-question-radio-button-template>\r\n\r\n <lib-question-dropdown-template #questionDropdownTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\"\r\n *ngIf=\"question.questionTypeId == questionTypeEnum.DropDown\"></lib-question-dropdown-template>\r\n\r\n <lib-question-dropdown-multi-template [setQuestion]=\"question\" (emitter)=\"onUpdateAnswer($event)\"\r\n *ngIf=\"question.questionTypeId == questionTypeEnum.DropDownMulti\">\r\n </lib-question-dropdown-multi-template>\r\n\r\n <lib-question-check-box-template #questionCheckBoxTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.CheckBox\">\r\n </lib-question-check-box-template>\r\n\r\n <lib-question-matrix-template #questionMatrixTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.Matrix\">\r\n </lib-question-matrix-template>\r\n\r\n <lib-question-cascade-template #questionCascadeTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.Cascade\"\r\n [applicantKey]=\"applicantKey\" [isPre]=\"isPre\" [surveyLanguageId]=\"surveyLanguageId\"\r\n [pageIndex]=\"surveyPageIndex\"></lib-question-cascade-template>\r\n </ng-container>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-container>\r\n </div>\r\n <div class=\"survay-card-footr\" *ngIf=\"surveyData != null\">\r\n <div class=\"container\" style=\" justify-content: start;\">\r\n <div class=\"survay-pagination fw-bold\">\r\n <span>{{curruntShowedSurveyPages}}</span>\r\n <span class=\"ms-2 me-2\">{{isArabicLang ? '\u0645\u0646' : 'of'}} </span>\r\n <span>{{showedSurveyPages?.length}}</span>\r\n </div>\r\n </div>\r\n </div>\r\n</div>", styles: [".disable__btn{background-color:gray!important;cursor:not-allowed}.quastion{padding:10px}.quastion .quastion-title{color:var(--dark-100, #363636);text-align:right;font-family:Almarai;font-size:18px;font-style:normal;font-weight:700;line-height:20.6px}\n"], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: QuestionTextTemplateComponent, selector: "lib-question-text-template", inputs: ["isArabicLang", "isTextArea", "setQuestion", "isDisabled"], outputs: ["emitter"] }, { kind: "component", type: QuestionRadioButtonTemplateComponent, selector: "lib-question-radio-button-template", inputs: ["setQuestion"], outputs: ["emitter"] }, { kind: "component", type: QuestionCheckBoxTemplateComponent, selector: "lib-question-check-box-template", inputs: ["setQuestion"], outputs: ["emitter"] }, { kind: "component", type: QuestionDropdownTemplateComponent, selector: "lib-question-dropdown-template", inputs: ["setQuestion"], outputs: ["emitter"] }, { kind: "component", type: QuestionMatrixTemplateComponent, selector: "lib-question-matrix-template", inputs: ["setQuestion"], outputs: ["emitter"] }, { kind: "component", type: QuestionBooleanTemplateComponent, selector: "lib-question-boolean-template", inputs: ["setQuestion"], outputs: ["emitter"] }, { kind: "component", type: QuestionDropdownMultiTemplateComponent, selector: "lib-question-dropdown-multi-template", inputs: ["setQuestion"], outputs: ["emitter"] }, { kind: "component", type: QuestionCascadeTemplateComponent, selector: "lib-question-cascade-template", inputs: ["pageIndex", "isPre", "surveyLanguageId", "applicantKey", "setQuestion"], outputs: ["emitter"] }] }); }
1574
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibComponent, deps: [{ token: SurveyLibService }, { token: i3.Store }, { token: i5.FormBuilder }, { token: CheckRuleExpsUsecase }], target: i0.ɵɵFactoryTarget.Component }); }
1575
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: SurveryLibComponent, selector: "lib-survery-lib", inputs: { isPre: "isPre", surveyLanguageId: "surveyLanguageId", applicantKey: "applicantKey", isArabicLang: "isArabicLang" }, outputs: { surveyResultEmit: "surveyResultEmit", selectLanguageEmit: "selectLanguageEmit" }, ngImport: i0, template: "<div id=\"survery-card-{{surveryLibraryDivId}}\" class=\"survay-card\">\r\n <div [attr.id]=\"'survey-page_'+fCtrls.currentPageId.value\">\r\n <ng-container *ngFor=\"let item of (pageQuestionGroups$ | async)\">\r\n <div class=\"survay-card\">\r\n <div class=\"survay-card-body\">\r\n <div class=\"survay-group\">\r\n <div class=\"title\">\r\n <h2 class=\"group-title\" [innerHTML]=\"item.questionGroupName\">\r\n </h2>\r\n <span class=\"group-sub-title \" [innerHTML]=\"item.questionGroupDescription\">\r\n </span>\r\n </div>\r\n <ng-container\r\n *ngFor=\"let question of ((pageQuestions$|async) |filterQuestion : item.questionGroupId); trackBy:questionIdentify\">\r\n <lib-question-boolean-template #questionBooleanTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.Boolean\">\r\n </lib-question-boolean-template>\r\n\r\n <lib-question-text-template #questionTextTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.TextInput\"\r\n [isArabicLang]=\"isArabicLang\"></lib-question-text-template>\r\n\r\n <lib-question-radio-button-template #questionRadioButtonTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.RadioButton\">\r\n </lib-question-radio-button-template>\r\n\r\n <lib-question-dropdown-template #questionDropdownTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.DropDown\"></lib-question-dropdown-template>\r\n\r\n <lib-question-dropdown-multi-template [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.DropDownMulti\">\r\n </lib-question-dropdown-multi-template>\r\n\r\n <lib-question-check-box-template #questionCheckBoxTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.CheckBox\">\r\n </lib-question-check-box-template>\r\n\r\n <lib-question-matrix-template #questionMatrixTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.Matrix\">\r\n </lib-question-matrix-template>\r\n\r\n <lib-question-cascade-template #questionCascadeTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.Cascade\"\r\n [applicantKey]=\"applicantKey\" [isPre]=\"isPre\" [surveyLanguageId]=\"surveyLanguageId\"\r\n [pageId]=\"question.surveyPageId\" [questionGroupId]=\"question.questionGroupId\"></lib-question-cascade-template>\r\n </ng-container>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-container>\r\n </div>\r\n <div class=\"survay-card-footr\" *ngIf=\"fCtrls.showedSurveyPages.value.length > 0\">\r\n <div class=\"container\" style=\" justify-content: start;\">\r\n <div class=\"survay-pagination fw-bold\">\r\n <span>{{ curruntShowedSurveyPages$ | async}}</span>\r\n <span class=\"ms-2 me-2\">{{isArabicLang ? '\u0645\u0646' : 'of'}} </span>\r\n <span>{{fCtrls.showedSurveyPages.value.length}}</span>\r\n </div>\r\n </div>\r\n </div>\r\n</div>", styles: [".disable__btn{background-color:gray!important;cursor:not-allowed}.quastion{padding:10px}.quastion .quastion-title{color:var(--dark-100, #363636);text-align:right;font-family:Almarai;font-size:18px;font-style:normal;font-weight:700;line-height:20.6px}\n"], dependencies: [{ kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: QuestionTextTemplateComponent, selector: "lib-question-text-template", inputs: ["isArabicLang", "setQuestion", "isDisabled"] }, { kind: "component", type: QuestionRadioButtonTemplateComponent, selector: "lib-question-radio-button-template", inputs: ["setQuestion"] }, { kind: "component", type: QuestionCheckBoxTemplateComponent, selector: "lib-question-check-box-template", inputs: ["setQuestion"] }, { kind: "component", type: QuestionDropdownTemplateComponent, selector: "lib-question-dropdown-template", inputs: ["setQuestion"], outputs: ["emitter"] }, { kind: "component", type: QuestionMatrixTemplateComponent, selector: "lib-question-matrix-template", inputs: ["setQuestion"] }, { kind: "component", type: QuestionBooleanTemplateComponent, selector: "lib-question-boolean-template", inputs: ["setQuestion"] }, { kind: "component", type: QuestionDropdownMultiTemplateComponent, selector: "lib-question-dropdown-multi-template", inputs: ["setQuestion"] }, { kind: "component", type: QuestionCascadeTemplateComponent, selector: "lib-question-cascade-template", inputs: ["pageId", "questionGroupId", "isPre", "surveyLanguageId", "applicantKey", "setQuestion"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }, { kind: "pipe", type: FilterQuestionPipe, name: "filterQuestion" }] }); }
1560
1576
  }
1561
1577
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibComponent, decorators: [{
1562
1578
  type: Component,
1563
- args: [{ selector: 'lib-survery-lib', template: "<div id=\"survery-card-{{surveryLibraryDivId}}\" class=\"survay-card\">\r\n <div *ngFor=\"let surveyPage of surveyData?.surveyPages; let surveyPageIndex = index\"\r\n [attr.id]=\"'survey-page_'+surveyPageIndex\" [ngClass]=\"{'d-none': surveyPageIndex != fCtrls.currentPageIndex.value}\">\r\n <ng-container *ngFor=\"let item of surveyPage.surveyQuestionGroups\">\r\n <div class=\"survay-card\">\r\n <div class=\"survay-card-body\">\r\n <div class=\"survay-group\">\r\n <div class=\"title\">\r\n <h2 class=\"group-title\" [innerHTML]=\"item.questionGroupName\">\r\n </h2>\r\n <span class=\"group-sub-title \" [innerHTML]=\"item.questionGroupDescription\">\r\n </span>\r\n </div>\r\n <ng-container *ngFor=\"let question of item.surveyQuestions\">\r\n <lib-question-boolean-template #questionBooleanTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.Boolean\">\r\n </lib-question-boolean-template>\r\n\r\n <lib-question-text-template #questionTextTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.TextInput\"\r\n [isTextArea]=\"question.isAdvanceTextArea\" [isArabicLang]=\"isArabicLang\"></lib-question-text-template>\r\n\r\n <lib-question-radio-button-template #questionRadioButtonTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.RadioButton\">\r\n </lib-question-radio-button-template>\r\n\r\n <lib-question-dropdown-template #questionDropdownTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\"\r\n *ngIf=\"question.questionTypeId == questionTypeEnum.DropDown\"></lib-question-dropdown-template>\r\n\r\n <lib-question-dropdown-multi-template [setQuestion]=\"question\" (emitter)=\"onUpdateAnswer($event)\"\r\n *ngIf=\"question.questionTypeId == questionTypeEnum.DropDownMulti\">\r\n </lib-question-dropdown-multi-template>\r\n\r\n <lib-question-check-box-template #questionCheckBoxTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.CheckBox\">\r\n </lib-question-check-box-template>\r\n\r\n <lib-question-matrix-template #questionMatrixTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.Matrix\">\r\n </lib-question-matrix-template>\r\n\r\n <lib-question-cascade-template #questionCascadeTemplate [setQuestion]=\"question\"\r\n (emitter)=\"onUpdateAnswer($event)\" *ngIf=\"question.questionTypeId == questionTypeEnum.Cascade\"\r\n [applicantKey]=\"applicantKey\" [isPre]=\"isPre\" [surveyLanguageId]=\"surveyLanguageId\"\r\n [pageIndex]=\"surveyPageIndex\"></lib-question-cascade-template>\r\n </ng-container>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-container>\r\n </div>\r\n <div class=\"survay-card-footr\" *ngIf=\"surveyData != null\">\r\n <div class=\"container\" style=\" justify-content: start;\">\r\n <div class=\"survay-pagination fw-bold\">\r\n <span>{{curruntShowedSurveyPages}}</span>\r\n <span class=\"ms-2 me-2\">{{isArabicLang ? '\u0645\u0646' : 'of'}} </span>\r\n <span>{{showedSurveyPages?.length}}</span>\r\n </div>\r\n </div>\r\n </div>\r\n</div>", styles: [".disable__btn{background-color:gray!important;cursor:not-allowed}.quastion{padding:10px}.quastion .quastion-title{color:var(--dark-100, #363636);text-align:right;font-family:Almarai;font-size:18px;font-style:normal;font-weight:700;line-height:20.6px}\n"] }]
1564
- }], ctorParameters: function () { return [{ type: SurveyLibService }, { type: i1.FormBuilder }, { type: CheckRuleExpsUsecase }]; }, propDecorators: { isPre: [{
1579
+ args: [{ selector: 'lib-survery-lib', template: "<div id=\"survery-card-{{surveryLibraryDivId}}\" class=\"survay-card\">\r\n <div [attr.id]=\"'survey-page_'+fCtrls.currentPageId.value\">\r\n <ng-container *ngFor=\"let item of (pageQuestionGroups$ | async)\">\r\n <div class=\"survay-card\">\r\n <div class=\"survay-card-body\">\r\n <div class=\"survay-group\">\r\n <div class=\"title\">\r\n <h2 class=\"group-title\" [innerHTML]=\"item.questionGroupName\">\r\n </h2>\r\n <span class=\"group-sub-title \" [innerHTML]=\"item.questionGroupDescription\">\r\n </span>\r\n </div>\r\n <ng-container\r\n *ngFor=\"let question of ((pageQuestions$|async) |filterQuestion : item.questionGroupId); trackBy:questionIdentify\">\r\n <lib-question-boolean-template #questionBooleanTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.Boolean\">\r\n </lib-question-boolean-template>\r\n\r\n <lib-question-text-template #questionTextTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.TextInput\"\r\n [isArabicLang]=\"isArabicLang\"></lib-question-text-template>\r\n\r\n <lib-question-radio-button-template #questionRadioButtonTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.RadioButton\">\r\n </lib-question-radio-button-template>\r\n\r\n <lib-question-dropdown-template #questionDropdownTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.DropDown\"></lib-question-dropdown-template>\r\n\r\n <lib-question-dropdown-multi-template [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.DropDownMulti\">\r\n </lib-question-dropdown-multi-template>\r\n\r\n <lib-question-check-box-template #questionCheckBoxTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.CheckBox\">\r\n </lib-question-check-box-template>\r\n\r\n <lib-question-matrix-template #questionMatrixTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.Matrix\">\r\n </lib-question-matrix-template>\r\n\r\n <lib-question-cascade-template #questionCascadeTemplate [setQuestion]=\"question\"\r\n *ngIf=\"question.questionType == questionTypeEnum.Cascade\"\r\n [applicantKey]=\"applicantKey\" [isPre]=\"isPre\" [surveyLanguageId]=\"surveyLanguageId\"\r\n [pageId]=\"question.surveyPageId\" [questionGroupId]=\"question.questionGroupId\"></lib-question-cascade-template>\r\n </ng-container>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-container>\r\n </div>\r\n <div class=\"survay-card-footr\" *ngIf=\"fCtrls.showedSurveyPages.value.length > 0\">\r\n <div class=\"container\" style=\" justify-content: start;\">\r\n <div class=\"survay-pagination fw-bold\">\r\n <span>{{ curruntShowedSurveyPages$ | async}}</span>\r\n <span class=\"ms-2 me-2\">{{isArabicLang ? '\u0645\u0646' : 'of'}} </span>\r\n <span>{{fCtrls.showedSurveyPages.value.length}}</span>\r\n </div>\r\n </div>\r\n </div>\r\n</div>", styles: [".disable__btn{background-color:gray!important;cursor:not-allowed}.quastion{padding:10px}.quastion .quastion-title{color:var(--dark-100, #363636);text-align:right;font-family:Almarai;font-size:18px;font-style:normal;font-weight:700;line-height:20.6px}\n"] }]
1580
+ }], ctorParameters: function () { return [{ type: SurveyLibService }, { type: i3.Store }, { type: i5.FormBuilder }, { type: CheckRuleExpsUsecase }]; }, propDecorators: { isPre: [{
1565
1581
  type: Input
1566
1582
  }], surveyLanguageId: [{
1567
1583
  type: Input
@@ -1575,20 +1591,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1575
1591
  type: Output
1576
1592
  }] } });
1577
1593
 
1578
- class FilterQuestionPipe {
1579
- transform(value, questionArr) {
1580
- return questionArr.find(x => x.questionId == value.questionId);
1581
- }
1582
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
1583
- static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, name: "filterQuestion" }); }
1584
- }
1585
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, decorators: [{
1586
- type: Pipe,
1587
- args: [{
1588
- name: 'filterQuestion'
1589
- }]
1590
- }] });
1591
-
1592
1594
  class DefaultQuestionAnswerPipe {
1593
1595
  transform(value, questionId, reloadId) {
1594
1596
  if (value != null) {
@@ -1623,13 +1625,109 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1623
1625
  }]
1624
1626
  }] });
1625
1627
 
1628
+ const { selectAll, selectIds } = questionAdapter.getSelectors();
1629
+ const initialSurveyState = {
1630
+ selectedPageId: null,
1631
+ questionGroupArr: questionGroupAdapter.getInitialState(),
1632
+ questionArr: questionAdapter.getInitialState(),
1633
+ ruleArr: ruleAdapter.getInitialState()
1634
+ };
1635
+ const _surveyReducer = createReducer(initialSurveyState, on(surveyActions.loadSurvey, (state, props) => {
1636
+ return {
1637
+ ...state,
1638
+ questionArr: questionAdapter.setAll(props.questionArr, state.questionArr),
1639
+ questionGroupArr: questionGroupAdapter.setAll(props.questionGroupArr, state.questionGroupArr),
1640
+ ruleArr: ruleAdapter.setAll(props.ruleArr, state.ruleArr),
1641
+ selectedPageId: props.selectedPageId
1642
+ };
1643
+ }), on(surveyActions.addQuestion, (state, props) => {
1644
+ return {
1645
+ ...state,
1646
+ questionArr: questionAdapter.addOne(props.question, state.questionArr)
1647
+ };
1648
+ }), on(surveyActions.updateQuestionAnswer, (state, props) => {
1649
+ const question = selectAll(state.questionArr).find(x => x.questionId == props.questionId);
1650
+ if (question) {
1651
+ var updateModel;
1652
+ if (question.questionType == QuestionTypeEnum.TextInput) {
1653
+ updateModel = {
1654
+ id: props.questionId,
1655
+ changes: {
1656
+ answerId: question.questionAllInfo.surveyAnswers[0].answerId,
1657
+ answerText: props.answer,
1658
+ isValid: props.isValid
1659
+ }
1660
+ };
1661
+ }
1662
+ else if (question.questionType == QuestionTypeEnum.CheckBox || question.questionType == QuestionTypeEnum.DropDownMulti) {
1663
+ updateModel = {
1664
+ id: props.questionId,
1665
+ changes: {
1666
+ answerIdArr: props.answer,
1667
+ isValid: props.isValid
1668
+ }
1669
+ };
1670
+ }
1671
+ else {
1672
+ updateModel = {
1673
+ id: props.questionId,
1674
+ changes: {
1675
+ answerId: props.answer,
1676
+ isValid: props.isValid
1677
+ }
1678
+ };
1679
+ }
1680
+ return {
1681
+ ...state,
1682
+ questionArr: questionAdapter.updateOne(updateModel, state.questionArr)
1683
+ };
1684
+ }
1685
+ return {
1686
+ ...state
1687
+ };
1688
+ }), on(surveyActions.updateQuestionShow, (state, props) => {
1689
+ return {
1690
+ ...state,
1691
+ questionArr: questionAdapter.updateOne({
1692
+ id: props.questionId,
1693
+ changes: {
1694
+ isShow: props.isShow
1695
+ }
1696
+ }, state.questionArr)
1697
+ };
1698
+ }), on(surveyActions.updateQuestionDisable, (state, props) => {
1699
+ const question = selectAll(state.questionArr).find(x => x.questionId == props.questionId);
1700
+ return {
1701
+ ...state,
1702
+ questionArr: questionAdapter.updateOne({
1703
+ id: props.questionId,
1704
+ changes: {
1705
+ isDisabled: props.isDisabled
1706
+ }
1707
+ }, state.questionArr)
1708
+ };
1709
+ }), on(surveyActions.removeQuestion, (state, props) => {
1710
+ return {
1711
+ ...state,
1712
+ questionArr: questionAdapter.removeOne(props.questionId, state.questionArr)
1713
+ };
1714
+ }), on(surveyActions.updatePageId, (state, props) => {
1715
+ return {
1716
+ ...state,
1717
+ selectedPageId: props.pageId
1718
+ };
1719
+ }));
1720
+ function surveyReducer(state, action) {
1721
+ return _surveyReducer(state, action);
1722
+ }
1723
+
1626
1724
  class SurveryLibModule {
1627
1725
  static forRoot(config) {
1628
1726
  return {
1629
1727
  ngModule: SurveryLibModule,
1630
1728
  providers: [
1631
1729
  { provide: LibConfigService, useValue: config }
1632
- ]
1730
+ ],
1633
1731
  };
1634
1732
  }
1635
1733
  static forChild() {
@@ -1651,8 +1749,12 @@ class SurveryLibModule {
1651
1749
  DefaultQuestionAnswersPipe,
1652
1750
  TextBoxTypeAttrPipe,
1653
1751
  QuestionCascadeTemplateComponent,
1654
- MaskedForMinMaxDirective], imports: [CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule], exports: [SurveryLibComponent] }); }
1655
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibModule, imports: [CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule] }); }
1752
+ MaskedForMinMaxDirective,
1753
+ FindQuestionPipe], imports: [CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule, i3.StoreFeatureModule, i2.EffectsFeatureModule], exports: [SurveryLibComponent,
1754
+ StoreModule] }); }
1755
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibModule, imports: [CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule,
1756
+ StoreModule.forFeature('survey-lib', surveyReducer),
1757
+ EffectsModule.forFeature([]), StoreModule] }); }
1656
1758
  }
1657
1759
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibModule, decorators: [{
1658
1760
  type: NgModule,
@@ -1671,13 +1773,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1671
1773
  DefaultQuestionAnswersPipe,
1672
1774
  TextBoxTypeAttrPipe,
1673
1775
  QuestionCascadeTemplateComponent,
1674
- MaskedForMinMaxDirective
1776
+ MaskedForMinMaxDirective,
1777
+ FindQuestionPipe
1675
1778
  ],
1676
1779
  imports: [
1677
- CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule
1780
+ CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule,
1781
+ StoreModule.forFeature('survey-lib', surveyReducer),
1782
+ EffectsModule.forFeature([])
1678
1783
  ],
1679
1784
  exports: [
1680
- SurveryLibComponent
1785
+ SurveryLibComponent,
1786
+ StoreModule
1681
1787
  ]
1682
1788
  }]
1683
1789
  }] });