Implement user deletion functionality and enhance user management UI with new button styles
This commit is contained in:
parent
8688949ec7
commit
4f86df1ca1
|
|
@ -46,10 +46,7 @@ public class UserController {
|
|||
public String managementPage(){
|
||||
return "management";
|
||||
}
|
||||
// @GetMapping("/user_management")
|
||||
// public String userManagementPage(){
|
||||
// return "user_management";
|
||||
// }
|
||||
|
||||
|
||||
@GetMapping("/user_management")
|
||||
public String listUsers(Model model) {
|
||||
|
|
@ -57,5 +54,13 @@ public class UserController {
|
|||
model.addAttribute("users", users);
|
||||
return "user_management";
|
||||
}
|
||||
@GetMapping("/delete_user")
|
||||
public String deleteUser(@RequestParam Long id) {
|
||||
User user = userService.getUserById(id);
|
||||
if (user != null) {
|
||||
userService.deleteUser(user);
|
||||
}
|
||||
return "redirect:/user_management";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,4 +30,10 @@ public class UserService {
|
|||
public List<User> getAllUsers() {
|
||||
return userRepository.findAll();
|
||||
}
|
||||
public void deleteUser(User user){
|
||||
userRepository.delete(user);
|
||||
}
|
||||
public User getUserById(Long id) {
|
||||
return userRepository.findById(id).orElse(null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,17 +35,15 @@ td{
|
|||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
table{
|
||||
border-collapse: collapse;
|
||||
box-shadow: 0 0 20px rgba(0,0,0,0.1);
|
||||
}
|
||||
.table-container{
|
||||
height: 500px;
|
||||
height: fit-content;
|
||||
overflow: auto;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.table1 thead {
|
||||
position: sticky;
|
||||
|
|
@ -67,6 +65,28 @@ table{
|
|||
.celda-acciones button:hover {
|
||||
background-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
.botones{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
.botones button {
|
||||
margin: 10px 30px;
|
||||
padding: 10px;
|
||||
background-color: #007bff;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.botones .button_salir {
|
||||
background-color: #ff5050;
|
||||
}
|
||||
.botones button:hover {
|
||||
filter: brightness(0.8); /* Reduce el brillo al 80% */
|
||||
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
/* Estilo para la barra de desplazamiento */
|
||||
::-webkit-scrollbar {
|
||||
border-radius: 100px;
|
||||
|
|
|
|||
|
|
@ -24,11 +24,26 @@
|
|||
<td th:text="${user.nombre}"></td>
|
||||
<td th:text="${user.role}"></td>
|
||||
<td th:title="${user.mail}" th:text="${user.mail}"></td>
|
||||
<td class="celda-acciones"><button th:title="Editar">✏️</button> <button th:title="Borrar">🗑️</button></td>
|
||||
<td class="celda-acciones">
|
||||
<button th:title="Editar">✏️</button>
|
||||
<form th:action="@{/delete_user}" method="get" style="display:inline;">
|
||||
<input type="hidden" th:name="id" th:value="${user.id}" />
|
||||
<button type="submit" th:title="Borrar" formaction="#" onclick="if(confirm('¿Estás seguro de que deseas borrar este usuario?')) { this.form.action = this.form.getAttribute('th:action'); } else { return false; }">🗑️</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="botones">
|
||||
<a href="/Inventario/home">
|
||||
<button class="button_salir">Volver al inicio</button>
|
||||
</a>
|
||||
<a href="/Inventario/register">
|
||||
<button>Añadir usuario</button>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in New Issue