we_bstly-web/src/app/app.component.ts

80 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-03-11 19:52:37 +01:00
import {Component, HostListener} from '@angular/core';
2020-11-02 08:29:52 +01:00
2021-03-11 19:52:37 +01:00
import {AuthService} from './services/auth.service';
import {I18nService} from './services/i18n.service';
import {Router} from '@angular/router';
import {DomSanitizer} from '@angular/platform-browser';
import {MatIconRegistry} from '@angular/material/icon';
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
2020-11-02 08:29:52 +01:00
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
opened = true;
title = 'we.bstly';
currentLocale: String;
2021-01-12 19:29:00 +01:00
locales;
2020-11-02 08:29:52 +01:00
auth;
2021-03-11 19:52:37 +01:00
constructor(private i18n: I18nService, private authService: AuthService, private router: Router, private iconRegistry: MatIconRegistry, private sanitizer: DomSanitizer, private _adapter: DateAdapter<any>) {
2021-03-18 15:12:30 +01:00
iconRegistry.addSvgIcon('logo', sanitizer.bypassSecurityTrustResourceUrl('assets/icons/logo.svg'));
}
ngOnInit() {
2020-11-02 08:29:52 +01:00
this.currentLocale = this.i18n.getLocale();
2021-01-12 19:29:00 +01:00
this.locales = this.i18n.getLocales();
2020-11-02 08:29:52 +01:00
this.authService.auth.subscribe(data => {
this.auth = data;
})
2021-03-11 19:52:37 +01:00
this._adapter.setLocale(this.currentLocale);
2020-11-02 08:29:52 +01:00
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
2021-03-11 19:52:37 +01:00
if(width < 768) {
2020-11-02 08:29:52 +01:00
this.opened = false;
} else {
this.opened = true;
}
}
setLocale(locale) {
localStorage.setItem("bstly.locale", locale);
window.location.reload();
}
logout() {
this.authService.logout().subscribe(data => {
2021-03-11 19:52:37 +01:00
this.router.navigate([""]).then(() => {
window.location.reload();
});
2020-11-02 08:29:52 +01:00
})
}
isBiggerScreen() {
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
2021-03-11 19:52:37 +01:00
if(width < 768) {
2020-11-02 08:29:52 +01:00
return false;
} else {
return true;
}
}
2021-03-14 20:33:34 +01:00
openExternal(url) {
window.open(url, '_blank');
}
2020-11-02 08:29:52 +01:00
@HostListener('window:resize', ['$event'])
onResize(event) {
2021-03-11 19:52:37 +01:00
if(event.target.innerWidth < 768) {
2020-11-02 08:29:52 +01:00
this.opened = false;
} else {
this.opened = true;
}
}
}