survery-lib 0.1.60 → 0.2.2

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 +99 -41
  20. package/esm2022/lib/survery-lib.component.mjs +84 -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 +823 -706
  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 -29
  45. package/lib/survery-lib.component.d.ts +16 -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 { Subject, 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,209 @@ 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
141
  get reloadSurveyObsrv() {
57
142
  return this.reloadSurveySubject.asObservable();
58
143
  }
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();
144
+ constructor(_Store) {
145
+ this._Store = _Store;
74
146
  this.reloadSurveySubject = new Subject();
75
- this.questionIsShowSubject = new Subject();
76
- this.questionIsDisabledSubject = new Subject();
77
- this.addQuestionSubject = new Subject();
78
- this.removeQuestionSubject = new Subject();
79
147
  }
80
148
  setSurveyData(survey) {
81
- this.surveyDataSubject.next(survey);
149
+ var questionArr = [];
150
+ var questionGroupArr = [];
151
+ survey.surveyPages.forEach((page, pageIndex) => {
152
+ page.surveyQuestionGroups.forEach(group => {
153
+ questionGroupArr.push({
154
+ questionGroupId: group.questionGroupId,
155
+ questionGroupName: group.questionGroupName,
156
+ questionGroupDescription: group.questionGroupDescription,
157
+ surveyPageId: page.pageId
158
+ });
159
+ group.surveyQuestions.forEach(question => {
160
+ var newQuestions = this.addQuestion(question, page.pageId, group.questionGroupId);
161
+ questionArr.push(...newQuestions);
162
+ });
163
+ });
164
+ });
165
+ var pageIdArr = survey.surveyPages.map(x => x.pageId);
166
+ this._Store.dispatch(surveyActions.loadSurvey({
167
+ questionArr: questionArr,
168
+ ruleArr: survey.surveyRules,
169
+ questionGroupArr: questionGroupArr,
170
+ selectedPageId: Math.min(...pageIdArr)
171
+ }));
82
172
  }
83
173
  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 });
174
+ model.defaultAnswers.forEach(answer => {
175
+ if (answer.QuestionType == QuestionTypeEnum.TextInput) {
176
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
177
+ questionId: answer.QuestionId,
178
+ answer: answer.AnswerText,
179
+ isValid: true
180
+ }));
181
+ }
182
+ else if (answer.QuestionType == QuestionTypeEnum.CheckBox
183
+ || answer.QuestionType == QuestionTypeEnum.DropDownMulti) {
184
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
185
+ questionId: answer.QuestionId,
186
+ answer: answer.AnswerIdArr,
187
+ isValid: true
188
+ }));
189
+ }
190
+ else {
191
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
192
+ questionId: answer.QuestionId,
193
+ answer: answer.AnswerId,
194
+ isValid: true
195
+ }));
196
+ }
197
+ });
91
198
  }
92
199
  setReloadSurvey() {
93
200
  this.reloadSurveySubject.next(v4());
94
201
  }
95
- setAddQuestion(question, pageIndex) {
96
- this.addQuestionSubject.next({ question, pageIndex });
97
- }
98
- setRemoveQuestion(questionId) {
99
- this.removeQuestionSubject.next({ questionId });
202
+ addQuestion(question, pageIndex, questionGroupId) {
203
+ var questionArr = [{
204
+ surveyPageId: pageIndex,
205
+ questionId: question.questionId,
206
+ questionType: question.questionTypeId,
207
+ inputTypeId: question.surveyAnswers[0].inputTypeId,
208
+ isMatrixGroup: question.questionTypeId == QuestionTypeEnum.Matrix,
209
+ answerId: null,
210
+ answerIdArr: null,
211
+ answerText: null,
212
+ isRequired: question.isRequired,
213
+ isValid: null,
214
+ isDisabled: question.isReadOnly,
215
+ isShow: question.isVisable,
216
+ isDisabled_default: question.isReadOnly,
217
+ isShow_default: question.isVisable,
218
+ questionGroupId: questionGroupId,
219
+ parentQuestionId: null,
220
+ questionAllInfo: question
221
+ }];
222
+ if (question.questionTypeId == QuestionTypeEnum.Matrix) {
223
+ question.surveySubQuestions.forEach(subQuestion => {
224
+ questionArr.push({
225
+ surveyPageId: pageIndex,
226
+ questionId: subQuestion.questionId,
227
+ questionType: question.questionTypeId,
228
+ inputTypeId: question.surveyAnswers[0].inputTypeId,
229
+ isMatrixGroup: false,
230
+ answerId: null,
231
+ answerIdArr: null,
232
+ answerText: null,
233
+ isRequired: question.isRequired,
234
+ isValid: null,
235
+ isDisabled: question.isReadOnly,
236
+ isShow: question.isVisable,
237
+ isDisabled_default: question.isReadOnly,
238
+ isShow_default: question.isVisable,
239
+ parentQuestionId: question.questionId,
240
+ questionGroupId: questionGroupId,
241
+ questionAllInfo: question
242
+ });
243
+ });
244
+ }
245
+ return questionArr;
100
246
  }
101
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveyLibService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
247
+ 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
248
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveyLibService, providedIn: 'root' }); }
103
249
  }
104
250
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveyLibService, decorators: [{
@@ -106,7 +252,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
106
252
  args: [{
107
253
  providedIn: 'root'
108
254
  }]
109
- }], ctorParameters: function () { return []; } });
255
+ }], ctorParameters: function () { return [{ type: i3.Store }]; } });
110
256
 
111
257
  var LogicPropertyEnum;
112
258
  (function (LogicPropertyEnum) {
@@ -405,54 +551,56 @@ class QuestionTextTemplateComponent {
405
551
  return null;
406
552
  }
407
553
  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)]);
554
+ if (!this.surveyQuestion) {
555
+ this.surveyQuestion = value.questionAllInfo;
556
+ this.isTextArea = value.questionAllInfo.isAdvanceTextArea;
557
+ this.rForm.patchValue({
558
+ id: value.questionId,
559
+ name: value.questionAllInfo.questionName,
560
+ title: value.questionAllInfo.questionTitle,
561
+ typeId: value.questionAllInfo.questionTypeId,
562
+ description: value.questionAllInfo.questionDescription,
563
+ isDisabled: value.questionAllInfo.isReadOnly,
564
+ isShow: value.questionAllInfo.isVisable
565
+ });
566
+ if (value.questionAllInfo.surveyAnswers[0]?.answerId != null && value.questionAllInfo.surveyAnswers[0]?.answerId != undefined) {
567
+ this.fCtrls.surveyAnswerId.setValue(value.questionAllInfo.surveyAnswers[0].answerId);
568
+ this.fCtrls.inputTypeId.setValue(value.questionAllInfo.surveyAnswers[0].inputTypeId);
569
+ }
570
+ if (value.isRequired == true) {
571
+ this.fCtrls.answer.addValidators([Validators.required]);
572
+ if (value.questionAllInfo.surveyAnswers[0].inputTypeId == InputTypeEnum.Number) {
573
+ if (value.questionAllInfo.surveyAnswers[0].inputMin != null) {
574
+ this.fCtrls.inputMin.setValue(value.questionAllInfo.surveyAnswers[0].inputMin);
575
+ this.fCtrls.answer.addValidators([Validators.min(value.questionAllInfo.surveyAnswers[0].inputMin)]);
576
+ }
577
+ if (value.questionAllInfo.surveyAnswers[0].inputMax != null) {
578
+ this.fCtrls.inputMax.setValue(value.questionAllInfo.surveyAnswers[0].inputMax);
579
+ this.fCtrls.answer.addValidators([Validators.max(value.questionAllInfo.surveyAnswers[0].inputMax)]);
580
+ }
581
+ if (value.questionAllInfo.surveyAnswers[0].inputMin != null || value.questionAllInfo.surveyAnswers[0].inputMax != null) {
582
+ this.fCtrls.inputTypeId.setValue(InputTypeEnum.Text);
583
+ }
428
584
  }
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)]);
585
+ else if (value.questionAllInfo.surveyAnswers[0].inputTypeId == InputTypeEnum.Email) {
586
+ this.fCtrls.answer.addValidators([Validators.email]);
432
587
  }
433
- if (value.surveyAnswers[0].inputMin != null || value.surveyAnswers[0].inputMax != null) {
434
- this.fCtrls.inputTypeId.setValue(InputTypeEnum.Text);
588
+ else if (value.questionAllInfo.surveyAnswers[0].inputTypeId == InputTypeEnum.Phone) {
589
+ this.fCtrls.answer.addValidators([PhoneValidator]);
435
590
  }
591
+ this.fCtrls.answer.updateValueAndValidity();
436
592
  }
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();
593
+ this.toggleEnableAnswer(value.questionAllInfo.isReadOnly);
444
594
  }
445
- this.toggleEnableAnswer(value.isReadOnly);
446
595
  }
447
596
  set isDisabled(value) {
448
597
  this.toggleEnableAnswer(value);
449
598
  }
450
- constructor(_formBuilder, _surveyLibService) {
599
+ constructor(_formBuilder, _surveyLibService, _Store) {
451
600
  this._formBuilder = _formBuilder;
452
601
  this._surveyLibService = _surveyLibService;
453
- this.emitter = new EventEmitter();
602
+ this._Store = _Store;
454
603
  this.isArabicLang = false;
455
- this.isTextArea = false;
456
604
  this.rForm = this._formBuilder.group({
457
605
  id: [null],
458
606
  name: [null],
@@ -469,7 +617,7 @@ class QuestionTextTemplateComponent {
469
617
  });
470
618
  }
471
619
  ngOnInit() {
472
- this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
620
+ this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200), distinctUntilChanged()).subscribe(value => {
473
621
  const formValue = this.rForm.value;
474
622
  if (formValue.inputTypeId == InputTypeEnum.Email) {
475
623
  const isRequired = this.fCtrls.answer.hasValidator(Validators.required);
@@ -485,27 +633,31 @@ class QuestionTextTemplateComponent {
485
633
  }
486
634
  setTimeout(() => {
487
635
  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
- });
636
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
637
+ questionId: formValue.id,
638
+ answer: value,
639
+ isValid: this.fCtrls.answer.valid
640
+ }));
494
641
  }, 100);
495
642
  });
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);
643
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
644
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
645
+ const oldValue = value[0];
646
+ const newValue = value[1];
647
+ //updated answer
648
+ if (oldValue?.answerText != newValue?.answerText) {
649
+ this.fCtrls.answer.setValue(newValue?.answerText, { emitEvent: false });
650
+ }
651
+ //updated isDisabled
652
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
653
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
654
+ }
655
+ //updated isShow
656
+ if (oldValue?.isShow != newValue?.isShow) {
657
+ this.fCtrls.isShow.setValue(newValue?.isShow);
658
+ if (newValue?.isShow == false) {
659
+ this.fCtrls.answer.setValue(null);
660
+ }
509
661
  }
510
662
  });
511
663
  }
@@ -521,17 +673,13 @@ class QuestionTextTemplateComponent {
521
673
  }
522
674
  this.fCtrls.answer.updateValueAndValidity();
523
675
  }
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" }] }); }
676
+ 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 }); }
677
+ 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
678
  }
527
679
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionTextTemplateComponent, decorators: [{
528
680
  type: Component,
529
681
  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: [{
682
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { isArabicLang: [{
535
683
  type: Input
536
684
  }], setQuestion: [{
537
685
  type: Input
@@ -547,33 +695,35 @@ class QuestionRadioButtonTemplateComponent {
547
695
  return QuestionTypeEnum;
548
696
  }
549
697
  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();
698
+ if (!this.surveyQuestion) {
699
+ this.surveyQuestion = value.questionAllInfo;
700
+ this.rForm.patchValue({
701
+ id: value.questionId,
702
+ name: value.questionAllInfo.questionName,
703
+ title: value.questionAllInfo.questionTitle,
704
+ typeId: value.questionAllInfo.questionTypeId,
705
+ description: value.questionAllInfo.questionDescription,
706
+ isDisabled: value.questionAllInfo.isReadOnly,
707
+ isShow: value.questionAllInfo.isVisable
708
+ });
709
+ value.questionAllInfo.surveyAnswers.forEach(surveryAnswer => {
710
+ this.fCtrls.answerArray.push(this._formBuilder.group({
711
+ id: [surveryAnswer.answerId],
712
+ title: [surveryAnswer.answerTitle],
713
+ isSelected: [false]
714
+ }));
715
+ });
716
+ if (value.isRequired == true) {
717
+ this.fCtrls.answer.addValidators([Validators.required]);
718
+ this.fCtrls.answer.updateValueAndValidity();
719
+ }
570
720
  }
571
721
  }
572
- constructor(_formBuilder, _surveyLibService) {
722
+ constructor(_formBuilder, _surveyLibService, _Store) {
573
723
  this._formBuilder = _formBuilder;
574
724
  this._surveyLibService = _surveyLibService;
725
+ this._Store = _Store;
575
726
  this.elemId = v4();
576
- this.emitter = new EventEmitter();
577
727
  this.rForm = this._formBuilder.group({
578
728
  id: [null],
579
729
  name: [null],
@@ -589,29 +739,34 @@ class QuestionRadioButtonTemplateComponent {
589
739
  ngOnInit() {
590
740
  this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
591
741
  const formValue = this.rForm.value;
592
- this.emitter.emit({
593
- QuestionId: formValue.id,
594
- IsValid: this.fCtrls.answer.valid,
595
- Answer: value
596
- });
742
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
743
+ questionId: formValue.id,
744
+ answer: value,
745
+ isValid: this.fCtrls.answer.valid
746
+ }));
597
747
  });
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);
748
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
749
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
750
+ const oldValue = value[0];
751
+ const newValue = value[1];
752
+ //updated answer
753
+ if (oldValue?.answerId != newValue?.answerId) {
754
+ this.fCtrls.answer.setValue(newValue?.answerId, { emitEvent: false });
755
+ const groupIndex = this.fCtrls.answerArray.value.findIndex(x => x.id == newValue?.answerId);
756
+ if (groupIndex > -1) {
757
+ this.fCtrls.answerArray.at(groupIndex).controls.isSelected.setValue(true);
758
+ }
606
759
  }
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);
760
+ //updated isDisabled
761
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
762
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
763
+ }
764
+ //updated isShow
765
+ if (oldValue?.isShow != newValue?.isShow) {
766
+ this.fCtrls.isShow.setValue(newValue?.isShow);
767
+ if (newValue?.isShow == false) {
768
+ this.fCtrls.answer.setValue(null);
769
+ }
615
770
  }
616
771
  });
617
772
  }
@@ -621,15 +776,13 @@ class QuestionRadioButtonTemplateComponent {
621
776
  convertToFormControl(element) {
622
777
  return element;
623
778
  }
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"] }] }); }
779
+ 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 }); }
780
+ 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
781
  }
627
782
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionRadioButtonTemplateComponent, decorators: [{
628
783
  type: Component,
629
784
  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: [{
785
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
633
786
  type: Input
634
787
  }] } });
635
788
 
@@ -641,33 +794,35 @@ class QuestionCheckBoxTemplateComponent {
641
794
  return QuestionTypeEnum;
642
795
  }
643
796
  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();
797
+ if (!this.surveyQuestion) {
798
+ this.surveyQuestion = value.questionAllInfo;
799
+ this.rForm.patchValue({
800
+ id: value.questionId,
801
+ name: value.questionAllInfo.questionName,
802
+ title: value.questionAllInfo.questionTitle,
803
+ typeId: value.questionAllInfo.questionTypeId,
804
+ description: value.questionAllInfo.questionDescription,
805
+ isDisabled: value.questionAllInfo.isReadOnly,
806
+ isShow: value.questionAllInfo.isVisable
807
+ });
808
+ value.questionAllInfo.surveyAnswers.forEach(surveryAnswer => {
809
+ this.fCtrls.answerArray.push(this._formBuilder.group({
810
+ id: [surveryAnswer.answerId],
811
+ title: [surveryAnswer.answerTitle],
812
+ isSelected: [false]
813
+ }));
814
+ });
815
+ if (value.isRequired == true) {
816
+ this.fCtrls.answer.addValidators([Validators.required]);
817
+ this.fCtrls.answer.updateValueAndValidity();
818
+ }
664
819
  }
665
820
  }
666
- constructor(_formBuilder, _surveyLibService) {
821
+ constructor(_formBuilder, _surveyLibService, _Store) {
667
822
  this._formBuilder = _formBuilder;
668
823
  this._surveyLibService = _surveyLibService;
824
+ this._Store = _Store;
669
825
  this.elemId = v4();
670
- this.emitter = new EventEmitter();
671
826
  this.rForm = this._formBuilder.group({
672
827
  id: [null],
673
828
  name: [null],
@@ -683,33 +838,37 @@ class QuestionCheckBoxTemplateComponent {
683
838
  ngOnInit() {
684
839
  this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
685
840
  const formValue = this.rForm.value;
686
- this.emitter.emit({
687
- QuestionId: formValue.id,
688
- IsValid: this.fCtrls.answer.valid,
689
- Answer: value
690
- });
841
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
842
+ questionId: formValue.id,
843
+ answer: value,
844
+ isValid: this.fCtrls.answer.valid
845
+ }));
691
846
  });
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);
847
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
848
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
849
+ const oldValue = value[0];
850
+ const newValue = value[1];
851
+ //updated answer
852
+ if (oldValue?.answerIdArr != newValue?.answerIdArr) {
853
+ const distinctArray = newValue?.answerIdArr.filter((n, i) => newValue?.answerIdArr.indexOf(n) === i);
854
+ this.fCtrls.answer.setValue(distinctArray, { emitEvent: false });
855
+ newValue?.answerIdArr.forEach(answerId => {
856
+ const groupIndex = this.fCtrls.answerArray.value.findIndex(x => x.id == answerId);
857
+ if (groupIndex > -1) {
858
+ this.fCtrls.answerArray.at(groupIndex).controls.isSelected.setValue(true);
859
+ }
860
+ });
861
+ }
862
+ //updated isDisabled
863
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
864
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
865
+ }
866
+ //updated isShow
867
+ if (oldValue?.isShow != newValue?.isShow) {
868
+ this.fCtrls.isShow.setValue(newValue?.isShow);
869
+ if (newValue?.isShow == false) {
870
+ this.fCtrls.answer.setValue(null);
703
871
  }
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
872
  }
714
873
  });
715
874
  }
@@ -727,15 +886,13 @@ class QuestionCheckBoxTemplateComponent {
727
886
  convertToFormControl(element) {
728
887
  return element;
729
888
  }
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"] }] }); }
889
+ 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 }); }
890
+ 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
891
  }
733
892
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionCheckBoxTemplateComponent, decorators: [{
734
893
  type: Component,
735
894
  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: [{
895
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
739
896
  type: Input
740
897
  }] } });
741
898
 
@@ -747,24 +904,27 @@ class QuestionDropdownTemplateComponent {
747
904
  return QuestionTypeEnum;
748
905
  }
749
906
  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();
907
+ if (!this.surveyQuestion) {
908
+ this.surveyQuestion = value.questionAllInfo;
909
+ this.rForm.patchValue({
910
+ id: value.questionId,
911
+ name: value.questionAllInfo.questionName,
912
+ title: value.questionAllInfo.questionTitle,
913
+ typeId: value.questionAllInfo.questionTypeId,
914
+ description: value.questionAllInfo.questionDescription,
915
+ isDisabled: value.questionAllInfo.isReadOnly,
916
+ isShow: value.questionAllInfo.isVisable
917
+ });
918
+ if (value.isRequired == true) {
919
+ this.fCtrls.answer.addValidators([Validators.required]);
920
+ this.fCtrls.answer.updateValueAndValidity();
921
+ }
763
922
  }
764
923
  }
765
- constructor(_formBuilder, _surveyLibService) {
924
+ constructor(_formBuilder, _surveyLibService, _Store) {
766
925
  this._formBuilder = _formBuilder;
767
926
  this._surveyLibService = _surveyLibService;
927
+ this._Store = _Store;
768
928
  this.emitter = new EventEmitter();
769
929
  this.rForm = this._formBuilder.group({
770
930
  id: [null],
@@ -778,41 +938,50 @@ class QuestionDropdownTemplateComponent {
778
938
  });
779
939
  }
780
940
  ngOnInit() {
781
- this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
941
+ this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200), distinctUntilChanged()).subscribe(value => {
782
942
  const formValue = this.rForm.value;
943
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
944
+ questionId: formValue.id,
945
+ answer: value,
946
+ isValid: this.fCtrls.answer.valid
947
+ }));
783
948
  this.emitter.emit({
784
949
  QuestionId: formValue.id,
785
950
  IsValid: this.fCtrls.answer.valid,
786
951
  Answer: value
787
952
  });
788
953
  });
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);
954
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
955
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
956
+ const oldValue = value[0];
957
+ const newValue = value[1];
958
+ //updated answer
959
+ if (oldValue?.answerId != newValue?.answerId) {
960
+ this.fCtrls.answer.setValue(newValue?.answerId, { emitEvent: false });
961
+ }
962
+ //updated isDisabled
963
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
964
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
965
+ }
966
+ //updated isShow
967
+ if (oldValue?.isShow != newValue?.isShow) {
968
+ this.fCtrls.isShow.setValue(newValue?.isShow);
969
+ if (newValue?.isShow == false) {
970
+ this.fCtrls.answer.setValue(null);
971
+ }
803
972
  }
804
973
  });
805
974
  }
806
975
  convertToFormControl(element) {
807
976
  return element;
808
977
  }
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"] }] }); }
978
+ 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 }); }
979
+ 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
980
  }
812
981
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionDropdownTemplateComponent, decorators: [{
813
982
  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: [{
983
+ 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"] }]
984
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { emitter: [{
816
985
  type: Output
817
986
  }], setQuestion: [{
818
987
  type: Input
@@ -826,39 +995,41 @@ class QuestionMatrixTemplateComponent {
826
995
  return QuestionTypeEnum;
827
996
  }
828
997
  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],
998
+ if (!this.surveyQuestion) {
999
+ this.surveyQuestion = value.questionAllInfo;
1000
+ this.rForm.patchValue({
1001
+ id: value.questionId,
1002
+ typeId: value.questionAllInfo.questionTypeId,
1003
+ isDisabled: value.questionAllInfo.isReadOnly,
1004
+ isShow: value.questionAllInfo.isVisable
841
1005
  });
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
1006
+ value.questionAllInfo.surveySubQuestions.forEach(x => {
1007
+ var group = this._formBuilder.group({
1008
+ subQuestionId: [x.questionId],
1009
+ questionTitle: [x.questionTitle],
1010
+ answer: [null],
852
1011
  });
1012
+ if (value.isRequired == true) {
1013
+ group.controls.answer.addValidators([Validators.required]);
1014
+ group.controls.answer.updateValueAndValidity();
1015
+ }
1016
+ group.controls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
1017
+ const formValue = this.rForm.value;
1018
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
1019
+ questionId: group.value.subQuestionId,
1020
+ answer: group.value.answer,
1021
+ isValid: group.controls.answer.valid
1022
+ }));
1023
+ });
1024
+ this.fCtrls.subQuestionArray.push(group);
853
1025
  });
854
- this.fCtrls.subQuestionArray.push(group);
855
- });
1026
+ }
856
1027
  }
857
- constructor(_formBuilder, _surveyLibService) {
1028
+ constructor(_formBuilder, _surveyLibService, _Store) {
858
1029
  this._formBuilder = _formBuilder;
859
1030
  this._surveyLibService = _surveyLibService;
1031
+ this._Store = _Store;
860
1032
  this.elemId = v4();
861
- this.emitter = new EventEmitter();
862
1033
  this.rForm = this._formBuilder.group({
863
1034
  id: [null],
864
1035
  typeId: [null],
@@ -868,46 +1039,53 @@ class QuestionMatrixTemplateComponent {
868
1039
  });
869
1040
  }
870
1041
  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 => {
1042
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
1043
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
1044
+ const oldValue = value[0];
1045
+ const newValue = value[1];
1046
+ //updated isDisabled
1047
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
1048
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
1049
+ }
1050
+ //updated isShow
1051
+ if (oldValue?.isShow != newValue?.isShow) {
1052
+ this.fCtrls.isShow.setValue(newValue?.isShow);
1053
+ // if (newValue?.isShow == false) {
1054
+ // this.fCtrls.answer.setValue(null);
1055
+ // }
1056
+ }
1057
+ });
1058
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.filter(x => x.parentQuestionId == this.fCtrls.id.value)))
1059
+ .pipe(filter(x => x.length > 0)).subscribe(questions => {
1060
+ //Update Answers
875
1061
  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);
1062
+ var question = questions.find(x => x.questionId == group.value.subQuestionId);
1063
+ if (question != null) {
1064
+ group.controls.answer.setValue(question.answerId, { emitEvent: false });
879
1065
  }
880
1066
  });
881
1067
  });
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
1068
  }
889
1069
  onChangeAnswer(question, answer) {
890
1070
  const index = this.fCtrls.subQuestionArray.value.findIndex(x => x.subQuestionId == question.subQuestionId);
891
1071
  var subQuestionGroup = this.fCtrls.subQuestionArray.controls[index];
892
1072
  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
- });
1073
+ // this.emitter.emit({
1074
+ // QuestionId: subQuestionGroup.value.subQuestionId,
1075
+ // Answer: subQuestionGroup.value.answer,
1076
+ // IsValid: subQuestionGroup.controls.answer.valid
1077
+ // });
898
1078
  }
899
1079
  convertToFormControl(element) {
900
1080
  return element;
901
1081
  }
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"] }] }); }
1082
+ 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 }); }
1083
+ 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
1084
  }
905
1085
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionMatrixTemplateComponent, decorators: [{
906
1086
  type: Component,
907
1087
  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: [{
1088
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
911
1089
  type: Input
912
1090
  }] } });
913
1091
 
@@ -919,34 +1097,35 @@ class QuestionBooleanTemplateComponent {
919
1097
  return QuestionTypeEnum;
920
1098
  }
921
1099
  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();
1100
+ if (!this.surveyQuestion) {
1101
+ this.surveyQuestion = value.questionAllInfo;
1102
+ this.rForm.patchValue({
1103
+ id: value.questionId,
1104
+ name: value.questionAllInfo.questionName,
1105
+ title: value.questionAllInfo.questionTitle,
1106
+ typeId: value.questionAllInfo.questionTypeId,
1107
+ description: value.questionAllInfo.questionDescription,
1108
+ isDisabled: value.questionAllInfo.isReadOnly,
1109
+ isShow: value.questionAllInfo.isVisable
1110
+ });
1111
+ value.questionAllInfo.surveyAnswers.forEach(surveryAnswer => {
1112
+ this.fCtrls.answerArray.push(this._formBuilder.group({
1113
+ id: [surveryAnswer.answerId],
1114
+ title: [surveryAnswer.answerTitle],
1115
+ isSelected: [false]
1116
+ }));
1117
+ });
1118
+ if (value.isRequired == true) {
1119
+ this.fCtrls.answer.addValidators([Validators.required]);
1120
+ this.fCtrls.answer.updateValueAndValidity();
1121
+ }
943
1122
  }
944
1123
  }
945
- constructor(_formBuilder, _surveyLibService) {
1124
+ constructor(_formBuilder, _surveyLibService, _Store) {
946
1125
  this._formBuilder = _formBuilder;
947
1126
  this._surveyLibService = _surveyLibService;
1127
+ this._Store = _Store;
948
1128
  this.elemId = v4();
949
- this.emitter = new EventEmitter();
950
1129
  this.rForm = this._formBuilder.group({
951
1130
  id: [null],
952
1131
  name: [null],
@@ -960,32 +1139,32 @@ class QuestionBooleanTemplateComponent {
960
1139
  });
961
1140
  }
962
1141
  ngOnInit() {
963
- this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
1142
+ this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200), distinctUntilChanged()).subscribe(value => {
964
1143
  const formValue = this.rForm.value;
965
- this.emitter.emit({
966
- QuestionId: formValue.id,
967
- IsValid: this.fCtrls.answer.valid,
968
- Answer: value
969
- });
1144
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
1145
+ questionId: formValue.id,
1146
+ answer: value,
1147
+ isValid: this.fCtrls.answer.valid
1148
+ }));
970
1149
  });
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);
1150
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
1151
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
1152
+ const oldValue = value[0];
1153
+ const newValue = value[1];
1154
+ //updated answer
1155
+ if (oldValue?.answerId != newValue?.answerId) {
1156
+ this.fCtrls.answer.setValue(newValue?.answerId, { emitEvent: false });
980
1157
  }
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);
1158
+ //updated isDisabled
1159
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
1160
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
1161
+ }
1162
+ //updated isShow
1163
+ if (oldValue?.isShow != newValue?.isShow) {
1164
+ this.fCtrls.isShow.setValue(newValue?.isShow);
1165
+ if (newValue?.isShow == false) {
1166
+ this.fCtrls.answer.setValue(null);
1167
+ }
989
1168
  }
990
1169
  });
991
1170
  }
@@ -995,15 +1174,13 @@ class QuestionBooleanTemplateComponent {
995
1174
  convertToFormControl(element) {
996
1175
  return element;
997
1176
  }
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"] }] }); }
1177
+ 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 }); }
1178
+ 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
1179
  }
1001
1180
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionBooleanTemplateComponent, decorators: [{
1002
1181
  type: Component,
1003
1182
  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: [{
1183
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
1007
1184
  type: Input
1008
1185
  }] } });
1009
1186
 
@@ -1015,33 +1192,35 @@ class QuestionDropdownMultiTemplateComponent {
1015
1192
  return QuestionTypeEnum;
1016
1193
  }
1017
1194
  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();
1195
+ if (!this.surveyQuestion) {
1196
+ this.surveyQuestion = value.questionAllInfo;
1197
+ this.rForm.patchValue({
1198
+ id: value.questionId,
1199
+ name: value.questionAllInfo.questionName,
1200
+ title: value.questionAllInfo.questionTitle,
1201
+ typeId: value.questionAllInfo.questionTypeId,
1202
+ description: value.questionAllInfo.questionDescription,
1203
+ isDisabled: value.questionAllInfo.isReadOnly,
1204
+ isShow: value.questionAllInfo.isVisable
1205
+ });
1206
+ value.questionAllInfo.surveyAnswers.forEach(surveryAnswer => {
1207
+ this.fCtrls.answerArray.push(this._formBuilder.group({
1208
+ id: [surveryAnswer.answerId],
1209
+ title: [surveryAnswer.answerTitle],
1210
+ isSelected: [false]
1211
+ }));
1212
+ });
1213
+ if (value.isRequired == true) {
1214
+ this.fCtrls.answer.addValidators([Validators$1.required]);
1215
+ this.fCtrls.answer.updateValueAndValidity();
1216
+ }
1038
1217
  }
1039
1218
  }
1040
- constructor(_formBuilder, _surveyLibService) {
1219
+ constructor(_formBuilder, _surveyLibService, _Store) {
1041
1220
  this._formBuilder = _formBuilder;
1042
1221
  this._surveyLibService = _surveyLibService;
1222
+ this._Store = _Store;
1043
1223
  this.elemId = v4();
1044
- this.emitter = new EventEmitter();
1045
1224
  this.rForm = this._formBuilder.group({
1046
1225
  id: [null],
1047
1226
  name: [null],
@@ -1057,42 +1236,44 @@ class QuestionDropdownMultiTemplateComponent {
1057
1236
  ngOnInit() {
1058
1237
  this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
1059
1238
  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);
1239
+ this._Store.dispatch(surveyActions.updateQuestionAnswer({
1240
+ questionId: formValue.id,
1241
+ answer: value,
1242
+ isValid: this.fCtrls.answer.valid
1243
+ }));
1076
1244
  });
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);
1245
+ this._Store.select(questionSelectors.pageQuestions).pipe(map(arr => arr.find(x => x.questionId == this.fCtrls.id.value)))
1246
+ .pipe(filter(x => x != null), pairwise()).subscribe(value => {
1247
+ const oldValue = value[0];
1248
+ const newValue = value[1];
1249
+ //updated answer
1250
+ if (oldValue?.answerIdArr != newValue?.answerIdArr) {
1251
+ const distinctArray = newValue?.answerIdArr.filter((n, i) => newValue?.answerIdArr.indexOf(n) === i);
1252
+ this.fCtrls.answer.setValue(distinctArray, { emitEvent: false });
1253
+ }
1254
+ //updated isDisabled
1255
+ if (oldValue?.isDisabled != newValue?.isDisabled) {
1256
+ this.fCtrls.isDisabled.setValue(newValue?.isDisabled);
1257
+ }
1258
+ //updated isShow
1259
+ if (oldValue?.isShow != newValue?.isShow) {
1260
+ this.fCtrls.isShow.setValue(newValue?.isShow);
1261
+ if (newValue?.isShow == false) {
1262
+ this.fCtrls.answer.setValue(null);
1263
+ }
1081
1264
  }
1082
1265
  });
1083
1266
  }
1084
1267
  convertToFormControl(element) {
1085
1268
  return element;
1086
1269
  }
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"] }] }); }
1270
+ 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 }); }
1271
+ 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
1272
  }
1090
1273
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionDropdownMultiTemplateComponent, decorators: [{
1091
1274
  type: Component,
1092
1275
  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: [{
1276
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: i3.Store }]; }, propDecorators: { setQuestion: [{
1096
1277
  type: Input
1097
1278
  }] } });
1098
1279
 
@@ -1121,6 +1302,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1121
1302
  args: [LibConfigService]
1122
1303
  }] }]; } });
1123
1304
 
1305
+ class FindQuestionPipe {
1306
+ transform(arr, questionId) {
1307
+ if (arr) {
1308
+ return arr.find(x => x.questionId == questionId);
1309
+ }
1310
+ return null;
1311
+ }
1312
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FindQuestionPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
1313
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: FindQuestionPipe, name: "findQuestion" }); }
1314
+ }
1315
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FindQuestionPipe, decorators: [{
1316
+ type: Pipe,
1317
+ args: [{
1318
+ name: 'findQuestion'
1319
+ }]
1320
+ }] });
1321
+
1124
1322
  class QuestionCascadeTemplateComponent {
1125
1323
  get fCtrls() {
1126
1324
  return this.rForm.controls;
@@ -1132,15 +1330,19 @@ class QuestionCascadeTemplateComponent {
1132
1330
  return this.fCtrls.questionArr;
1133
1331
  }
1134
1332
  set setQuestion(value) {
1135
- this.setQuestions(value);
1333
+ if (this.surveyQuestionArr?.length == 0) {
1334
+ this.setQuestions(value.questionAllInfo);
1335
+ }
1136
1336
  }
1137
- constructor(_formBuilder, _surveyLibService, _ApiService) {
1337
+ constructor(_formBuilder, _surveyLibService, _ApiService, _Store) {
1138
1338
  this._formBuilder = _formBuilder;
1139
1339
  this._surveyLibService = _surveyLibService;
1140
1340
  this._ApiService = _ApiService;
1341
+ this._Store = _Store;
1141
1342
  this.surveyQuestionArr = [];
1142
- this.emitter = new EventEmitter();
1143
- this.pageIndex = null;
1343
+ this.pageQuestions$ = this._Store.select(questionSelectors.pageQuestions);
1344
+ this.pageId = null;
1345
+ this.questionGroupId = null;
1144
1346
  this.isPre = false;
1145
1347
  this.surveyLanguageId = null;
1146
1348
  this.applicantKey = null;
@@ -1149,9 +1351,9 @@ class QuestionCascadeTemplateComponent {
1149
1351
  });
1150
1352
  }
1151
1353
  ngOnInit() {
1152
- this.fCtrls.questionArr.statusChanges.subscribe(v => {
1153
- console.log(v);
1154
- });
1354
+ // this.fCtrls.questionArr.statusChanges.subscribe(v => {
1355
+ // console.log(v);
1356
+ // })
1155
1357
  }
1156
1358
  onUpdateAnswer(model) {
1157
1359
  if (this.surveyQuestionArr.length > 1) {
@@ -1164,7 +1366,7 @@ class QuestionCascadeTemplateComponent {
1164
1366
  for (let index = 0; index < sortDeletedArr.length; index++) {
1165
1367
  const elementIndex = sortDeletedArr[index];
1166
1368
  const questionId = this.surveyQuestionArr[elementIndex].questionId;
1167
- this._surveyLibService.setRemoveQuestion(questionId);
1369
+ this._Store.dispatch(surveyActions.removeQuestion({ questionId: questionId }));
1168
1370
  this.surveyQuestionArr = this.surveyQuestionArr.filter(x => x.questionId != questionId);
1169
1371
  this.questionFormArray.removeAt(elementIndex);
1170
1372
  }
@@ -1177,12 +1379,29 @@ class QuestionCascadeTemplateComponent {
1177
1379
  surveyLanguageId: this.surveyLanguageId
1178
1380
  }).subscribe(res => {
1179
1381
  if (res.errors.filter(x => x.code == 17).length == 0) {
1382
+ this._Store.dispatch(surveyActions.addQuestion({ question: {
1383
+ surveyPageId: this.pageId,
1384
+ questionId: res.questionId,
1385
+ questionType: res.questionTypeId,
1386
+ inputTypeId: res.surveyAnswers[0].inputTypeId,
1387
+ isMatrixGroup: false,
1388
+ answerId: null,
1389
+ answerIdArr: null,
1390
+ answerText: null,
1391
+ isRequired: res.isRequired,
1392
+ isValid: null,
1393
+ isDisabled: res.isReadOnly,
1394
+ isShow: res.isVisable,
1395
+ isDisabled_default: res.isReadOnly,
1396
+ isShow_default: res.isVisable,
1397
+ questionGroupId: this.questionGroupId,
1398
+ parentQuestionId: model.QuestionId,
1399
+ questionAllInfo: res
1400
+ } }));
1180
1401
  this.setQuestions(res);
1181
- this._surveyLibService.setAddQuestion(res, this.pageIndex);
1182
1402
  }
1183
1403
  });
1184
1404
  }
1185
- this.emitter.emit(model);
1186
1405
  }
1187
1406
  identify(index, item) {
1188
1407
  return item.id;
@@ -1199,16 +1418,17 @@ class QuestionCascadeTemplateComponent {
1199
1418
  group.controls.answer.updateValueAndValidity();
1200
1419
  }
1201
1420
  this.fCtrls.questionArr.push(group);
1421
+ console.log(this.fCtrls.questionArr.value);
1202
1422
  }
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"] }] }); }
1423
+ 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 }); }
1424
+ 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
1425
  }
1206
1426
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: QuestionCascadeTemplateComponent, decorators: [{
1207
1427
  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: [{
1428
+ 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>" }]
1429
+ }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: SurveyLibService }, { type: ApiService }, { type: i3.Store }]; }, propDecorators: { pageId: [{
1430
+ type: Input
1431
+ }], questionGroupId: [{
1212
1432
  type: Input
1213
1433
  }], isPre: [{
1214
1434
  type: Input
@@ -1220,62 +1440,50 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1220
1440
  type: Input
1221
1441
  }] } });
1222
1442
 
1443
+ class FilterQuestionPipe {
1444
+ transform(arr, questionGroupId) {
1445
+ return arr.filter(x => x.questionGroupId == questionGroupId && x.parentQuestionId == null);
1446
+ }
1447
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
1448
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, name: "filterQuestion" }); }
1449
+ }
1450
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: FilterQuestionPipe, decorators: [{
1451
+ type: Pipe,
1452
+ args: [{
1453
+ name: 'filterQuestion'
1454
+ }]
1455
+ }] });
1456
+
1223
1457
  class SurveryLibComponent {
1224
1458
  get fCtrls() {
1225
1459
  return this.rForm.controls;
1226
1460
  }
1227
- get questionTypeEnum() {
1228
- return QuestionTypeEnum;
1229
- }
1230
1461
  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);
1462
+ const formValue = this.rForm.value;
1463
+ return formValue.showedSurveyPages.findIndex(x => x == formValue.currentPageId) == 0;
1254
1464
  }
1255
- get curruntShowedSurveyPages() {
1256
- return this.showedSurveyPages.findIndex(x => x == this.fCtrls.currentPageIndex.value) + 1;
1465
+ get questionTypeEnum() {
1466
+ return QuestionTypeEnum;
1257
1467
  }
1258
1468
  get surveyResult() {
1259
1469
  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
- })
1470
+ currentPageIndex: this.fCtrls.currentPageId.value,
1471
+ answers: this.questionAnswerArr
1271
1472
  };
1272
1473
  }
1273
- constructor(_surveyLibService, _formBuilder, _checkRuleExpsUsecase) {
1474
+ constructor(_surveyLibService, _Store, _formBuilder, _checkRuleExpsUsecase) {
1274
1475
  this._surveyLibService = _surveyLibService;
1476
+ this._Store = _Store;
1275
1477
  this._formBuilder = _formBuilder;
1276
1478
  this._checkRuleExpsUsecase = _checkRuleExpsUsecase;
1277
1479
  this.surveryLibraryDivId = v4();
1278
1480
  this.reloadDefaultAnswerId = v4();
1481
+ this.questionAnswerArr = [];
1482
+ this.pageQuestionGroups$ = this._Store.select(questionGroupSelectors.pageQuestionGroups);
1483
+ this.pageQuestions$ = this._Store.select(questionSelectors.pageQuestions);
1484
+ this.isFirstPage$ = this._Store.select(surveySelectors.isFirstPage);
1485
+ this.isLastPage$ = this._Store.select(surveySelectors.isLastPage);
1486
+ this.curruntShowedSurveyPages$ = this._Store.select(surveySelectors.selectedPageIndex).pipe(map(x => x + 1));
1279
1487
  this.isPre = false;
1280
1488
  this.surveyLanguageId = null;
1281
1489
  this.applicantKey = null;
@@ -1283,119 +1491,59 @@ class SurveryLibComponent {
1283
1491
  this.surveyResultEmit = new EventEmitter();
1284
1492
  this.selectLanguageEmit = new EventEmitter();
1285
1493
  this.rForm = this._formBuilder.group({
1286
- currentPageIndex: [0],
1287
- questionArray: this._formBuilder.array([]),
1288
- ruleQuestionArray: this._formBuilder.array([])
1494
+ currentPageId: new FormControl(null),
1495
+ showedSurveyPages: new FormControl([])
1496
+ });
1497
+ this._Store.select(questionSelectors.questionAnswers).subscribe(arr => {
1498
+ this.questionAnswerArr = arr;
1289
1499
  });
1290
1500
  }
1291
1501
  ngAfterViewInit() {
1292
1502
  }
1503
+ questionIdentify(index, item) {
1504
+ return item.questionId;
1505
+ }
1293
1506
  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
- }
1507
+ this._Store.select(surveySelectors.selectedPageId).subscribe(value => {
1508
+ this.fCtrls.currentPageId.setValue(value);
1302
1509
  });
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);
1510
+ this._Store.select(surveySelectors.showedSurveyPages).subscribe(value => {
1511
+ this.fCtrls.showedSurveyPages.setValue(value);
1309
1512
  });
1310
1513
  }
1311
1514
  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);
1515
+ this._Store.select(questionSelectors.pageQuestions).pipe(take(1)).subscribe(arr => {
1516
+ var invalidRecords = this.haveInValidateQuestions(arr);
1517
+ if (invalidRecords.length == 0) {
1518
+ const nextPageId = this.getNextShowedPage();
1519
+ if (nextPageId != null) {
1520
+ this._Store.dispatch(surveyActions.updatePageId({ pageId: nextPageId }));
1521
+ $('html, body').animate({
1522
+ scrollTop: $(`#survery-card-${this.surveryLibraryDivId}`).offset().top - 30
1523
+ }, 300);
1524
+ }
1525
+ else {
1526
+ this.surveyResultEmit.emit(this.questionAnswerArr);
1527
+ }
1323
1528
  }
1324
1529
  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);
1530
+ var firstQuestion = $('.invalid-question')[0];
1531
+ $('html, body').animate({
1532
+ scrollTop: $(firstQuestion).offset().top - 250
1533
+ }, 300);
1336
1534
  }
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
1535
  });
1355
1536
  }
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
- }
1537
+ onPaggingBack() {
1538
+ const prevPageId = this.getPrevShowedPage();
1539
+ if (prevPageId != null) {
1540
+ this._Store.dispatch(surveyActions.updatePageId({ pageId: prevPageId }));
1376
1541
  }
1377
1542
  }
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;
1543
+ haveInValidateQuestions(questionArr) {
1544
+ const formValue = this.rForm.value;
1397
1545
  var invalidRecords = [];
1398
- var arr = this.fCtrls.questionArray.value.filter(x => x.surveyPageIndex == currentPageIndex && x.isDisabled == false && x.isShow == true);
1546
+ var arr = questionArr.filter(x => x.isDisabled == false && x.isShow == true);
1399
1547
  arr.map(x => {
1400
1548
  if (x.isRequired == true && x.isValid != true && x.isMatrixGroup != true) {
1401
1549
  invalidRecords.push(x);
@@ -1409,159 +1557,38 @@ class SurveryLibComponent {
1409
1557
  }
1410
1558
  });
1411
1559
  if (invalidRecords.length > 0) {
1412
- $(`#survey-page_${currentPageIndex}`).addClass('survey-page_submitted');
1560
+ $(`#survey-page_${formValue.currentPageId}`).addClass('survey-page_submitted');
1561
+ }
1562
+ else {
1563
+ $(`#survey-page_${formValue.currentPageId}`).removeClass('survey-page_submitted');
1413
1564
  }
1414
1565
  return invalidRecords;
1415
1566
  }
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
1567
  getNextShowedPage() {
1479
- var currentPageIndex = this.fCtrls.currentPageIndex.value;
1480
- var showedPages = this.showedSurveyPages;
1481
- var nextShowedPages = showedPages.filter(x => x > currentPageIndex);
1568
+ const formValue = this.rForm.value;
1569
+ var showedPages = formValue.showedSurveyPages;
1570
+ var nextShowedPages = showedPages.filter(x => x > formValue.currentPageId);
1482
1571
  if (nextShowedPages.length > 0) {
1483
1572
  return nextShowedPages[0];
1484
1573
  }
1485
1574
  return null;
1486
1575
  }
1487
1576
  getPrevShowedPage() {
1488
- var currentPageIndex = this.fCtrls.currentPageIndex.value;
1489
- var showedPages = this.showedSurveyPages;
1490
- var prevShowedPages = showedPages.filter(x => x < currentPageIndex);
1577
+ const formValue = this.rForm.value;
1578
+ var showedPages = formValue.showedSurveyPages;
1579
+ var prevShowedPages = showedPages.filter(x => x < formValue.currentPageId);
1491
1580
  if (prevShowedPages.length > 0) {
1492
1581
  return prevShowedPages[prevShowedPages.length - 1];
1493
1582
  }
1494
1583
  return null;
1495
1584
  }
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"] }] }); }
1585
+ 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 }); }
1586
+ 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
1587
  }
1561
1588
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibComponent, decorators: [{
1562
1589
  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: [{
1590
+ 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"] }]
1591
+ }], ctorParameters: function () { return [{ type: SurveyLibService }, { type: i3.Store }, { type: i5.FormBuilder }, { type: CheckRuleExpsUsecase }]; }, propDecorators: { isPre: [{
1565
1592
  type: Input
1566
1593
  }], surveyLanguageId: [{
1567
1594
  type: Input
@@ -1575,20 +1602,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1575
1602
  type: Output
1576
1603
  }] } });
1577
1604
 
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
1605
  class DefaultQuestionAnswerPipe {
1593
1606
  transform(value, questionId, reloadId) {
1594
1607
  if (value != null) {
@@ -1623,13 +1636,109 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1623
1636
  }]
1624
1637
  }] });
1625
1638
 
1639
+ const { selectAll, selectIds } = questionAdapter.getSelectors();
1640
+ const initialSurveyState = {
1641
+ selectedPageId: null,
1642
+ questionGroupArr: questionGroupAdapter.getInitialState(),
1643
+ questionArr: questionAdapter.getInitialState(),
1644
+ ruleArr: ruleAdapter.getInitialState()
1645
+ };
1646
+ const _surveyReducer = createReducer(initialSurveyState, on(surveyActions.loadSurvey, (state, props) => {
1647
+ return {
1648
+ ...state,
1649
+ questionArr: questionAdapter.setAll(props.questionArr, state.questionArr),
1650
+ questionGroupArr: questionGroupAdapter.setAll(props.questionGroupArr, state.questionGroupArr),
1651
+ ruleArr: ruleAdapter.setAll(props.ruleArr, state.ruleArr),
1652
+ selectedPageId: props.selectedPageId
1653
+ };
1654
+ }), on(surveyActions.addQuestion, (state, props) => {
1655
+ return {
1656
+ ...state,
1657
+ questionArr: questionAdapter.addOne(props.question, state.questionArr)
1658
+ };
1659
+ }), on(surveyActions.updateQuestionAnswer, (state, props) => {
1660
+ const question = selectAll(state.questionArr).find(x => x.questionId == props.questionId);
1661
+ if (question) {
1662
+ var updateModel;
1663
+ if (question.questionType == QuestionTypeEnum.TextInput) {
1664
+ updateModel = {
1665
+ id: props.questionId,
1666
+ changes: {
1667
+ answerId: question.questionAllInfo.surveyAnswers[0].answerId,
1668
+ answerText: props.answer,
1669
+ isValid: props.isValid
1670
+ }
1671
+ };
1672
+ }
1673
+ else if (question.questionType == QuestionTypeEnum.CheckBox || question.questionType == QuestionTypeEnum.DropDownMulti) {
1674
+ updateModel = {
1675
+ id: props.questionId,
1676
+ changes: {
1677
+ answerIdArr: props.answer,
1678
+ isValid: props.isValid
1679
+ }
1680
+ };
1681
+ }
1682
+ else {
1683
+ updateModel = {
1684
+ id: props.questionId,
1685
+ changes: {
1686
+ answerId: props.answer,
1687
+ isValid: props.isValid
1688
+ }
1689
+ };
1690
+ }
1691
+ return {
1692
+ ...state,
1693
+ questionArr: questionAdapter.updateOne(updateModel, state.questionArr)
1694
+ };
1695
+ }
1696
+ return {
1697
+ ...state
1698
+ };
1699
+ }), on(surveyActions.updateQuestionShow, (state, props) => {
1700
+ return {
1701
+ ...state,
1702
+ questionArr: questionAdapter.updateOne({
1703
+ id: props.questionId,
1704
+ changes: {
1705
+ isShow: props.isShow
1706
+ }
1707
+ }, state.questionArr)
1708
+ };
1709
+ }), on(surveyActions.updateQuestionDisable, (state, props) => {
1710
+ const question = selectAll(state.questionArr).find(x => x.questionId == props.questionId);
1711
+ return {
1712
+ ...state,
1713
+ questionArr: questionAdapter.updateOne({
1714
+ id: props.questionId,
1715
+ changes: {
1716
+ isDisabled: props.isDisabled
1717
+ }
1718
+ }, state.questionArr)
1719
+ };
1720
+ }), on(surveyActions.removeQuestion, (state, props) => {
1721
+ return {
1722
+ ...state,
1723
+ questionArr: questionAdapter.removeOne(props.questionId, state.questionArr)
1724
+ };
1725
+ }), on(surveyActions.updatePageId, (state, props) => {
1726
+ return {
1727
+ ...state,
1728
+ selectedPageId: props.pageId
1729
+ };
1730
+ }));
1731
+ function surveyReducer(state, action) {
1732
+ return _surveyReducer(state, action);
1733
+ }
1734
+
1626
1735
  class SurveryLibModule {
1627
1736
  static forRoot(config) {
1628
1737
  return {
1629
1738
  ngModule: SurveryLibModule,
1630
1739
  providers: [
1631
1740
  { provide: LibConfigService, useValue: config }
1632
- ]
1741
+ ],
1633
1742
  };
1634
1743
  }
1635
1744
  static forChild() {
@@ -1651,8 +1760,12 @@ class SurveryLibModule {
1651
1760
  DefaultQuestionAnswersPipe,
1652
1761
  TextBoxTypeAttrPipe,
1653
1762
  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] }); }
1763
+ MaskedForMinMaxDirective,
1764
+ FindQuestionPipe], imports: [CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule, i3.StoreFeatureModule, i2.EffectsFeatureModule], exports: [SurveryLibComponent,
1765
+ StoreModule] }); }
1766
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibModule, imports: [CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule,
1767
+ StoreModule.forFeature('survey-lib', surveyReducer),
1768
+ EffectsModule.forFeature([]), StoreModule] }); }
1656
1769
  }
1657
1770
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SurveryLibModule, decorators: [{
1658
1771
  type: NgModule,
@@ -1671,13 +1784,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImpor
1671
1784
  DefaultQuestionAnswersPipe,
1672
1785
  TextBoxTypeAttrPipe,
1673
1786
  QuestionCascadeTemplateComponent,
1674
- MaskedForMinMaxDirective
1787
+ MaskedForMinMaxDirective,
1788
+ FindQuestionPipe
1675
1789
  ],
1676
1790
  imports: [
1677
- CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule
1791
+ CommonModule, HttpClientModule, ReactiveFormsModule, FormsModule, NgsFormsModule, NgSelectModule,
1792
+ StoreModule.forFeature('survey-lib', surveyReducer),
1793
+ EffectsModule.forFeature([])
1678
1794
  ],
1679
1795
  exports: [
1680
- SurveryLibComponent
1796
+ SurveryLibComponent,
1797
+ StoreModule
1681
1798
  ]
1682
1799
  }]
1683
1800
  }] });