survery-lib 0.1.9 → 0.1.11
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.
- package/assets/style.css +325 -0
- package/assets/style.css.map +1 -1
- package/ng-package.json +11 -0
- package/package.json +15 -27
- package/scss/style.scss +88 -0
- package/src/lib/components/question-boolean-template/question-boolean-template.component.html +13 -0
- package/src/lib/components/question-boolean-template/question-boolean-template.component.scss +0 -0
- package/src/lib/components/question-boolean-template/question-boolean-template.component.spec.ts +21 -0
- package/src/lib/components/question-boolean-template/question-boolean-template.component.ts +109 -0
- package/src/lib/components/question-check-box-template/question-check-box-template.component.html +13 -0
- package/src/lib/components/question-check-box-template/question-check-box-template.component.scss +0 -0
- package/src/lib/components/question-check-box-template/question-check-box-template.component.spec.ts +21 -0
- package/src/lib/components/question-check-box-template/question-check-box-template.component.ts +124 -0
- package/src/lib/components/question-dropdown-multi-template/question-dropdown-multi-template.component.html +10 -0
- package/src/lib/components/question-dropdown-multi-template/question-dropdown-multi-template.component.scss +3 -0
- package/src/lib/components/question-dropdown-multi-template/question-dropdown-multi-template.component.spec.ts +21 -0
- package/src/lib/components/question-dropdown-multi-template/question-dropdown-multi-template.component.ts +100 -0
- package/src/lib/components/question-dropdown-template/question-dropdown-template.component.html +10 -0
- package/src/lib/components/question-dropdown-template/question-dropdown-template.component.scss +0 -0
- package/src/lib/components/question-dropdown-template/question-dropdown-template.component.spec.ts +21 -0
- package/src/lib/components/question-dropdown-template/question-dropdown-template.component.ts +87 -0
- package/src/lib/components/question-matrix-template/question-matrix-template.component.html +36 -0
- package/src/lib/components/question-matrix-template/question-matrix-template.component.scss +0 -0
- package/src/lib/components/question-matrix-template/question-matrix-template.component.spec.ts +21 -0
- package/src/lib/components/question-matrix-template/question-matrix-template.component.ts +110 -0
- package/src/lib/components/question-radio-button-template/question-radio-button-template.component.html +13 -0
- package/src/lib/components/question-radio-button-template/question-radio-button-template.component.scss +0 -0
- package/src/lib/components/question-radio-button-template/question-radio-button-template.component.spec.ts +21 -0
- package/src/lib/components/question-radio-button-template/question-radio-button-template.component.ts +111 -0
- package/src/lib/components/question-text-template/question-text-template.component.html +13 -0
- package/src/lib/components/question-text-template/question-text-template.component.scss +0 -0
- package/src/lib/components/question-text-template/question-text-template.component.spec.ts +21 -0
- package/src/lib/components/question-text-template/question-text-template.component.ts +105 -0
- package/src/lib/pipes/default-question-answer.pipe.spec.ts +8 -0
- package/src/lib/pipes/default-question-answer.pipe.ts +18 -0
- package/src/lib/pipes/default-question-answers.pipe.spec.ts +8 -0
- package/src/lib/pipes/default-question-answers.pipe.ts +17 -0
- package/src/lib/pipes/filter-question.pipe.spec.ts +8 -0
- package/src/lib/pipes/filter-question.pipe.ts +14 -0
- package/src/lib/services/survey-lib.service.spec.ts +16 -0
- package/src/lib/services/survey-lib.service.ts +31 -0
- package/src/lib/survery-lib.component.spec.ts +21 -0
- package/src/lib/survery-lib.component.ts +308 -0
- package/src/lib/survery-lib.module.ts +47 -0
- package/src/lib/survey-lib.component.html +67 -0
- package/src/lib/survey-lib.component.scss +4 -0
- package/{lib/usecases/base/use-case.d.ts → src/lib/usecases/base/use-case.ts} +9 -7
- package/src/lib/usecases/check-rule-exps.usecase.ts +188 -0
- package/{public-api.d.ts → src/public-api.ts} +5 -1
- package/src/shared/dtos/default-question-answers.dto.ts +10 -0
- package/{shared/dtos/rule-exp-answer.dto.d.ts → src/shared/dtos/rule-exp-answer.dto.ts} +5 -5
- package/{shared/dtos/rule-exp.dto.d.ts → src/shared/dtos/rule-exp.dto.ts} +14 -13
- package/{shared/dtos/rule-result-question.dto.d.ts → src/shared/dtos/rule-result-question.dto.ts} +5 -4
- package/{shared/dtos/survey-answer.dto.d.ts → src/shared/dtos/survey-answer.dto.ts} +16 -16
- package/{shared/dtos/survey-answers-subject.dto.d.ts → src/shared/dtos/survey-answers-subject.dto.ts} +6 -5
- package/{shared/dtos/survey-page.dto.d.ts → src/shared/dtos/survey-page.dto.ts} +10 -9
- package/{shared/dtos/survey-question-group.dto.d.ts → src/shared/dtos/survey-question-group.dto.ts} +9 -8
- package/{shared/dtos/survey-question.dto.d.ts → src/shared/dtos/survey-question.dto.ts} +19 -18
- package/{shared/dtos/survey-rule.dto.d.ts → src/shared/dtos/survey-rule.dto.ts} +11 -10
- package/{shared/dtos/survey-sub-question.dto.d.ts → src/shared/dtos/survey-sub-question.dto.ts} +9 -9
- package/{shared/dtos/survey.dto.d.ts → src/shared/dtos/survey.dto.ts} +17 -16
- package/{shared/enums/logic-action.enum.d.ts → src/shared/enums/logic-action.enum.ts} +7 -7
- package/src/shared/enums/logic-property.enum.ts +12 -0
- package/src/shared/enums/operator.enum.ts +4 -0
- package/{shared/enums/question-type.enum.d.ts → src/shared/enums/question-type.enum.ts} +9 -8
- package/src/shared/form-interfaces/question-boolean-template.form-interface.ts +17 -0
- package/src/shared/form-interfaces/question-check-box-template.form-interface.ts +18 -0
- package/src/shared/form-interfaces/question-dropdown-multi-template.form-interface.ts +17 -0
- package/src/shared/form-interfaces/question-dropdown-template.form-interface.ts +10 -0
- package/{shared/form-interfaces/question-matrix-template.form-interface.d.ts → src/shared/form-interfaces/question-matrix-template.form-interface.ts} +13 -11
- package/src/shared/form-interfaces/question-radio-button-template.form-interface.ts +17 -0
- package/src/shared/form-interfaces/question-text-template.form-interface.ts +11 -0
- package/src/shared/form-interfaces/survery-lib.form-interface.ts +27 -0
- package/src/shared/models/question-answer.model.ts +6 -0
- package/src/shared/models/survery-question-result.model.ts +8 -0
- package/tsconfig.lib.json +14 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +14 -0
- package/esm2022/lib/components/question-boolean-template/question-boolean-template.component.mjs +0 -97
- package/esm2022/lib/components/question-check-box-template/question-check-box-template.component.mjs +0 -108
- package/esm2022/lib/components/question-dropdown-template/question-dropdown-template.component.mjs +0 -83
- package/esm2022/lib/components/question-matrix-template/question-matrix-template.component.mjs +0 -101
- package/esm2022/lib/components/question-radio-button-template/question-radio-button-template.component.mjs +0 -97
- package/esm2022/lib/components/question-text-template/question-text-template.component.mjs +0 -99
- package/esm2022/lib/pipes/default-question-answer.pipe.mjs +0 -19
- package/esm2022/lib/pipes/default-question-answers.pipe.mjs +0 -19
- package/esm2022/lib/pipes/filter-question.pipe.mjs +0 -16
- package/esm2022/lib/services/survey-lib.service.mjs +0 -30
- package/esm2022/lib/survery-lib.component.mjs +0 -270
- package/esm2022/lib/survery-lib.module.mjs +0 -59
- package/esm2022/lib/usecases/base/use-case.mjs +0 -2
- package/esm2022/lib/usecases/check-rule-exps.usecase.mjs +0 -154
- package/esm2022/public-api.mjs +0 -8
- package/esm2022/shared/dtos/default-question-answers.dto.mjs +0 -3
- package/esm2022/shared/dtos/rule-exp-answer.dto.mjs +0 -2
- package/esm2022/shared/dtos/rule-exp.dto.mjs +0 -2
- package/esm2022/shared/dtos/rule-result-question.dto.mjs +0 -2
- package/esm2022/shared/dtos/survey-answer.dto.mjs +0 -2
- package/esm2022/shared/dtos/survey-answers-subject.dto.mjs +0 -3
- package/esm2022/shared/dtos/survey-page.dto.mjs +0 -2
- package/esm2022/shared/dtos/survey-question-group.dto.mjs +0 -2
- package/esm2022/shared/dtos/survey-question.dto.mjs +0 -2
- package/esm2022/shared/dtos/survey-rule.dto.mjs +0 -2
- package/esm2022/shared/dtos/survey-sub-question.dto.mjs +0 -2
- package/esm2022/shared/dtos/survey.dto.mjs +0 -2
- package/esm2022/shared/enums/Logic-Property.enum.mjs +0 -14
- package/esm2022/shared/enums/logic-action.enum.mjs +0 -9
- package/esm2022/shared/enums/operator.enum.mjs +0 -6
- package/esm2022/shared/enums/question-type.enum.mjs +0 -10
- package/esm2022/shared/form-interfaces/question-boolean-template.form-interface.mjs +0 -2
- package/esm2022/shared/form-interfaces/question-check-box-template.form-interface.mjs +0 -3
- package/esm2022/shared/form-interfaces/question-dropdown-template.form-interface.mjs +0 -3
- package/esm2022/shared/form-interfaces/question-matrix-template.form-interface.mjs +0 -2
- package/esm2022/shared/form-interfaces/question-radio-button-template.form-interface.mjs +0 -3
- package/esm2022/shared/form-interfaces/question-text-template.form-interface.mjs +0 -2
- package/esm2022/shared/form-interfaces/survery-lib.form-interface.mjs +0 -2
- package/esm2022/shared/models/question-answer.model.mjs +0 -3
- package/esm2022/shared/models/survery-question-result.model.mjs +0 -3
- package/esm2022/survery-lib.mjs +0 -5
- package/fesm2022/survery-lib.mjs +0 -1114
- package/fesm2022/survery-lib.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/components/question-boolean-template/question-boolean-template.component.d.ts +0 -36
- package/lib/components/question-check-box-template/question-check-box-template.component.d.ts +0 -37
- package/lib/components/question-dropdown-template/question-dropdown-template.component.d.ts +0 -33
- package/lib/components/question-matrix-template/question-matrix-template.component.d.ts +0 -33
- package/lib/components/question-radio-button-template/question-radio-button-template.component.d.ts +0 -36
- package/lib/components/question-text-template/question-text-template.component.d.ts +0 -35
- package/lib/pipes/default-question-answer.pipe.d.ts +0 -8
- package/lib/pipes/default-question-answers.pipe.d.ts +0 -8
- package/lib/pipes/filter-question.pipe.d.ts +0 -9
- package/lib/services/survey-lib.service.d.ts +0 -14
- package/lib/survery-lib.component.d.ts +0 -45
- package/lib/survery-lib.module.d.ts +0 -22
- package/lib/usecases/check-rule-exps.usecase.d.ts +0 -21
- package/shared/dtos/default-question-answers.dto.d.ts +0 -9
- package/shared/enums/Logic-Property.enum.d.ts +0 -12
- package/shared/enums/operator.enum.d.ts +0 -4
- package/shared/form-interfaces/question-boolean-template.form-interface.d.ts +0 -15
- package/shared/form-interfaces/question-check-box-template.form-interface.d.ts +0 -15
- package/shared/form-interfaces/question-dropdown-template.form-interface.d.ts +0 -9
- package/shared/form-interfaces/question-radio-button-template.form-interface.d.ts +0 -15
- package/shared/form-interfaces/question-text-template.form-interface.d.ts +0 -10
- package/shared/form-interfaces/survery-lib.form-interface.d.ts +0 -24
- package/shared/models/question-answer.model.d.ts +0 -6
- package/shared/models/survery-question-result.model.d.ts +0 -8
package/src/lib/components/question-check-box-template/question-check-box-template.component.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
2
|
+
import { FormControl, Validators } from '@angular/forms';
|
|
3
|
+
import { FormBuilder, FormGroup } from '@ng-stack/forms';
|
|
4
|
+
import { SurveyAnswerDto } from '../../../shared/dtos/survey-answer.dto';
|
|
5
|
+
import { SurveyQuestionDto } from '../../../shared/dtos/survey-question.dto';
|
|
6
|
+
import { QuestionTypeEnum } from '../../../shared/enums/question-type.enum';
|
|
7
|
+
import {
|
|
8
|
+
AnswerChildOfQuestionCheckBoxTemplateFormInterface,
|
|
9
|
+
QuestionCheckBoxTemplateFormInterface
|
|
10
|
+
} from '../../../shared/form-interfaces/question-check-box-template.form-interface';
|
|
11
|
+
import { QuestionRadioButtonTemplateFormInterface } from '../../../shared/form-interfaces/question-radio-button-template.form-interface';
|
|
12
|
+
import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs';
|
|
13
|
+
import { v4 as guidGenerator } from 'uuid';
|
|
14
|
+
import { QuestionAnswerModel } from '../../../shared/models/question-answer.model';
|
|
15
|
+
import { DefaultQuestionAnswerDto } from '../../../shared/dtos/default-question-answers.dto';
|
|
16
|
+
import { AnswerChildOfQuestionBooleanTemplateFormInterface } from '../../../shared/form-interfaces/question-boolean-template.form-interface';
|
|
17
|
+
import { SurveyLibService } from '../../services/survey-lib.service';
|
|
18
|
+
|
|
19
|
+
@Component({
|
|
20
|
+
selector: 'lib-question-check-box-template',
|
|
21
|
+
templateUrl: './question-check-box-template.component.html',
|
|
22
|
+
styleUrls: ['./question-check-box-template.component.scss']
|
|
23
|
+
})
|
|
24
|
+
export class QuestionCheckBoxTemplateComponent implements OnInit {
|
|
25
|
+
elemId = guidGenerator() as string;
|
|
26
|
+
surveyQuestion: SurveyQuestionDto;
|
|
27
|
+
rForm: FormGroup<QuestionCheckBoxTemplateFormInterface>;
|
|
28
|
+
|
|
29
|
+
get fCtrls() {
|
|
30
|
+
return this.rForm.controls;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get questionTypeEnum() {
|
|
34
|
+
return QuestionTypeEnum;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Output() emitter = new EventEmitter<QuestionAnswerModel>();
|
|
38
|
+
|
|
39
|
+
@Input() isShow: boolean = true;
|
|
40
|
+
@Input() isDisabled: boolean = false;
|
|
41
|
+
@Input() set setQuestion(value: SurveyQuestionDto) {
|
|
42
|
+
this.surveyQuestion = value;
|
|
43
|
+
this.rForm.patchValue({
|
|
44
|
+
id: value.questionId,
|
|
45
|
+
name: value.questionName,
|
|
46
|
+
title: value.questionTitle,
|
|
47
|
+
typeId: value.questionTypeId,
|
|
48
|
+
description: value.questionDescription
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
value.surveyAnswers.forEach(surveryAnswer => {
|
|
52
|
+
this.fCtrls.answerArray.push(this._formBuilder.group<AnswerChildOfQuestionCheckBoxTemplateFormInterface>({
|
|
53
|
+
id: [surveryAnswer.answerId],
|
|
54
|
+
title: [surveryAnswer.answerTitle],
|
|
55
|
+
isSelected: [false]
|
|
56
|
+
}))
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
if (value.isRequired == true) {
|
|
60
|
+
this.fCtrls.answer.addValidators([Validators.required]);
|
|
61
|
+
this.fCtrls.answer.updateValueAndValidity();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.isShow = value.isVisable;
|
|
65
|
+
this.isDisabled = value.isReadOnly;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
constructor(private _formBuilder: FormBuilder, private _surveyLibService: SurveyLibService) {
|
|
69
|
+
this.rForm = this._formBuilder.group<QuestionCheckBoxTemplateFormInterface>({
|
|
70
|
+
id: [null],
|
|
71
|
+
name: [null],
|
|
72
|
+
title: [null],
|
|
73
|
+
typeId: [null],
|
|
74
|
+
description: [null],
|
|
75
|
+
answer: [null],
|
|
76
|
+
answerArray: this._formBuilder.array<AnswerChildOfQuestionCheckBoxTemplateFormInterface>([])
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
ngOnInit(): void {
|
|
81
|
+
this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
|
|
82
|
+
const formValue = this.rForm.value;
|
|
83
|
+
this.emitter.emit({
|
|
84
|
+
QuestionId: formValue.id,
|
|
85
|
+
IsValid: this.fCtrls.answer.valid,
|
|
86
|
+
Answer: value
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
this.fCtrls.answer.setValue(null);
|
|
91
|
+
|
|
92
|
+
this._surveyLibService.surveyAnswersObsrv
|
|
93
|
+
.pipe(map(x => x.defaultAnswers.filter(x => x.QuestionId == this.fCtrls.id.value)))
|
|
94
|
+
.pipe(filter(x => x.length > 0)).pipe(map(x => x.at(0)))
|
|
95
|
+
.subscribe(answer => {
|
|
96
|
+
const distinctArray = answer.AnswerIdArr.filter((n, i) => answer.AnswerIdArr.indexOf(n) === i);
|
|
97
|
+
this.fCtrls.answer.setValue(distinctArray);
|
|
98
|
+
|
|
99
|
+
answer.AnswerIdArr.forEach(answerId => {
|
|
100
|
+
const groupIndex = this.fCtrls.answerArray.value.findIndex(x => x.id == answerId);
|
|
101
|
+
if (groupIndex > -1) {
|
|
102
|
+
this.fCtrls.answerArray.at(groupIndex).controls.isSelected.setValue(true);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
onChangeAnswer(item: AnswerChildOfQuestionBooleanTemplateFormInterface, event: Event) {
|
|
109
|
+
var answerArr: number[] = this.fCtrls.answer.value || [];
|
|
110
|
+
|
|
111
|
+
if ((event.target as any).checked == true) {
|
|
112
|
+
answerArr.push(item.id);
|
|
113
|
+
} else {
|
|
114
|
+
answerArr = answerArr.filter(x => x != item.id);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
answerArr = answerArr.length == 0 ? [] : answerArr;
|
|
118
|
+
this.fCtrls.answer.setValue(answerArr);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
convertToFormControl(element: any) {
|
|
122
|
+
return element as FormControl;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<div class="quastion" [attr.id]="'question_'+fCtrls.id.value" [ngClass]="{'invalid-question': fCtrls.answer.invalid , 'd-none':isShow != true}">
|
|
2
|
+
<h3 class="quastion-title ">
|
|
3
|
+
{{fCtrls.title.value}}
|
|
4
|
+
</h3>
|
|
5
|
+
<div class="text-quastion">
|
|
6
|
+
<ng-select [items]="this.fCtrls.answerArray.value" bindValue="id" bindLabel="title" class="form-control"
|
|
7
|
+
[formControl]="convertToFormControl(fCtrls.answer)" [disabled]="isDisabled" [multiple]="true">
|
|
8
|
+
</ng-select>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { QuestionDropdownMultiTemplateComponent } from './question-dropdown-multi-template.component';
|
|
4
|
+
|
|
5
|
+
describe('QuestionDropdownMultiTemplateComponent', () => {
|
|
6
|
+
let component: QuestionDropdownMultiTemplateComponent;
|
|
7
|
+
let fixture: ComponentFixture<QuestionDropdownMultiTemplateComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
declarations: [QuestionDropdownMultiTemplateComponent]
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(QuestionDropdownMultiTemplateComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
2
|
+
import { FormControl } from '@angular/forms';
|
|
3
|
+
import { FormGroup, Validators , FormBuilder} from '@ng-stack/forms';
|
|
4
|
+
import { QuestionCheckBoxTemplateFormInterface } from '../../../shared/form-interfaces/question-check-box-template.form-interface';
|
|
5
|
+
import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs';
|
|
6
|
+
import { SurveyQuestionDto } from '../../../shared/dtos/survey-question.dto';
|
|
7
|
+
import { QuestionTypeEnum } from '../../../shared/enums/question-type.enum';
|
|
8
|
+
import { QuestionAnswerModel } from '../../../shared/models/question-answer.model';
|
|
9
|
+
import { v4 as guidGenerator } from 'uuid';
|
|
10
|
+
import { AnswerChildOfQuestionDropDownMultiTemplateFormInterface, QuestionDropDownMultiTemplateFormInterface } from '../../../shared/form-interfaces/question-dropdown-multi-template.form-interface';
|
|
11
|
+
import { SurveyLibService } from '../../services/survey-lib.service';
|
|
12
|
+
import { AnswerChildOfQuestionBooleanTemplateFormInterface } from '../../../shared/form-interfaces/question-boolean-template.form-interface';
|
|
13
|
+
|
|
14
|
+
@Component({
|
|
15
|
+
selector: 'lib-question-dropdown-multi-template',
|
|
16
|
+
templateUrl: './question-dropdown-multi-template.component.html',
|
|
17
|
+
styleUrls: ['./question-dropdown-multi-template.component.scss']
|
|
18
|
+
})
|
|
19
|
+
export class QuestionDropdownMultiTemplateComponent {
|
|
20
|
+
|
|
21
|
+
elemId = guidGenerator() as string;
|
|
22
|
+
surveyQuestion: SurveyQuestionDto;
|
|
23
|
+
rForm: FormGroup<QuestionDropDownMultiTemplateFormInterface>;
|
|
24
|
+
|
|
25
|
+
get fCtrls() {
|
|
26
|
+
return this.rForm.controls;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get questionTypeEnum() {
|
|
30
|
+
return QuestionTypeEnum;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Output() emitter = new EventEmitter<QuestionAnswerModel>();
|
|
34
|
+
|
|
35
|
+
@Input() isShow: boolean = true;
|
|
36
|
+
@Input() isDisabled: boolean = false;
|
|
37
|
+
@Input() set setQuestion(value: SurveyQuestionDto) {
|
|
38
|
+
this.surveyQuestion = value;
|
|
39
|
+
this.rForm.patchValue({
|
|
40
|
+
id: value.questionId,
|
|
41
|
+
name: value.questionName,
|
|
42
|
+
title: value.questionTitle,
|
|
43
|
+
typeId: value.questionTypeId,
|
|
44
|
+
description: value.questionDescription
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
value.surveyAnswers.forEach(surveryAnswer => {
|
|
48
|
+
this.fCtrls.answerArray.push(this._formBuilder.group<AnswerChildOfQuestionDropDownMultiTemplateFormInterface>({
|
|
49
|
+
id: [surveryAnswer.answerId],
|
|
50
|
+
title: [surveryAnswer.answerTitle],
|
|
51
|
+
isSelected: [false]
|
|
52
|
+
}))
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
if (value.isRequired == true) {
|
|
56
|
+
this.fCtrls.answer.addValidators([Validators.required]);
|
|
57
|
+
this.fCtrls.answer.updateValueAndValidity();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.isShow = value.isVisable;
|
|
61
|
+
this.isDisabled = value.isReadOnly;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
constructor(private _formBuilder: FormBuilder, private _surveyLibService: SurveyLibService) {
|
|
65
|
+
this.rForm = this._formBuilder.group<QuestionDropDownMultiTemplateFormInterface>({
|
|
66
|
+
id: [null],
|
|
67
|
+
name: [null],
|
|
68
|
+
title: [null],
|
|
69
|
+
typeId: [null],
|
|
70
|
+
description: [null],
|
|
71
|
+
answer: [null],
|
|
72
|
+
answerArray: this._formBuilder.array<AnswerChildOfQuestionDropDownMultiTemplateFormInterface>([])
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
ngOnInit(): void {
|
|
77
|
+
this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
|
|
78
|
+
const formValue = this.rForm.value;
|
|
79
|
+
this.emitter.emit({
|
|
80
|
+
QuestionId: formValue.id,
|
|
81
|
+
IsValid: this.fCtrls.answer.valid,
|
|
82
|
+
Answer: value
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.fCtrls.answer.setValue(null);
|
|
87
|
+
|
|
88
|
+
this._surveyLibService.surveyAnswersObsrv
|
|
89
|
+
.pipe(map(x => x.defaultAnswers.filter(x => x.QuestionId == this.fCtrls.id.value)))
|
|
90
|
+
.pipe(filter(x => x.length > 0)).pipe(map(x => x.at(0)))
|
|
91
|
+
.subscribe(answer => {
|
|
92
|
+
const distinctArray = answer.AnswerIdArr.filter((n, i) => answer.AnswerIdArr.indexOf(n) === i);
|
|
93
|
+
this.fCtrls.answer.setValue(distinctArray);
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
convertToFormControl(element: any) {
|
|
98
|
+
return element as FormControl;
|
|
99
|
+
}
|
|
100
|
+
}
|
package/src/lib/components/question-dropdown-template/question-dropdown-template.component.html
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<div class="quastion" [attr.id]="'question_'+fCtrls.id.value" [ngClass]="{'invalid-question': fCtrls.answer.invalid , 'd-none':isShow != true}">
|
|
2
|
+
<h3 class="quastion-title ">
|
|
3
|
+
{{fCtrls.title.value}}
|
|
4
|
+
</h3>
|
|
5
|
+
<div class="text-quastion">
|
|
6
|
+
<select class="form-control" [formControl]="convertToFormControl(fCtrls.answer)" [disabled]="isDisabled">
|
|
7
|
+
<option *ngFor="let item of surveyQuestion?.surveyAnswers" [value]="item.answerId">{{item.answerTitle}}</option>
|
|
8
|
+
</select>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
package/src/lib/components/question-dropdown-template/question-dropdown-template.component.scss
ADDED
|
File without changes
|
package/src/lib/components/question-dropdown-template/question-dropdown-template.component.spec.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { QuestionDropdownTemplateComponent } from './question-dropdown-template.component';
|
|
4
|
+
|
|
5
|
+
describe('QuestionDropdownTemplateComponent', () => {
|
|
6
|
+
let component: QuestionDropdownTemplateComponent;
|
|
7
|
+
let fixture: ComponentFixture<QuestionDropdownTemplateComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
declarations: [QuestionDropdownTemplateComponent]
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(QuestionDropdownTemplateComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
2
|
+
import { FormControl, Validators } from '@angular/forms';
|
|
3
|
+
import { FormBuilder, FormGroup } from '@ng-stack/forms';
|
|
4
|
+
import { SurveyQuestionDto } from '../../../shared/dtos/survey-question.dto';
|
|
5
|
+
import { QuestionTypeEnum } from '../../../shared/enums/question-type.enum';
|
|
6
|
+
import { QuestionDropdownTemplateFormInterface } from '../../../shared/form-interfaces/question-dropdown-template.form-interface';
|
|
7
|
+
import { QuestionRadioButtonTemplateFormInterface } from '../../../shared/form-interfaces/question-radio-button-template.form-interface';
|
|
8
|
+
import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs';
|
|
9
|
+
import { QuestionAnswerModel } from '../../../shared/models/question-answer.model';
|
|
10
|
+
import { DefaultQuestionAnswerDto } from '../../../shared/dtos/default-question-answers.dto';
|
|
11
|
+
import { SurveyLibService } from '../../services/survey-lib.service';
|
|
12
|
+
|
|
13
|
+
@Component({
|
|
14
|
+
selector: 'lib-question-dropdown-template',
|
|
15
|
+
templateUrl: './question-dropdown-template.component.html',
|
|
16
|
+
styleUrls: ['./question-dropdown-template.component.scss']
|
|
17
|
+
})
|
|
18
|
+
export class QuestionDropdownTemplateComponent implements OnInit {
|
|
19
|
+
surveyQuestion: SurveyQuestionDto;
|
|
20
|
+
rForm: FormGroup<QuestionDropdownTemplateFormInterface>;
|
|
21
|
+
|
|
22
|
+
get fCtrls() {
|
|
23
|
+
return this.rForm.controls;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get questionTypeEnum() {
|
|
27
|
+
return QuestionTypeEnum;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Output() emitter = new EventEmitter<QuestionAnswerModel>();
|
|
31
|
+
|
|
32
|
+
@Input() isShow: boolean = true;
|
|
33
|
+
@Input() isDisabled: boolean = false;
|
|
34
|
+
@Input() set setQuestion(value: SurveyQuestionDto) {
|
|
35
|
+
this.surveyQuestion = value;
|
|
36
|
+
this.rForm.patchValue({
|
|
37
|
+
id: value.questionId,
|
|
38
|
+
name: value.questionName,
|
|
39
|
+
title: value.questionTitle,
|
|
40
|
+
typeId: value.questionTypeId,
|
|
41
|
+
description: value.questionDescription
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (value.isRequired == true) {
|
|
45
|
+
this.fCtrls.answer.addValidators([Validators.required]);
|
|
46
|
+
this.fCtrls.answer.updateValueAndValidity();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.isShow = value.isVisable;
|
|
50
|
+
this.isDisabled = value.isReadOnly;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
constructor(private _formBuilder: FormBuilder ,private _surveyLibService :SurveyLibService) {
|
|
54
|
+
this.rForm = this._formBuilder.group<QuestionDropdownTemplateFormInterface>({
|
|
55
|
+
id: [null],
|
|
56
|
+
name: [null],
|
|
57
|
+
title: [null],
|
|
58
|
+
typeId: [null],
|
|
59
|
+
description: [null],
|
|
60
|
+
answer: [null]
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ngOnInit(): void {
|
|
65
|
+
this.fCtrls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
|
|
66
|
+
const formValue = this.rForm.value;
|
|
67
|
+
this.emitter.emit({
|
|
68
|
+
QuestionId: formValue.id,
|
|
69
|
+
IsValid: this.fCtrls.answer.valid,
|
|
70
|
+
Answer: value
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
this.fCtrls.answer.setValue(null);
|
|
75
|
+
|
|
76
|
+
this._surveyLibService.surveyAnswersObsrv
|
|
77
|
+
.pipe(map(x=> x.defaultAnswers.filter(x=>x.QuestionId == this.fCtrls.id.value)))
|
|
78
|
+
.pipe(filter(x=>x.length > 0)).pipe(map(x=> x.at(0)))
|
|
79
|
+
.subscribe(answer=>{
|
|
80
|
+
this.fCtrls.answer.setValue(answer.AnswerId);
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
convertToFormControl(element: any) {
|
|
85
|
+
return element as FormControl;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<div class="quastion" [attr.id]="'question_'+fCtrls.id.value" style=" border-collapse: collapse;"
|
|
2
|
+
[ngClass]="{'d-none':isShow != true}">
|
|
3
|
+
<h3 class="quastion-title ">
|
|
4
|
+
{{surveyQuestion?.questionTitle}}
|
|
5
|
+
</h3>
|
|
6
|
+
<div class="matrix-question" [formGroup]="rForm">
|
|
7
|
+
<div class="matrix-table" formArrayName="subQuestionArray">
|
|
8
|
+
<div class="matrix-head-row">
|
|
9
|
+
<div class="matrix-col">
|
|
10
|
+
</div>
|
|
11
|
+
<div class="matrix-col" *ngFor="let answers of surveyQuestion?.surveyAnswers">
|
|
12
|
+
{{answers.answerTitle}}
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<div class="matrix-row"
|
|
17
|
+
*ngFor="let questionGroup of fCtrls.subQuestionArray.controls ;let subQuestionIndex = index"
|
|
18
|
+
[ngClass]="{'invalid-question': questionGroup.controls.answer.invalid}">
|
|
19
|
+
<div class="matrix-col matrix-sub-quastion">
|
|
20
|
+
{{questionGroup.value.questionTitle}}
|
|
21
|
+
</div>
|
|
22
|
+
<div class="matrix-col" *ngFor="let answer of surveyQuestion?.surveyAnswers;let answerIndex = index">
|
|
23
|
+
<div class="form-check form-check-radio form-check-inline">
|
|
24
|
+
<input class="form-check-input" type="radio" name="{{elemId}}__radio-btn-option_{{subQuestionIndex}}"
|
|
25
|
+
id="{{elemId}}__radio-btn_{{subQuestionIndex}}_{{answerIndex}}" (change)="onChangeAnswer(questionGroup.value ,answer)"
|
|
26
|
+
value="{{answer.answerId}}" [checked]="answer.answerId == questionGroup.value.answer">
|
|
27
|
+
<label class="form-check-label d-md-inline d-lg-none"
|
|
28
|
+
for="{{elemId}}__radio-btn_{{subQuestionIndex}}_{{answerIndex}}"> {{answer.answerTitle}}</label>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
File without changes
|
package/src/lib/components/question-matrix-template/question-matrix-template.component.spec.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { QuestionMatrixTemplateComponent } from './question-matrix-template.component';
|
|
4
|
+
|
|
5
|
+
describe('QuestionMatrixTemplateComponent', () => {
|
|
6
|
+
let component: QuestionMatrixTemplateComponent;
|
|
7
|
+
let fixture: ComponentFixture<QuestionMatrixTemplateComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
declarations: [QuestionMatrixTemplateComponent]
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(QuestionMatrixTemplateComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
2
|
+
import { FormControl, Validators } from '@angular/forms';
|
|
3
|
+
import { FormBuilder, FormGroup } from '@ng-stack/forms';
|
|
4
|
+
import { SurveyAnswerDto } from '../../../shared/dtos/survey-answer.dto';
|
|
5
|
+
import { SurveyQuestionGroupDto } from '../../../shared/dtos/survey-question-group.dto';
|
|
6
|
+
import { SurveyQuestionDto } from '../../../shared/dtos/survey-question.dto';
|
|
7
|
+
import { SurveySubQuestionDto } from '../../../shared/dtos/survey-sub-question.dto';
|
|
8
|
+
import { QuestionTypeEnum } from '../../../shared/enums/question-type.enum';
|
|
9
|
+
import { QuestionMatrixTemplateFormInterface, SubQuestionChildOfQuestionMatrixTemplateFormInterface } from '../../../shared/form-interfaces/question-matrix-template.form-interface';
|
|
10
|
+
import { QuestionAnswerModel } from '../../../shared/models/question-answer.model';
|
|
11
|
+
import { v4 as guidGenerator } from 'uuid';
|
|
12
|
+
import { DefaultQuestionAnswerDto } from '../../../shared/dtos/default-question-answers.dto';
|
|
13
|
+
import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs';
|
|
14
|
+
import { SurveyLibService } from '../../services/survey-lib.service';
|
|
15
|
+
|
|
16
|
+
@Component({
|
|
17
|
+
selector: 'lib-question-matrix-template',
|
|
18
|
+
templateUrl: './question-matrix-template.component.html',
|
|
19
|
+
styleUrls: ['./question-matrix-template.component.scss']
|
|
20
|
+
})
|
|
21
|
+
export class QuestionMatrixTemplateComponent implements OnInit {
|
|
22
|
+
elemId = guidGenerator() as string;
|
|
23
|
+
surveyQuestion: SurveyQuestionDto;
|
|
24
|
+
rForm: FormGroup<QuestionMatrixTemplateFormInterface>;
|
|
25
|
+
|
|
26
|
+
get fCtrls() {
|
|
27
|
+
return this.rForm.controls;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get questionTypeEnum() {
|
|
31
|
+
return QuestionTypeEnum;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Output() emitter = new EventEmitter<QuestionAnswerModel>();
|
|
35
|
+
|
|
36
|
+
@Input() isShow: boolean = true;
|
|
37
|
+
@Input() isDisabled: boolean = false;
|
|
38
|
+
@Input() set setQuestion(value: SurveyQuestionDto) {
|
|
39
|
+
this.surveyQuestion = value;
|
|
40
|
+
this.rForm.patchValue({
|
|
41
|
+
id: value.questionId,
|
|
42
|
+
typeId: value.questionTypeId
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
value.surveySubQuestions.forEach(x => {
|
|
46
|
+
var group = this._formBuilder.group<SubQuestionChildOfQuestionMatrixTemplateFormInterface>({
|
|
47
|
+
subQuestionId: [x.questionId],
|
|
48
|
+
questionTitle: [x.questionTitle],
|
|
49
|
+
answer: [null],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (value.isRequired == true) {
|
|
53
|
+
group.controls.answer.addValidators([Validators.required]);
|
|
54
|
+
group.controls.answer.updateValueAndValidity();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
group.controls.answer.valueChanges.pipe().pipe(debounceTime(200)).subscribe(value => {
|
|
58
|
+
const formValue = this.rForm.value;
|
|
59
|
+
this.emitter.emit({
|
|
60
|
+
QuestionId: group.value.subQuestionId,
|
|
61
|
+
Answer: group.value.answer,
|
|
62
|
+
IsValid: group.controls.answer.valid
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
this.fCtrls.subQuestionArray.push(group);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
this.isShow = value.isVisable;
|
|
70
|
+
this.isDisabled = value.isReadOnly;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
constructor(private _formBuilder: FormBuilder , private _surveyLibService:SurveyLibService) {
|
|
74
|
+
this.rForm = this._formBuilder.group<QuestionMatrixTemplateFormInterface>({
|
|
75
|
+
id: [null],
|
|
76
|
+
typeId: [null],
|
|
77
|
+
subQuestionArray: this._formBuilder.array<SubQuestionChildOfQuestionMatrixTemplateFormInterface>([])
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
ngOnInit(): void {
|
|
81
|
+
this._surveyLibService.surveyAnswersObsrv
|
|
82
|
+
.pipe(map(x=> x.defaultAnswers.filter(x=>x.ParentQuestionId == this.fCtrls.id.value)))
|
|
83
|
+
.pipe(filter(x=>x.length > 0))
|
|
84
|
+
.subscribe(answers=>{
|
|
85
|
+
this.fCtrls.subQuestionArray.controls.forEach(group => {
|
|
86
|
+
var answer = answers.find(x => x.QuestionId == group.value.subQuestionId);
|
|
87
|
+
if (answer != null) {
|
|
88
|
+
group.controls.answer.setValue(answer.AnswerId);
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onChangeAnswer(question: SubQuestionChildOfQuestionMatrixTemplateFormInterface, answer: SurveyAnswerDto) {
|
|
95
|
+
const index = this.fCtrls.subQuestionArray.value.findIndex(x => x.subQuestionId == question.subQuestionId);
|
|
96
|
+
var subQuestionGroup = this.fCtrls.subQuestionArray.controls[index];
|
|
97
|
+
|
|
98
|
+
subQuestionGroup.controls.answer.setValue(answer.answerId);
|
|
99
|
+
|
|
100
|
+
this.emitter.emit({
|
|
101
|
+
QuestionId: subQuestionGroup.value.subQuestionId,
|
|
102
|
+
Answer: subQuestionGroup.value.answer,
|
|
103
|
+
IsValid: subQuestionGroup.controls.answer.valid
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
convertToFormControl(element: any) {
|
|
108
|
+
return element as FormControl;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div class="quastion" [attr.id]="'question_'+fCtrls.id.value" [ngClass]="{'invalid-question': fCtrls.answer.invalid , 'd-none':isShow != true}">
|
|
2
|
+
<h3 class="quastion-title ">
|
|
3
|
+
{{fCtrls.title.value}}
|
|
4
|
+
</h3>
|
|
5
|
+
<div class="radio-button-quastion">
|
|
6
|
+
<div class="form-check form-check-radio form-check-inline"
|
|
7
|
+
*ngFor="let item of fCtrls.answerArray.controls;let i = index">
|
|
8
|
+
<input class="form-check-input" type="radio" (change)="onChangeAnswer(item.value)" [disabled]="isDisabled"
|
|
9
|
+
name="{{elemId}}__radio-btn-option" id="{{elemId}}__radio-btn_{{i}}" [checked]="item.value.isSelected == true? true : null">
|
|
10
|
+
<label class="form-check-label" for="{{elemId}}__radio-btn_{{i}}">{{item.value.title}}</label>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { QuestionRadioButtonTemplateComponent } from './question-radio-button-template.component';
|
|
4
|
+
|
|
5
|
+
describe('QuestionRadioButtonTemplateComponent', () => {
|
|
6
|
+
let component: QuestionRadioButtonTemplateComponent;
|
|
7
|
+
let fixture: ComponentFixture<QuestionRadioButtonTemplateComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
declarations: [QuestionRadioButtonTemplateComponent]
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(QuestionRadioButtonTemplateComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|