Merge branch 'maintainance/19-refactor-js', fixes #19

This commit is contained in:
Technoir committed 2026-10-09 20:33:19 +02:00
commit 4d69c8167a
15 files changed
+150 -145

No files matched your search

@@ -1,10 +1,5 @@
package de.timaldinger.einkaufsliste.Controller;
import de.timaldinger.einkaufsliste.Dto.ShoppingCategoryDTO;
import de.timaldinger.einkaufsliste.Dto.ShoppingItemResponseDTO;
import de.timaldinger.einkaufsliste.Dto.ShoppingItemDTO;
import de.timaldinger.einkaufsliste.Models.ShoppingList;
import de.timaldinger.einkaufsliste.Models.ShoppingCategory;
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
import de.timaldinger.einkaufsliste.Repository.ShoppingCategoryRepository;
import de.timaldinger.einkaufsliste.Repository.ShoppingItemRepository;
@@ -1,83 +0,0 @@
export async function addItem(listID, itemName, itemAmount, categoryID) {
const newItem = await fetch(`/api/item`,
{
method: "POST",
body: JSON.stringify({
"itemName": itemName,
"itemAmount": itemAmount,
"categoryID": categoryID,
"listID": listID
}),
headers: { "Content-Type": "application/json" }
});
return await newItem.json();
}
export async function deleteItem(itemID) {
const response = await fetch(`/api/item/${itemID}`, { method: "DELETE" });
if (response.status == 204) {
console.log(`deleted item ${itemID}`);
}
return response;
}
export async function editItem(itemID, toChange) {
const response = await fetch(`/api/item/${itemID}`,
{
method: "PATCH",
body: JSON.stringify(toChange),
headers: { "Content-Type": "application/json" }
});
return response;
}
export async function addCategory(listID, categoryName) {
const newCategory = await fetch(`/api/category`,
{
method: "POST"
, body: JSON.stringify({ "categoryName": categoryName, "listID": listID })
, headers: { "Content-Type": "application/json" }
});
return await newCategory.json();
}
export async function editCategory(categoryID, toChange) {
const response = await fetch(`/api/category/${categoryID}`,
{
method: "PATCH",
body: JSON.stringify(toChange),
headers: { "Content-Type": "application/json" }
});
return response;
}
export async function deleteCategory(deleteAllItems, categoryID) {
const response = await fetch(`/api/category/${categoryID}?deleteAllItems=${deleteAllItems}`, { method: "DELETE" });
if (response.status == 204) {
console.log(`deleted item ${categoryID}`);
}
return response;
}
export async function deleteAllDoneItems(listID) {
const response = await fetch(`/api/list/${listID}?deleteAllDoneItems=true`, { method: "DELETE" });
if (response.status == 204) {
console.log(`items have been deleted`);
}
return response;
}
@@ -0,0 +1,30 @@
export async function addCategory(listID, categoryName) {
const newCategory = await fetch(`/api/category`,
{
method: "POST"
, body: JSON.stringify({ "categoryName": categoryName, "listID": listID })
, headers: { "Content-Type": "application/json" }
});
return await newCategory.json();
}
export async function editCategory(categoryID, toChange) {
const response = await fetch(`/api/category/${categoryID}`,
{
method: "PATCH",
body: JSON.stringify(toChange),
headers: { "Content-Type": "application/json" }
});
return response;
}
export async function deleteCategory(deleteAllItems, categoryID) {
const response = await fetch(`/api/category/${categoryID}?deleteAllItems=${deleteAllItems}`, { method: "DELETE" });
if (response.status == 204) {
console.log(`deleted item ${categoryID}`);
}
return response;
}
@@ -0,0 +1,44 @@
export async function addItem(listID, itemName, itemAmount, categoryID) {
const newItem = await fetch(`/api/item`,
{
method: "POST",
body: JSON.stringify({
"itemName": itemName,
"itemAmount": itemAmount,
"categoryID": categoryID,
"listID": listID
}),
headers: { "Content-Type": "application/json" }
});
return await newItem.json();
}
export async function deleteItem(itemID) {
const response = await fetch(`/api/item/${itemID}`, { method: "DELETE" });
if (response.status == 204) {
console.log(`deleted item ${itemID}`);
}
return response;
}
export async function editItem(itemID, toChange) {
const response = await fetch(`/api/item/${itemID}`,
{
method: "PATCH",
body: JSON.stringify(toChange),
headers: { "Content-Type": "application/json" }
});
return response;
}
@@ -0,0 +1,14 @@
export * from "./itemAPI.js";
export * from "./categoryAPI.js"
export async function deleteAllDoneItems(listID) {
const response = await fetch(`/api/list/${listID}?deleteAllDoneItems=true`, { method: "DELETE" });
if (response.status == 204) {
console.log(`items have been deleted`);
}
return response;
}
@@ -1,50 +1,5 @@
import { ShoppingCategory } from "./ShoppingCategory.js";
import { ShoppingItem } from "./ShoppingItem.js";
export function addItem(itemAsJSON) {
let list;
if (!itemAsJSON.categoryID) {
list = document.querySelector(".displayedList");
} else {
list = document.getElementById(`${itemAsJSON.categoryID}`).querySelector("ul");
}
const item = ShoppingItem.fromJSON(itemAsJSON);
list.appendChild(item.render());
}
export function createEditItemForm(textElement) {
const editForm = document.createElement("form");
const inputName = document.createElement("input");
const inputAmount = document.createElement("input");
const abortButton = document.createElement("button");
const saveButton = document.createElement("button");
inputName.setAttribute("name", "newItemName");
inputName.setAttribute("value", textElement.querySelector(".item__textName").textContent);
inputName.classList.add("editForm__name");
inputAmount.setAttribute("name", "newItemAmount");
inputAmount.setAttribute("value", textElement.querySelector(".item__textAmount").textContent);
inputAmount.classList.add("editForm__amount");
abortButton.textContent = "Abbrechen";
saveButton.textContent = "Speichern";
editForm.appendChild(inputName);
editForm.appendChild(inputAmount);
editForm.appendChild(saveButton);
editForm.appendChild(abortButton);
return editForm;
}
export function deleteItem(li) {
li.remove();
}
import { ShoppingCategory } from "../../../models/ShoppingCategory.js";
export function addCategory(categoryAsJSON) {
const list = document.querySelector(".displayedList");
@@ -101,10 +56,3 @@ export function editCategory(id, formElement, formData, categoryDiv) {
document.querySelector(`option[value='${id}']`).textContent = newName;
}
export function deleteAllDoneItems() {
const doneItems = document.querySelectorAll("li.item:has(input[type=checkbox]:checked)");
doneItems.forEach((li) => {
li.remove();
})
}
@@ -0,0 +1,48 @@
import { ShoppingItem } from "../../../models/ShoppingItem.js";
export function addItem(itemAsJSON) {
let list;
if (!itemAsJSON.categoryID) {
list = document.querySelector(".displayedList");
} else {
list = document.getElementById(`${itemAsJSON.categoryID}`).querySelector("ul");
}
const item = ShoppingItem.fromJSON(itemAsJSON);
list.appendChild(item.render());
}
export function createEditItemForm(textElement) {
const editForm = document.createElement("form");
const inputName = document.createElement("input");
const inputAmount = document.createElement("input");
const abortButton = document.createElement("button");
const saveButton = document.createElement("button");
inputName.setAttribute("name", "newItemName");
inputName.setAttribute("value", textElement.querySelector(".item__textName").textContent);
inputName.classList.add("editForm__name");
inputAmount.setAttribute("name", "newItemAmount");
inputAmount.setAttribute("value", textElement.querySelector(".item__textAmount").textContent);
inputAmount.classList.add("editForm__amount");
abortButton.textContent = "Abbrechen";
saveButton.textContent = "Speichern";
editForm.appendChild(inputName);
editForm.appendChild(inputAmount);
editForm.appendChild(saveButton);
editForm.appendChild(abortButton);
return editForm;
}
export function deleteItem(li) {
li.remove();
}
@@ -0,0 +1,9 @@
export * from "./itemUI.js";
export * from "./categoryUI.js";
export function deleteAllDoneItems() {
const doneItems = document.querySelectorAll("li.item:has(input[type=checkbox]:checked)");
doneItems.forEach((li) => {
li.remove();
})
}
@@ -1,5 +1,5 @@
import * as api from "./listAPI.js"
import * as ui from "./listFrontend.js"
import * as api from "./api/listAPI.js"
import * as ui from "./frontend/listUI.js"
const addCategoryForm = document.querySelector(".addCategoryForm");
+1 -1
View File
@@ -8,7 +8,7 @@ xmlns:th="http://www.thymeleaf.org">
<meta name="author" content="" />
<link href="/css/base.css" rel="stylesheet">
<link href="/css/index.css" rel="stylesheet" >
<script src="/js/index.js" type="module"></script>
<script src="/js/pages/index/index.js" type="module"></script>
<body>
+1 -1
View File
@@ -6,7 +6,7 @@
<title>Einkaufsliste</title>
<link href="/css/base.css" rel="stylesheet">
<link href="/css/list.css" rel="stylesheet">
<script src="/js/list/list.js" type="module"></script>
<script src="/js/pages/list/list.js" type="module"></script>
</head>
<body>
<div class="title">