2021-07-04 01:33:58 +00:00
|
|
|
import { Component, OnInit, Renderer2, ViewChild, ElementRef, Directive } from '@angular/core';
|
|
|
|
// import { ROUTES } from '../.././sidebar/sidebar.component';
|
|
|
|
import { Router, ActivatedRoute, NavigationEnd, NavigationStart } from '@angular/router';
|
|
|
|
import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';
|
|
|
|
import { Subscription } from 'rxjs';
|
2021-07-04 02:37:04 +00:00
|
|
|
import { Account } from 'app/core/auth/account.model';
|
2021-07-04 01:33:58 +00:00
|
|
|
|
|
|
|
var misc: any = {
|
|
|
|
navbar_menu_visible: 0,
|
|
|
|
active_collapse: true,
|
|
|
|
disabled_collapse_init: 0,
|
|
|
|
};
|
2021-07-03 21:48:27 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'jhi-navbar',
|
|
|
|
templateUrl: './navbar.component.html',
|
|
|
|
styleUrls: ['./navbar.component.scss'],
|
|
|
|
})
|
|
|
|
export class NavbarComponent implements OnInit {
|
2021-07-04 01:33:58 +00:00
|
|
|
private listTitles: any[] = [];
|
|
|
|
location: Location;
|
|
|
|
private nativeElement: Node;
|
|
|
|
private toggleButton: any;
|
|
|
|
private sidebarVisible: boolean;
|
|
|
|
// private _router: Subscription;
|
|
|
|
public open: boolean = false;
|
2021-07-04 02:37:04 +00:00
|
|
|
account: Account | null = null;
|
2021-07-04 01:33:58 +00:00
|
|
|
|
|
|
|
@ViewChild('jhi-navbar', { static: false }) button: any;
|
|
|
|
|
|
|
|
constructor(location: Location, private renderer: Renderer2, private element: ElementRef, private router: Router) {
|
|
|
|
this.location = location;
|
|
|
|
this.nativeElement = element.nativeElement;
|
|
|
|
this.sidebarVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
// this.listTitles = ROUTES.filter(listTitle => listTitle);
|
|
|
|
|
|
|
|
const navbar: HTMLElement = this.element.nativeElement;
|
|
|
|
const body = document.getElementsByTagName('body')[0];
|
|
|
|
this.toggleButton = navbar.getElementsByClassName('navbar-toggler')[0];
|
|
|
|
if (body.classList.contains('sidebar-mini')) {
|
|
|
|
misc.sidebar_mini_active = true;
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
2021-07-04 01:33:58 +00:00
|
|
|
// this._router = this.router.events.filter(event => event instanceof NavigationEnd).subscribe((event: NavigationEnd) => {
|
|
|
|
// const $layer = document.getElementsByClassName('close-layer')[0];
|
|
|
|
// if ($layer) {
|
|
|
|
// $layer.remove();
|
|
|
|
// }
|
|
|
|
// });
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 01:33:58 +00:00
|
|
|
minimizeSidebar() {
|
|
|
|
const body = document.getElementsByTagName('body')[0];
|
|
|
|
|
|
|
|
if (misc.sidebar_mini_active === true) {
|
|
|
|
body.classList.remove('sidebar-mini');
|
|
|
|
misc.sidebar_mini_active = false;
|
|
|
|
} else {
|
|
|
|
setTimeout(function () {
|
|
|
|
body.classList.add('sidebar-mini');
|
|
|
|
|
|
|
|
misc.sidebar_mini_active = true;
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we simulate the window Resize so the charts will get updated in realtime.
|
|
|
|
const simulateWindowResize = setInterval(function () {
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
}, 180);
|
|
|
|
|
|
|
|
// we stop the simulation of Window Resize after the animations are completed
|
|
|
|
setTimeout(function () {
|
|
|
|
clearInterval(simulateWindowResize);
|
|
|
|
}, 1000);
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 01:33:58 +00:00
|
|
|
isMobileMenu() {
|
|
|
|
if (window.outerWidth < 991) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 01:33:58 +00:00
|
|
|
sidebarOpen() {
|
|
|
|
var toggleButton = this.toggleButton;
|
|
|
|
var html = document.getElementsByTagName('html')[0];
|
|
|
|
setTimeout(function () {
|
|
|
|
toggleButton.classList.add('toggled');
|
|
|
|
}, 500);
|
|
|
|
const mainPanel = <HTMLElement>document.getElementsByClassName('main-panel')[0];
|
|
|
|
if (window.innerWidth < 991) {
|
|
|
|
mainPanel.style.position = 'fixed';
|
|
|
|
}
|
|
|
|
html.classList.add('nav-open');
|
|
|
|
this.sidebarVisible = true;
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
2021-07-04 01:33:58 +00:00
|
|
|
sidebarClose() {
|
|
|
|
var html = document.getElementsByTagName('html')[0];
|
|
|
|
this.toggleButton.classList.remove('toggled');
|
|
|
|
this.sidebarVisible = false;
|
|
|
|
html.classList.remove('nav-open');
|
|
|
|
const mainPanel = <HTMLElement>document.getElementsByClassName('main-panel')[0];
|
2021-07-03 21:48:27 +00:00
|
|
|
|
2021-07-04 01:33:58 +00:00
|
|
|
if (window.innerWidth < 991) {
|
|
|
|
setTimeout(function () {
|
|
|
|
mainPanel.style.position = '';
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sidebarToggle() {
|
|
|
|
// var toggleButton = this.toggleButton;
|
|
|
|
// var body = document.getElementsByTagName('body')[0];
|
|
|
|
if (this.sidebarVisible == false) {
|
|
|
|
this.sidebarOpen();
|
|
|
|
} else {
|
|
|
|
this.sidebarClose();
|
|
|
|
}
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 01:33:58 +00:00
|
|
|
getTitle() {
|
|
|
|
var titlee = this.location.prepareExternalUrl(this.location.path());
|
|
|
|
if (titlee.charAt(0) === '#') {
|
|
|
|
titlee = titlee.slice(1);
|
|
|
|
}
|
|
|
|
for (var item = 0; item < this.listTitles.length; item++) {
|
|
|
|
var parent = this.listTitles[item];
|
|
|
|
if (parent.path === titlee) {
|
|
|
|
return parent.title;
|
|
|
|
} else if (parent.children) {
|
|
|
|
var children_from_url = titlee.split('/')[2];
|
|
|
|
for (var current = 0; current < parent.children.length; current++) {
|
|
|
|
if (parent.children[current].path === children_from_url) {
|
|
|
|
return parent.children[current].title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 'Dashboard';
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 01:33:58 +00:00
|
|
|
getPath() {
|
|
|
|
// console.log(this.location);
|
|
|
|
return this.location.prepareExternalUrl(this.location.path());
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
|
|
|
}
|