-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
495 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { LookupGuard } from './lookup-guard'; | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule } from '@angular/router'; | ||
import { ObjectNotFoundComponent } from './objectnotfound/objectnotfound.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
RouterModule.forChild([ | ||
{ path: ':idType/:id', canActivate: [LookupGuard], component: ObjectNotFoundComponent } | ||
]) | ||
], | ||
providers: [ | ||
LookupGuard | ||
] | ||
}) | ||
|
||
export class LookupRoutingModule { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { NgModule } from '@angular/core'; | ||
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'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
LookupRoutingModule, | ||
CommonModule, | ||
SharedModule, | ||
], | ||
declarations: [ | ||
ObjectNotFoundComponent | ||
], | ||
providers: [ | ||
DsoDataRedirectService | ||
] | ||
}) | ||
export class LookupIdModule { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; | ||
import { DsoDataRedirectService } from '../core/data/dso-data-redirect.service'; | ||
import { Injectable } from '@angular/core'; | ||
import { IdentifierType } from '../core/index/index.reducer'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { RemoteData } from '../core/data/remote-data'; | ||
import { FindByIDRequest } from '../core/data/request.models'; | ||
|
||
interface LookupParams { | ||
type: IdentifierType; | ||
id: string; | ||
} | ||
|
||
@Injectable() | ||
export class LookupGuard implements CanActivate { | ||
constructor(private dsoService: DsoDataRedirectService, private router: Router) { | ||
} | ||
|
||
canActivate(route: ActivatedRouteSnapshot, state:RouterStateSnapshot): Observable<boolean> { | ||
const params = this.getLookupParams(route); | ||
return this.dsoService.findById(params.id, params.type).pipe( | ||
map((response: RemoteData<FindByIDRequest>) => response.hasFailed) | ||
); | ||
} | ||
|
||
private getLookupParams(route: ActivatedRouteSnapshot): LookupParams { | ||
let type; | ||
let id; | ||
const idType = route.params.idType; | ||
|
||
// If the idType is not recognized, assume a legacy handle request (handle/prefix/id) | ||
if (idType !== IdentifierType.HANDLE && idType !== IdentifierType.UUID) { | ||
type = IdentifierType.HANDLE; | ||
const prefix = route.params.idType; | ||
const handleId = route.params.id; | ||
id = `${prefix}%2F${handleId}`; | ||
|
||
} else if (route.params.idType === IdentifierType.HANDLE) { | ||
type = IdentifierType.HANDLE; | ||
id = route.params.id; | ||
|
||
} else { | ||
type = IdentifierType.UUID; | ||
id = route.params.id; | ||
} | ||
return { | ||
type: type, | ||
id: id | ||
}; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/app/+lookup-by-id/objectnotfound/objectnotfound.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="object-not-found container"> | ||
<h1>{{"error.item" | translate}}</h1> | ||
<h2><small><em>{{missingItem}}</em></small></h2> | ||
<br /> | ||
<p class="text-center"> | ||
<a routerLink="/home" class="btn btn-primary">{{"404.link.home-page" | translate}}</a> | ||
</p> | ||
</div> |
Empty file.
45 changes: 45 additions & 0 deletions
45
src/app/+lookup-by-id/objectnotfound/objectnotfound.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
|
||
/** | ||
* This component representing the `PageNotFound` DSpace page. | ||
*/ | ||
@Component({ | ||
selector: 'ds-objnotfound', | ||
styleUrls: ['./objectnotfound.component.scss'], | ||
templateUrl: './objectnotfound.component.html', | ||
changeDetection: ChangeDetectionStrategy.Default | ||
}) | ||
export class ObjectNotFoundComponent implements OnInit { | ||
|
||
idType: string; | ||
|
||
id: string; | ||
|
||
missingItem: string; | ||
|
||
/** | ||
* Initialize instance variables | ||
* | ||
* @param {AuthService} authservice | ||
* @param {ServerResponseService} responseService | ||
*/ | ||
constructor(private route: ActivatedRoute) { | ||
route.params.subscribe((params) => { | ||
this.idType = params.idType; | ||
this.id = params.id; | ||
}) | ||
} | ||
|
||
ngOnInit(): void { | ||
if (this.idType.startsWith('handle')) { | ||
this.missingItem = 'handle: ' + this.id; | ||
} else if (this.idType.startsWith('uuid')) { | ||
this.missingItem = 'uuid: ' + this.id; | ||
} else { | ||
this.missingItem = 'handle: ' + this.idType + '/' + this.id; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.