From 6bcdb6f0cd1e43a1c36ea3b98e44e42c53e96fd9 Mon Sep 17 00:00:00 2001
From: BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
Date: Sun, 26 Sep 2021 23:59:22 +0200
Subject: [PATCH] Added simple navigation bar. #4

---
 .../fr/unistra/sil/erp/back/WebMvcConfig.java | 11 ----
 .../back/controller/web/LoginController.java  |  3 +-
 .../back/controller/web/RootController.java   | 19 +++++++
 src/main/resources/application.properties     |  2 +-
 src/main/resources/messages.properties        |  8 +++
 src/main/resources/messages_en.properties     |  8 +++
 src/main/resources/messages_fr.properties     |  8 +++
 src/main/resources/static/main.css            | 57 +++++++++++++++++++
 .../resources/templates/fragments/head.html   | 12 ++++
 .../resources/templates/fragments/navbar.html | 13 +++++
 .../templates/fragments/navbarGuest.html      | 10 ++++
 src/main/resources/templates/items.html       |  0
 src/main/resources/templates/login.html       |  7 +--
 13 files changed, 141 insertions(+), 17 deletions(-)
 create mode 100644 src/main/java/fr/unistra/sil/erp/back/controller/web/RootController.java
 create mode 100644 src/main/resources/static/main.css
 create mode 100644 src/main/resources/templates/fragments/head.html
 create mode 100644 src/main/resources/templates/fragments/navbar.html
 create mode 100644 src/main/resources/templates/fragments/navbarGuest.html
 create mode 100644 src/main/resources/templates/items.html

diff --git a/src/main/java/fr/unistra/sil/erp/back/WebMvcConfig.java b/src/main/java/fr/unistra/sil/erp/back/WebMvcConfig.java
index ac9009f..73cfdc5 100644
--- a/src/main/java/fr/unistra/sil/erp/back/WebMvcConfig.java
+++ b/src/main/java/fr/unistra/sil/erp/back/WebMvcConfig.java
@@ -10,8 +10,6 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
 import org.springframework.context.annotation.PropertySources;
 import org.springframework.core.env.Environment;
-import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
-import org.springframework.web.servlet.config.annotation.EnableWebMvc;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@@ -20,7 +18,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  * @author BEAUVAIS ANTOINE
  */
 @Configuration
-@EnableWebMvc
 @PropertySources(
         @PropertySource("/apikey.properties")
 )
@@ -76,14 +73,6 @@ public class WebMvcConfig implements WebMvcConfigurer {
      */
     public static final String MAPPING_LOGIN = "/login";
     
-    /*
-    // TODO: Define default servlet.
-    @Override
-    public void configureDefaultServletHandling(
-            DefaultServletHandlerConfigurer configurer) {
-        configurer.enable();
-    }*/
-    
     /**
      * Adds interceptors to the application.
      * 
diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/web/LoginController.java b/src/main/java/fr/unistra/sil/erp/back/controller/web/LoginController.java
index fc1e5e7..4dcb024 100644
--- a/src/main/java/fr/unistra/sil/erp/back/controller/web/LoginController.java
+++ b/src/main/java/fr/unistra/sil/erp/back/controller/web/LoginController.java
@@ -25,8 +25,9 @@ public class LoginController {
      * TODO: Actual implementation.
      */
     @GetMapping(MAPPING_LOGIN)
-    public void login()
+    public String login()
     {
+        return "login";
     }
     
 }
diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/web/RootController.java b/src/main/java/fr/unistra/sil/erp/back/controller/web/RootController.java
new file mode 100644
index 0000000..464340f
--- /dev/null
+++ b/src/main/java/fr/unistra/sil/erp/back/controller/web/RootController.java
@@ -0,0 +1,19 @@
+/*
+ * CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
+ * https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
+ */
+package fr.unistra.sil.erp.back.controller.web;
+
+/**
+ * Controller for the root page.
+ * 
+ * The root page will typically redirect to the 
+ * main interface.
+ * 
+ * @author BEAUVAIS ANTOINE
+ */
+public class RootController {
+    
+    
+    
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 8b13789..6e04b84 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1 +1 @@
-
+spring.mvc.static-path-pattern=/static/**
diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties
index 3969e04..3e26a4b 100644
--- a/src/main/resources/messages.properties
+++ b/src/main/resources/messages.properties
@@ -8,3 +8,11 @@ web.ui.login.username=Username
 web.ui.login.password=Password
 #Login page: Button's label.
 web.ui.login.submit=Log in
+#Product.
+web.ui.product=Product
+#Products (plural).
+web.ui.products=Products
+#Financial registry.
+web.ui.registry=Registry
+#Documents.
+web.ui.property.documents=Documents
diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties
index 3969e04..3e26a4b 100644
--- a/src/main/resources/messages_en.properties
+++ b/src/main/resources/messages_en.properties
@@ -8,3 +8,11 @@ web.ui.login.username=Username
 web.ui.login.password=Password
 #Login page: Button's label.
 web.ui.login.submit=Log in
+#Product.
+web.ui.product=Product
+#Products (plural).
+web.ui.products=Products
+#Financial registry.
+web.ui.registry=Registry
+#Documents.
+web.ui.property.documents=Documents
diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties
index 362c0b6..7f43ca2 100644
--- a/src/main/resources/messages_fr.properties
+++ b/src/main/resources/messages_fr.properties
@@ -8,3 +8,11 @@ web.ui.login.username=Nom d'utilisateur
 web.ui.login.password=Mot de passe
 #Login page: Button's label.
 web.ui.login.submit=Se connecter
+#Product.
+web.ui.product=Produit
+#Products (plural).
+web.ui.products=Produits
+#Financial registry.
+web.ui.registry=Registre
+#Documents.
+web.ui.property.documents=Documents
diff --git a/src/main/resources/static/main.css b/src/main/resources/static/main.css
new file mode 100644
index 0000000..4426b73
--- /dev/null
+++ b/src/main/resources/static/main.css
@@ -0,0 +1,57 @@
+ /* Add a black background color to the top navigation */
+ .topnav {
+    background-color: #333;
+    overflow: hidden;
+}
+
+/* Style the links inside the navigation bar */
+.topnav a {
+    float: left;
+    display: block;
+    color: #f2f2f2;
+    text-align: center;
+    padding: 14px 16px;
+    text-decoration: none;
+    font-size: 17px;
+}
+
+/* Change the color of links on hover */
+.topnav a:hover {
+    background-color: #ddd;
+    color: black;
+}
+
+/* Add an active class to highlight the current page */
+.topnav a.active {
+    background-color: #04AA6D;
+    color: white;
+}
+
+/* Hide the link that should open and close the topnav on small screens */
+.topnav .icon {
+    display: none;
+}
+
+/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
+@media screen and (max-width: 600px) {
+    .topnav a:not(:first-child) {display: none;}
+    .topnav a.icon {
+        float: right;
+        display: block;
+    }
+}
+
+/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
+@media screen and (max-width: 600px) {
+    .topnav.responsive {position: relative;}
+    .topnav.responsive a.icon {
+        position: absolute;
+        right: 0;
+        top: 0;
+    }
+    .topnav.responsive a {
+        float: none;
+        display: block;
+        text-align: left;
+    }
+}
\ No newline at end of file
diff --git a/src/main/resources/templates/fragments/head.html b/src/main/resources/templates/fragments/head.html
new file mode 100644
index 0000000..e88d520
--- /dev/null
+++ b/src/main/resources/templates/fragments/head.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head th:fragment="sharedHead (pageName)">
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <link rel="stylesheet" href="/static/main.css">
+    <title th:text="${pageName} +  ' - ' + #{application.name}"></title>
+</head>
+
+<body>
+
+</body>
+</html>
diff --git a/src/main/resources/templates/fragments/navbar.html b/src/main/resources/templates/fragments/navbar.html
new file mode 100644
index 0000000..d204132
--- /dev/null
+++ b/src/main/resources/templates/fragments/navbar.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head></head>
+<body>
+    <div class="topnav" id="topNavBar" th:fragment="topNavBar">
+        <a href="/" th:text="#{application.name}"></a>
+        <a href="#products" class="active" th:text="#{web.ui.products}"></a>
+        <a href="#registry" th:text="#{web.ui.registry}"></a>
+        <a href="#documents" th:text="#{web.ui.documents}"></a>
+        <a href="javascript:void(0);" class="icon" onclick="toggleNavBar()">☰</a>
+    </div>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/main/resources/templates/fragments/navbarGuest.html b/src/main/resources/templates/fragments/navbarGuest.html
new file mode 100644
index 0000000..54b81e9
--- /dev/null
+++ b/src/main/resources/templates/fragments/navbarGuest.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head></head>
+<body>
+    <div class="topnav" id="topNavBar" th:fragment="topNavBar">
+        <a href="/" th:text="#{application.name}"></a>
+        <a href="javascript:void(0);" class="icon" onclick="toggleNavBar()">☰</a>
+    </div>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/main/resources/templates/items.html b/src/main/resources/templates/items.html
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html
index 887851e..2ee83ed 100644
--- a/src/main/resources/templates/login.html
+++ b/src/main/resources/templates/login.html
@@ -1,11 +1,10 @@
 <!DOCTYPE html>
-<html lang="fr" xmlns:th="http://www.thymeleaf.org">
-    <head>
-        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-        <title th:text="#{web.ui.login.login} +  ' - ' + #{application.name}"></title>
+<html xmlns:th="http://www.thymeleaf.org">
+    <head th:replace="fragments/head :: sharedHead (pageName=#{web.ui.login.login})">
     </head>
 
     <body>
+        <div th:replace="fragments/navbarGuest :: topNavBar"></div>
         <h1 th:text="#{web.ui.login.login}"></h1>
         <p>TODO</p>
     </body>
-- 
GitLab