2019-10-04 09:53:35 +02:00
|
|
|
|
2019-11-19 17:28:25 +01:00
|
|
|
import { of as observableOf, Subscription } from 'rxjs';
|
2019-10-04 09:53:35 +02:00
|
|
|
|
2020-05-27 16:19:38 +02:00
|
|
|
import { switchMap, filter, map, takeUntil } from 'rxjs/operators';
|
2021-03-05 10:05:09 +01:00
|
|
|
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
2017-12-14 11:41:26 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-08-30 13:09:36 +02:00
|
|
|
import { environment } from '../environments/environment';
|
2019-01-18 18:03:45 +01:00
|
|
|
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';
|
2019-09-16 17:46:19 +02:00
|
|
|
import { Title } from '@angular/platform-browser';
|
2019-11-19 17:28:25 +01:00
|
|
|
import { NgcCookieConsentService, NgcStatusChangeEvent } from "ngx-cookieconsent";
|
|
|
|
import { CookieService } from "ngx-cookie-service";
|
2020-01-23 17:35:11 +01:00
|
|
|
import { LanguageService } from './core/services/language/language.service';
|
2020-03-26 17:44:12 +01:00
|
|
|
import { ConfigurationService } from './core/services/configuration/configuration.service';
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2020-05-27 18:08:02 +02:00
|
|
|
import { Location } from '@angular/common';
|
2020-12-10 14:29:24 +01:00
|
|
|
import { MatomoInjector } from 'ngx-matomo';
|
|
|
|
import { MatomoService } from './core/services/matomo/matomo-service';
|
2021-03-05 10:05:09 +01:00
|
|
|
import { SideNavService } from './core/services/sidenav/side-nav.sevice';
|
2021-09-24 20:52:14 +02:00
|
|
|
import { MatSidenav } from '@angular/material/sidenav';
|
2020-05-27 18:08:02 +02:00
|
|
|
|
2017-11-08 14:33:14 +01:00
|
|
|
|
2017-11-27 11:52:52 +01:00
|
|
|
declare const gapi: any;
|
2017-12-19 18:34:00 +01:00
|
|
|
declare var $: any;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
2019-01-18 18:03:45 +01:00
|
|
|
styleUrls: ['./app.component.scss']
|
2017-09-14 12:37:36 +02:00
|
|
|
})
|
2021-03-05 10:05:09 +01:00
|
|
|
export class AppComponent implements OnInit, AfterViewInit {
|
2017-11-14 15:06:00 +01:00
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
hasBreadCrumb = observableOf(false);
|
2021-03-05 10:05:09 +01:00
|
|
|
// sideNavOpen = false;
|
|
|
|
private sideNavSubscription: Subscription;
|
2020-05-27 16:19:38 +02:00
|
|
|
helpContentEnabled: boolean;
|
2019-11-19 17:28:25 +01:00
|
|
|
private statusChangeSubscription: Subscription;
|
2020-07-03 11:45:52 +02:00
|
|
|
onlySplash = true;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
2021-09-24 20:52:14 +02:00
|
|
|
@ViewChild('sidenav') sidenav:MatSidenav;
|
2021-03-05 10:05:09 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private authentication: AuthService,
|
|
|
|
private translate: TranslateService,
|
|
|
|
private breadCrumbResolverService: BreadCrumbResolverService,
|
2019-09-16 17:46:19 +02:00
|
|
|
private titleService: Title,
|
2019-11-19 17:28:25 +01:00
|
|
|
private cultureService: CultureService,
|
|
|
|
private cookieService: CookieService,
|
2020-01-23 17:35:11 +01:00
|
|
|
private ccService: NgcCookieConsentService,
|
2020-03-26 17:44:12 +01:00
|
|
|
private language: LanguageService,
|
2020-05-27 18:08:02 +02:00
|
|
|
private configurationService: ConfigurationService,
|
2020-12-10 14:29:24 +01:00
|
|
|
private location: Location,
|
2021-03-05 10:05:09 +01:00
|
|
|
private matomoService: MatomoService,
|
|
|
|
private sidenavService: SideNavService
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
|
|
|
this.initializeServices();
|
2020-12-10 14:29:24 +01:00
|
|
|
this.matomoService.init();
|
2020-03-26 17:44:12 +01:00
|
|
|
this.helpContentEnabled = configurationService.helpService.enabled;
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2021-03-05 10:05:09 +01:00
|
|
|
ngAfterViewInit(): void {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.sideNavSubscription = this.sidenavService.status().subscribe(isopen=>{
|
2021-03-12 17:19:51 +01:00
|
|
|
const hamburger = document.getElementById('hamburger');
|
2021-03-05 10:05:09 +01:00
|
|
|
if(isopen){
|
|
|
|
//update value of hamburfer
|
2021-03-12 17:19:51 +01:00
|
|
|
if(!hamburger){//try later
|
|
|
|
setTimeout(() => {
|
|
|
|
const hamburger = document.getElementById('hamburger');
|
|
|
|
if(hamburger){
|
|
|
|
hamburger.classList.add('change');
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
}else{
|
|
|
|
hamburger.classList.add('change');
|
|
|
|
}
|
2021-03-05 10:05:09 +01:00
|
|
|
this.sidenav.open()
|
2021-03-12 17:19:51 +01:00
|
|
|
}else{//closed
|
|
|
|
if(!hamburger){//try later
|
|
|
|
setTimeout(() => {
|
|
|
|
const hamburger = document.getElementById('hamburger');
|
|
|
|
if(hamburger){
|
|
|
|
hamburger.classList.remove('change');
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
}else{
|
|
|
|
hamburger.classList.remove('change');
|
|
|
|
}
|
2021-03-05 10:05:09 +01:00
|
|
|
this.sidenav.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
onActivate(event: any) {
|
|
|
|
this.breadCrumbResolverService.push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeactivate(event: any) {
|
|
|
|
//this.breadCrumbResolverService.clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-07-03 11:45:52 +02:00
|
|
|
if (this.location.path() === '') {
|
|
|
|
if (!this.configurationService.useSplash) {
|
|
|
|
this.onlySplash = false;
|
2020-05-27 18:08:02 +02:00
|
|
|
this.router.navigate(['/reload']).then(() => this.router.navigate(['/home']));
|
2020-07-03 11:45:52 +02:00
|
|
|
} else {
|
|
|
|
this.onlySplash = true;
|
|
|
|
this.router.navigate(['/reload']).then(() => this.router.navigate(['/splash']));
|
2020-05-27 18:08:02 +02:00
|
|
|
}
|
2020-07-03 11:45:52 +02:00
|
|
|
} else if (this.location.path() === '/splash') {
|
|
|
|
this.onlySplash = true;
|
|
|
|
} else {
|
|
|
|
this.onlySplash = false;
|
2020-05-27 16:19:38 +02:00
|
|
|
}
|
2019-11-19 17:28:25 +01:00
|
|
|
if (!this.cookieService.check("cookiesConsent")) {
|
2021-03-18 13:48:58 +01:00
|
|
|
// this.cookieService.set("cookiesConsent", "false", 356);
|
|
|
|
this.cookieService.set("cookiesConsent", "false", 356,null,null,false, 'Lax');
|
|
|
|
|
2019-11-19 17:28:25 +01:00
|
|
|
}
|
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
this.hasBreadCrumb = this.router.events.pipe(
|
|
|
|
filter(event => event instanceof NavigationEnd),
|
|
|
|
map(() => this.route),
|
|
|
|
map(route => route.firstChild),
|
|
|
|
switchMap(route => route.data),
|
2019-11-19 17:28:25 +01:00
|
|
|
map(data => data['breadcrumb']));
|
2019-09-16 17:46:19 +02:00
|
|
|
|
|
|
|
const appTitle = this.titleService.getTitle();
|
|
|
|
this.router
|
|
|
|
.events.pipe(
|
|
|
|
filter(event => event instanceof NavigationEnd),
|
|
|
|
map(() => {
|
|
|
|
let child = this.route.firstChild;
|
2020-08-27 16:38:07 +02:00
|
|
|
if (child != null) {
|
|
|
|
while (child.firstChild) {
|
|
|
|
child = child.firstChild;
|
|
|
|
}
|
|
|
|
if (child.snapshot.data['title']) {
|
|
|
|
return child.snapshot.data['title'];
|
|
|
|
}
|
2019-09-16 17:46:19 +02:00
|
|
|
}
|
|
|
|
return appTitle;
|
|
|
|
})
|
|
|
|
).subscribe((ttl: string) => {
|
2020-08-07 16:14:51 +02:00
|
|
|
this.translateTitle(ttl);
|
|
|
|
this.translate.onLangChange.subscribe(() => this.translateTitle(ttl));
|
2019-09-16 17:46:19 +02:00
|
|
|
});
|
2019-11-19 17:28:25 +01:00
|
|
|
|
2019-11-20 10:04:27 +01:00
|
|
|
this.statusChangeSubscription = this.ccService.statusChange$.subscribe((event: NgcStatusChangeEvent) => {
|
|
|
|
if (event.status == "dismiss") {
|
2021-03-18 13:48:58 +01:00
|
|
|
// this.cookieService.set("cookiesConsent", "true", 365);
|
|
|
|
this.cookieService.set("cookiesConsent", "true", 356,null,null,false, 'Lax');
|
2019-11-20 10:04:27 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-25 16:52:00 +02:00
|
|
|
this.ccService.getConfig().content.href = this.configurationService.app + "cookies-policy";
|
2020-03-26 17:44:12 +01:00
|
|
|
this.ccService.getConfig().cookie.domain = this.configurationService.app;
|
2019-11-20 10:04:27 +01:00
|
|
|
this.translate
|
|
|
|
.get(['COOKIE.MESSAGE', 'COOKIE.DISMISS', 'COOKIE.DENY', 'COOKIE.LINK', 'COOKIE.POLICY'])
|
|
|
|
.subscribe(data => {
|
|
|
|
this.ccService.getConfig().content = this.ccService.getConfig().content || {};
|
|
|
|
// Override default messages with the translated ones
|
|
|
|
this.ccService.getConfig().content.message = data['COOKIE.MESSAGE'];
|
|
|
|
this.ccService.getConfig().content.dismiss = data['COOKIE.DISMISS'];
|
|
|
|
this.ccService.getConfig().content.deny = data['COOKIE.DENY'];
|
|
|
|
this.ccService.getConfig().content.link = data['COOKIE.LINK'];
|
|
|
|
this.ccService.getConfig().content.policy = data['COOKIE.POLICY'];
|
|
|
|
|
|
|
|
if (this.cookieService.get("cookiesConsent") == "true") {
|
|
|
|
this.ccService.getConfig().enabled = false;
|
2019-11-19 17:28:25 +01:00
|
|
|
}
|
2019-11-20 10:04:27 +01:00
|
|
|
this.ccService.destroy();
|
|
|
|
this.ccService.init(this.ccService.getConfig());
|
2021-03-05 10:05:09 +01:00
|
|
|
});
|
2019-11-19 17:28:25 +01:00
|
|
|
}
|
|
|
|
|
2020-08-07 16:14:51 +02:00
|
|
|
translateTitle(ttl: string) {
|
|
|
|
if (ttl.length > 0) {
|
|
|
|
this.translate.get(ttl).subscribe((translated: string) => {
|
|
|
|
this.translate.get('GENERAL.TITLES.PREFIX').subscribe((titlePrefix: string) => {
|
|
|
|
this.titleService.setTitle(titlePrefix + translated);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.translate.get('GENERAL.TITLES.GENERAL').subscribe((translated: string) => {
|
|
|
|
this.titleService.setTitle(translated);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 17:28:25 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.statusChangeSubscription.unsubscribe();
|
2021-03-08 10:24:30 +01:00
|
|
|
if(this.sideNavSubscription){
|
|
|
|
this.sideNavSubscription.unsubscribe();
|
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-10-04 09:53:35 +02:00
|
|
|
// ----------- UNCOMMENT TO ADD AGAIN GRANTS --------
|
|
|
|
// goToGrants() {
|
|
|
|
// this.router.navigate(['/grants'], { queryParams: { /*refresh : Math.random() ,returnUrl: this.state.url*/ } });
|
|
|
|
// }
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
initializeServices() {
|
|
|
|
this.translate.setDefaultLang('en');
|
2020-03-26 17:44:12 +01:00
|
|
|
this.authentication.current() && this.authentication.current().culture ? this.cultureService.cultureSelected(this.authentication.current().culture) : this.cultureService.cultureSelected(this.configurationService.defaultCulture);
|
2020-01-23 17:35:11 +01:00
|
|
|
this.authentication.current() && this.authentication.current().language ? this.language.changeLanguage(this.authentication.current().language) : this.language.changeLanguage('en');
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2020-06-26 11:08:51 +02:00
|
|
|
|
|
|
|
toggleNavbar(event) {
|
|
|
|
document.getElementById('hamburger').classList.toggle("change");
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
2017-11-01 18:18:27 +01:00
|
|
|
|