frontend ordner entfernt, frontend dateien nach src/main/resources/static verschoben
This commit is contained in:
1 parent
faf1933147
commit
a609dde372
12 files changed
+2
-955
No files matched your search
@@ -1 +0,0 @@
|
||||
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=class{constructor(e,t,n){this.itemName=e,this.itemAmount=t,this.isEditing=!1,this.isDone=!1,this.remove=!1,this.onChange=n}render(){let e;return e=this.isEditing?this.#e():this.#t(),e}#e(){let e=document.createElement(`li`),t=document.createElement(`form`),n=document.createElement(`input`),r=document.createElement(`input`),i=document.createElement(`button`),a=document.createElement(`button`);return n.setAttribute(`name`,`newItemName`),n.setAttribute(`value`,this.itemName),r.setAttribute(`itemName`,`newItemAmount`),r.setAttribute(`value`,this.itemAmount),a.textContent=`Abbrechen`,a.addEventListener(`click`,e=>{e.preventDefault(),this.isEditing=!1,this.onChange()}),i.textContent=`Speichern`,t.addEventListener(`submit`,e=>{e.preventDefault();let n=Object.fromEntries(new FormData(t));(n.newItemName||n.newItemAmount)&&(this.itemName=n.newItemName,this.itemAmount=n.newItemAmount,this.isEditing=!1,this.onChange())}),t.appendChild(n),t.appendChild(r),t.appendChild(i),t.appendChild(a),e.appendChild(t),e}#t(){let e=document.createElement(`li`),t=document.createElement(`span`),n=document.createElement(`button`),r=document.createElement(`input`);return r.setAttribute(`type`,`checkbox`),r.addEventListener(`change`,()=>{this.isDone=!0,e.classList.toggle(`displayedList__item--checked`)}),t.addEventListener(`click`,()=>{this.isEditing=!0,this.onChange()}),n.textContent=`Löschen`,n.addEventListener(`click`,()=>{this.remove=!0,this.onChange()}),t.textContent=this.itemName+` `+this.itemAmount,e.appendChild(r),e.appendChild(t),e.appendChild(n),e}},t=class{constructor(e,t,n){this.categoryName=e,this.itemsInCategory=[],this.remove=!1,this.isEditing=!1,this.onDelete=t,this.onUpdate=n}render(){let e,t=document.createElement(`li`);return e=this.isEditing?this.#e():this.#t(),t.append(e),t}#e(){let e=document.createElement(`form`),t=document.createElement(`input`),n=document.createElement(`button`),r=document.createElement(`button`);return t.setAttribute(`name`,`newCategoryName`),t.setAttribute(`value`,this.categoryName),r.textContent=`Abbrechen`,r.addEventListener(`click`,e=>{e.preventDefault(),this.isEditing=!1,this.onUpdate()}),n.textContent=`Speichern`,e.addEventListener(`submit`,t=>{t.preventDefault();let n=Object.fromEntries(new FormData(e));n.newCategoryName&&(this.categoryName=n.newCategoryName,this.isEditing=!1,this.onUpdate(),this.onDelete())}),e.appendChild(t),e.appendChild(n),e.appendChild(r),e}#t(){let e=document.createElement(`span`),t=document.createElement(`button`),n=document.createElement(`input`),r=document.createElement(`span`),i=document.createElement(`ul`),a=this.itemsInCategory.filter(e=>!e.remove);return e.textContent=this.categoryName,e.classList.add(`category__name--big`,`category__name--bold`),e.addEventListener(`click`,()=>{this.isEditing=!0,this.onUpdate()}),n.setAttribute(`type`,`checkbox`),r.textContent=`Alle Gegenstände in dieser Kategorie löschen? :`,t.textContent=`Löschen`,t.addEventListener(`click`,()=>{this.remove=!0,n.checked||this.itemsInCategory.forEach(e=>{c(e.itemName,e.itemAmount,``)}),this.onUpdate(),this.onDelete()}),i.appendChild(e),i.appendChild(t),i.appendChild(r),i.appendChild(n),a.forEach((e,t)=>{i.append(e.render())}),i}addItem(e){this.itemsInCategory.push(e)}},n=document.querySelector(`.addItemForm`),r=document.querySelector(`.addCategoryForm`),i=document.querySelector(`.displayedList`),a=document.querySelector(`.deleteAllDoneItemsButton`),o=[];function s(e){return o.push(new t(e,d,l)),l(),0}function c(n,r,i){return i?(i=o.find(e=>e instanceof t&&e.categoryName==i),i.addItem(new e(n,r,l))):o.push(new e(n,r,l)),l(),0}function l(){o=o.filter(e=>!e.remove),i.innerHTML=``,o.forEach((e,t)=>{i.appendChild(e.render(t))})}function u(){o.forEach((e,n)=>{e instanceof t&&(e.itemsInCategory=e.itemsInCategory.filter(e=>!e.isDone))}),o=o.filter(e=>!e.isDone),l()}function d(){let e=document.querySelector(`.addItemForm__categorySelect`),n=o.filter(e=>e instanceof t),r=document.createElement(`option`);r.setAttribute(`value`,``),r.selected=!0,r.textContent=`Keine`,e.innerHTML=``,e.appendChild(r),n.forEach(t=>{let n=document.createElement(`option`);n.setAttribute(`value`,t.categoryName),n.textContent=t.categoryName,e.appendChild(n)})}function f(){d(),n.addEventListener(`submit`,e=>{if(!n.checkValidity())return;e.preventDefault();let tLine truncated
|
||||
@@ -1 +0,0 @@
|
||||
li.displayedList__item--checked{text-decoration:line-through}.category__name--big{font-size:2rem;font-weight:700}
|
||||
@@ -4,8 +4,8 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Einkaufsliste</title>
|
||||
<script type="module" crossorigin src="/assets/index-DaqKi9ke.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-Dk1Kzh8u.css">
|
||||
<link href="/src/style.css" rel="stylesheet">
|
||||
<script src="/src/main.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="title">
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { addNewItem } from "./main.js";
|
||||
|
||||
export class ShoppingCategory {
|
||||
|
||||
constructor(categoryName, onDelete, onUpdate) {
|
||||
this.categoryName = categoryName;
|
||||
this.itemsInCategory = [];
|
||||
this.remove = false;
|
||||
this.isEditing = false;
|
||||
this.onDelete = onDelete;
|
||||
this.onUpdate = onUpdate;
|
||||
}
|
||||
|
||||
render() {
|
||||
let element;
|
||||
const outerLi = document.createElement("li");
|
||||
//if (this.itemsInCategory.length == 0) return;
|
||||
|
||||
|
||||
if (this.isEditing) {
|
||||
element = this.#renderEditing();
|
||||
} else {
|
||||
element = this.#renderNormal();
|
||||
}
|
||||
outerLi.append(element);
|
||||
return outerLi;
|
||||
}
|
||||
|
||||
#renderEditing() {
|
||||
//const li = document.createElement("li");
|
||||
const editForm = document.createElement("form");
|
||||
const editCategoryNameField = document.createElement("input");
|
||||
const saveButton = document.createElement("button");
|
||||
const abortButton = document.createElement("button");
|
||||
|
||||
|
||||
editCategoryNameField.setAttribute("name", "newCategoryName");
|
||||
editCategoryNameField.setAttribute("value", this.categoryName);
|
||||
|
||||
|
||||
abortButton.textContent = "Abbrechen";
|
||||
abortButton.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
this.isEditing = false;
|
||||
this.onUpdate();
|
||||
});
|
||||
|
||||
saveButton.textContent = "Speichern";
|
||||
editForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const editFormData = Object.fromEntries(new FormData(editForm));
|
||||
|
||||
if (!editFormData.newCategoryName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.categoryName = editFormData.newCategoryName;
|
||||
this.isEditing = false;
|
||||
this.onUpdate();
|
||||
this.onDelete();
|
||||
});
|
||||
|
||||
editForm.appendChild(editCategoryNameField);
|
||||
editForm.appendChild(saveButton);
|
||||
editForm.appendChild(abortButton);
|
||||
//li.appendChild(editForm);
|
||||
|
||||
return editForm;
|
||||
|
||||
}
|
||||
|
||||
#renderNormal() {
|
||||
|
||||
const spanCategoryName = document.createElement("span");
|
||||
const removeCategoryButton = document.createElement("button"); // Entfernen der Kategorie
|
||||
const removeCategoryItemsCheckbox = document.createElement("input"); // alle Gegenstände drunter entfernen oder nicht
|
||||
const removeCategoryItemsText = document.createElement("span");
|
||||
const ul = document.createElement("ul");
|
||||
const items = this.itemsInCategory.filter((item) => !item.remove);
|
||||
|
||||
spanCategoryName.textContent = this.categoryName;
|
||||
spanCategoryName.classList.add("category__name--big", "category__name--bold");
|
||||
spanCategoryName.addEventListener("click", () => {
|
||||
this.isEditing = true;
|
||||
this.onUpdate();
|
||||
});
|
||||
|
||||
removeCategoryItemsCheckbox.setAttribute("type", "checkbox");
|
||||
removeCategoryItemsText.textContent = "Alle Gegenstände in dieser Kategorie löschen? :";
|
||||
|
||||
|
||||
removeCategoryButton.textContent = "Löschen";
|
||||
removeCategoryButton.addEventListener("click", () => {
|
||||
this.remove = true;
|
||||
if (!removeCategoryItemsCheckbox.checked) {
|
||||
this.itemsInCategory.forEach((element) => {
|
||||
addNewItem(element.itemName, element.itemAmount, "");
|
||||
});
|
||||
}
|
||||
this.onUpdate();
|
||||
this.onDelete();
|
||||
|
||||
});
|
||||
|
||||
ul.appendChild(spanCategoryName);
|
||||
ul.appendChild(removeCategoryButton);
|
||||
ul.appendChild(removeCategoryItemsText);
|
||||
ul.appendChild(removeCategoryItemsCheckbox);
|
||||
items.forEach((item, index) => {
|
||||
ul.append(item.render());
|
||||
});
|
||||
|
||||
return ul;
|
||||
}
|
||||
|
||||
addItem(item) {
|
||||
this.itemsInCategory.push(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
export class ShoppingListItem {
|
||||
|
||||
constructor(itemName, itemAmount, onChange) {
|
||||
this.itemName = itemName;
|
||||
this.itemAmount = itemAmount;
|
||||
this.isEditing = false;
|
||||
this.isDone = false;
|
||||
this.remove = false;
|
||||
this.onChange = onChange;
|
||||
}
|
||||
|
||||
//gibt ein <li> Element zurück
|
||||
render() {
|
||||
let li;
|
||||
if (this.isEditing) {
|
||||
li = this.#renderEditing();
|
||||
} else {
|
||||
li = this.#renderNormal()
|
||||
}
|
||||
return li;
|
||||
|
||||
}
|
||||
|
||||
#renderEditing() {
|
||||
const li = document.createElement("li");
|
||||
const editForm = document.createElement("form");
|
||||
const editItemNameField = document.createElement("input");
|
||||
const editItemAmountField = document.createElement("input");
|
||||
const saveButton = document.createElement("button");
|
||||
const abortButton = document.createElement("button");
|
||||
|
||||
|
||||
editItemNameField.setAttribute("name", "newItemName");
|
||||
editItemNameField.setAttribute("value", this.itemName);
|
||||
|
||||
editItemAmountField.setAttribute("itemName", "newItemAmount");
|
||||
editItemAmountField.setAttribute("value", this.itemAmount);
|
||||
|
||||
abortButton.textContent = "Abbrechen";
|
||||
abortButton.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
this.isEditing = false;
|
||||
this.onChange();
|
||||
});
|
||||
|
||||
saveButton.textContent = "Speichern";
|
||||
editForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const editFormData = Object.fromEntries(new FormData(editForm));
|
||||
|
||||
if (!editFormData.newItemName && !editFormData.newItemAmount) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.itemName = editFormData.newItemName;
|
||||
this.itemAmount = editFormData.newItemAmount;
|
||||
this.isEditing = false;
|
||||
this.onChange();
|
||||
});
|
||||
|
||||
editForm.appendChild(editItemNameField);
|
||||
editForm.appendChild(editItemAmountField);
|
||||
editForm.appendChild(saveButton);
|
||||
editForm.appendChild(abortButton);
|
||||
li.appendChild(editForm);
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
#renderNormal() {
|
||||
const li = document.createElement("li");
|
||||
const listContent = document.createElement("span");
|
||||
const removeButton = document.createElement("button");
|
||||
const doneButton = document.createElement("input");
|
||||
|
||||
|
||||
doneButton.setAttribute("type", "checkbox");
|
||||
doneButton.addEventListener("change", () => {
|
||||
this.isDone = true;
|
||||
li.classList.toggle("displayedList__item--checked");
|
||||
});
|
||||
|
||||
listContent.addEventListener("click", () => {
|
||||
this.isEditing = true;
|
||||
this.onChange();
|
||||
});
|
||||
|
||||
removeButton.textContent = "Löschen";
|
||||
removeButton.addEventListener("click", () => {
|
||||
this.remove = true;
|
||||
this.onChange();
|
||||
});
|
||||
|
||||
listContent.textContent = this.itemName + " " + this.itemAmount;
|
||||
|
||||
li.appendChild(doneButton);
|
||||
li.appendChild(listContent);
|
||||
li.appendChild(removeButton);
|
||||
|
||||
return li;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import { ShoppingListItem } from "./ShoppingListItem.js";
|
||||
import { ShoppingCategory } from "./ShoppingCategory.js";
|
||||
|
||||
const addItemForm = document.querySelector(".addItemForm");
|
||||
const addCategoryForm = document.querySelector(".addCategoryForm")
|
||||
const itemListElement = document.querySelector(".displayedList");
|
||||
const deleteAllDoneItemsButton = document.querySelector(".deleteAllDoneItemsButton");
|
||||
|
||||
let listElements = []; // Liste der erstellten Items und Kategorien
|
||||
|
||||
function addNewCategory(categoryName) {
|
||||
|
||||
listElements.push(new ShoppingCategory(categoryName, renderAddItemPrompt, renderItemList));
|
||||
renderItemList();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
export function addNewItem(itemName, itemAmount, category) {
|
||||
if (category) {
|
||||
category = listElements.find((element) => element instanceof ShoppingCategory && element.categoryName == category)
|
||||
category.addItem(new ShoppingListItem(itemName, itemAmount, renderItemList));
|
||||
} else {
|
||||
listElements.push(new ShoppingListItem(itemName, itemAmount, renderItemList));
|
||||
}
|
||||
renderItemList();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function renderItemList() {
|
||||
listElements = listElements.filter(item => !item.remove)
|
||||
itemListElement.innerHTML = ""; //reset innerItemList
|
||||
|
||||
listElements.forEach((element, index) => {
|
||||
itemListElement.appendChild(element.render(index));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function deleteAllDoneItems() {
|
||||
listElements.forEach((category, index) => {
|
||||
if (category instanceof ShoppingCategory) {
|
||||
category.itemsInCategory = category.itemsInCategory.filter((item) => !item.isDone);
|
||||
}
|
||||
});
|
||||
listElements = listElements.filter((element) => !element.isDone);
|
||||
renderItemList();
|
||||
}
|
||||
|
||||
function renderAddItemPrompt() {
|
||||
const selectMenu = document.querySelector(".addItemForm__categorySelect");
|
||||
let categories = listElements.filter(element => element instanceof ShoppingCategory);
|
||||
const emptySelection = document.createElement("option");
|
||||
|
||||
|
||||
emptySelection.setAttribute("value", "");
|
||||
emptySelection.selected = true;
|
||||
emptySelection.textContent = "Keine"
|
||||
|
||||
selectMenu.innerHTML = "";
|
||||
selectMenu.appendChild(emptySelection);
|
||||
|
||||
categories.forEach(category => {
|
||||
const option = document.createElement("option");
|
||||
option.setAttribute("value", category.categoryName);
|
||||
option.textContent = category.categoryName;
|
||||
|
||||
selectMenu.appendChild(option);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
renderAddItemPrompt();
|
||||
|
||||
addItemForm.addEventListener("submit", (event) => {
|
||||
if (!addItemForm.checkValidity()) return;
|
||||
event.preventDefault();
|
||||
const addItemFormData = Object.fromEntries(new FormData(addItemForm));
|
||||
addNewItem(addItemFormData.itemName, addItemFormData.itemAmount, addItemFormData.itemCategory);
|
||||
});
|
||||
|
||||
|
||||
addCategoryForm.addEventListener("submit", (event) => {
|
||||
if (!addCategoryForm.checkValidity()) return;
|
||||
event.preventDefault();
|
||||
const addCategoryFormData = Object.fromEntries(new FormData(addCategoryForm));
|
||||
addNewCategory(addCategoryFormData.categoryName);
|
||||
renderAddItemPrompt();
|
||||
});
|
||||
|
||||
deleteAllDoneItemsButton.addEventListener("click", (event) => {
|
||||
deleteAllDoneItems();
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
Reference in new issue
Block a user