diff --git a/angular.json b/angular.json index eb49900d0b3b8a838190bf9338aaf4bdff1d3f33..01c15efae2a3f4a235517cb1f4b8418eb151097e 100644 --- a/angular.json +++ b/angular.json @@ -29,12 +29,21 @@ "assets": [ "src/assets", "src/favicon.ico", - "src/robots.txt" + "src/robots.txt", + { + "glob": "**/*", + "input":"./node_modules/tarteaucitronjs", + "output":"/" + } + ], "styles": [ "src/styles.scss" ], - "scripts": [] + "scripts": [ + "./node_modules/tarteaucitronjs/tarteaucitron.js", + "./node_modules/tarteaucitronjs/tarteaucitron.services.js" + ] }, "configurations": { "aot-fr": { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ff3ae86a393dd1332c24044f654c69543353e9bf..40d99b6aa46fec924ee3b26529352a68794db38c 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,14 +1,13 @@ import { Component, OnInit } from '@angular/core'; import { Title } from '@angular/platform-browser'; -import { tarteaucitron } from 'tarteaucitronjs/tarteaucitron.js'; import { Angulartics2Piwik } from 'angulartics2/piwik'; import { filter, map } from 'rxjs/operators'; import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; import { environment } from '../environments/environment'; import { NavigationHistoryService } from './core/services'; import { AppRoutes } from './routes'; -import { APP_CONFIG } from './core/services/app-config.service'; +declare var tarteaucitron: any; @Component({ selector: 'app-root', templateUrl: './app.component.html', @@ -25,7 +24,8 @@ export class AppComponent implements OnInit { this._angulartics2Piwik.startTracking(); } - ngOnInit() { + ngOnInit() + { this._router.events.pipe( filter(e => e instanceof NavigationEnd), ).subscribe((e) => { @@ -52,8 +52,6 @@ export class AppComponent implements OnInit { const title = titles.join(' - '); this._titleService.setTitle(title); }); - - this.initializeTarteaucitron(); } // Return true if origin url and destination url are both in datasetDetail @@ -65,32 +63,4 @@ export class AppComponent implements OnInit { } return res; } - - initializeTarteaucitron() { - var tarteaucitronForceLanguage = 'fr'; - var tarteaucitronForceExpire = '365'; - - tarteaucitron.init({ - "hashtag" : "#tarteaucitron", - "highPrivacy" : true, - "AcceptAllCta" : true, - "orientation" : "top", - "adblocker" : true, - "showAlertSmall" : false, - "cookieslist" : true, - "removeCredit" : true, - "handleBrowserDNTRequest" : true, - "cookieDomain" : ".grandlyon.com", - "cookieName" : "tarteaucitron", - "useExternalCss" : false, - "External CSS Url" : "", - "tarteaucitronForceLanguage" : "fr", - "tarteaucitronForceExpire" : "365", - }); - console.log(APP_CONFIG); - tarteaucitron.user.matomoId = APP_CONFIG.statistics.matomoId; - tarteaucitron.user.matomoHost = APP_CONFIG.statistics.matomoHost; - - (tarteaucitron.job = tarteaucitron.job || []).push('matomo'); - } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 163dc5c2add0af7747609a4b6dbaf64262408474..e0f0f14d19236c10a2dd5a25ad434ee7f7d7f58b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,13 +10,13 @@ import { EditorialisationModule } from './editorialisation/editorialisation.modu import { Angulartics2Module } from 'angulartics2'; import { UserModule } from './user/user.module'; import { UserService } from './user/services'; -import { AppConfigService, NotificationService } from './core/services'; +import { AppConfigService, NotificationService, TarteAuCitronService } from './core/services'; import { timeout } from 'rxjs/operators'; import { notificationMessages } from '../i18n/traductions'; // Function used by APP_INITIALIZER before the app start: init user info / statut (expect a promise) export function initUserService(authService: UserService, notificationService: NotificationService) { - return (): Promise<any> => { + return (): Promise<void> => { return new Promise((resolve, reject) => { authService.initializeService().pipe(timeout(3000)).subscribe( () => { @@ -35,8 +35,17 @@ export function initUserService(authService: UserService, notificationService: N }; } +export function initTarteaucitronService(tarteaucitronService: TarteAuCitronService) { + return (): Promise<void> => { + return new Promise( (resolve, reject) => { + tarteaucitronService.load(); + resolve(); + }); + } +} + export function initAppConfig(appConfigService: AppConfigService) { - return (): Promise<any> => { + return (): Promise<void> => { return new Promise((resolve, reject) => { appConfigService.load(); resolve(); @@ -66,6 +75,12 @@ export function initAppConfig(appConfigService: AppConfigService) { deps: [AppConfigService], multi: true, }, + { + provide: APP_INITIALIZER, + useFactory: initTarteaucitronService, + deps: [TarteAuCitronService], + multi: true, + }, { provide: APP_INITIALIZER, useFactory: initUserService, diff --git a/src/app/core/components/main/footer/footer.component.ts b/src/app/core/components/main/footer/footer.component.ts index 968bc6a618caf9a44d40140881a00b570b9afadc..56cad8cac1da2f8d249cf087be060c4c687dac65 100644 --- a/src/app/core/components/main/footer/footer.component.ts +++ b/src/app/core/components/main/footer/footer.component.ts @@ -3,6 +3,8 @@ import { AppRoutes } from '../../../../routes'; import { AppStateService } from '../../../services'; import { APP_CONFIG } from '../../../services/app-config.service'; +declare var tarteaucitron: any; + @Component({ selector: 'app-footer', templateUrl: './footer.component.html', @@ -21,7 +23,8 @@ export class FooterComponent implements OnInit { ngOnInit() { } openCookieModal() { - this._appStateService.changeCookieModalState(true); + //this._appStateService.changeCookieModalState(true); + tarteaucitron.userInterface.openPanel(); } } diff --git a/src/app/core/services/app-config.service.ts b/src/app/core/services/app-config.service.ts index 3c58e684d1c14c3ddacee572048d5fbb5d326a0c..f9e894f40356379b86519721da79c07f229ee1cc 100644 --- a/src/app/core/services/app-config.service.ts +++ b/src/app/core/services/app-config.service.ts @@ -50,7 +50,7 @@ export class AppConfigService { constructor() { } public load() { - return new Promise((resolve, reject) => { + return new Promise<void>((resolve, reject) => { const conf = new AppConfig(); APP_CONFIG = Object.assign(conf, window['portailDataEnvConfig']); resolve(); diff --git a/src/app/core/services/index.ts b/src/app/core/services/index.ts index dfd0f3ab0eb4d04e39f9cad93a373d4c79a0f5dd..559306ab20af5ac644221ca41f27d39b1e37dc11 100644 --- a/src/app/core/services/index.ts +++ b/src/app/core/services/index.ts @@ -7,10 +7,11 @@ import { MatomoService } from './matomo.service'; import { NavigationHistoryService } from './navigation-history.service'; import { NotificationService } from './notification.service'; import { StorageService } from './storage.service'; +import { TarteAuCitronService } from './tarteaucitron.service'; import { ToolsService } from './tools.service'; // tslint:disable-next-line: max-line-length -export { ErrorService, NotificationService, MatomoService, NavigationHistoryService, EmailService, FileService, AppConfigService, AppStateService, }; +export { ErrorService, NotificationService, MatomoService, TarteAuCitronService, NavigationHistoryService, EmailService, FileService, AppConfigService, AppStateService, }; // tslint:disable-next-line:variable-name export const CoreServices = [ @@ -22,6 +23,7 @@ export const CoreServices = [ EmailService, FileService, AppConfigService, + TarteAuCitronService, AppStateService, ToolsService, ]; diff --git a/src/app/core/services/tarteaucitron.service.ts b/src/app/core/services/tarteaucitron.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..bc279692e537e9849e91ca5d46cb373c0dffdedf --- /dev/null +++ b/src/app/core/services/tarteaucitron.service.ts @@ -0,0 +1,51 @@ +import { Injectable } from "@angular/core"; +import { APP_CONFIG } from "./app-config.service"; + +declare var tarteaucitron: any; + +@Injectable() +export class TarteAuCitronService { + + public load () + { + return new Promise<void>((resolve, reject) => { + tarteaucitron.init({ + "privacyUrl":"", + + "hashtag" : "#tarteaucitron", + "cookieName" : "tarteaucitron", + + "orientation" : "bottom", + + "showAlertSmall" : false, + "cookieslist" : true, + "iconPosition": "BottomRight", + + "AcceptAllCta" : true, + "DenyAllCta": false, + "highPrivacy" : true, + + "adblocker" : false, + + "handleBrowserDNTRequest" : false, + + "removeCredit" : true, + "moreInfoLink": false, + + "useExternalCss" : false, + "readmoreLink": "", + + }); + console.log(tarteaucitron); + var tarteaucitronForceLanguage = 'fr'; + var tarteaucitronForceExpire = '365'; + + tarteaucitron.user.matomoId = APP_CONFIG.statistics.matomoId; + tarteaucitron.user.matomoHost = APP_CONFIG.statistics.matomoHost; + + (tarteaucitron.job = tarteaucitron.job || []).push('matomo'); + + resolve(); + }); + } +}