Skip to content

Commit b563b4b

Browse files
committed
Resolving item version page routing by using config nameSpace #4358
1 parent addd1b0 commit b563b4b

File tree

2 files changed

+52
-21
lines changed

2 files changed

+52
-21
lines changed

src/app/item-page/item-page-routing-paths.ts

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,71 @@ import { isNotEmpty } from '../shared/empty.util';
44

55
export const ITEM_MODULE_PATH = 'items';
66

7-
export function getItemModuleRoute() {
8-
return `/${ITEM_MODULE_PATH}`;
9-
}
107

118
export const ENTITY_MODULE_PATH = 'entities';
129

10+
/**
11+
* Normalize a namespace by ensuring it starts with '/' and doesn't end with '/'
12+
*/
13+
function normalizeNamespace(namespace?: string): string {
14+
if (!namespace || namespace === '/') {
15+
return '';
16+
}
17+
18+
let normalized = namespace;
19+
if (!normalized.startsWith('/')) {
20+
normalized = '/' + normalized;
21+
}
22+
if (normalized.endsWith('/')) {
23+
normalized = normalized.slice(0, -1);
24+
}
25+
return normalized;
26+
}
27+
28+
export function getItemModuleRoute(namespace?: string) {
29+
const normalizedNamespace = normalizeNamespace(namespace);
30+
return `${normalizedNamespace}/${ITEM_MODULE_PATH}`;
31+
}
32+
1333
/**
1434
* Get the route to an item's page
1535
* Depending on the item's entity type, the route will either start with /items or /entities
16-
* @param item The item to retrieve the route for
36+
* @param item The item to retrieve the route for
37+
* @param namespace Optional namespace to prepend to the route
1738
*/
18-
export function getItemPageRoute(item: Item) {
39+
export function getItemPageRoute(item: Item, namespace?: string) {
1940
const type = item.firstMetadataValue('dspace.entity.type');
20-
return getEntityPageRoute(type, item.uuid);
41+
return getEntityPageRoute(type, item.uuid, namespace);
2142
}
2243

23-
export function getItemEditRoute(item: Item) {
24-
return new URLCombiner(getItemPageRoute(item), ITEM_EDIT_PATH).toString();
44+
export function getItemEditRoute(item: Item, namespace?: string) {
45+
return new URLCombiner(getItemPageRoute(item, namespace), ITEM_EDIT_PATH).toString();
2546
}
2647

27-
export function getItemEditVersionhistoryRoute(item: Item) {
28-
return new URLCombiner(getItemPageRoute(item), ITEM_EDIT_PATH, ITEM_EDIT_VERSIONHISTORY_PATH).toString();
48+
export function getItemEditVersionhistoryRoute(item: Item, namespace?: string) {
49+
return new URLCombiner(getItemPageRoute(item, namespace), ITEM_EDIT_PATH, ITEM_EDIT_VERSIONHISTORY_PATH).toString();
2950
}
3051

31-
export function getEntityPageRoute(entityType: string, itemId: string) {
52+
export function getEntityPageRoute(entityType: string, itemId: string, namespace?: string) {
53+
const normalizedNamespace = normalizeNamespace(namespace);
3254
if (isNotEmpty(entityType)) {
33-
return new URLCombiner('/entities', encodeURIComponent(entityType.toLowerCase()), itemId).toString();
55+
return new URLCombiner(`${normalizedNamespace}/entities`, encodeURIComponent(entityType.toLowerCase()), itemId).toString();
3456
} else {
35-
return new URLCombiner(getItemModuleRoute(), itemId).toString();
57+
return new URLCombiner(getItemModuleRoute(namespace), itemId).toString();
3658
}
3759
}
3860

39-
export function getEntityEditRoute(entityType: string, itemId: string) {
40-
return new URLCombiner(getEntityPageRoute(entityType, itemId), ITEM_EDIT_PATH).toString();
61+
export function getEntityEditRoute(entityType: string, itemId: string, namespace?: string) {
62+
return new URLCombiner(getEntityPageRoute(entityType, itemId, namespace), ITEM_EDIT_PATH).toString();
4163
}
4264

4365
/**
4466
* Get the route to an item's version
4567
* @param versionId the ID of the version for which the route will be retrieved
68+
* @param namespace Optional namespace to prepend to the route
4669
*/
47-
export function getItemVersionRoute(versionId: string) {
48-
return new URLCombiner(getItemModuleRoute(), ITEM_VERSION_PATH, versionId).toString();
70+
export function getItemVersionRoute(versionId: string, namespace?: string) {
71+
return new URLCombiner(getItemModuleRoute(namespace), ITEM_VERSION_PATH, versionId).toString();
4972
}
5073

5174
export const ITEM_EDIT_PATH = 'edit';

src/app/item-page/versions/notice/item-versions-notice.component.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { AsyncPipe } from '@angular/common';
1+
import {
2+
AsyncPipe,
3+
NgIf,
4+
} from '@angular/common';
25
import {
36
Component,
7+
inject,
48
Input,
59
OnInit,
610
} from '@angular/core';
@@ -16,6 +20,7 @@ import {
1620
switchMap,
1721
} from 'rxjs/operators';
1822

23+
import { APP_CONFIG } from '../../../../config/app-config.interface';
1924
import { RemoteData } from '../../../core/data/remote-data';
2025
import { VersionHistoryDataService } from '../../../core/data/version-history-data.service';
2126
import { Item } from '../../../core/shared/item.model';
@@ -39,8 +44,9 @@ import { getItemPageRoute } from '../../item-page-routing-paths';
3944
templateUrl: './item-versions-notice.component.html',
4045
standalone: true,
4146
imports: [
42-
AlertComponent,
43-
AsyncPipe,
47+
NgIf,
48+
AlertComponent,
49+
AsyncPipe,
4450
TranslateModule,
4551
],
4652
})
@@ -85,6 +91,8 @@ export class ItemVersionsNoticeComponent implements OnInit {
8591
*/
8692
public AlertTypeEnum = AlertType;
8793

94+
private appConfig = inject(APP_CONFIG);
95+
8896
constructor(private versionHistoryService: VersionHistoryDataService) {
8997
}
9098

@@ -134,7 +142,7 @@ export class ItemVersionsNoticeComponent implements OnInit {
134142
*/
135143
getItemPage(item: Item): string {
136144
if (hasValue(item)) {
137-
return getItemPageRoute(item);
145+
return getItemPageRoute(item, this.appConfig.ui.nameSpace);
138146
}
139147
}
140148
}

0 commit comments

Comments
 (0)