openaire-library/dashboard/sharedComponents/sidebar/sideBar.component.ts

68 lines
2.1 KiB
TypeScript

import {Component, Input, OnInit} from '@angular/core';
import {MenuItem} from "../../../sharedComponents/menu";
import {Router} from "@angular/router";
import {DomSanitizer} from "@angular/platform-browser";
import {properties} from "../../../../../environments/environment";
import {LayoutService} from "./layout.service";
@Component({
selector: 'dashboard-sidebar',
templateUrl: 'sideBar.component.html'
})
export class SideBarComponent implements OnInit {
@Input() items: MenuItem[] = [];
@Input() logoLabel: string;
@Input() headerName: string;
@Input() headerPosition: "left" | "center" | "right" = "center";
@Input() headerLogoUrl: string;
@Input() headerUrl: string;
@Input() showHeader: boolean = true;
@Input() activeItem: string = '';
@Input() activeSubItem: string = '';
@Input() specialMenuItem: MenuItem = null;
@Input() searchParams = {};
@Input() queryParamsHandling = "";
properties;
constructor(private router: Router, private sanitizer: DomSanitizer, private layoutService: LayoutService) {
this.properties = properties;
}
ngOnInit(): void {
}
isTheActiveMenuItem(item: MenuItem, subItem: MenuItem = null): boolean {
if (this.activeItem || this.activeSubItem) {
return (!subItem && this.activeItem === item._id) ||
(subItem && this.activeItem === item._id && this.activeSubItem === subItem._id);
} else {
if (subItem) {
return MenuItem.isTheActiveMenu(subItem, this.router.url.split('?')[0]) || MenuItem.isTheActiveMenu(subItem, this.router.url.split('#')[0]);
}
return MenuItem.isTheActiveMenu(item,this.router.url.split('?')[0]) || MenuItem.isTheActiveMenu(item,this.router.url.split('#')[0]);
}
}
isTheActiveUrl(menuItemURL): boolean {
return (menuItemURL == this.router.url.split('?')[0])
}
satinizeHTML(html) {
return this.sanitizer.bypassSecurityTrustHtml(html);
}
public get isSmallScreen() {
return this.layoutService.isSmallScreen;
}
public get open() {
return this.layoutService.open;
}
public toggleOpen(event: MouseEvent) {
event.preventDefault();
this.layoutService.setOpen(!this.open);
}
}