import { DSpaceObject } from './../../shared/dspace-object.model'; import { followLink } from './../../../shared/utils/follow-link-config.model'; import { ChildHALResource } from './../../shared/child-hal-resource.model'; import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router'; import { Observable } from 'rxjs'; import { Store } from '@ngrx/store'; import { switchMap } from 'rxjs/operators'; import { DataService } from '../../data/data.service'; import { RemoteData } from '../../data/remote-data'; import { getFirstCompletedRemoteData } from '../../shared/operators'; /** * This class represents a resolver that requests a specific item before the route is activated */ @Injectable() export class SubmissionObjectResolver implements Resolve> { constructor( protected dataService: DataService, protected store: Store ) { } /** * Method for resolving an item based on the parameters in the current route * @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot * @param {RouterStateSnapshot} state The current RouterStateSnapshot * @returns Observable<> Emits the found item based on the parameters in the current route, * or an error if something went wrong */ resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable> { const itemRD$ = this.dataService.findById(route.params.id, true, false, followLink('item'), ).pipe( getFirstCompletedRemoteData(), switchMap((wfiRD: RemoteData) => wfiRD.payload.item as Observable>), getFirstCompletedRemoteData() ); return itemRD$; } }