Skip to content

Commit da0111d

Browse files
FrancescoMolinarovins01-4science
authored andcommitted
Merged in task/main-cris/DSC-2269 (pull request DSpace#3086)
[DSC-2269] fix link resolution Approved-by: Andrea Barbasso Approved-by: Giuseppe Digilio
2 parents f08d8ee + 92b6a9c commit da0111d

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/app/item-page/item-page.resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ export const itemPageResolver: ResolveFn<RemoteData<Item>> = (
7575
map((rd: RemoteData<Item>) => {
7676
store.dispatch(new ResolvedAction(state.url, rd.payload));
7777
if (rd.hasSucceeded && hasValue(rd.payload)) {
78+
const itemRoute = router.parseUrl(getItemPageRoute(rd.payload)).toString();
7879
// Check if custom url not empty and if the current id parameter is different from the custom url redirect to custom url
7980
if (hasValue(rd.payload.metadata) && isNotEmpty(rd.payload.metadata['cris.customurl'])) {
8081
if (route.params.id !== rd.payload.metadata['cris.customurl'][0].value) {
81-
const newUrl = state.url.replace(route.params.id, rd.payload.metadata['cris.customurl'][0].value);
82+
const newUrl = itemRoute.replace(route.params.id, rd.payload.metadata['cris.customurl'][0].value);
8283
router.navigateByUrl(newUrl);
8384
}
8485
} else {
@@ -88,7 +89,6 @@ export const itemPageResolver: ResolveFn<RemoteData<Item>> = (
8889
// or semicolons) and thisRoute has been encoded with that function. If we want to compare
8990
// it with itemRoute, we have to run itemRoute through Angular's version as well to ensure
9091
// the same characters are encoded the same way.
91-
const itemRoute = router.parseUrl(getItemPageRoute(rd.payload)).toString();
9292

9393
if (!thisRoute.startsWith(itemRoute)) {
9494
const itemId = rd.payload.uuid;

src/app/shared/metadata-link-view/metadata-link-view.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
container="body"
1111
triggers="mouseenter">
1212
<a rel="noopener noreferrer" data-test="linkToAuthority"
13-
[routerLink]="['/items/' + metadataView.authority]">
13+
[routerLink]="[relatedDsoRoute]">
1414
<span dsEntityIcon
1515
[iconPosition]="iconPosition"
1616
[entityType]="metadataView.entityType"

src/app/shared/metadata-link-view/metadata-link-view.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
switchMap,
2323
take,
2424
} from 'rxjs/operators';
25+
import { getItemPageRoute } from 'src/app/item-page/item-page-routing-paths';
2526

2627
import { environment } from '../../../environments/environment';
2728
import { ItemDataService } from '../../core/data/item-data.service';
@@ -97,6 +98,11 @@ export class MetadataLinkViewComponent implements OnInit {
9798
*/
9899
relatedItem: Item;
99100

101+
/**
102+
* Route of related item page
103+
*/
104+
relatedDsoRoute: string;
105+
100106
/**
101107
* Map all entities with the icons specified in the environment configuration file
102108
*/
@@ -149,6 +155,7 @@ export class MetadataLinkViewComponent implements OnInit {
149155
private createMetadataView(itemRD: RemoteData<Item>, metadataValue: MetadataValue): MetadataView {
150156
if (itemRD.hasSucceeded) {
151157
this.relatedItem = itemRD.payload;
158+
this.relatedDsoRoute = this.getItemPageRoute(this.relatedItem);
152159
const entityStyleValue = this.getCrisRefMetadata(itemRD.payload?.entityType);
153160
return {
154161
authority: metadataValue.authority,
@@ -207,4 +214,8 @@ export class MetadataLinkViewComponent implements OnInit {
207214
return metadata ?? this.crisRefMetadata?.default;
208215
}
209216

217+
getItemPageRoute(item: Item): string {
218+
return getItemPageRoute(item);
219+
}
220+
210221
}

0 commit comments

Comments
 (0)