mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Revert "replace menu decorators with switches to solve an issue where decorators were not loaded in time"
This reverts commit ece84332a0
.
This commit is contained in:

committed by
Giuseppe Digilio

parent
a27c10e980
commit
0308c8bc8e
@@ -2,6 +2,7 @@ import { Component, Inject, Injector, OnInit } from '@angular/core';
|
|||||||
import { MenuSectionComponent } from '../../../shared/menu/menu-section/menu-section.component';
|
import { MenuSectionComponent } from '../../../shared/menu/menu-section/menu-section.component';
|
||||||
import { MenuID } from '../../../shared/menu/initial-menus-state';
|
import { MenuID } from '../../../shared/menu/initial-menus-state';
|
||||||
import { MenuService } from '../../../shared/menu/menu.service';
|
import { MenuService } from '../../../shared/menu/menu.service';
|
||||||
|
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
|
||||||
import { LinkMenuItemModel } from '../../../shared/menu/menu-item/models/link.model';
|
import { LinkMenuItemModel } from '../../../shared/menu/menu-item/models/link.model';
|
||||||
import { MenuSection } from '../../../shared/menu/menu.reducer';
|
import { MenuSection } from '../../../shared/menu/menu.reducer';
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ import { MenuSection } from '../../../shared/menu/menu.reducer';
|
|||||||
styleUrls: ['./admin-sidebar-section.component.scss'],
|
styleUrls: ['./admin-sidebar-section.component.scss'],
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@rendersSectionForMenu(MenuID.ADMIN, false)
|
||||||
export class AdminSidebarSectionComponent extends MenuSectionComponent implements OnInit {
|
export class AdminSidebarSectionComponent extends MenuSectionComponent implements OnInit {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -8,6 +8,7 @@ import { MenuID } from '../../../shared/menu/initial-menus-state';
|
|||||||
import { MenuService } from '../../../shared/menu/menu.service';
|
import { MenuService } from '../../../shared/menu/menu.service';
|
||||||
import { combineLatest as combineLatestObservable, Observable } from 'rxjs';
|
import { combineLatest as combineLatestObservable, Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a expandable section in the sidebar
|
* Represents a expandable section in the sidebar
|
||||||
@@ -19,6 +20,7 @@ import { map } from 'rxjs/operators';
|
|||||||
animations: [rotate, slide, bgColor]
|
animations: [rotate, slide, bgColor]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@rendersSectionForMenu(MenuID.ADMIN, true)
|
||||||
export class ExpandableAdminSidebarSectionComponent extends AdminSidebarSectionComponent implements OnInit {
|
export class ExpandableAdminSidebarSectionComponent extends AdminSidebarSectionComponent implements OnInit {
|
||||||
/**
|
/**
|
||||||
* This section resides in the Admin Sidebar
|
* This section resides in the Admin Sidebar
|
||||||
|
@@ -5,6 +5,7 @@ import { MenuID } from '../../shared/menu/initial-menus-state';
|
|||||||
import { slide } from '../../shared/animations/slide';
|
import { slide } from '../../shared/animations/slide';
|
||||||
import { first } from 'rxjs/operators';
|
import { first } from 'rxjs/operators';
|
||||||
import { HostWindowService } from '../../shared/host-window.service';
|
import { HostWindowService } from '../../shared/host-window.service';
|
||||||
|
import { rendersSectionForMenu } from '../../shared/menu/menu-section.decorator';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an expandable section in the navbar
|
* Represents an expandable section in the navbar
|
||||||
@@ -15,6 +16,7 @@ import { HostWindowService } from '../../shared/host-window.service';
|
|||||||
styleUrls: ['./expandable-navbar-section.component.scss'],
|
styleUrls: ['./expandable-navbar-section.component.scss'],
|
||||||
animations: [slide]
|
animations: [slide]
|
||||||
})
|
})
|
||||||
|
@rendersSectionForMenu(MenuID.PUBLIC, true)
|
||||||
export class ExpandableNavbarSectionComponent extends NavbarSectionComponent implements OnInit {
|
export class ExpandableNavbarSectionComponent extends NavbarSectionComponent implements OnInit {
|
||||||
/**
|
/**
|
||||||
* This section resides in the Public Navbar
|
* This section resides in the Public Navbar
|
||||||
|
@@ -2,6 +2,7 @@ import { Component, Inject, Injector, OnInit } from '@angular/core';
|
|||||||
import { MenuSectionComponent } from '../../shared/menu/menu-section/menu-section.component';
|
import { MenuSectionComponent } from '../../shared/menu/menu-section/menu-section.component';
|
||||||
import { MenuService } from '../../shared/menu/menu.service';
|
import { MenuService } from '../../shared/menu/menu.service';
|
||||||
import { MenuID } from '../../shared/menu/initial-menus-state';
|
import { MenuID } from '../../shared/menu/initial-menus-state';
|
||||||
|
import { rendersSectionForMenu } from '../../shared/menu/menu-section.decorator';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a non-expandable section in the navbar
|
* Represents a non-expandable section in the navbar
|
||||||
@@ -11,6 +12,7 @@ import { MenuID } from '../../shared/menu/initial-menus-state';
|
|||||||
templateUrl: './navbar-section.component.html',
|
templateUrl: './navbar-section.component.html',
|
||||||
styleUrls: ['./navbar-section.component.scss']
|
styleUrls: ['./navbar-section.component.scss']
|
||||||
})
|
})
|
||||||
|
@rendersSectionForMenu(MenuID.PUBLIC, false)
|
||||||
export class NavbarSectionComponent extends MenuSectionComponent implements OnInit {
|
export class NavbarSectionComponent extends MenuSectionComponent implements OnInit {
|
||||||
/**
|
/**
|
||||||
* This section resides in the Public Navbar
|
* This section resides in the Public Navbar
|
||||||
|
@@ -1,7 +1,20 @@
|
|||||||
import { MenuItemType } from './initial-menus-state';
|
import { MenuItemType } from './initial-menus-state';
|
||||||
import { LinkMenuItemComponent } from './menu-item/link-menu-item.component';
|
|
||||||
import { OnClickMenuItemComponent } from './menu-item/onclick-menu-item.component';
|
const menuMenuItemComponentMap = new Map();
|
||||||
import { TextMenuItemComponent } from './menu-item/text-menu-item.component';
|
|
||||||
|
/**
|
||||||
|
* Decorator function to link a MenuItemType to a Component
|
||||||
|
* @param {MenuItemType} type The MenuItemType of the MenuSection's model
|
||||||
|
* @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
|
||||||
@@ -9,12 +22,5 @@ import { TextMenuItemComponent } from './menu-item/text-menu-item.component';
|
|||||||
* @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) {
|
||||||
switch (type) {
|
return menuMenuItemComponentMap.get(type);
|
||||||
case MenuItemType.LINK:
|
|
||||||
return LinkMenuItemComponent;
|
|
||||||
case MenuItemType.ONCLICK:
|
|
||||||
return OnClickMenuItemComponent;
|
|
||||||
case MenuItemType.TEXT:
|
|
||||||
return TextMenuItemComponent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
import { Component, Inject, OnInit } from '@angular/core';
|
import { Component, Inject, Input, OnInit } from '@angular/core';
|
||||||
import { LinkMenuItemModel } from './models/link.model';
|
import { LinkMenuItemModel } from './models/link.model';
|
||||||
|
import { MenuItemType } from '../initial-menus-state';
|
||||||
|
import { rendersMenuItemForType } from '../menu-item.decorator';
|
||||||
import { isNotEmpty } from '../../empty.util';
|
import { isNotEmpty } from '../../empty.util';
|
||||||
import { environment } from '../../../../environments/environment';
|
import { environment } from '../../../../environments/environment';
|
||||||
|
|
||||||
@@ -10,6 +12,7 @@ import { environment } from '../../../../environments/environment';
|
|||||||
selector: 'ds-link-menu-item',
|
selector: 'ds-link-menu-item',
|
||||||
templateUrl: './link-menu-item.component.html'
|
templateUrl: './link-menu-item.component.html'
|
||||||
})
|
})
|
||||||
|
@rendersMenuItemForType(MenuItemType.LINK)
|
||||||
export class LinkMenuItemComponent implements OnInit {
|
export class LinkMenuItemComponent implements OnInit {
|
||||||
item: LinkMenuItemModel;
|
item: LinkMenuItemModel;
|
||||||
hasLink: boolean;
|
hasLink: boolean;
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
import { Component, Inject } from '@angular/core';
|
import { Component, Inject } from '@angular/core';
|
||||||
|
import { MenuItemType } from '../initial-menus-state';
|
||||||
|
import { rendersMenuItemForType } from '../menu-item.decorator';
|
||||||
import { OnClickMenuItemModel } from './models/onclick.model';
|
import { OnClickMenuItemModel } from './models/onclick.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,6 +11,7 @@ import { OnClickMenuItemModel } from './models/onclick.model';
|
|||||||
styleUrls: ['./onclick-menu-item.component.scss'],
|
styleUrls: ['./onclick-menu-item.component.scss'],
|
||||||
templateUrl: './onclick-menu-item.component.html'
|
templateUrl: './onclick-menu-item.component.html'
|
||||||
})
|
})
|
||||||
|
@rendersMenuItemForType(MenuItemType.ONCLICK)
|
||||||
export class OnClickMenuItemComponent {
|
export class OnClickMenuItemComponent {
|
||||||
item: OnClickMenuItemModel;
|
item: OnClickMenuItemModel;
|
||||||
constructor(@Inject('itemModelProvider') item: OnClickMenuItemModel) {
|
constructor(@Inject('itemModelProvider') item: OnClickMenuItemModel) {
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
import { Component, Inject } from '@angular/core';
|
import { Component, Inject, Input } from '@angular/core';
|
||||||
import { TextMenuItemModel } from './models/text.model';
|
import { TextMenuItemModel } from './models/text.model';
|
||||||
|
import { MenuItemType } from '../initial-menus-state';
|
||||||
|
import { rendersMenuItemForType } from '../menu-item.decorator';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that renders a menu section of type TEXT
|
* Component that renders a menu section of type TEXT
|
||||||
@@ -8,6 +10,7 @@ import { TextMenuItemModel } from './models/text.model';
|
|||||||
selector: 'ds-text-menu-item',
|
selector: 'ds-text-menu-item',
|
||||||
templateUrl: './text-menu-item.component.html',
|
templateUrl: './text-menu-item.component.html',
|
||||||
})
|
})
|
||||||
|
@rendersMenuItemForType(MenuItemType.TEXT)
|
||||||
export class TextMenuItemComponent {
|
export class TextMenuItemComponent {
|
||||||
item: TextMenuItemModel;
|
item: TextMenuItemModel;
|
||||||
constructor(@Inject('itemModelProvider') item: TextMenuItemModel) {
|
constructor(@Inject('itemModelProvider') item: TextMenuItemModel) {
|
||||||
|
@@ -1,8 +1,24 @@
|
|||||||
import { MenuID } from './initial-menus-state';
|
import { MenuID } from './initial-menus-state';
|
||||||
import { NavbarSectionComponent } from '../../navbar/navbar-section/navbar-section.component';
|
|
||||||
import { ExpandableNavbarSectionComponent } from '../../navbar/expandable-navbar-section/expandable-navbar-section.component';
|
const menuComponentMap = new Map();
|
||||||
import { ExpandableAdminSidebarSectionComponent } from '../../+admin/admin-sidebar/expandable-admin-sidebar-section/expandable-admin-sidebar-section.component';
|
|
||||||
import { AdminSidebarSectionComponent } from '../../+admin/admin-sidebar/admin-sidebar-section/admin-sidebar-section.component';
|
/**
|
||||||
|
* Decorator function to render a MenuSection for a menu
|
||||||
|
* @param {MenuID} menuID The ID of the Menu in which the section is rendered
|
||||||
|
* @param {boolean} expandable True when the section should be expandable, false when if should not
|
||||||
|
* @returns {(menuSectionWrapperComponent: GenericConstructor) => void}
|
||||||
|
*/
|
||||||
|
export function rendersSectionForMenu(menuID: MenuID, expandable: boolean) {
|
||||||
|
return function decorator(menuSectionWrapperComponent: any) {
|
||||||
|
if (!menuSectionWrapperComponent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!menuComponentMap.get(menuID)) {
|
||||||
|
menuComponentMap.set(menuID, new Map());
|
||||||
|
}
|
||||||
|
menuComponentMap.get(menuID).set(expandable, menuSectionWrapperComponent);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the component matching the given MenuID and whether or not it should be expandable
|
* Retrieves the component matching the given MenuID and whether or not it should be expandable
|
||||||
@@ -11,13 +27,5 @@ import { AdminSidebarSectionComponent } from '../../+admin/admin-sidebar/admin-s
|
|||||||
* @returns {GenericConstructor} The constructor of the matching Component
|
* @returns {GenericConstructor} The constructor of the matching Component
|
||||||
*/
|
*/
|
||||||
export function getComponentForMenu(menuID: MenuID, expandable: boolean) {
|
export function getComponentForMenu(menuID: MenuID, expandable: boolean) {
|
||||||
if (menuID === MenuID.PUBLIC && expandable === true) {
|
return menuComponentMap.get(menuID).get(expandable);
|
||||||
return ExpandableNavbarSectionComponent;
|
|
||||||
} else if (menuID === MenuID.PUBLIC && expandable === false) {
|
|
||||||
return NavbarSectionComponent;
|
|
||||||
} else if (menuID === MenuID.ADMIN && expandable === true) {
|
|
||||||
return ExpandableAdminSidebarSectionComponent;
|
|
||||||
} else if (menuID === MenuID.ADMIN && expandable === false) {
|
|
||||||
return AdminSidebarSectionComponent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user