Refactor button rendering logic in home page; update button URLs and integrate button fragment for improved dynamic rendering

This commit is contained in:
jon ander 2025-04-11 18:03:15 +02:00
parent b56442d48b
commit d60b10f4d8
3 changed files with 15 additions and 19 deletions

View File

@ -30,8 +30,8 @@ public class UserController {
@GetMapping("/home")
public String homePage(Model model) {
List<BotonDTO> botones = List.of(
new BotonDTO("Inventario", "/Inventario/management", false, null),
new BotonDTO("Gestión", "/Inventario/management", true, "button_salir")
new BotonDTO("Inventario", "/management", false, null),
new BotonDTO("Gestión", "/management", true, null)
);
model.addAttribute("buttons", botones);
return "home"; // Retorna la vista home.html

View File

@ -5,7 +5,18 @@
<div th:fragment="buttonList(buttons)">
<div class="container1">
<div th:each="button : ${buttons}">
<div th:utext="${button.isRequireAdmin()}"></div>
<div th:if="${!button.isRequireAdmin()}">
<a th:href="@{${button.getUrl()}}">
<button th:class="${button.getCssClass()}" th:text="${button.getTexto()}"></button>
</a>
</div>
<div th:if="${button.isRequireAdmin()}">
<div sec:authorize="hasRole('ADMIN')">
<a th:href="@{${button.getUrl()}}">
<button th:class="${button.getCssClass()}" th:text="${button.getTexto()}"></button>
</a>
</div>
</div>
</div>
</div>
</div>
@ -14,15 +25,3 @@
<!-- <div th:if="${!button.isRequireAdmin()}">-->
<!-- <a th:href="@{${button.getUrl()}}">-->
<!-- <button th:class="${button.getCssClass()}" th:text="${button.getTexto()}"></button>-->
<!-- </a>-->
<!-- </div>-->
<!-- <div th:if="${button.isRequireAdmin()}">-->
<!-- <div sec:authorize="hasRole('ADMIN')">-->
<!-- <a th:href="@{${button.getUrl()}}">-->
<!-- <button th:class="${button.getCssClass()}" th:text="${button.getTexto()}"></button>-->
<!-- </a>-->
<!-- </div>-->
<!-- </div>-->

View File

@ -7,11 +7,8 @@
</head>
<body>
<h2>Bienvenido a Gestión de Inventario</h2>
<div th:each="button : ${buttons}">
<div th:utext="${button.isRequireAdmin()}"></div>
</div>
<!-- Reemplaza los botones por el fragmento reutilizable -->
<div th:replace="fragments/buttons :: buttonList(buttons)"></div>
<div th:replace="fragments/buttons :: buttonList(${buttons})"></div>
<!-- Formulario de Logout (estático y fuera del fragmento) -->
<form th:action="@{/logout}" method="post">