[Explore | Library | new-theme]: resources.service.ts & menu.ts & navigationBar.component.ts & navigationBar.component.html & app.component.ts: Removed deprecated RootMenuItem and used MenuItem instead.

This commit is contained in:
Konstantina Galouni 2022-09-20 18:00:19 +03:00
parent b1842543e7
commit 4cec2907da
4 changed files with 36 additions and 60 deletions

View File

@ -1,5 +1,5 @@
import {Injectable} from "@angular/core";
import {MenuItem, RootMenuItem} from "../../sharedComponents/menu";
import {MenuItem} from "../../sharedComponents/menu";
import {Option} from "../../sharedComponents/input/input.component";
import {StakeholderEntities} from "../entities/stakeholder";
import {from, Subscription} from "rxjs";
@ -64,12 +64,12 @@ export class ResourcesService {
/**
* @deprecated
* */
setResourcesDeprecated(items: RootMenuItem[], prefix = '', portal: string = null) {
setResourcesDeprecated(items: MenuItem[], prefix = '', portal: string = null) {
if (this.subscription) {
this.subscription.unsubscribe();
}
let resources = new MenuItem('resources', 'Resources', "", "", false, [], null, {});
let index = items.push({rootItem: resources, items: []}) - 1;
let index = items.push(resources) - 1;
this.subscription = from(this.getResourcesItemsAsync(prefix, portal)).subscribe(resourcesItems => {
items[index].items = resourcesItems;
});

View File

@ -24,7 +24,7 @@ export class MenuItem {
constructor(id: string, title: string, url: string, route: string, needsAuthorization: boolean, entitiesRequired: string[],
routeRequired: string[], params, icon: Icon = null, fragment = null, customClass = null, routeActive = null,
target: string = "_blank", type: string = "internal", isFeatured: boolean = false) {
target: string = "_blank", type: string = "internal", isFeatured: boolean = false, items: MenuItem[] = []) {
this._id = id;
this.title = title;
this.url = url;
@ -34,7 +34,7 @@ export class MenuItem {
this.entitiesRequired = entitiesRequired;
this.routeRequired = routeRequired;
this.params = params;
this.items = [];
this.items = items;
this.icon = icon;
this.fragment = fragment;
this.customClass = customClass;
@ -80,30 +80,6 @@ export class Menu {
menuItems: MenuItemExtended[] = [];
}
/**
* @deprecated
* */
export class RootMenuItem {
rootItem: MenuItem;
items: MenuItem[] = [];
public static isTheActiveRootMenu(menu: RootMenuItem, currentRoute: string): boolean {
if (currentRoute == menu.rootItem.route) {
return true;
} else if (menu.items.length > 0) {
for (let menuItem of menu.items) {
let isActive = MenuItem.isTheActiveMenu(menuItem, currentRoute);
if (isActive) {
return true;
}
}
return false;
}
}
}
export class SideMenuItem {
rootItem: MenuItem;
items: RootMenuItem[] = [];
export class SideMenuItem extends MenuItem {
ukIcon: string = '';
}

View File

@ -36,19 +36,19 @@
<a routerLink="/" (click)="closeCanvas(canvas)">Home</a>
</li>
<li [class.uk-active]="isTheActiveMenu(menu)"
*ngIf="isAtleastOneEnabled(menu.rootItem.entitiesRequired,showEntity) && isAtleastOneEnabled(menu.rootItem.routeRequired, showPage)">
*ngIf="isAtleastOneEnabled(menu.entitiesRequired,showEntity) && isAtleastOneEnabled(menu.routeRequired, showPage)">
<!--a routerLink="{{menu.rootItem.route}}" [queryParams]=menu.rootItem.params class="uk-offcanvas-close custom-offcanvas-close">{{menu.rootItem.title}}</a-->
<a *ngIf="menu.rootItem.route.length > 0 && (isEnabled([menu.rootItem.route], showPage) || !menu.rootItem.routeRequired)"
routerLink="{{menu.rootItem.route}}" (click)="closeCanvas(canvas)"
[queryParams]="menu.rootItem.params"
[fragment]="menu.rootItem.fragment">{{menu.rootItem.title}}</a>
<a *ngIf="menu.rootItem.route.length == 0 && menu.rootItem.url.length > 0"
href="{{menu.rootItem.url}}" (click)="closeCanvas(canvas)" [class.custom-external]="menu.rootItem.target != '_self'"
target="{{menu.rootItem.target}}">{{menu.rootItem.title}}</a>
<a *ngIf="(menu.rootItem.route.length == 0 && menu.rootItem.url.length == 0) ||
(menu.rootItem.route.length >0 && menu.rootItem.routeRequired && !isEnabled([menu.rootItem.route], showPage)
&& isAtleastOneEnabled(menu.rootItem.routeRequired, showPage))"
(click)="closeCanvas(canvas)">{{menu.rootItem.title}}</a>
<a *ngIf="menu.route.length > 0 && (isEnabled([menu.route], showPage) || !menu.routeRequired)"
routerLink="{{menu.route}}" (click)="closeCanvas(canvas)"
[queryParams]="menu.params"
[fragment]="menu.fragment">{{menu.title}}</a>
<a *ngIf="menu.route.length == 0 && menu.url.length > 0"
href="{{menu.url}}" (click)="closeCanvas(canvas)" [class.custom-external]="menu.target != '_self'"
target="{{menu.target}}">{{menu.title}}</a>
<a *ngIf="(menu.route.length == 0 && menu.url.length == 0) ||
(menu.route.length >0 && menu.routeRequired && !isEnabled([menu.route], showPage)
&& isAtleastOneEnabled(menu.routeRequired, showPage))"
(click)="closeCanvas(canvas)">{{menu.title}}</a>
<ul class="uk-nav-sub">
<ng-container *ngFor="let submenu of menu.items">
<li [class.uk-active]="isTheActiveMenu(submenu)"
@ -131,16 +131,16 @@
</li>
<ng-container *ngFor="let menu of menuItems">
<li class="uk-parent" [class.uk-active]="isTheActiveMenu(menu)"
*ngIf="isAtleastOneEnabled(menu.rootItem.entitiesRequired,showEntity) && isAtleastOneEnabled(menu.rootItem.routeRequired, showPage)">
*ngIf="isAtleastOneEnabled(menu.entitiesRequired,showEntity) && isAtleastOneEnabled(menu.routeRequired, showPage)">
<!--a routerLink="{{menu.rootItem.route}}" [queryParams]=menu.rootItem.params class="" aria-expanded="false">{{menu.rootItem.title}}</a-->
<a *ngIf="menu.rootItem.route.length > 0 && (isEnabled([menu.rootItem.route], showPage) || !menu.rootItem.routeRequired )"
routerLink="{{menu.rootItem.route}}"
[queryParams]="menu.rootItem.params"
[fragment]="menu.rootItem.fragment"> {{menu.rootItem.title}}</a>
<a *ngIf="menu.rootItem.route.length == 0 && menu.rootItem.url.length > 0"
href="{{menu.rootItem.url}}" target="{{menu.rootItem.target}}"
[class.custom-external]="menu.rootItem.target != '_self'">{{menu.rootItem.title}}</a>
<a *ngIf="(menu.rootItem.route.length == 0 && menu.rootItem.url.length == 0) || ( menu.rootItem.route.length >0 && menu.rootItem.routeRequired && !isEnabled([menu.rootItem.route], showPage) && isAtleastOneEnabled(menu.rootItem.routeRequired, showPage))">{{menu.rootItem.title}}</a>
<a *ngIf="menu.route.length > 0 && (isEnabled([menu.route], showPage) || !menu.routeRequired )"
routerLink="{{menu.route}}"
[queryParams]="menu.params"
[fragment]="menu.fragment"> {{menu.title}}</a>
<a *ngIf="menu.route.length == 0 && menu.url.length > 0"
href="{{menu.url}}" target="{{menu.target}}"
[class.custom-external]="menu.target != '_self'">{{menu.title}}</a>
<a *ngIf="(menu.route.length == 0 && menu.url.length == 0) || ( menu.route.length >0 && menu.routeRequired && !isEnabled([menu.route], showPage) && isAtleastOneEnabled(menu.routeRequired, showPage))">{{menu.title}}</a>
<div *ngIf="menu.items.length > 0" class="uk-navbar-dropdown uk-navbar-dropdown-bottom-left uk-height-max-medium uk-overflow-auto">
<!-- Do not delete this div, because it will remove the margin bottom of navbar -->
<div>

View File

@ -2,7 +2,7 @@ import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Session, User} from '../login/utils/helper.class';
import {ConfigurationService} from '../utils/configuration/configuration.service';
import {MenuItem, RootMenuItem} from './menu';
import {MenuItem} from './menu';
import {EnvProperties} from '../utils/properties/env-properties';
import {Subscription} from 'rxjs';
import {HelpContentService} from '../services/help-content.service';
@ -38,7 +38,7 @@ export class NavigationBarComponent implements OnInit, OnDestroy {
@Input() communityId;
@Input() showCommunityName: boolean = false;
@Input() userMenuItems: MenuItem[];
@Input() menuItems: RootMenuItem [];
@Input() menuItems: MenuItem[];
@Input() header: Header;
@Input() showMenu: boolean = true;
@Input() homeurl: boolean = true;
@ -182,13 +182,13 @@ export class NavigationBarComponent implements OnInit, OnDestroy {
}
}
isTheActiveMenu(menu: MenuItem | RootMenuItem): boolean {
if(menu instanceof MenuItem || !menu.rootItem) {
isTheActiveMenu(menu: MenuItem): boolean {
// if(menu instanceof MenuItem) {
return MenuItem.isTheActiveMenu(<MenuItem> menu, this.currentRoute, this.layoutService.activeMenuItem);
} else {
let item: MenuItem = menu.rootItem;
item.items = menu.items;
return MenuItem.isTheActiveMenu(item, this.currentRoute, this.layoutService.activeMenuItem);
}
// } else {
// let item: MenuItem = menu.rootItem;
// item.items = menu.items;
// return MenuItem.isTheActiveMenu(item, this.currentRoute, this.layoutService.activeMenuItem);
// }
}
}