Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
laurens-ritense committed May 28, 2024
1 parent 251a5b0 commit 7e71971
Showing 1 changed file with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
import moment from 'moment';
import {
BehaviorSubject,
BehaviorSubject, catchError,
combineLatest,
debounceTime,
debounceTime, EMPTY,
filter,
Observable, of,
pairwise,
Expand Down Expand Up @@ -144,21 +144,24 @@ export class FormViewModelComponent implements OnInit {

public beforeSubmit(submission: any, callback: FormioSubmissionCallback): void {
combineLatest([this.formName$, this.taskInstanceId$])
.pipe(take(1))
.subscribe(([formName, taskInstanceId]) => {
this.viewModelService
.submitViewModel(formName, taskInstanceId, submission.data)
.pipe(take(1))
.subscribe({
next: response => {
.pipe(
take(1),
switchMap(([formName, taskInstanceId]) =>
this.viewModelService.submitViewModel(formName, taskInstanceId, submission.data).pipe(
take(1),
switchMap(response => {
callback(null, submission);
},
error: error => {
return of(response);
}),
catchError(error => {
this.handleFormError(error);
callback({message: error.error.error, component: null}, null);
},
});
});
return EMPTY; // return an empty observable to complete the stream
})
)
)
)
.subscribe();
}

private handleFormError(error: HttpErrorResponse): void {
Expand Down Expand Up @@ -190,15 +193,20 @@ export class FormViewModelComponent implements OnInit {

public loadInitialViewModel(): void {
combineLatest([this.formName$, this.taskInstanceId$])
.pipe(take(1))
.subscribe(([formName, taskInstanceId]) => {
this.viewModelService.getViewModel(formName, taskInstanceId).subscribe(viewModel => {
this.change$.pipe(take(1)).subscribe(change => {
this.loading$.next(false);
});
this.submission$.next({data: viewModel});
});
});
.pipe(
take(1),
switchMap(([formName, taskInstanceId]) =>
this.viewModelService.getViewModel(formName, taskInstanceId).pipe(
tap(viewModel => {
this.submission$.next({data: viewModel});
this.change$.pipe(take(1)).subscribe(() => {
this.loading$.next(false);
});
})
)
)
)
.subscribe();
}

public updateViewModel(): void {
Expand Down

0 comments on commit 7e71971

Please sign in to comment.