Skip to content

Commit

Permalink
Added update call when switching between pages
Browse files Browse the repository at this point in the history
  • Loading branch information
laurens-ritense committed Nov 8, 2024
1 parent 7412b30 commit 2136d2e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@
(submit)="onSubmit($event)"
(change)="onChange($event)"
(focusout)="onBlur($event)"
(nextPage)="onNextPage($event)"
(prevPage)="onPreviousPage($event)"
></formio>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class FormViewModelComponent implements OnInit {

public errors: string[] = [];

private preventNextPage = false;
private preventPreviousPage = false;

public readonly submission$ = new BehaviorSubject<any>({});
public readonly form$ = new BehaviorSubject<object>(undefined);
public readonly formName$ = new BehaviorSubject<string>(undefined);
Expand Down Expand Up @@ -237,6 +240,28 @@ export class FormViewModelComponent implements OnInit {
}
}

public onNextPage(event: any): void {
this.preventNextPage = true;
this.formio.formio.setPage(this.formio.formio.page - 1);
this.handleChanges();
}

public onPreviousPage(event: any): void {
this.preventPreviousPage = true;
this.formio.formio.setPage(this.formio.formio.page + 1);
this.handleChanges();
}

private handlePageChange(): void {
if (this.preventNextPage) {
this.preventNextPage = false;
this.formio.formio.setPage(this.formio.formio.page + 1);
} else if (this.preventPreviousPage) {
this.preventPreviousPage = false;
this.formio.formio.setPage(this.formio.formio.page - 1);
}
}

public loadInitialViewModel(): void {
combineLatest([this.formName$, this.taskInstanceId$])
.pipe(
Expand Down Expand Up @@ -265,12 +290,13 @@ export class FormViewModelComponent implements OnInit {
return combineLatest([this.formName$, this.taskInstanceId$, this.change$]).pipe(
take(1),
switchMap(([formName, taskInstanceId, change]) =>
this.viewModelService.updateViewModel(formName, taskInstanceId, change.data).pipe(
this.viewModelService.updateViewModel(formName, taskInstanceId, change.data, this.formio.formio.page).pipe(
tap({
next: viewModel => {
const submission = this.submission$.value;
submission.data = viewModel;
this.submission$.next(submission);
this.handlePageChange();
this.loading$.next(false);
this.errors = [];
},
Expand Down Expand Up @@ -318,11 +344,14 @@ export class FormViewModelComponent implements OnInit {
take(1),
switchMap(([formName, processDefinitionKey, change]) =>
this.viewModelService
.updateViewModelForStartForm(formName, processDefinitionKey, change.data)
.updateViewModelForStartForm(formName, processDefinitionKey, change.data, this.formio.formio.page)
.pipe(
tap({
next: viewModel => {
this.submission$.next({data: viewModel});
const submission = this.submission$.value;
submission.data = viewModel;
this.submission$.next(submission);
this.handlePageChange();
this.loading$.next(false);
this.errors = [];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders, HttpParams, HttpResponse} from '@angular/common/http';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Observable} from 'rxjs';
import {BaseApiService, ConfigService} from '@valtimo/config';
import {InterceptorSkip} from '@valtimo/security';
Expand All @@ -42,13 +42,18 @@ export class ViewModelService extends BaseApiService {
public updateViewModel(
formName: string,
taskInstanceId: string,
viewModel: object
viewModel: object,
page: number
): Observable<object> {
return this.httpClient.post(this.getApiUrl(`/v1/form/view-model/user-task`), viewModel, {
params: {
const params = {
formName,
taskInstanceId,
},
}
if (!isNaN(page)) {
params['page'] = page;
}
return this.httpClient.post(this.getApiUrl(`/v1/form/view-model/user-task`), viewModel, {
params: params,
headers: new HttpHeaders().set(InterceptorSkip, '400'),
});
}
Expand Down Expand Up @@ -83,13 +88,18 @@ export class ViewModelService extends BaseApiService {
public updateViewModelForStartForm(
formName: string,
processDefinitionKey: string,
viewModel: object
viewModel: object,
page: number
): Observable<object> {
const params = {
formName,
processDefinitionKey,
}
if (!isNaN(page)) {
params['page'] = page;
}
return this.httpClient.post(this.getApiUrl(`/v1/form/view-model/start-form`), viewModel, {
params: {
formName,
processDefinitionKey,
},
params: params,
headers: new HttpHeaders().set(InterceptorSkip, '400'),
});
}
Expand Down

0 comments on commit 2136d2e

Please sign in to comment.