60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import {Component} from '@angular/core';
|
|
import {MatCard} from "@angular/material/card";
|
|
import {MatSidenavModule} from "@angular/material/sidenav";
|
|
import {HasRoleDirective} from "@/directives/has-role.directive";
|
|
import {Router, RouterOutlet} from "@angular/router";
|
|
import AuthApiService from "@api/v1/authApi.service";
|
|
import {MatListItem, MatNavList} from "@angular/material/list";
|
|
import {AuthRoles} from "@model/authRoles";
|
|
import {MatIcon} from "@angular/material/icon";
|
|
|
|
@Component({
|
|
selector: 'app-admin',
|
|
standalone: true,
|
|
imports: [
|
|
MatCard,
|
|
HasRoleDirective,
|
|
MatNavList,
|
|
MatSidenavModule,
|
|
RouterOutlet,
|
|
MatListItem,
|
|
MatIcon,
|
|
],
|
|
templateUrl: './admin.component.html',
|
|
styleUrl: './admin.component.css',
|
|
providers: [AuthApiService]
|
|
})
|
|
export class AdminComponent {
|
|
navLinks = [
|
|
{label: 'Расписание', route: 'schedule', icon: 'calendar_month'},
|
|
{label: 'Институт', route: 'institute', icon: 'school'},
|
|
{label: 'Аккаунт', route: 'account', icon: 'person'},
|
|
{label: 'Сервер', route: 'server', icon: 'settings'},
|
|
];
|
|
|
|
constructor(private auth: AuthApiService, private router: Router) {
|
|
this.auth.getRole()
|
|
.subscribe(data => {
|
|
if (data === null)
|
|
router.navigate(['login']).then();
|
|
});
|
|
}
|
|
|
|
isActive(route: string): boolean {
|
|
return this.router.isActive(`/admin/${route}`, {
|
|
paths: 'exact',
|
|
queryParams: 'ignored',
|
|
fragment: 'ignored',
|
|
matrixParams: 'ignored',
|
|
});
|
|
}
|
|
|
|
navigate(route: string): void {
|
|
if (!this.isActive(route)) {
|
|
this.router.navigate([`/admin/${route}`]).then();
|
|
}
|
|
}
|
|
|
|
protected readonly AuthRoles = AuthRoles;
|
|
}
|