From 37e5d1011e4752cf0b1db7db6322f82a6f85304b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Flores?= <raphael.flores@inrae.fr>
Date: Wed, 15 Jun 2022 11:47:02 +0200
Subject: [PATCH] Change assets dir/path by resources. GNP-6148.

This change allows for distinguish with /assets directory/path used in
faidare-search app, hence makes Apache redirection working.
---
 backend/build.gradle.kts                            |   2 +-
 .../static/{assets => resources}/images/favicon.ico | Bin
 .../static/{assets => resources}/images/logo.png    | Bin
 .../images/marker-icon-blue.png                     | Bin
 .../images/marker-icon-green.png                    | Bin
 .../images/marker-icon-purple.png                   | Bin
 .../images/marker-icon-red.png                      | Bin
 .../src/main/resources/templates/fragments/map.html |   8 ++++----
 .../src/main/resources/templates/layout/main.html   |   8 ++++----
 web/src/map/map.ts                                  |   2 +-
 web/webpack.config.js                               |   4 ++--
 11 files changed, 12 insertions(+), 12 deletions(-)
 rename backend/src/main/resources/static/{assets => resources}/images/favicon.ico (100%)
 rename backend/src/main/resources/static/{assets => resources}/images/logo.png (100%)
 rename backend/src/main/resources/static/{assets => resources}/images/marker-icon-blue.png (100%)
 rename backend/src/main/resources/static/{assets => resources}/images/marker-icon-green.png (100%)
 rename backend/src/main/resources/static/{assets => resources}/images/marker-icon-purple.png (100%)
 rename backend/src/main/resources/static/{assets => resources}/images/marker-icon-red.png (100%)

diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts
index 94379502..824cba29 100644
--- a/backend/build.gradle.kts
+++ b/backend/build.gradle.kts
@@ -51,7 +51,7 @@ tasks {
         // replace the script.js and style.css file names referenced in main.html
         // by their actual name, containing the content hash
         filesMatching("**/layout/main.html") {
-            val webAssetsDir = project(":web").file("build/dist/assets/");
+            val webAssetsDir = project(":web").file("build/dist/resources/");
             val scriptFileName = webAssetsDir.list().first { it.startsWith("script") && it.endsWith(".js") }
             val styleFileName = webAssetsDir.list().first { it.startsWith("style") && it.endsWith(".css") }
 
diff --git a/backend/src/main/resources/static/assets/images/favicon.ico b/backend/src/main/resources/static/resources/images/favicon.ico
similarity index 100%
rename from backend/src/main/resources/static/assets/images/favicon.ico
rename to backend/src/main/resources/static/resources/images/favicon.ico
diff --git a/backend/src/main/resources/static/assets/images/logo.png b/backend/src/main/resources/static/resources/images/logo.png
similarity index 100%
rename from backend/src/main/resources/static/assets/images/logo.png
rename to backend/src/main/resources/static/resources/images/logo.png
diff --git a/backend/src/main/resources/static/assets/images/marker-icon-blue.png b/backend/src/main/resources/static/resources/images/marker-icon-blue.png
similarity index 100%
rename from backend/src/main/resources/static/assets/images/marker-icon-blue.png
rename to backend/src/main/resources/static/resources/images/marker-icon-blue.png
diff --git a/backend/src/main/resources/static/assets/images/marker-icon-green.png b/backend/src/main/resources/static/resources/images/marker-icon-green.png
similarity index 100%
rename from backend/src/main/resources/static/assets/images/marker-icon-green.png
rename to backend/src/main/resources/static/resources/images/marker-icon-green.png
diff --git a/backend/src/main/resources/static/assets/images/marker-icon-purple.png b/backend/src/main/resources/static/resources/images/marker-icon-purple.png
similarity index 100%
rename from backend/src/main/resources/static/assets/images/marker-icon-purple.png
rename to backend/src/main/resources/static/resources/images/marker-icon-purple.png
diff --git a/backend/src/main/resources/static/assets/images/marker-icon-red.png b/backend/src/main/resources/static/resources/images/marker-icon-red.png
similarity index 100%
rename from backend/src/main/resources/static/assets/images/marker-icon-red.png
rename to backend/src/main/resources/static/resources/images/marker-icon-red.png
diff --git a/backend/src/main/resources/templates/fragments/map.html b/backend/src/main/resources/templates/fragments/map.html
index cad10ae8..aa51b67e 100644
--- a/backend/src/main/resources/templates/fragments/map.html
+++ b/backend/src/main/resources/templates/fragments/map.html
@@ -10,13 +10,13 @@ to display
     <div th:fragment="map" id="map-container" class="d-none">
       <div id="map" class="border rounded"></div>
       <div class="map-legend mt-1 small">
-        <img th:src="@{/assets/images/marker-icon-red.png}" id="red" />
+        <img th:src="@{/resources/images/marker-icon-red.png}" id="red" />
         <label for="red" class="me-2">Origin site</label>
-        <img th:src="@{/assets/images/marker-icon-blue.png}" id="blue" />
+        <img th:src="@{/resources/images/marker-icon-blue.png}" id="blue" />
         <label for="blue" class="me-2">Collecting site</label>
-        <img th:src="@{/assets/images/marker-icon-green.png}" id="green" />
+        <img th:src="@{/resources/images/marker-icon-green.png}" id="green" />
         <label for="green" class="me-2">Evaluation site</label>
-        <img th:src="@{/assets/images/marker-icon-purple.png}" id="purple" />
+        <img th:src="@{/resources/images/marker-icon-purple.png}" id="purple" />
         <label for="purple">Multi-purpose site</label>
       </div>
     </div>
diff --git a/backend/src/main/resources/templates/layout/main.html b/backend/src/main/resources/templates/layout/main.html
index 0ceb3ebf..7b1bb775 100644
--- a/backend/src/main/resources/templates/layout/main.html
+++ b/backend/src/main/resources/templates/layout/main.html
@@ -10,11 +10,11 @@
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <meta content="width=device-width, initial-scale=1" name="viewport" />
 
-    <link th:href="@{/assets/style.css}" rel="stylesheet" />
+    <link th:href="@{/resources/style.css}" rel="stylesheet" />
 
     <link
       rel="shortcut icon"
-      th:href="@{/assets/images/favicon.ico}"
+      th:href="@{/resources/images/favicon.ico}"
       type="image/x-icon"
     />
   </head>
@@ -26,7 +26,7 @@
           class="navbar-brand py-0"
           href="https://urgi.versailles.inrae.fr/faidare"
         >
-          <img th:src="@{/assets/images/logo.png}" style="height: 40px" />
+          <img th:src="@{/resources/images/logo.png}" style="height: 40px" />
         </a>
         <button
           class="navbar-toggler"
@@ -86,7 +86,7 @@
         <p>Layout content</p>
       </div>
     </div>
-    <script type="text/javascript" th:src="@{/assets/script.js}"></script>
+    <script type="text/javascript" th:src="@{/resources/script.js}"></script>
     <script type="text/javascript" th:replace="${script}"></script>
   </body>
 </html>
diff --git a/web/src/map/map.ts b/web/src/map/map.ts
index a61002a4..37cf126d 100644
--- a/web/src/map/map.ts
+++ b/web/src/map/map.ts
@@ -27,7 +27,7 @@ function markerColor(location: MapLocation) {
 }
 
 function markerIconUrl(contextPath: string, location: MapLocation) {
-    return `${contextPath}/assets/images/marker-icon-${markerColor(location)}.png`;
+    return `${contextPath}/resources/images/marker-icon-${markerColor(location)}.png`;
 }
 
 export function initializeMap(options: MapOptions) {
diff --git a/web/webpack.config.js b/web/webpack.config.js
index a8ffae0a..2606ec0d 100644
--- a/web/webpack.config.js
+++ b/web/webpack.config.js
@@ -58,8 +58,8 @@ module.exports = (env, argv) => ({
         extensions: ['.ts', '.js'],
     },
     output: {
-        // the output is stored in build/dist/assets
-        path: path.resolve(__dirname, 'build/dist/assets'),
+        // the output is stored in build/dist/resources
+        path: path.resolve(__dirname, 'build/dist/resources'),
         filename: argv.mode === 'production' ? '[name].[contenthash].js' : '[name].js'
     },
     optimization: {
-- 
GitLab