multi-project/projects/app/_modules/administration/page/administration-page.compone...

46 lines
1.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import {Component} from '@angular/core';
import {ActivatedRoute, NavigationEnd, Router} from "@angular/router";
import {Subscription} from "rxjs";
import {AuthenticationService} from "@app/_services";
@Component({
templateUrl: 'administration-page.component.html',
styleUrls: ['administration-page.component.scss']
})
export class AdministrationPageComponent {
public tabs = <any>[];
routeSubscription: Subscription;
constructor(private route: ActivatedRoute, private router: Router, private authService: AuthenticationService) {
this.routeSubscription = this.router.events.subscribe(event => {
if (event instanceof NavigationEnd && (this.route.snapshot.paramMap.get('tab') !== this.tab?.name)) this.switchTab(this.route.snapshot.paramMap.get('tab'));
});
}
get tab() {
return this.tabs.filter(tab => {return tab.active})[0];
}
ngOnInit() {
this.authService.user.subscribe(val => {
this.makeTabs();
});
}
ngOnDestroy() {
this.routeSubscription?.unsubscribe();
}
makeTabs() {
//this.tabs = [{name: 'company', title: 'Структура ФАУ «ФЦС»'}, {name: 'committee', title: 'Структура ТК 465'}];
//if (this.authService.isSuperAdmin) this.tabs.push({name: 'site-pages', title: 'Структура сайта'});
this.tabs = [{name: 'site-pages', title: 'Структура сайта'}];
this.switchTab(this.route.snapshot.paramMap.get('tab'));
}
switchTab(name: string) {
this.tabs.map(tab => {tab.active = tab.name === name});
}
}