Update search form in list.html; modify UserController for user list handling and enhance application properties
This commit is contained in:
parent
e7eeb45db1
commit
ebbb373cf6
|
|
@ -11,6 +11,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
|
@ -119,6 +120,8 @@ public class UserController {
|
|||
return "redirect:/user_list"; // Redirige al login tras registrarse
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/delete_user")
|
||||
public String deleteUser(@RequestParam("id") Long id) {
|
||||
User user = userService.getUserById(id);
|
||||
|
|
@ -126,15 +129,24 @@ public class UserController {
|
|||
return "redirect:/user_list"; // Redirige a la página de gestión de usuarios
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/user_list")
|
||||
public String genericPage(Model model) {
|
||||
public String userList(Model model) {
|
||||
return buildUserList(model, userService.getAllUsers());
|
||||
}
|
||||
|
||||
private String buildUserList(Model model, List<User> users) {
|
||||
model.addAttribute("title", "Gestión de usuarios");
|
||||
model.addAttribute("headers", List.of("ID", "Nombre", "Rol", "Email","Departamento", "Acciones"));
|
||||
model.addAttribute("items", userService.getAllUsers().stream()
|
||||
model.addAttribute("headers", List.of("ID", "Nombre", "Rol", "Email","Departamento"));
|
||||
model.addAttribute("items", users.stream()
|
||||
.map(user -> Map.of(
|
||||
"id", user.getId(),
|
||||
"values", List.of(user.getId(), user.getNombre(), user.getRole(), user.getMail(), user.getDepartamento() != null ? user.getDepartamento().getNombre() : " ")
|
||||
"values", List.of(
|
||||
user.getId(),
|
||||
user.getNombre(),
|
||||
user.getRole(),
|
||||
user.getMail(),
|
||||
user.getDepartamento() != null ? user.getDepartamento().getNombre() : " "
|
||||
)
|
||||
))
|
||||
.toList());
|
||||
model.addAttribute("actionsUrl", Map.of(
|
||||
|
|
@ -143,21 +155,24 @@ public class UserController {
|
|||
));
|
||||
model.addAttribute("backUrl", "/Inventario/home");
|
||||
model.addAttribute("addUrl", "/Inventario/userPage");
|
||||
|
||||
return "list";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/departamento_list")
|
||||
public String genericPageDepartamento(Model model) {
|
||||
model.addAttribute("title", "Gestión de Departamentos");
|
||||
model.addAttribute("headers", List.of("ID", "Nombre","Acciones"));
|
||||
|
||||
model.addAttribute("headers", List.of("ID", "Nombre"));
|
||||
model.addAttribute(
|
||||
"items",
|
||||
departamentoService.getAllDepartamentos().stream().map(departamento -> Map.of("id", departamento.getId(),
|
||||
"values", List.of(departamento.getId(), departamento.getNombre()))).toList()
|
||||
);
|
||||
|
||||
model.addAttribute("actionsUrl", Map.of(
|
||||
"edit", "",
|
||||
"delete", ""
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ spring.datasource.url=jdbc:mysql://localhost:3306/Inventario?useSSL=false&server
|
|||
spring.datasource.username=InventarioSpring
|
||||
spring.datasource.password=1234567891
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
|
||||
# Configuración de JPA e Hibernate
|
||||
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
|
|
|
|||
|
|
@ -9,24 +9,25 @@
|
|||
<h2 th:text="${title}"></h2>
|
||||
|
||||
<!-- Formulario de búsqueda -->
|
||||
<form th:action="@{/search}" method="get" class="search-form">
|
||||
<form th:action="@{/filtered_list}" method="get" class="search-form">
|
||||
<label for="headers">Filtro:</label>
|
||||
<select id="headers" name="filter">
|
||||
<option value="">-- Sin filtro --</option>
|
||||
<option th:each="header : ${headers}"
|
||||
th:value="${header}"
|
||||
th:text="${header}">
|
||||
</option>
|
||||
</select>
|
||||
<input type="text" name="query" placeholder="Buscar..." required>
|
||||
<button type="submit">Buscar</button>
|
||||
</form>
|
||||
|
||||
<label for="headers">Filtro:</label>
|
||||
<select id="headers" name="">
|
||||
<option value="">-- Sin filtro --</option>
|
||||
<option th:each="headers : ${headers}"
|
||||
th:value="${headers}"
|
||||
th:text="${headers}">
|
||||
</option>
|
||||
</select>
|
||||
<div class="table-container">
|
||||
<table class="table1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th th:each="header : ${headers}" th:text="${header}"></th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
|
|||
Loading…
Reference in New Issue