import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
LoggerFactory.getLogger(DemoController.class);
- @RequestMapping("/")
+ @RequestMapping(path = "/", params = { "!card", "!add", "!remove" })
public String display(@ModelAttribute Form form)
{
for (Integer id : form.cards.keySet())
return "form";
}
- @RequestMapping(path = "/", params = "card=add")
+ @RequestMapping(path = "/", params = { "card=add", "!add", "!remove" })
public String addCard(@ModelAttribute Form form)
{
Integer next =
.stream()
.reduce(0, (a, b) -> a > b ? a : b) + 1;
- LOG.info("Adding new card #{}", next);
- form.cards.put(next, new HashMap<>());
+ Map<String, Boolean> 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";
}
- @RequestMapping(path = "/", params = "card!=add")
+ @RequestMapping(path = "/", params = { "card", "!add", "!remove" })
public String removeCard(@ModelAttribute Form form, @RequestParam Integer card)
{
Map<String, Boolean> 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")
+ @RequestMapping(path = "/", params = { "!card", "add", "!remove" })
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";
}
- @RequestMapping(path = "/", params = "remove")
+ @RequestMapping(path = "/", params = { "!card", "!add", "remove" })
public String removeRow(@ModelAttribute Form form, @RequestParam String remove)
{
String[] parts = remove.split(":", 2);
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";
}
}