argos/dmp-frontend/src/app/app.component.ts

80 lines
2.4 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { environment } from '../environments/environment';
import { AuthService } from './core/services/auth/auth.service';
import { CultureService } from './core/services/culture/culture-service';
import { BreadCrumbResolverService } from './ui/misc/breadcrumb/service/breadcrumb.service';
declare const gapi: any;
declare var $: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
hasBreadCrumb = Observable.of(false);
sideNavOpen = false;
helpContentEnabled = environment.HelpService.Enabled;
constructor(
private router: Router,
private route: ActivatedRoute,
private authentication: AuthService,
private translate: TranslateService,
private breadCrumbResolverService: BreadCrumbResolverService,
private cultureService: CultureService
) {
this.initializeServices();
}
onActivate(event: any) {
this.breadCrumbResolverService.push(event);
}
onDeactivate(event: any) {
//this.breadCrumbResolverService.clear()
}
ngOnInit() {
this.hasBreadCrumb = this.router.events
.filter(event => event instanceof NavigationEnd)
.map(() => this.route)
.map(route => route.firstChild)
.switchMap(route => route.data)
.map(data => data['breadcrumb']);
}
login() {
//redirect to login page
this.router.navigate(['/login'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
}
logout() {
}
public isAuthenticated(): boolean {
return !(!this.authentication.current());
}
goToDMPs() {
this.router.navigate(['/plans'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
}
goToProjects() {
this.router.navigate(['/projects'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
}
initializeServices() {
this.translate.setDefaultLang('en');
this.authentication.current() && this.authentication.current().culture ? this.cultureService.cultureSelected(this.authentication.current().culture) : this.cultureService.cultureSelected(environment.defaultCulture);
}
}