Commit 38964bf1 authored by Lukas Burgey's avatar Lukas Burgey

Make answers user editable

parent 1b7ba703
......@@ -19,8 +19,6 @@ export class DialogService {
credentialsDialog: MatDialogRef<any>;
messageDialog: MatDialogRef<any>;
constructor(
private dialog: MatDialog,
) { }
......@@ -52,9 +50,7 @@ export class DialogService {
public openQuestionnaire(stateItem: DeploymentState) {
this.questionnaireDialog = this.dialog.open(
QuestionnaireComponent,
this.settingsData({
stateItem: stateItem,
}),
this.settingsData(stateItem),
);
}
......
<div class="mat-typography">
<div *ngIf="(state$ | async) as state" class="mat-typography">
<h2>Data questionnaire</h2>
<p>
The site {{stateItem.site.name}} needs the following data to give you access to the service {{
stateItem.service.name}}.
The site {{ state.site.name }} needs the following data to give you access to the service {{ state.service.name }}.
</p>
<form class="form-vertical" #questionnaireForm="ngForm">
<mat-form-field *ngFor="let key of stateItem.questionnaire | ObjKeys">
<input matInput required
placeholder="{{stateItem.questionnaire[key]}}" [(ngModel)]="answers[key]" name="key">
<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 mat-dialog-close mat-raised-button (click)="sendAnswers()" color="primary" type="submit" [disabled]="!questionnaireForm.form.valid">Submit</button>
<button (click)="sendAnswers(state, answers)" color="primary" type="submit" [disabled]="!answerForm.form.valid" mat-dialog-close mat-raised-button>
Submit
</button>
</form>
</div>
import { Component, OnInit, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material';
import { Observable, BehaviorSubject } from 'rxjs';
import { UserService } from '../../user.service';
import * as t from '../../types/types.module';
import { JSONObject, DeploymentState } from '../../types/types.module';
@Component({
selector: 'app-questionnaire',
......@@ -10,23 +12,42 @@ import * as t from '../../types/types.module';
styleUrls: ['./questionnaire.component.css']
})
export class QuestionnaireComponent implements OnInit {
public answers: Object = {};
public stateItem: t.DeploymentState;
public answers$ = <BehaviorSubject<JSONObject>> new BehaviorSubject(undefined);;
constructor(
public userService: UserService,
@Inject(MAT_DIALOG_DATA) public data: any,
@Inject(MAT_DIALOG_DATA) public state$: Observable<DeploymentState>,
) {
this.stateItem = data.stateItem;
}
ngOnInit() {
this.state$.subscribe(
(state: DeploymentState) => {
let answers = undefined;
// initialize the answers if needed
if (state.answers == undefined) {
answers = state.questionnaire;
Object.keys(state.questionnaire).forEach(
(key: string) => {
answers[key] = "";
}
);
sendAnswers() {
this.userService.sentQuestionnaire(
this.stateItem.id,
this.answers,
// console.log('Initialized answers');
} else {
answers = state.answers;
// console.log('Old answers:', answers);
}
this.answers$.next(answers);
}
);
}
sendAnswers(state: DeploymentState, answers: JSONObject) {
this.userService.sentQuestionnaire(state.id, answers);
}
}
......@@ -4,6 +4,7 @@ import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'ObjKeys', pure: false })
export class ObjKeysPipe implements PipeTransform {
transform(value: any, args: any[] = null): any {
return Object.keys(value);//.map(key => value[key]);
const transformation = Object.keys(value);//.map(key => value[key]);
return transformation;
}
}
......@@ -44,6 +44,14 @@
</span>
</td>
<td *ngIf="stateItem.answers != undefined" matTooltip="Change previously submitted answers" class="spaced">
<span>
<button (click)="dialog.openQuestionnaire(state$)" mat-icon-button>
<mat-icon>edit</mat-icon>
</button>
</span>
</td>
<td class="spaced">
<span *ngIf="!stateItem.is_pending && stateItem.is_credential_pending" class="spaced">
<mat-progress-spinner diameter="24" mode="indeterminate"></mat-progress-spinner>
......
......@@ -56,7 +56,7 @@ export interface Service {
vos: VO[];
}
interface JSONObject {
export interface JSONObject {
[key: string]: string;
}
......@@ -68,13 +68,14 @@ export interface CredentialState {
}
export interface DeploymentState {
answers: JSONObject | undefined;
credential_states: CredentialState[];
credentials: JSONObject;
id: number;
is_credential_pending: boolean;
is_pending: boolean;
message: string;
questionnaire: JSONObject;
questionnaire: JSONObject | undefined;
service: Service;
site: Site;
state: string;
......
......@@ -11,7 +11,7 @@ import { SnackBarService } from './snackbar.service';
import { IdpService } from './idp.service';
import {
VO, User, Update, State, Deployment, DeploymentState, SSHKey, NewSSHKey, IdP, Service, Site
VO, User, Update, State, Deployment, DeploymentState, SSHKey, NewSSHKey, IdP, Service, Site, JSONObject
} from './types/types.module';
......@@ -261,14 +261,14 @@ export class UserService {
);
}
public sentQuestionnaire(stateItemID: number, answers: Object) {
public sentQuestionnaire(stateItemID: number, answers: JSONObject) {
return this.http.patch<DeploymentState>(
`/rest/dep-state?id=${ stateItemID }`,
{
'questionnaire': answers,
'answers': answers,
},
).pipe(
catchError(this.handleError(true, "Error submitting questionnaire")),
catchError(this.handleError(true, "Error submitting answers")),
).subscribe(
(state: DeploymentState) => this.updateDeploymentState(state),
this.logErrorAndFetch,
......
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