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

87 lines
2.8 KiB
TypeScript
Raw Normal View History

2017-12-19 18:34:00 +01:00
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2018-06-28 11:28:16 +02:00
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, ActivatedRoute, NavigationExtras, NavigationEnd } from '@angular/router';
2017-12-14 11:41:26 +01:00
import { TranslateService } from '@ngx-translate/core';
2018-03-28 15:24:47 +02:00
import { LanguageResolverService } from './services/language-resolver/language-resolver.service';
2018-06-27 12:29:21 +02:00
import { BreadCrumbResolverService } from './services/breadcrumb/breadcrumb-resolver.service';
2018-06-28 11:28:16 +02:00
import { Observable } from 'rxjs/Observable';
2018-07-23 15:09:19 +02:00
import { AuthService } from './services/auth/auth.service';
2018-08-30 13:09:36 +02:00
import { CultureService } from './utilities/culture/culture-service';
import { environment } from '../environments/environment';
2017-11-08 14:33:14 +01:00
declare const gapi: any;
2017-11-08 14:33:14 +01:00
2017-12-19 18:34:00 +01:00
declare var $: any;
@Component({
selector: 'app-root',
2017-11-01 18:18:27 +01:00
templateUrl: './app.component.html',
2017-12-19 18:34:00 +01:00
styleUrls: ['./app.component.scss'],
providers: [],
2017-12-11 09:10:54 +01:00
encapsulation: ViewEncapsulation.None
})
2017-11-02 15:19:12 +01:00
export class AppComponent implements OnInit {
2017-11-14 15:06:00 +01:00
2018-06-28 11:28:16 +02:00
hasBreadCrumb = Observable.of(false);
2018-06-29 10:29:43 +02:00
sideNavOpen = false;
2018-07-23 15:09:19 +02:00
2018-06-27 12:29:21 +02:00
constructor(
private router: Router,
private route: ActivatedRoute,
2018-07-23 15:09:19 +02:00
private authentication: AuthService,
2018-06-27 12:29:21 +02:00
private translate: TranslateService,
private languageService: LanguageResolverService,
2018-08-30 13:09:36 +02:00
private breadCrumbResolverService: BreadCrumbResolverService,
private cultureService: CultureService
2018-06-27 12:29:21 +02:00
) {
2018-08-30 13:09:36 +02:00
this.initializeServices()
2017-11-01 18:18:27 +01:00
}
2018-06-27 12:29:21 +02:00
onActivate(event: any) {
this.breadCrumbResolverService.push(event)
}
onDeactivate(event: any) {
//this.breadCrumbResolverService.clear()
}
2017-11-02 15:19:12 +01:00
ngOnInit() {
2018-06-28 11:28:16 +02:00
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'])
}
2017-12-19 18:34:00 +01:00
login() {
2017-11-01 18:18:27 +01:00
//redirect to login page
2017-12-19 18:34:00 +01:00
this.router.navigate(['/login'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
2017-11-01 18:18:27 +01:00
}
2017-12-19 18:34:00 +01:00
logout() {
2017-11-01 18:18:27 +01:00
2017-11-13 18:13:49 +01:00
}
2018-07-23 15:09:19 +02:00
public isAuthenticated(): boolean {
return !(!this.authentication.current())
}
2017-12-19 18:34:00 +01:00
goToDMPs() {
this.router.navigate(['/dmps'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
2017-11-13 18:13:49 +01:00
}
2017-12-19 18:34:00 +01:00
goToProjects() {
this.router.navigate(['/projects'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
}
2018-08-30 13:09:36 +02:00
initializeServices() {
// this language will be used as a fallback when a translation isn't found in the current language
this.translate.setDefaultLang('en');
2018-08-31 10:14:56 +02:00
this.authentication.current() ? this.cultureService.cultureSelected(this.authentication.current().culture) : this.cultureService.cultureSelected(environment.defaultCulture);
2018-08-30 13:09:36 +02:00
//this.setupChangeListeners();
}
}
2017-11-01 18:18:27 +01:00