2023-08-20 22:54:12 +02:00
|
|
|
import { Component, OnInit, Output, EventEmitter, HostListener } from '@angular/core';
|
2023-08-17 18:51:39 +02:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { ApiService } from '../../services/api.service';
|
|
|
|
import { MenuGroup } from '../../interfaces/services.interface';
|
2023-08-20 08:11:55 +02:00
|
|
|
import { StorageService } from '../../services/storage.service';
|
2023-08-20 22:53:33 +02:00
|
|
|
import { Router } from '@angular/router';
|
2023-08-17 18:51:39 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-menu',
|
|
|
|
templateUrl: './menu.component.html',
|
|
|
|
styleUrls: ['./menu.component.scss']
|
|
|
|
})
|
|
|
|
|
|
|
|
export class MenuComponent implements OnInit {
|
2023-08-20 22:53:33 +02:00
|
|
|
@Output() loggedOut = new EventEmitter<boolean>();
|
|
|
|
|
2023-08-18 17:56:07 +02:00
|
|
|
navOpen: boolean = false;
|
2023-08-17 18:51:39 +02:00
|
|
|
userMenuGroups$: Observable<MenuGroup[]> | undefined;
|
2023-08-18 18:04:40 +02:00
|
|
|
userAuth: any | undefined;
|
2023-08-20 22:53:33 +02:00
|
|
|
isServices = false;
|
2023-08-17 18:51:39 +02:00
|
|
|
|
|
|
|
constructor(
|
2023-08-20 08:11:55 +02:00
|
|
|
private apiService: ApiService,
|
2023-08-20 22:53:33 +02:00
|
|
|
private storageService: StorageService,
|
|
|
|
private router: Router
|
2023-08-17 18:51:39 +02:00
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2023-08-20 08:11:55 +02:00
|
|
|
this.userAuth = this.storageService.getAuth();
|
2023-08-17 18:51:39 +02:00
|
|
|
this.userMenuGroups$ = this.apiService.getUserMenuGroups$();
|
2023-08-20 22:53:33 +02:00
|
|
|
|
|
|
|
this.isServices = this.router.url.includes('/services/');
|
|
|
|
this.navOpen = this.isServices && !this.isSmallScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
isSmallScreen() {
|
|
|
|
return window.innerWidth <= 767.98;
|
2023-08-17 18:51:39 +02:00
|
|
|
}
|
2023-08-17 22:13:06 +02:00
|
|
|
|
|
|
|
logout(): void {
|
2023-08-18 17:56:07 +02:00
|
|
|
this.apiService.logout$().subscribe();
|
2023-08-18 18:33:09 +02:00
|
|
|
this.loggedOut.emit(true);
|
2023-08-18 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
2023-08-20 22:53:33 +02:00
|
|
|
onLinkClick() {
|
|
|
|
if (!this.isServices || this.isSmallScreen()) {
|
|
|
|
this.navOpen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 17:56:07 +02:00
|
|
|
hambugerClick() {
|
|
|
|
this.navOpen = !this.navOpen;
|
2023-08-17 22:13:06 +02:00
|
|
|
}
|
2023-08-20 22:54:12 +02:00
|
|
|
|
|
|
|
@HostListener('window:resize', ['$event'])
|
|
|
|
onResize(event) {
|
|
|
|
if (this.isServices) {
|
|
|
|
this.navOpen = !this.isSmallScreen();
|
|
|
|
}
|
|
|
|
}
|
2023-08-17 18:51:39 +02:00
|
|
|
}
|