2020-10-29 15:20:41 +01:00
|
|
|
import {Component, Input, OnInit} from '@angular/core';
|
2019-12-23 13:52:26 +01:00
|
|
|
import {MenuItem} from "../../../sharedComponents/menu";
|
2022-03-28 10:40:21 +02:00
|
|
|
import {ActivatedRoute, QueryParamsHandling, Router} from "@angular/router";
|
2020-06-11 18:59:00 +02:00
|
|
|
import {DomSanitizer} from "@angular/platform-browser";
|
|
|
|
import {properties} from "../../../../../environments/environment";
|
2020-10-12 14:39:42 +02:00
|
|
|
import {LayoutService} from "./layout.service";
|
2019-12-23 13:52:26 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'dashboard-sidebar',
|
|
|
|
templateUrl: 'sideBar.component.html'
|
|
|
|
})
|
|
|
|
export class SideBarComponent implements OnInit {
|
|
|
|
@Input() items: MenuItem[] = [];
|
|
|
|
@Input() activeItem: string = '';
|
|
|
|
@Input() activeSubItem: string = '';
|
2020-10-29 15:20:41 +01:00
|
|
|
@Input() specialMenuItem: MenuItem = null;
|
2022-03-17 12:28:25 +01:00
|
|
|
@Input() queryParamsHandling;
|
2020-06-11 18:59:00 +02:00
|
|
|
properties;
|
2020-10-29 15:20:41 +01:00
|
|
|
|
2022-03-28 10:40:21 +02:00
|
|
|
constructor(private route: ActivatedRoute, private router: Router, private sanitizer: DomSanitizer, private layoutService: LayoutService) {
|
2020-06-11 18:59:00 +02:00
|
|
|
this.properties = properties;
|
|
|
|
}
|
2020-10-29 15:20:41 +01:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
}
|
2022-03-28 10:40:21 +02:00
|
|
|
|
|
|
|
get currentRoute() {
|
|
|
|
return {
|
|
|
|
route: this.router.url.split('?')[0].split('#')[0],
|
|
|
|
fragment: this.route.snapshot.fragment
|
|
|
|
}
|
|
|
|
}
|
2020-10-29 15:20:41 +01:00
|
|
|
|
2022-03-17 12:28:25 +01:00
|
|
|
get activeIndex(): number {
|
|
|
|
return this.items?this.items.findIndex(item => this.isTheActiveMenuItem(item)):0;
|
|
|
|
}
|
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
isTheActiveMenuItem(item: MenuItem, subItem: MenuItem = null): boolean {
|
2020-10-29 15:20:41 +01:00
|
|
|
if (this.activeItem || this.activeSubItem) {
|
2022-01-05 15:41:49 +01:00
|
|
|
return (!subItem && this.activeItem === item._id) ||
|
|
|
|
(subItem && this.activeItem === item._id && this.activeSubItem === subItem._id);
|
2020-10-29 15:20:41 +01:00
|
|
|
} else {
|
|
|
|
if (subItem) {
|
2022-03-28 10:40:21 +02:00
|
|
|
return MenuItem.isTheActiveMenu(subItem, this.currentRoute);
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
2022-03-28 10:40:21 +02:00
|
|
|
return MenuItem.isTheActiveMenu(item,this.currentRoute);
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 15:20:41 +01:00
|
|
|
|
2020-07-13 11:15:00 +02:00
|
|
|
isTheActiveUrl(menuItemURL): boolean {
|
|
|
|
return (menuItemURL == this.router.url.split('?')[0])
|
|
|
|
}
|
2020-10-29 15:20:41 +01:00
|
|
|
|
|
|
|
satinizeHTML(html) {
|
2020-06-11 18:59:00 +02:00
|
|
|
return this.sanitizer.bypassSecurityTrustHtml(html);
|
|
|
|
}
|
2020-10-29 15:20:41 +01:00
|
|
|
|
2020-10-12 14:39:42 +02:00
|
|
|
public get isSmallScreen() {
|
|
|
|
return this.layoutService.isSmallScreen;
|
|
|
|
}
|
2020-10-29 15:20:41 +01:00
|
|
|
|
2020-10-12 14:39:42 +02:00
|
|
|
public get open() {
|
|
|
|
return this.layoutService.open;
|
|
|
|
}
|
2020-10-29 15:20:41 +01:00
|
|
|
|
2020-10-12 14:39:42 +02:00
|
|
|
public toggleOpen(event: MouseEvent) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.layoutService.setOpen(!this.open);
|
|
|
|
}
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|