From 94d02c5019ecc876ebdb87e6f903650b47643cd8 Mon Sep 17 00:00:00 2001
From: Etienne LOUPIAS <eloupias@grandlyon.com>
Date: Tue, 12 Nov 2024 09:44:53 +0100
Subject: [PATCH] ci(data): fix get cities from data.grandlyon

---
 nginx/default.conf                            |  8 +--
 proxy.conf.json                               |  5 +-
 src/app/data/data.component.ts                | 50 +++++++++----------
 .../more-filters/more-filters.component.html  |  4 +-
 4 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/nginx/default.conf b/nginx/default.conf
index 97bc59ae9..3cc40f5d5 100644
--- a/nginx/default.conf
+++ b/nginx/default.conf
@@ -33,6 +33,10 @@ server {
   #allow 80.14.51.82;      # Erasme
   #deny all;
 
+  location /data-grandlyon-cities {
+    proxy_pass https://data.grandlyon.com/fr/datapusher/ws/grandlyon/adr_voie_lieu.adrcomgl/all.json;
+  }
+
   location / {
     add_header X-Frame-Options SAMEORIGIN always;
     add_header X-Content-Type-Options nosniff;
@@ -75,10 +79,6 @@ server {
     proxy_pass https://download.data.grandlyon.com/wfs/grandlyon;
   }
 
-  location /fr/datapusher {
-    proxy_pass https://data.grandlyon.com/fr/datapusher;
-  }
-
   # REALLY important for JavaScript modules (type="module") to work as expected!!!
   location ~ \.js {
     add_header  Content-Type   text/javascript;
diff --git a/proxy.conf.json b/proxy.conf.json
index 48ad4e755..699e461eb 100644
--- a/proxy.conf.json
+++ b/proxy.conf.json
@@ -29,10 +29,13 @@
     "changeOrigin": true,
     "logLevel": "info"
   },
-  "/fr/datapusher": {
+  "/data-grandlyon-cities": {
     "target": "https://data.grandlyon.com",
     "secure": false,
     "changeOrigin": true,
+    "pathRewrite": {
+      "^/data-grandlyon-cities": "/fr/datapusher/ws/grandlyon/adr_voie_lieu.adrcomgl/all.json"
+    },
     "logLevel": "info"
   }
 }
diff --git a/src/app/data/data.component.ts b/src/app/data/data.component.ts
index 226379e6f..4a0152157 100644
--- a/src/app/data/data.component.ts
+++ b/src/app/data/data.component.ts
@@ -67,32 +67,30 @@ export class DataComponent implements OnInit {
     });
 
     // Get cities from data.grandlyon.com
-    // To change to have new city Oullins-Pierre-Bénite :
-    // .get('/fr/datapusher/ws/grandlyon/adr_voie_lieu.adrcomgl_2024/all.json', { headers: { skip: 'true' } })
-    this.http
-      .get('/fr/datapusher/ws/grandlyon/adr_voie_lieu.adrcomgl/all.json', { headers: { skip: 'true' } })
-      .subscribe((data: { values: any[] }) => {
-        this.categoriesInseeCodes = [
-          {
-            id: 'inseeCode',
-            name: 'Commune',
-            theme: 'Commune',
-            modules: data.values
-              .flatMap((value) => {
-                if (value.nom === 'Lyon') {
-                  // Replace city "Lyon" by the 9 districts of Lyon
-                  return Array.from({ length: 9 }, (_, index) => ({
-                    disabled: false,
-                    name: `Lyon ${index + 1}`,
-                    id: `6938${index + 1}`, // Insee code for district of Lyon
-                  }));
-                }
-                return [{ disabled: false, name: value.nom, id: value.insee }];
-              })
-              .sort((a, b) => a.name.localeCompare(b.name)),
-          },
-        ];
-      });
+    // To change in proxy.conf.json and default.conf to have new city Oullins-Pierre-Bénite :
+    // /fr/datapusher/ws/grandlyon/adr_voie_lieu.adrcomgl_2024/all.json
+    this.http.get('/data-grandlyon-cities', { headers: { skip: 'true' } }).subscribe((data: { values: any[] }) => {
+      this.categoriesInseeCodes = [
+        {
+          id: 'inseeCode',
+          name: 'Commune',
+          theme: 'Commune',
+          modules: data.values
+            .flatMap((value) => {
+              if (value.nom === 'Lyon') {
+                // Replace city "Lyon" by the 9 districts of Lyon
+                return Array.from({ length: 9 }, (_, index) => ({
+                  disabled: false,
+                  name: `Lyon ${index + 1}`,
+                  id: `6938${index + 1}`, // Insee code for district of Lyon
+                }));
+              }
+              return [{ disabled: false, name: value.nom, id: value.insee }];
+            })
+            .sort((a, b) => a.name.localeCompare(b.name)),
+        },
+      ];
+    });
 
     this.resetFilters();
   }
diff --git a/src/app/structure-list/components/more-filters/more-filters.component.html b/src/app/structure-list/components/more-filters/more-filters.component.html
index 46ebcb686..994405507 100644
--- a/src/app/structure-list/components/more-filters/more-filters.component.html
+++ b/src/app/structure-list/components/more-filters/more-filters.component.html
@@ -18,7 +18,7 @@
       />
     </div>
     <!-- Filter with single category -->
-    <div *ngIf="categories.length === 1" class="modalContent">
+    <div *ngIf="categories?.length === 1" class="modalContent">
       <ng-container *ngIf="isRadio">
         <app-radio
           *ngFor="let module of categories[0].modules"
@@ -41,7 +41,7 @@
       </ng-container>
     </div>
     <!-- Filter with multiple categories -->
-    <div *ngIf="categories.length > 1" class="modalContent multipleCollapse">
+    <div *ngIf="categories?.length > 1" class="modalContent multipleCollapse">
       <app-collapse *ngFor="let c of categories">
         <app-collapse-header>
           <div class="collapseHeader">
-- 
GitLab