fixt #24 grade mit weil es sehr schnell zu implementieren war
This commit is contained in:
commit
340e524945
7 files changed
+81
-12
No files matched your search
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@@ -40,6 +41,8 @@ public class PageController {
|
||||
@GetMapping("/list/{id}")
|
||||
public String list(Model model, @PathVariable UUID id){
|
||||
ShoppingList list = shoppingListRepository.findById(id).orElseThrow();
|
||||
List<ShoppingList> lists = shoppingListRepository.findAll();
|
||||
model.addAttribute("lists", lists);
|
||||
model.addAttribute("list", list);
|
||||
model.addAttribute("categories", shoppingCategoryRepository.findByList(list));
|
||||
model.addAttribute("items", shoppingItemRepository.findByList_IdAndCategoryIsNull(id));
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
li.displayedList__item--checked{
|
||||
text-decoration: line-through;
|
||||
|
||||
.nav__dropdown {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.category__name--big{
|
||||
font-weight: bold;
|
||||
.nav__dropdownMenu {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.nav__dropdown:hover .nav__dropdownMenu,
|
||||
.nav__dropdown.is-open .nav__dropdownMenu{
|
||||
display: block;
|
||||
}
|
||||
|
||||
.category__name--big{
|
||||
font-size: 2rem;
|
||||
.nav > ul {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
list-style: none;
|
||||
margin: 1;
|
||||
padding: 1;
|
||||
}
|
||||
|
||||
.nav__dropdownMenu {
|
||||
background-color: grey;
|
||||
}
|
||||
@@ -21,7 +21,7 @@ export class ShoppingList {
|
||||
const deleteButton = document.createElement("button");
|
||||
|
||||
li.classList.add("list");
|
||||
li.id = this.listID;
|
||||
li.dataset.id = this.listID;
|
||||
|
||||
a.setAttribute("href", `/list/${this.listID}`);
|
||||
a.classList.add("list__name");
|
||||
@@ -37,4 +37,19 @@ export class ShoppingList {
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
renderNavElement() {
|
||||
const li = document.createElement("li");
|
||||
const a = document.createElement("a");
|
||||
|
||||
li.classList.add("navbar__list");
|
||||
li.dataset.id = this.listID;
|
||||
|
||||
a.setAttribute("href", `/list/${this.listID}`);
|
||||
a.textContent = this.listName;
|
||||
|
||||
li.append(a);
|
||||
|
||||
return li;
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,16 @@ import { ShoppingList } from "../../../models/ShoppingList.js";
|
||||
|
||||
export function addList(listAsJSON) {
|
||||
const list = document.querySelector(".displayedList");
|
||||
const navList = document.querySelector(".nav__dropdownMenu");
|
||||
const listElement = ShoppingList.fromJSON(listAsJSON);
|
||||
|
||||
list.append(listElement.render());
|
||||
navList.append(listElement.renderNavElement());
|
||||
}
|
||||
|
||||
export function deleteList(listElement) {
|
||||
|
||||
document.querySelector(`li.navbar__list[data-id='${listElement.dataset.id}']`).remove();
|
||||
listElement.remove();
|
||||
}
|
||||
|
||||
@@ -35,6 +40,9 @@ export function editList(id, formElement, formData, listLi) {
|
||||
|
||||
let newName = formData.newListName;
|
||||
|
||||
|
||||
document.querySelector(`.navbar__list[data-id='${listLi.dataset.id}'] > a`).textContent = newName;
|
||||
|
||||
listLi.querySelector(".list__name").textContent = newName;
|
||||
listLi.setAttribute("href", `/list/${id}`);
|
||||
formElement.replaceWith(listLi);
|
||||
|
||||
@@ -12,9 +12,8 @@ async function addList(listName) {
|
||||
|
||||
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;
|
||||
let id = listLi.dataset.id;
|
||||
|
||||
listLi.replaceWith(formElement);
|
||||
|
||||
@@ -43,7 +42,7 @@ function editList(listLi) {
|
||||
|
||||
async function deleteList(listElement) {
|
||||
|
||||
const response = await api.deleteList(listElement.id);
|
||||
const response = await api.deleteList(listElement.dataset.id);
|
||||
|
||||
if (response.status == 204) ui.deleteList(listElement);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,20 @@ xmlns:th="http://www.thymeleaf.org">
|
||||
<script src="/js/pages/index/index.js" type="module"></script>
|
||||
|
||||
<body>
|
||||
|
||||
<nav class="nav">
|
||||
<ul class="nav__links">
|
||||
<li class="nav__link"><a href="/">Alle Einkaufslisten</a></li>
|
||||
<li class="nav__dropdown">Listen >
|
||||
<ul class="nav__dropdownMenu">
|
||||
<li th:each="list : ${lists}" th:data-id="${list.id}" class="navbar__list">
|
||||
<a th:text="${list.listName}" th:href="@{/list/{id}(id=${list.id})}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="index">
|
||||
<form class="addListForm">
|
||||
<input type="text" name="listName" required />
|
||||
@@ -18,7 +32,7 @@ xmlns:th="http://www.thymeleaf.org">
|
||||
</form>
|
||||
|
||||
<ul class="displayedList">
|
||||
<li th:each="list : ${lists}" class="list" th:id="${list.id}">
|
||||
<li th:each="list : ${lists}" class="list" th:data-id="${list.id}">
|
||||
<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>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -9,6 +9,20 @@
|
||||
<script src="/js/pages/list/list.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="nav">
|
||||
<ul class="nav__links">
|
||||
<li class="nav__link"><a href="/">Alle Einkaufslisten</a></li>
|
||||
<li class="nav__dropdown">Listen >
|
||||
<ul class="nav__dropdownMenu">
|
||||
<li th:each="list : ${lists}" th:data-id="${list.id}" class="navbar__list">
|
||||
<a th:text="${list.listName}" th:href="@{/list/{id}(id=${list.id})}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="title">
|
||||
<h1 th:text="${list.listName}"></h1>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user