78 lines
2.4 KiB
TypeScript
78 lines
2.4 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';
|
|
|
|
|
|
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
|
|
) {
|
|
// this language will be used as a fallback when a translation isn't found in the current language
|
|
translate.setDefaultLang('en');
|
|
// the lang to use, if the lang isn't available, it will use the current loader to get them
|
|
translate.use('en');
|
|
}
|
|
|
|
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*/ } });
|
|
}
|
|
}
|
|
|