Commit 7a0b6bf2 authored by lukas.burgey's avatar lukas.burgey

Add handling of questionnaire_answers

parent 3370ee72
<div *ngIf="(state$ | async) as state" class="mat-typography">
<h2>Data questionnaire</h2>
<p>
The site {{ state.site.name }} needs the following data to give you access to the service {{ state.service.name }}.
</p>
<form *ngIf="(answers$ | async) as answers" class="form-vertical" #answerForm="ngForm">
<mat-form-field *ngFor="let key of (state.questionnaire | ObjKeys)">
<input matInput required placeholder="{{ state.questionnaire[key] }}" [(ngModel)]="answers[key]" [name]="key">
</mat-form-field>
<button (click)="sendAnswers(state, answers)" color="primary" type="submit" [disabled]="!answerForm.form.valid" mat-dialog-close mat-raised-button>
Submit
</button>
</form>
<h2>Complete registration</h2>
<p>
The site {{ state.site.name }} needs the following data to give you access to the service {{ state.service.name }}.
</p>
<form *ngIf="(answers$ | async) as answers" class="form-vertical" #answerForm="ngForm">
<mat-form-field *ngFor="let key of (state.questionnaire | ObjKeys)">
<div>
{{ state.questionnaire[key] }}
</div>
<div [ngSwitch]="getInputType(state, key)">
<input *ngSwitchCase="input" matInput required [(ngModel)]="answers[key]" [name]="key">
<mat-checkbox *ngSwitchCase="checkbox" required [(ngModel)]="answers[key]" [name]="key"></mat-checkbox>
<select *ngSwitchCase="selector" matNativeControl required [(ngModel)]="answers[key]" [name]="key">
<option *ngFor="let value of state.questionnaire[key]" [value]="value">{{value}}</option>
</select>
</div>
</mat-form-field>
<button (click)="sendAnswers(state, answers)" color="primary" type="submit" [disabled]="!answerForm.form.valid" mat-dialog-close mat-raised-button>
Submit
</button>
</form>
</div>
......@@ -30,7 +30,7 @@ export class QuestionnaireComponent implements OnInit {
Object.keys(state.questionnaire).forEach(
(key: string) => {
answers[key] = '';
answers[key] = this.getDefaultValue(state, key);
}
);
......@@ -47,7 +47,31 @@ export class QuestionnaireComponent implements OnInit {
ngOnInit() {
}
sendAnswers(state: DeploymentState, answers: Answers) {
sendAnswers(state: DeploymentState, answers: Answers): void {
this.userService.sentQuestionnaire(state.id, answers);
}
getDefaultValue(state: DeploymentState, key: string): any {
if (state.questionnaire_answers.has(key)) {
const val = state.questionnaire_answers.get(key);
if (Array.isArray(val)) {
return val.length > 0 ? val[0] : '';
}
return val;
}
return '';
}
getInputType(state: DeploymentState, key: string): string {
if (state.questionnaire_answers.has(key)) {
const val = state.questionnaire_answers.get(key);
if (Array.isArray(val)) {
return 'selector';
}
if (typeof val === 'boolean') {
return 'checkbox';
}
}
return 'input';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment