83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import { Component, ComponentRef, EmbeddedViewRef, OnInit, Type, ViewContainerRef } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { DialogService } from 'primeng/dynamicdialog';
|
|
import {Toast} from "primeng/toast";
|
|
import { ExitComponentComponent } from './components/exit-component/exit-component.component';
|
|
import { CookiesService } from './services/cookies.service';
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.scss'],
|
|
providers: [DialogService],
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
public opened: boolean = false;
|
|
public isAuth!: boolean;
|
|
private messageComponent!: ComponentRef<Toast>;
|
|
title = 'selfdelivery-admin-panel';
|
|
|
|
constructor(
|
|
private cookiesService: CookiesService,
|
|
private viewContainerRef: ViewContainerRef,
|
|
public dialogService: DialogService,
|
|
private router: Router,
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
this.messageComponent = this.appendComponent(Toast);
|
|
const token = decodeURI(this.cookiesService.getItem('token') ?? '')
|
|
this.isAuth = token.length ? true : false;
|
|
this.router.navigate(['/clients'])
|
|
}
|
|
|
|
|
|
appendComponent<C>(component: Type<C>): ComponentRef<C> {
|
|
const componentRef = this.viewContainerRef.createComponent(component);
|
|
const domElem = (componentRef.hostView as EmbeddedViewRef<any>)
|
|
.rootNodes[0] as HTMLElement;
|
|
document.body.appendChild(domElem);
|
|
return componentRef;
|
|
}
|
|
|
|
openSidenav() {
|
|
this.opened = true
|
|
}
|
|
|
|
setIsAuth() {
|
|
const token = decodeURI(this.cookiesService.getItem('token') ?? '')
|
|
this.isAuth = token.length ? true : false;
|
|
}
|
|
|
|
signOut() {
|
|
const ref = this.dialogService.open(ExitComponentComponent, {
|
|
width: 'auto',
|
|
style: {
|
|
'max-width': '90vw',
|
|
'max-height': '90vh',
|
|
},
|
|
contentStyle: {
|
|
'max-height': '90vh',
|
|
height: 'auto',
|
|
'max-width': '90vw',
|
|
overflow: 'auto',
|
|
'border-radius': '7px',
|
|
'padding-top': '20px'
|
|
},
|
|
baseZIndex: 10000,
|
|
autoZIndex: true,
|
|
dismissableMask: true,
|
|
closeOnEscape: true,
|
|
showHeader: false,
|
|
});
|
|
ref.onClose.subscribe(
|
|
result => {
|
|
if (result) {
|
|
this.cookiesService.deleteCookie('token')
|
|
this.setIsAuth()
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|