mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Added matcher function to router that supports handle paths (eliminates the need to encode the forward slash).
Fixed comment.
This commit is contained in:
@@ -1,12 +1,36 @@
|
||||
import { LookupGuard } from './lookup-guard';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { RouterModule, UrlSegment } from '@angular/router';
|
||||
import { ObjectNotFoundComponent } from './objectnotfound/objectnotfound.component';
|
||||
import { hasValue } from '../shared/empty.util';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild([
|
||||
{ path: ':idType/:id', canActivate: [LookupGuard], component: ObjectNotFoundComponent }
|
||||
{
|
||||
matcher: (url) => {
|
||||
// The expected path is :idType/:id
|
||||
const idType = url[0].path;
|
||||
let id;
|
||||
// Allow for handles that are delimited with a forward slash.
|
||||
if (url.length === 3) {
|
||||
id = url[1].path + '/' + url[2].path;
|
||||
} else {
|
||||
id = url[1].path;
|
||||
}
|
||||
if (hasValue(idType) && hasValue(id)) {
|
||||
return {
|
||||
consumed: url,
|
||||
posParams: {
|
||||
idType: new UrlSegment(idType, {}),
|
||||
id: new UrlSegment(id, {})
|
||||
}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
},
|
||||
canActivate: [LookupGuard],
|
||||
component: ObjectNotFoundComponent }
|
||||
])
|
||||
],
|
||||
providers: [
|
||||
|
@@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common';
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
import { LookupRoutingModule } from './lookup-by-id-routing.module';
|
||||
import { ObjectNotFoundComponent } from './objectnotfound/objectnotfound.component';
|
||||
import { DsoDataRedirectService } from '../core/data/dso-data-redirect.service';
|
||||
import { DsoRedirectDataService } from '../core/data/dso-redirect-data.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -15,7 +15,7 @@ import { DsoDataRedirectService } from '../core/data/dso-data-redirect.service';
|
||||
ObjectNotFoundComponent
|
||||
],
|
||||
providers: [
|
||||
DsoDataRedirectService
|
||||
DsoRedirectDataService
|
||||
]
|
||||
})
|
||||
export class LookupIdModule {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { DsoDataRedirectService } from '../core/data/dso-data-redirect.service';
|
||||
import { DsoRedirectDataService } from '../core/data/dso-redirect-data.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { IdentifierType } from '../core/index/index.reducer';
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -14,7 +14,7 @@ interface LookupParams {
|
||||
|
||||
@Injectable()
|
||||
export class LookupGuard implements CanActivate {
|
||||
constructor(private dsoService: DsoDataRedirectService) {
|
||||
constructor(private dsoService: DsoRedirectDataService) {
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state:RouterStateSnapshot): Observable<boolean> {
|
||||
|
@@ -9,13 +9,13 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { IdentifierType } from '../index/index.reducer';
|
||||
import { DsoDataRedirectService } from './dso-data-redirect.service';
|
||||
import { DsoRedirectDataService } from './dso-redirect-data.service';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { CoreState } from '../core.reducers';
|
||||
|
||||
describe('DsoDataRedirectService', () => {
|
||||
describe('DsoRedirectDataService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: DsoDataRedirectService;
|
||||
let service: DsoRedirectDataService;
|
||||
let halService: HALEndpointService;
|
||||
let requestService: RequestService;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
@@ -66,7 +66,7 @@ describe('DsoDataRedirectService', () => {
|
||||
a: remoteData
|
||||
})
|
||||
});
|
||||
service = new DsoDataRedirectService(
|
||||
service = new DsoRedirectDataService(
|
||||
requestService,
|
||||
rdbService,
|
||||
dataBuildService,
|
@@ -20,7 +20,7 @@ import { getFinishedRemoteData } from '../shared/operators';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Injectable()
|
||||
export class DsoDataRedirectService extends DataService<any> {
|
||||
export class DsoRedirectDataService extends DataService<any> {
|
||||
|
||||
protected linkPath = 'pid';
|
||||
protected forceBypassCache = false;
|
Reference in New Issue
Block a user