Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b10ce153d | ||
|
|
80220c903c | ||
|
|
297f338a17 | ||
|
|
714d523020 | ||
|
|
d572a55ce6 |
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Exceptions.ResourceNotFoundException;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingItemRepository;
|
||||
@@ -40,7 +41,7 @@ public class PageController {
|
||||
*/
|
||||
@GetMapping("/list/{id}")
|
||||
public String list(Model model, @PathVariable UUID id){
|
||||
ShoppingList list = shoppingListRepository.findById(id).orElseThrow();
|
||||
ShoppingList list = shoppingListRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Seite",id));
|
||||
List<ShoppingList> lists = shoppingListRepository.findAll();
|
||||
model.addAttribute("lists", lists);
|
||||
model.addAttribute("list", list);
|
||||
|
||||
@@ -10,6 +10,6 @@ public record ShoppingItemPatchDTO(String itemName, String itemAmount, Boolean i
|
||||
private boolean isAtleastOneNotBlank(){
|
||||
boolean n = itemName != null && !itemName.isBlank();
|
||||
boolean a = itemAmount != null && !itemAmount.isBlank();
|
||||
return n || a;
|
||||
return n || a || isDone != null || categoryID != null;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
export class ShoppingCategory {
|
||||
constructor(categoryName) {
|
||||
this.categoryName = categoryName;
|
||||
@@ -15,9 +16,10 @@ export class ShoppingCategory {
|
||||
const categoryHeaderDiv = document.createElement("div");
|
||||
const span = document.createElement("span");
|
||||
const deleteCategoryButton = document.createElement("button");
|
||||
const labelDeleteAllItems = document.createElement("label");
|
||||
const deleteAllItemsCheckbox = document.createElement("input");
|
||||
const innerUl = document.createElement("ul");
|
||||
li.id = this.categoryID;
|
||||
li.dataset.id = this.categoryID;
|
||||
li.classList.add("category");
|
||||
|
||||
|
||||
@@ -26,12 +28,17 @@ export class ShoppingCategory {
|
||||
span.textContent = this.categoryName;
|
||||
span.classList.add("category__name", "category__name--bold", "category__name--big");
|
||||
|
||||
labelDeleteAllItems.classList.add("category__labelDeleteAll");
|
||||
labelDeleteAllItems.textContent = "Gegenstände mit Kategorie löschen?";
|
||||
|
||||
deleteCategoryButton.classList.add("category__deleteButton");
|
||||
deleteCategoryButton.textContent = "Kategorie löschen";
|
||||
|
||||
deleteAllItemsCheckbox.setAttribute("type", "checkbox");
|
||||
|
||||
categoryHeaderDiv.append(span, deleteCategoryButton, deleteAllItemsCheckbox);
|
||||
labelDeleteAllItems.append(deleteAllItemsCheckbox);
|
||||
|
||||
categoryHeaderDiv.append(span, deleteCategoryButton, labelDeleteAllItems);
|
||||
|
||||
li.append(categoryHeaderDiv, innerUl);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export class ShoppingItem {
|
||||
|
||||
const deleteItemButton = document.createElement("button");
|
||||
|
||||
li.id = this.itemID;
|
||||
li.dataset.id = this.itemID;
|
||||
li.classList.add("item");
|
||||
|
||||
checkboxDone.setAttribute("type", "checkbox");
|
||||
|
||||
@@ -16,7 +16,7 @@ export function addCategory(categoryAsJSON) {
|
||||
}
|
||||
|
||||
export function deleteCategory(deleteAllItems, categoryID) {
|
||||
const category = document.getElementById(categoryID);
|
||||
const category = document.querySelector(`li[data-id='${categoryID}']`);
|
||||
if (!deleteAllItems) {
|
||||
const ul = category.querySelector("ul");
|
||||
if (ul) document.querySelector(".displayedList").append(...ul.children);
|
||||
|
||||
@@ -5,7 +5,7 @@ export function addItem(itemAsJSON) {
|
||||
if (!itemAsJSON.categoryID) {
|
||||
list = document.querySelector(".displayedList");
|
||||
} else {
|
||||
list = document.getElementById(`${itemAsJSON.categoryID}`).querySelector("ul");
|
||||
list = document.querySelector(`li[data-id='${itemAsJSON.categoryID}']`).querySelector("ul");
|
||||
}
|
||||
|
||||
const item = ShoppingItem.fromJSON(itemAsJSON);
|
||||
|
||||
@@ -9,9 +9,9 @@ const currentList = document.querySelector(".list");
|
||||
const deleteAllDoneItemsButton = document.querySelector(".deleteAllDoneItemsButton");
|
||||
|
||||
async function addItem(itemName, itemAmount, categoryID) {
|
||||
console.log(` adding item with id:${currentList.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`)
|
||||
console.log(` adding item with id:${currentList.dataset.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`)
|
||||
|
||||
const response = await api.addItem(currentList.id, itemName, itemAmount, categoryID);
|
||||
const response = await api.addItem(currentList.dataset.id, itemName, itemAmount, categoryID);
|
||||
const json = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -27,7 +27,7 @@ async function addItem(itemName, itemAmount, categoryID) {
|
||||
async function addCategory(categoryName) {
|
||||
console.log(`adding category ${categoryName}`)
|
||||
|
||||
const response = await api.addCategory(currentList.id, categoryName);
|
||||
const response = await api.addCategory(currentList.dataset.id, categoryName);
|
||||
const json = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -47,7 +47,7 @@ async function editItem(textElement) {
|
||||
|
||||
//erstellen das Forms
|
||||
const formElement = ui.createEditItemForm(textElement)
|
||||
let id = textElement.id;
|
||||
let id = textElement.dataset.id;
|
||||
|
||||
textElement.replaceWith(formElement);
|
||||
|
||||
@@ -87,7 +87,7 @@ function editCategory(categoryElement) {
|
||||
//wir nutzen für das Element nur das div, weil sonst alle items mitgelöscht werden würden
|
||||
const categoryDiv = categoryElement.querySelector(".category__div");
|
||||
const formElement = ui.createEditCategoryForm(categoryDiv);
|
||||
let id = categoryElement.id;
|
||||
let id = categoryElement.dataset.id;
|
||||
|
||||
categoryDiv.replaceWith(formElement);
|
||||
|
||||
@@ -122,7 +122,7 @@ function editCategory(categoryElement) {
|
||||
}
|
||||
|
||||
async function deleteItem(li) {
|
||||
const response = await api.deleteItem(li.id);
|
||||
const response = await api.deleteItem(li.dataset.id);
|
||||
|
||||
if (!response.ok) {
|
||||
const json = await response.json();
|
||||
@@ -149,7 +149,7 @@ async function deleteCategory(deleteAllItems, categoryID) {
|
||||
|
||||
async function deleteAllDoneItems() {
|
||||
console.log(`deleting all done items...`)
|
||||
const response = await api.deleteAllDoneItems(currentList.id);
|
||||
const response = await api.deleteAllDoneItems(currentList.dataset.id);
|
||||
|
||||
if (!response.ok) {
|
||||
const json = await response.json();
|
||||
@@ -189,7 +189,7 @@ function init() {
|
||||
} else if (event.target.matches(".category__deleteButton")) {
|
||||
const li = event.target.closest("li");
|
||||
const checkbox = li.querySelector("input[type=checkbox]");
|
||||
deleteCategory(checkbox.checked, li.id);
|
||||
deleteCategory(checkbox.checked, li.dataset.id);
|
||||
|
||||
} else if (event.target.closest(".item__text")) {
|
||||
editItem(event.target.closest("li"));
|
||||
@@ -201,7 +201,7 @@ function init() {
|
||||
document.querySelector(".displayedList").addEventListener("change", (e) => {
|
||||
if (e.target.matches(".item__markAsDone")) {
|
||||
const item = e.target.closest("li");
|
||||
api.editItem(item.id, { isDone: e.target.checked });
|
||||
api.editItem(item.dataset.id, { isDone: e.target.checked });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<h1 th:text="${list.listName}"></h1>
|
||||
</div>
|
||||
|
||||
<div class="list" th:id="${list.id}">
|
||||
<div class="list" th:data-id="${list.id}">
|
||||
<form class="addCategoryForm">
|
||||
<span>Neue Kategorie hinzufügen:</span>
|
||||
<input type="text" class="addCategoryForm__nameInput" name="categoryName" placeholder="Neue Kategorie hinzufügen...">
|
||||
@@ -52,15 +52,18 @@
|
||||
|
||||
<ul class="displayedList">
|
||||
<!-- Es werden erste alle Kategorien erstellt, jede Kategorie muss ein ul in einem li sein um Verschachtelung zu ermöglichen -->
|
||||
<li th:each="category: ${categories}" th:id="${category.id}" class="category">
|
||||
<li th:each="category: ${categories}" th:data-id="${category.id}" class="category">
|
||||
<div class="category__div">
|
||||
<span class="category__name category__name--big category__name--bold" th:text="${category.categoryName}"></span>
|
||||
<button class="category__deleteButton">Kategorie löschen</button>
|
||||
<input type="checkbox">
|
||||
<label class="category__labelCheckbox">
|
||||
Gegenstände mit Kategorie löschen?
|
||||
<input name="deleteAllInCategory" type="checkbox">
|
||||
</label>
|
||||
</div>
|
||||
<!-- Items der Kategorie -->
|
||||
<ul>
|
||||
<li th:each="item: ${category.itemsInCategory}" th:id="${item.id}" class="item"> <!-- erstellung von einem Item -->
|
||||
<li th:each="item: ${category.itemsInCategory}" th:data-id="${item.id}" class="item"> <!-- erstellung von einem Item -->
|
||||
<input type="checkbox" class="item__markAsDone" th:checked="${item.isDone}" autocomplete="off">
|
||||
<span class="item__text">
|
||||
<span th:text="${item.itemName}" class="item__textName"></span>
|
||||
@@ -71,7 +74,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li th:each="item: ${items}" th:id="${item.id}" class="item"> <!-- erstellung items ohne Kategorie -->
|
||||
<li th:each="item: ${items}" th:data-id="${item.id}" class="item"> <!-- erstellung items ohne Kategorie -->
|
||||
<input type="checkbox" class="item__markAsDone" th:checked="${item.isDone}" autocomplete="off">
|
||||
<span class="item__text">
|
||||
<span th:text="${item.itemName}" class="item__textName"></span>
|
||||
|
||||
Reference in new issue
Block a user