@@ -4,48 +4,71 @@ import { isNotEmpty } from '../shared/empty.util';
44
55export const ITEM_MODULE_PATH = 'items' ;
66
7- export function getItemModuleRoute ( ) {
8- return `/${ ITEM_MODULE_PATH } ` ;
9- }
107
118export 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
5174export const ITEM_EDIT_PATH = 'edit' ;
0 commit comments