From ba08f31da673b5cae8c8b8f9ee60bde7fc59e834 Mon Sep 17 00:00:00 2001
From: BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
Date: Tue, 19 Oct 2021 16:02:21 +0200
Subject: [PATCH] Working item list in Web interface.

---
 .../controller/web/WebProductsController.java    | 16 +++++++++++++++-
 src/main/resources/messages.properties           |  4 ++++
 src/main/resources/messages_en.properties        |  4 ++++
 src/main/resources/messages_fr.properties        |  4 ++++
 src/main/resources/templates/items.html          | 16 +++++++++++++++-
 5 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/web/WebProductsController.java b/src/main/java/fr/unistra/sil/erp/back/controller/web/WebProductsController.java
index 87981ea..bb9b2df 100644
--- a/src/main/java/fr/unistra/sil/erp/back/controller/web/WebProductsController.java
+++ b/src/main/java/fr/unistra/sil/erp/back/controller/web/WebProductsController.java
@@ -1,8 +1,15 @@
 package fr.unistra.sil.erp.back.controller.web;
 
 
+import fr.unistra.sil.erp.back.DatabaseSystem;
 import static fr.unistra.sil.erp.back.WebMvcConfig.WEB_MAPPING_ITEMS;
+import fr.unistra.sil.erp.back.db.DatabaseConnectionException;
+import fr.unistra.sil.erp.back.model.Item;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
 
 /*
@@ -19,11 +26,18 @@ public class WebProductsController {
     
     /**
      * Handles the item list view.
+     * @param model the view's model.
      * @return the template to use.
      */
     @GetMapping(WEB_MAPPING_ITEMS)
-    public String products()
+    public String products(Model model)
     {
+        try {
+            List<Item> li = DatabaseSystem.getInstance().getAllItems();
+            model.addAttribute("items", li);
+        } catch (DatabaseConnectionException ex) {
+            Logger.getLogger(WebProductsController.class.getName()).log(Level.SEVERE, null, ex);
+        }
         return "items";
     }
     
diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties
index d74cad6..3f1dcdc 100644
--- a/src/main/resources/messages.properties
+++ b/src/main/resources/messages.properties
@@ -16,3 +16,7 @@ web.ui.products=Products
 web.ui.registry=Registry
 #Documents.
 web.ui.documents=Documents
+#Product price.
+web.ui.price=Price
+#Price for subscribers.
+web.ui.subscriberPrice=Subscriber Price
diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties
index d74cad6..3f1dcdc 100644
--- a/src/main/resources/messages_en.properties
+++ b/src/main/resources/messages_en.properties
@@ -16,3 +16,7 @@ web.ui.products=Products
 web.ui.registry=Registry
 #Documents.
 web.ui.documents=Documents
+#Product price.
+web.ui.price=Price
+#Price for subscribers.
+web.ui.subscriberPrice=Subscriber Price
diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties
index 7bdcdde..f9f08b4 100644
--- a/src/main/resources/messages_fr.properties
+++ b/src/main/resources/messages_fr.properties
@@ -16,3 +16,7 @@ web.ui.products=Produits
 web.ui.registry=Registre
 #Documents.
 web.ui.documents=Documents
+#Product price.
+web.ui.price=Prix
+#Price for subscribers.
+web.ui.subscriberPrice=Prix adh\u00e9rent
diff --git a/src/main/resources/templates/items.html b/src/main/resources/templates/items.html
index 73e70e1..7b92937 100644
--- a/src/main/resources/templates/items.html
+++ b/src/main/resources/templates/items.html
@@ -7,7 +7,21 @@
         <div th:replace="fragments/navbar :: topNavBar"></div>
         <article>
             <h1 th:text="#{web.ui.products}"></h1>
-            <p>TODO</p>
+            <div class="mainFrame" id="productsArea">
+                <table class="mainList" id="productsList">
+                    <tr>
+                        <th th:text="#{web.ui.product}"></th>
+                        <th th:text="#{web.ui.price}"></th>
+                        <th th:text="#{web.ui.subscriberPrice}"></th>
+                    </tr>
+
+                    <tr th:each="item: ${items}">
+                        <td th:text="${item.name}"></td>
+                        <td th:text="${item.price}"></td>
+                        <td th:text="${item.subscriberPrice}"></td>
+                    </tr>
+                </table>
+            </div>
         </article>
     </body>
 </html>
\ No newline at end of file
-- 
GitLab