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

87 lines
2.8 KiB
TypeScript

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, ActivatedRoute, NavigationExtras, NavigationEnd } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { LanguageResolverService } from './services/language-resolver/language-resolver.service';
import { BreadCrumbResolverService } from './services/breadcrumb/breadcrumb-resolver.service';
import { Observable } from 'rxjs/Observable';
import { AuthService } from './services/auth/auth.service';
import { CultureService } from './utilities/culture/culture-service';
import { environment } from '../environments/environment';
declare const gapi: any;
declare var $: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
providers: [],
encapsulation: ViewEncapsulation.None
})
export class AppComponent implements OnInit {
hasBreadCrumb = Observable.of(false);
sideNavOpen = false;
constructor(
private router: Router,
private route: ActivatedRoute,
private authentication: AuthService,
private translate: TranslateService,
private languageService: LanguageResolverService,
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(['/dmps'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
}
goToProjects() {
this.router.navigate(['/projects'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
}
initializeServices() {
// this language will be used as a fallback when a translation isn't found in the current language
this.translate.setDefaultLang('en');
this.authentication.current() && this.authentication.current().culture ? this.cultureService.cultureSelected(this.authentication.current().culture) : this.cultureService.cultureSelected(environment.defaultCulture);
//this.setupChangeListeners();
}
}