mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[DURACOM-191] set static map for menu-item decorator
This commit is contained in:
@@ -1,20 +1,12 @@
|
|||||||
import { MenuItemType } from './menu-item-type.model';
|
import { MenuItemType } from './menu-item-type.model';
|
||||||
|
import { defer } from 'rxjs';
|
||||||
|
|
||||||
const menuMenuItemComponentMap = new Map();
|
const menuMenuItemComponentMap = {
|
||||||
|
[MenuItemType.EXTERNAL]: defer(() => import('./menu-item/external-link-menu-item.component').then(m => m.ExternalLinkMenuItemComponent)),
|
||||||
/**
|
[MenuItemType.LINK]: defer(() => import('./menu-item/link-menu-item.component').then(m => m.LinkMenuItemComponent)),
|
||||||
* Decorator function to link a MenuItemType to a Component
|
[MenuItemType.ONCLICK]: defer(() => import('./menu-item/onclick-menu-item.component').then(m => m.OnClickMenuItemComponent)),
|
||||||
* @param {MenuItemType} type The MenuItemType of the MenuSection's model
|
[MenuItemType.TEXT]: defer(() => import('./menu-item/text-menu-item.component').then(m => m.TextMenuItemComponent))
|
||||||
* @returns {(sectionComponent: GenericContructor) => void}
|
};
|
||||||
*/
|
|
||||||
export function rendersMenuItemForType(type: MenuItemType) {
|
|
||||||
return function decorator(sectionComponent: any) {
|
|
||||||
if (!sectionComponent) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
menuMenuItemComponentMap.set(type, sectionComponent);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the Component matching a given MenuItemType
|
* Retrieves the Component matching a given MenuItemType
|
||||||
@@ -22,5 +14,5 @@ export function rendersMenuItemForType(type: MenuItemType) {
|
|||||||
* @returns {GenericConstructor} The constructor of the Component that matches the MenuItemType
|
* @returns {GenericConstructor} The constructor of the Component that matches the MenuItemType
|
||||||
*/
|
*/
|
||||||
export function getComponentForMenuItemType(type: MenuItemType) {
|
export function getComponentForMenuItemType(type: MenuItemType) {
|
||||||
return menuMenuItemComponentMap.get(type);
|
return menuMenuItemComponentMap[type];
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
import { Component, Inject, OnInit } from '@angular/core';
|
import { Component, Inject, OnInit } from '@angular/core';
|
||||||
import { rendersMenuItemForType } from '../menu-item.decorator';
|
|
||||||
import { isNotEmpty } from '../../empty.util';
|
import { isNotEmpty } from '../../empty.util';
|
||||||
import { ExternalLinkMenuItemModel } from './models/external-link.model';
|
import { ExternalLinkMenuItemModel } from './models/external-link.model';
|
||||||
import { MenuItemType } from '../menu-item-type.model';
|
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { NgClass } from '@angular/common';
|
import { NgClass } from '@angular/common';
|
||||||
|
|
||||||
@@ -15,7 +13,6 @@ import { NgClass } from '@angular/common';
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [NgClass, TranslateModule]
|
imports: [NgClass, TranslateModule]
|
||||||
})
|
})
|
||||||
@rendersMenuItemForType(MenuItemType.EXTERNAL)
|
|
||||||
export class ExternalLinkMenuItemComponent implements OnInit {
|
export class ExternalLinkMenuItemComponent implements OnInit {
|
||||||
item: ExternalLinkMenuItemModel;
|
item: ExternalLinkMenuItemModel;
|
||||||
|
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
import { Component, Inject, OnInit } from '@angular/core';
|
import { Component, Inject, OnInit } from '@angular/core';
|
||||||
import { LinkMenuItemModel } from './models/link.model';
|
import { LinkMenuItemModel } from './models/link.model';
|
||||||
import { rendersMenuItemForType } from '../menu-item.decorator';
|
|
||||||
import { isNotEmpty } from '../../empty.util';
|
import { isNotEmpty } from '../../empty.util';
|
||||||
import { MenuItemType } from '../menu-item-type.model';
|
|
||||||
import { Router, RouterLink } from '@angular/router';
|
import { Router, RouterLink } from '@angular/router';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { NgClass } from '@angular/common';
|
import { NgClass } from '@angular/common';
|
||||||
@@ -16,7 +14,6 @@ import { NgClass } from '@angular/common';
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [NgClass, RouterLink, TranslateModule]
|
imports: [NgClass, RouterLink, TranslateModule]
|
||||||
})
|
})
|
||||||
@rendersMenuItemForType(MenuItemType.LINK)
|
|
||||||
export class LinkMenuItemComponent implements OnInit {
|
export class LinkMenuItemComponent implements OnInit {
|
||||||
item: LinkMenuItemModel;
|
item: LinkMenuItemModel;
|
||||||
hasLink: boolean;
|
hasLink: boolean;
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
import { Component, Inject } from '@angular/core';
|
import { Component, Inject } from '@angular/core';
|
||||||
import { rendersMenuItemForType } from '../menu-item.decorator';
|
|
||||||
import { OnClickMenuItemModel } from './models/onclick.model';
|
import { OnClickMenuItemModel } from './models/onclick.model';
|
||||||
import { MenuItemType } from '../menu-item-type.model';
|
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { NgIf } from '@angular/common';
|
import { NgIf } from '@angular/common';
|
||||||
|
|
||||||
@@ -15,7 +13,6 @@ import { NgIf } from '@angular/common';
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [NgIf, TranslateModule]
|
imports: [NgIf, TranslateModule]
|
||||||
})
|
})
|
||||||
@rendersMenuItemForType(MenuItemType.ONCLICK)
|
|
||||||
export class OnClickMenuItemComponent {
|
export class OnClickMenuItemComponent {
|
||||||
item: OnClickMenuItemModel;
|
item: OnClickMenuItemModel;
|
||||||
|
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
import { Component, Inject } from '@angular/core';
|
import { Component, Inject } from '@angular/core';
|
||||||
import { TextMenuItemModel } from './models/text.model';
|
import { TextMenuItemModel } from './models/text.model';
|
||||||
import { rendersMenuItemForType } from '../menu-item.decorator';
|
|
||||||
import { MenuItemType } from '../menu-item-type.model';
|
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,7 +11,6 @@ import { TranslateModule } from '@ngx-translate/core';
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [TranslateModule]
|
imports: [TranslateModule]
|
||||||
})
|
})
|
||||||
@rendersMenuItemForType(MenuItemType.TEXT)
|
|
||||||
export class TextMenuItemComponent {
|
export class TextMenuItemComponent {
|
||||||
item: TextMenuItemModel;
|
item: TextMenuItemModel;
|
||||||
constructor(@Inject('itemModelProvider') item: TextMenuItemModel) {
|
constructor(@Inject('itemModelProvider') item: TextMenuItemModel) {
|
||||||
|
Reference in New Issue
Block a user