1
0

[DURACOM-234] Migrate fo functional resolver

This commit is contained in:
Giuseppe Digilio
2024-03-28 23:34:37 +01:00
parent 549609e2ea
commit 1f4aca800b
59 changed files with 2057 additions and 2144 deletions

View File

@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { inject } from '@angular/core';
import {
ActivatedRouteSnapshot,
ResolveFn,
RouterStateSnapshot,
} from '@angular/router';
import { Observable } from 'rxjs';
@@ -11,28 +12,17 @@ import { WorkflowItem } from '../core/submission/models/workflowitem.model';
import { WorkflowItemDataService } from '../core/submission/workflowitem-data.service';
import { followLink } from '../shared/utils/follow-link-config.model';
/**
* This class represents a resolver that requests a specific workflow item before the route is activated
*/
@Injectable({ providedIn: 'root' })
export class WorkflowItemPageResolver {
constructor(private workflowItemService: WorkflowItemDataService) {
}
/**
* Method for resolving a workflow item based on the parameters in the current route
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
* @returns Observable<<RemoteData<Item>> Emits the found workflow item based on the parameters in the current route,
* or an error if something went wrong
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<WorkflowItem>> {
return this.workflowItemService.findById(route.params.id,
true,
false,
followLink('item'),
).pipe(
getFirstCompletedRemoteData(),
);
}
}
export const WorkflowItemPageResolver: ResolveFn<RemoteData<WorkflowItem>> = (
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot,
workflowItemService: WorkflowItemDataService = inject(WorkflowItemDataService),
): Observable<RemoteData<WorkflowItem>> => {
return workflowItemService.findById(
route.params.id,
true,
false,
followLink('item'),
).pipe(
getFirstCompletedRemoteData(),
);
};