From 2357cd0c20c337af2a6af6d09def3ff68243f44d Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 21 Jan 2020 21:31:40 +0100 Subject: [PATCH] WIP --- .../java/de/juplo/demo/DemoController.java | 37 +++++++++++++++++-- src/main/java/de/juplo/demo/Form.java | 10 ++--- src/main/resources/templates/form.html | 18 ++++++--- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/juplo/demo/DemoController.java b/src/main/java/de/juplo/demo/DemoController.java index 7a23173..7c65a60 100644 --- a/src/main/java/de/juplo/demo/DemoController.java +++ b/src/main/java/de/juplo/demo/DemoController.java @@ -2,6 +2,7 @@ package de.juplo.demo; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,8 +42,15 @@ public class DemoController .stream() .reduce(0, (a, b) -> a > b ? a : b) + 1; - LOG.info("Adding new card #{}", next); - form.cards.put(next, new HashMap<>()); + Map content = new LinkedHashMap<>(); + content.put(form.names.get(0), Boolean.FALSE); + LOG.info("Adding new card #{} with content: {}", next, content); + form.cards.put(next, content); + + for (Integer id : form.cards.keySet()) + for (String entry : form.cards.get(id).keySet()) + LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry)); + return "form"; } @@ -51,14 +59,24 @@ public class DemoController { Map content = form.cards.remove(card); LOG.info("Removed card #{} with content: {}", card, content); + + for (Integer id : form.cards.keySet()) + for (String entry : form.cards.get(id).keySet()) + LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry)); + return "form"; } @RequestMapping(path = "/", params = "add") public String addRow(@ModelAttribute Form form, @RequestParam Integer add) { - LOG.info("Adding row {} to card #{}", form.row.get(add), add); - form.cards.get(add).put(form.row.get(add), Boolean.FALSE); + LOG.info("Adding row {} to card #{}", form.names.get(add), add); + form.cards.get(add).put(form.names.get(add), Boolean.FALSE); + + for (Integer id : form.cards.keySet()) + for (String entry : form.cards.get(id).keySet()) + LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry)); + return "form"; } @@ -70,6 +88,17 @@ public class DemoController String row = parts[1]; Boolean value = form.cards.get(card).remove(row); LOG.info("Removed row {} with value {} from card #{}", row, value, card); + + if (form.cards.get(card).isEmpty()) + { + LOG.info("Card #{} is empty: Removing card!", card); + form.cards.remove(card); + } + + for (Integer id : form.cards.keySet()) + for (String entry : form.cards.get(id).keySet()) + LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry)); + return "form"; } } diff --git a/src/main/java/de/juplo/demo/Form.java b/src/main/java/de/juplo/demo/Form.java index 7dceac3..38ac7a5 100644 --- a/src/main/java/de/juplo/demo/Form.java +++ b/src/main/java/de/juplo/demo/Form.java @@ -13,7 +13,7 @@ import java.util.TreeMap; public class Form { Map> cards = new TreeMap<>(); - Map row = new HashMap<>(); + Map names = new HashMap<>(); public Map> getCards() @@ -26,13 +26,13 @@ public class Form this.cards = cards; } - public Map getRow() + public Map getNames() { - return row; + return names; } - public void setRow(Map row) + public void setNames(Map names) { - this.row = row; + this.names = names; } } diff --git a/src/main/resources/templates/form.html b/src/main/resources/templates/form.html index 4105325..eb6fb24 100644 --- a/src/main/resources/templates/form.html +++ b/src/main/resources/templates/form.html @@ -8,12 +8,12 @@
-
-

Card #X

+
+

Card #X

@@ -22,7 +22,7 @@
- +
@@ -31,7 +31,15 @@
-

+
+

Add A New Card...

+
+
+ + +
+
+
-- 2.20.1