Compare commits

...
9 Commits
Author SHA1 Message Date
Technoir 390b3b266c Merge branch 'feature/16-rename-lists', fixes #16 2026-10-09 23:08:06 +02:00
Technoir ddec4d8335 editList implementiert
funktionert wie die anderen zwei kack dinger
2026-10-09 23:07:52 +02:00
Technoir f83f3bf4b1 patch-handler für bearbetein von listen implementiert 2026-10-09 23:07:32 +02:00
Technoir 5ee6f07089 beim frontend erstellen kriegt a auch die klasse list__name 2026-10-09 23:07:21 +02:00
Technoir 67c0a5e9b2 fetch-call für patch list im[olementier 2026-10-09 23:07:01 +02:00
Technoir e8319d304a createEditForm implementiert 2026-10-09 23:06:50 +02:00
Technoir de56ba242c a hat nun auch classe list__name 2026-10-09 23:06:41 +02:00
Technoir f84660f0be retard vergisst await 2026-10-09 23:05:54 +02:00
Technoir 113e9cdb82 retard vergisst await 2026-10-09 23:05:35 +02:00
6 changed files with 87 additions and 4 deletions

No files matched your search

@@ -1,5 +1,6 @@
package de.timaldinger.einkaufsliste.Controller;
import de.timaldinger.einkaufsliste.Dto.Patch.ShoppingListPatchDTO;
import de.timaldinger.einkaufsliste.Dto.Post.ShoppingListPostDTO;
import de.timaldinger.einkaufsliste.Dto.Response.ShoppingListResponseDTO;
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
@@ -40,4 +41,15 @@ public class ShoppingListController {
shoppingListService.deleteList(listID);
return ResponseEntity.noContent().build();
}
@PatchMapping("/api/list/{listID}")
public ResponseEntity<Void> editList(@PathVariable UUID listID,@RequestBody ShoppingListPatchDTO toChange){
ShoppingList list = shoppingListRepository.findById(listID).orElseThrow();
if(toChange.newListName() != null) list.setListName(toChange.newListName());
shoppingListRepository.save(list);
return ResponseEntity.noContent().build();
}
}
@@ -24,6 +24,7 @@ export class ShoppingList {
li.id = this.listID;
a.setAttribute("href", `/list/${this.listID}`);
a.classList.add("list__name");
a.textContent = this.listName;
editButton.classList.add("list__editButton");
@@ -19,3 +19,15 @@ export async function deleteList(id) {
return response;
}
export async function editList(listID, toChange) {
const response = await fetch(`/api/list/${listID}`,
{
method: "PATCH",
body: JSON.stringify(toChange),
headers: { "Content-Type": "application/json" }
});
return response;
}
@@ -10,3 +10,33 @@ export function addList(listAsJSON) {
export function deleteList(listElement) {
listElement.remove();
}
export function createEditListForm(textElement) {
const editForm = document.createElement("form");
const inputName = document.createElement("input");
const abortButton = document.createElement("button");
const saveButton = document.createElement("button");
inputName.setAttribute("name", "newListName");
inputName.setAttribute("value", textElement.querySelector(".list__name").textContent);
inputName.classList.add("editForm__name");
abortButton.textContent = "Abbrechen";
saveButton.textContent = "Speichern";
editForm.appendChild(inputName);
editForm.appendChild(saveButton);
editForm.appendChild(abortButton);
return editForm;
}
export function editList(id, formElement, formData, listLi) {
let newName = formData.newListName;
listLi.querySelector(".list__name").textContent = newName;
listLi.setAttribute("href", `/list/${id}`);
formElement.replaceWith(listLi);
}
@@ -10,13 +10,40 @@ async function addList(listName) {
if (listAsJson) ui.addList(listAsJson);
}
function editList() {
function editList(listLi) {
//erstellen das Forms
//wir nutzen für das Element nur das div, weil sonst alle items mitgelöscht werden würden
const formElement = ui.createEditListForm(listLi);
let id = listLi.id;
listLi.replaceWith(formElement);
formElement.querySelector(".editForm__name").focus();
function save() {
let formData = Object.fromEntries(new FormData(formElement));
ui.editList(id, formElement, formData, listLi);
console.log(`editing catogory ${id} with ${formData}`)
api.editList(id, { newListName: formData.newListName });
}
formElement.addEventListener("submit", (event) => {
event.preventDefault();
save();
});
formElement.addEventListener("keydown", (e) => {
if (e.key == "Escape") formElement.replaceWith(listLi);
})
}
function deleteList(listElement) {
async function deleteList(listElement) {
const response = api.deleteList(listElement.id);
const response = await api.deleteList(listElement.id);
if (response.status == 204) ui.deleteList(listElement);
}
@@ -31,6 +58,7 @@ function init() {
document.querySelector(".index").addEventListener("click", (event) => {
if (event.target.matches(".list__editButton")) {
editList(event.target.closest("li"));
} else if (event.target.matches(".list__deleteButton")) {
deleteList(event.target.closest("li"));
+1 -1
View File
@@ -19,7 +19,7 @@ xmlns:th="http://www.thymeleaf.org">
<ul class="displayedList">
<li th:each="list : ${lists}" class="list" th:id="${list.id}">
<a th:text="${list.listName}" th:href="@{/list/{id}(id=${list.id})}"></a>
<a class="list__name" th:text="${list.listName}" th:href="@{/list/{id}(id=${list.id})}"></a>
<button type="button" class="list__editButton">Liste bearbeiten</button>
<button type="button" class="list__deleteButton">Liste löschen</button>
</li>