mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
121550: Use IDs on the routes in order to assign AbstractRouteContextMenuProviders
This commit is contained in:
@@ -27,10 +27,8 @@ import { RegistriesMenuProvider } from './shared/menu/providers/registries.menu'
|
|||||||
import { StatisticsMenuProvider } from './shared/menu/providers/statistics.menu';
|
import { StatisticsMenuProvider } from './shared/menu/providers/statistics.menu';
|
||||||
import { SystemWideAlertMenuProvider } from './shared/menu/providers/system-wide-alert.menu';
|
import { SystemWideAlertMenuProvider } from './shared/menu/providers/system-wide-alert.menu';
|
||||||
import { WorkflowMenuProvider } from './shared/menu/providers/workflow.menu';
|
import { WorkflowMenuProvider } from './shared/menu/providers/workflow.menu';
|
||||||
import { COMMUNITY_MODULE_PATH } from './community-page/community-page-routing-paths';
|
|
||||||
import { COLLECTION_MODULE_PATH } from './collection-page/collection-page-routing-paths';
|
|
||||||
import { ENTITY_MODULE_PATH, ITEM_MODULE_PATH } from './item-page/item-page-routing-paths';
|
|
||||||
import { DsoOptionMenu } from './shared/menu/providers/dso-option.menu';
|
import { DsoOptionMenu } from './shared/menu/providers/dso-option.menu';
|
||||||
|
import { MenuRoute } from './shared/menu/menu-route.model';
|
||||||
|
|
||||||
export const MENUS = buildMenuStructure({
|
export const MENUS = buildMenuStructure({
|
||||||
[MenuID.PUBLIC]: [
|
[MenuID.PUBLIC]: [
|
||||||
@@ -54,11 +52,29 @@ export const MENUS = buildMenuStructure({
|
|||||||
],
|
],
|
||||||
[MenuID.DSO_EDIT]: [
|
[MenuID.DSO_EDIT]: [
|
||||||
DsoOptionMenu.withSubs([
|
DsoOptionMenu.withSubs([
|
||||||
SubscribeMenuProvider.onRoute(COMMUNITY_MODULE_PATH, COLLECTION_MODULE_PATH),
|
SubscribeMenuProvider.onRoute(
|
||||||
DSpaceObjectEditMenuProvider.onRoute(COMMUNITY_MODULE_PATH, COLLECTION_MODULE_PATH, ITEM_MODULE_PATH, ENTITY_MODULE_PATH),
|
MenuRoute.SIMPLE_COMMUNITY_PAGE,
|
||||||
VersioningMenuProvider.onRoute(ITEM_MODULE_PATH, ENTITY_MODULE_PATH),
|
MenuRoute.SIMPLE_COLLECTION_PAGE,
|
||||||
OrcidMenuProvider.onRoute(ITEM_MODULE_PATH, ENTITY_MODULE_PATH),
|
),
|
||||||
ClaimMenuProvider.onRoute(ITEM_MODULE_PATH, ENTITY_MODULE_PATH, COLLECTION_MODULE_PATH),
|
DSpaceObjectEditMenuProvider.onRoute(
|
||||||
|
MenuRoute.SIMPLE_COMMUNITY_PAGE,
|
||||||
|
MenuRoute.SIMPLE_COLLECTION_PAGE,
|
||||||
|
MenuRoute.SIMPLE_ITEM_PAGE,
|
||||||
|
MenuRoute.FULL_ITEM_PAGE,
|
||||||
|
),
|
||||||
|
VersioningMenuProvider.onRoute(
|
||||||
|
MenuRoute.SIMPLE_ITEM_PAGE,
|
||||||
|
MenuRoute.FULL_ITEM_PAGE,
|
||||||
|
),
|
||||||
|
OrcidMenuProvider.onRoute(
|
||||||
|
MenuRoute.SIMPLE_ITEM_PAGE,
|
||||||
|
MenuRoute.FULL_ITEM_PAGE,
|
||||||
|
),
|
||||||
|
ClaimMenuProvider.onRoute(
|
||||||
|
MenuRoute.SIMPLE_ITEM_PAGE,
|
||||||
|
MenuRoute.FULL_ITEM_PAGE,
|
||||||
|
MenuRoute.SIMPLE_COLLECTION_PAGE,
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@@ -19,6 +19,7 @@ import { DeleteCollectionPageComponent } from './delete-collection-page/delete-c
|
|||||||
import { ItemTemplatePageResolver } from './edit-item-template-page/item-template-page.resolver';
|
import { ItemTemplatePageResolver } from './edit-item-template-page/item-template-page.resolver';
|
||||||
import { ThemedEditItemTemplatePageComponent } from './edit-item-template-page/themed-edit-item-template-page.component';
|
import { ThemedEditItemTemplatePageComponent } from './edit-item-template-page/themed-edit-item-template-page.component';
|
||||||
import { ThemedCollectionPageComponent } from './themed-collection-page.component';
|
import { ThemedCollectionPageComponent } from './themed-collection-page.component';
|
||||||
|
import { MenuRoute } from '../shared/menu/menu-route.model';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -62,6 +63,9 @@ import { ThemedCollectionPageComponent } from './themed-collection-page.componen
|
|||||||
path: '',
|
path: '',
|
||||||
component: ThemedCollectionPageComponent,
|
component: ThemedCollectionPageComponent,
|
||||||
pathMatch: 'full',
|
pathMatch: 'full',
|
||||||
|
data: {
|
||||||
|
menuRoute: MenuRoute.SIMPLE_COLLECTION_PAGE,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@@ -15,6 +15,7 @@ import { CreateCommunityPageComponent } from './create-community-page/create-com
|
|||||||
import { CreateCommunityPageGuard } from './create-community-page/create-community-page.guard';
|
import { CreateCommunityPageGuard } from './create-community-page/create-community-page.guard';
|
||||||
import { DeleteCommunityPageComponent } from './delete-community-page/delete-community-page.component';
|
import { DeleteCommunityPageComponent } from './delete-community-page/delete-community-page.component';
|
||||||
import { ThemedCommunityPageComponent } from './themed-community-page.component';
|
import { ThemedCommunityPageComponent } from './themed-community-page.component';
|
||||||
|
import { MenuRoute } from '../shared/menu/menu-route.model';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -48,6 +49,9 @@ import { ThemedCommunityPageComponent } from './themed-community-page.component'
|
|||||||
path: '',
|
path: '',
|
||||||
component: ThemedCommunityPageComponent,
|
component: ThemedCommunityPageComponent,
|
||||||
pathMatch: 'full',
|
pathMatch: 'full',
|
||||||
|
data: {
|
||||||
|
menuRoute: MenuRoute.SIMPLE_COMMUNITY_PAGE,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@@ -18,6 +18,7 @@ import { OrcidPageGuard } from './orcid-page/orcid-page.guard';
|
|||||||
import { ThemedItemPageComponent } from './simple/themed-item-page.component';
|
import { ThemedItemPageComponent } from './simple/themed-item-page.component';
|
||||||
import { VersionPageComponent } from './version-page/version-page/version-page.component';
|
import { VersionPageComponent } from './version-page/version-page/version-page.component';
|
||||||
import { VersionResolver } from './version-page/version.resolver';
|
import { VersionResolver } from './version-page/version.resolver';
|
||||||
|
import { MenuRoute } from '../shared/menu/menu-route.model';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -34,10 +35,16 @@ import { VersionResolver } from './version-page/version.resolver';
|
|||||||
path: '',
|
path: '',
|
||||||
component: ThemedItemPageComponent,
|
component: ThemedItemPageComponent,
|
||||||
pathMatch: 'full',
|
pathMatch: 'full',
|
||||||
|
data: {
|
||||||
|
menuRoute: MenuRoute.SIMPLE_ITEM_PAGE,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'full',
|
path: 'full',
|
||||||
component: ThemedFullItemPageComponent,
|
component: ThemedFullItemPageComponent,
|
||||||
|
data: {
|
||||||
|
menuRoute: MenuRoute.FULL_ITEM_PAGE,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: ITEM_EDIT_PATH,
|
path: ITEM_EDIT_PATH,
|
||||||
|
@@ -11,6 +11,7 @@ import { Observable, } from 'rxjs';
|
|||||||
import { MenuID } from './menu-id.model';
|
import { MenuID } from './menu-id.model';
|
||||||
import { MenuItemModels } from './menu-section.model';
|
import { MenuItemModels } from './menu-section.model';
|
||||||
import { Type } from '@angular/core';
|
import { Type } from '@angular/core';
|
||||||
|
import { MenuRoute } from './menu-route.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Partial menu section
|
* Partial menu section
|
||||||
@@ -52,7 +53,7 @@ export interface MenuProvider {
|
|||||||
*/
|
*/
|
||||||
export class MenuProviderTypeWithOptions {
|
export class MenuProviderTypeWithOptions {
|
||||||
providerType: Type<MenuProvider>;
|
providerType: Type<MenuProvider>;
|
||||||
paths?: string[];
|
paths?: MenuRoute[];
|
||||||
childProviderTypes?: (Type<MenuProvider> | MenuProviderTypeWithOptions)[];
|
childProviderTypes?: (Type<MenuProvider> | MenuProviderTypeWithOptions)[];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,7 @@ export abstract class AbstractMenuProvider implements MenuProvider {
|
|||||||
* This will be automatically set based on the paths added based on the paths provided through the 'onRoute' static
|
* This will be automatically set based on the paths added based on the paths provided through the 'onRoute' static
|
||||||
* method in the app.menus.ts file
|
* method in the app.menus.ts file
|
||||||
*/
|
*/
|
||||||
activePaths?: string[];
|
activePaths?: MenuRoute[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the parent provider of this provider.
|
* The ID of the parent provider of this provider.
|
||||||
@@ -110,7 +111,7 @@ export abstract class AbstractMenuProvider implements MenuProvider {
|
|||||||
* Static method to be called from the app.menus.ts file to define paths on which this provider should the active
|
* Static method to be called from the app.menus.ts file to define paths on which this provider should the active
|
||||||
* @param paths - The paths on which the sections of this provider should be active
|
* @param paths - The paths on which the sections of this provider should be active
|
||||||
*/
|
*/
|
||||||
public static onRoute(...paths: string[]): MenuProviderTypeWithOptions {
|
public static onRoute(...paths: MenuRoute[]): MenuProviderTypeWithOptions {
|
||||||
if (!AbstractMenuProvider.isPrototypeOf(this)) {
|
if (!AbstractMenuProvider.isPrototypeOf(this)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'onRoute should only be called from concrete subclasses of AbstractMenuProvider'
|
'onRoute should only be called from concrete subclasses of AbstractMenuProvider'
|
||||||
|
@@ -16,6 +16,7 @@ import { AbstractMenuProvider, PartialMenuSection } from './menu-provider.model'
|
|||||||
import { MenuState } from './menu-state.model';
|
import { MenuState } from './menu-state.model';
|
||||||
import { MenuService } from './menu.service';
|
import { MenuService } from './menu.service';
|
||||||
import { MENU_PROVIDER } from './menu.structure';
|
import { MENU_PROVIDER } from './menu.structure';
|
||||||
|
import { MenuRoute } from './menu-route.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service that is responsible for adding and removing the menu sections created by the providers, both for
|
* Service that is responsible for adding and removing the menu sections created by the providers, both for
|
||||||
@@ -126,8 +127,8 @@ export class MenuProviderService {
|
|||||||
.filter(provider => {
|
.filter(provider => {
|
||||||
let shouldUpdate = false;
|
let shouldUpdate = false;
|
||||||
if (!provider.shouldPersistOnRouteChange && isNotEmpty(provider.activePaths)) {
|
if (!provider.shouldPersistOnRouteChange && isNotEmpty(provider.activePaths)) {
|
||||||
provider.activePaths.forEach((path) => {
|
provider.activePaths.forEach((path: MenuRoute) => {
|
||||||
if (state.url.includes(path)) {
|
if (route.data.menuRoute === path) {
|
||||||
shouldUpdate = true;
|
shouldUpdate = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
9
src/app/shared/menu/menu-route.model.ts
Normal file
9
src/app/shared/menu/menu-route.model.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* The menu route IDs that can be used for route resolvers
|
||||||
|
*/
|
||||||
|
export enum MenuRoute {
|
||||||
|
SIMPLE_COMMUNITY_PAGE = 'simple-community-page',
|
||||||
|
SIMPLE_COLLECTION_PAGE = 'simple-collection-page',
|
||||||
|
SIMPLE_ITEM_PAGE = 'simple-item-page',
|
||||||
|
FULL_ITEM_PAGE = 'full-item-page',
|
||||||
|
}
|
@@ -10,6 +10,7 @@ import { MenuID } from './menu-id.model';
|
|||||||
import { AbstractMenuProvider, MenuProviderTypeWithOptions } from './menu-provider.model';
|
import { AbstractMenuProvider, MenuProviderTypeWithOptions } from './menu-provider.model';
|
||||||
import { MenuProviderService } from './menu-provider.service';
|
import { MenuProviderService } from './menu-provider.service';
|
||||||
import { hasValue, isNotEmpty } from '../empty.util';
|
import { hasValue, isNotEmpty } from '../empty.util';
|
||||||
|
import { MenuRoute } from './menu-route.model';
|
||||||
|
|
||||||
export const MENU_PROVIDER = new InjectionToken<AbstractMenuProvider>('MENU_PROVIDER');
|
export const MENU_PROVIDER = new InjectionToken<AbstractMenuProvider>('MENU_PROVIDER');
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ function processProviderType(providers: Provider[], menuID: string, providerType
|
|||||||
* @param hasSubProviders - Whether this provider has sub providers
|
* @param hasSubProviders - Whether this provider has sub providers
|
||||||
* @param paths - The paths this provider should be active on if relevant
|
* @param paths - The paths this provider should be active on if relevant
|
||||||
*/
|
*/
|
||||||
function addProviderToList(providers: Provider[], providerType: Type<AbstractMenuProvider>, menuID: string, index: number, parentID?: string, hasSubProviders?: boolean, paths?: string[]) {
|
function addProviderToList(providers: Provider[], providerType: Type<AbstractMenuProvider>, menuID: string, index: number, parentID?: string, hasSubProviders?: boolean, paths?: MenuRoute[]) {
|
||||||
const resolvedProvider = {
|
const resolvedProvider = {
|
||||||
provide: MENU_PROVIDER,
|
provide: MENU_PROVIDER,
|
||||||
multi: true,
|
multi: true,
|
||||||
|
Reference in New Issue
Block a user