From 927c0a55faaacd0486c2472e8d7e92ecac98bf26 Mon Sep 17 00:00:00 2001
From: Matthieu Benoist <mbenoist@ausy-group.com>
Date: Thu, 29 Apr 2021 15:01:44 +0200
Subject: [PATCH] tac

---
 angular.json                                  | 13 ++++-
 src/app/app.component.ts                      | 36 ++-----------
 src/app/app.module.ts                         | 21 ++++++--
 .../main/footer/footer.component.ts           |  5 +-
 src/app/core/services/app-config.service.ts   |  2 +-
 src/app/core/services/index.ts                |  4 +-
 .../core/services/tarteaucitron.service.ts    | 51 +++++++++++++++++++
 7 files changed, 91 insertions(+), 41 deletions(-)
 create mode 100644 src/app/core/services/tarteaucitron.service.ts

diff --git a/angular.json b/angular.json
index eb49900d..01c15efa 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 ff3ae86a..40d99b6a 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 163dc5c2..e0f0f14d 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 968bc6a6..56cad8ca 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 3c58e684..f9e894f4 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 dfd0f3ab..559306ab 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 00000000..bc279692
--- /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();
+    });
+  }
+}
-- 
GitLab