Фикс заголовков в пользователях

This commit is contained in:
Никита Потапов 2024-06-21 09:50:12 +04:00
parent 1aba31e5ab
commit 7b13fb6f8b
3 changed files with 136 additions and 62 deletions

View File

@ -55,6 +55,7 @@ public class AdminUserController {
@GetMapping("/create")
public String getCreateView(Model model) {
model.addAttribute(USER_ATTRIBUTE, new UserEditDTO());
model.addAttribute("title", "Новый пользователь");
return USER_EDIT_VIEW;
}
@ -67,6 +68,8 @@ public class AdminUserController {
throw new IllegalArgumentException();
}
model.addAttribute("title", "Редактировать пользователя");
UserEntity userEntity = userService.get(id);
UserEditDTO userEditDTO = new UserEditDTO();
userEditDTO.setId(userEntity.getId());
@ -91,6 +94,8 @@ public class AdminUserController {
Model model,
RedirectAttributes redirectAttributes) {
model.addAttribute("title", "Редактировать пользователя");
UserEntity userEntity;
if (userEditDTO.getId() == null) {

View File

@ -1,63 +1,132 @@
<!DOCTYPE html>
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{index}">
<html
lang="ru"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{index}"
>
<head>
<title>[[${title}]]</title>
</head>
<head>
<title>Редакторовать пользователя</title>
</head>
<body>
<main layout:fragment="content">
<form action="#" th:action="@{/admin/users/edit(page=${page})}" th:object="${user}" method="post">
<input type="hidden" th:field="*{id}" id="id" class="form-control" readonly>
<div class="mb-3">
<label for="username" class="form-label">Логин*</label>
<input type="text" th:field="*{username}" id="username" class="form-control">
<div th:if="${#fields.hasErrors('username')}" th:errors="*{username}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="userRole" class="form-label">Роль в системе*</label>
<select th:field="*{role}" id="userRole" class="form-control">
<option
th:each="userRoleOpt : ${T(com.example.nekontakte.users.model.UserRole).values()}"
th:value="${userRoleOpt}"
th:text="${userRoleOpt.displayName}">
</option>
</select>
</div>
<div class="mb-3">
<label for="password" class="form-label">Пароль</label>
<input type="password" th:field="*{password}" id="password" class="form-control">
<div th:if="${#fields.hasErrors('password')}" th:errors="*{password}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="passwordConfirm" class="form-label">Пароль (подтверждение)</label>
<input type="password" th:field="*{passwordConfirm}" id="passwordConfirm" class="form-control">
<div th:if="${#fields.hasErrors('passwordConfirm')}" th:errors="*{passwordConfirm}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="name" class="form-label">Имя</label>
<input type="text" th:field="*{name}" id="name" class="form-control">
</div>
<div class="mb-3">
<label for="surname" class="form-label">Имя пользователя</label>
<input type="text" th:field="*{surname}" id="surname" class="form-control">
</div>
<div class="mb-3">
<label for="birthday" class="form-label">Дата рождения</label>
<input type="date" th:field="*{birthday}" id="birthday" class="form-control">
</div>
<div class="mb-3">
<label for="city" class="form-label">Место проживания</label>
<input type="text" th:field="*{city}" id="city" class="form-control">
</div>
<div class="mb-3">
<label for="status" class="form-label">Статус</label>
<input type="text" th:field="*{status}" id="status" class="form-control">
</div>
<button class="btn btn-success me-3" type="submit">Применить</button>
<a th:href="@{/admin/users(page=${page})}" class="btn btn-danger" >Отмена</a>
</form>
</main>
</body>
</html>
<body>
<main layout:fragment="content">
<form
action="#"
th:action="@{/admin/users/edit(page=${page})}"
th:object="${user}"
method="post"
>
<input
type="hidden"
th:field="*{id}"
id="id"
class="form-control"
readonly
/>
<div class="mb-3">
<label for="username" class="form-label">Логин*</label>
<input
type="text"
th:field="*{username}"
id="username"
class="form-control"
/>
<div
th:if="${#fields.hasErrors('username')}"
th:errors="*{username}"
class="invalid-feedback"
></div>
</div>
<div class="mb-3">
<label for="userRole" class="form-label">Роль в системе*</label>
<select th:field="*{role}" id="userRole" class="form-control">
<option
th:each="userRoleOpt : ${T(com.example.nekontakte.users.model.UserRole).values()}"
th:value="${userRoleOpt}"
th:text="${userRoleOpt.displayName}"
></option>
</select>
</div>
<div class="mb-3">
<label for="password" class="form-label">Пароль</label>
<input
type="password"
th:field="*{password}"
id="password"
class="form-control"
/>
<div
th:if="${#fields.hasErrors('password')}"
th:errors="*{password}"
class="invalid-feedback"
></div>
</div>
<div class="mb-3">
<label for="passwordConfirm" class="form-label"
>Пароль (подтверждение)</label
>
<input
type="password"
th:field="*{passwordConfirm}"
id="passwordConfirm"
class="form-control"
/>
<div
th:if="${#fields.hasErrors('passwordConfirm')}"
th:errors="*{passwordConfirm}"
class="invalid-feedback"
></div>
</div>
<div class="mb-3">
<label for="name" class="form-label">Имя</label>
<input
type="text"
th:field="*{name}"
id="name"
class="form-control"
/>
</div>
<div class="mb-3">
<label for="surname" class="form-label">Фамилия</label>
<input
type="text"
th:field="*{surname}"
id="surname"
class="form-control"
/>
</div>
<div class="mb-3">
<label for="birthday" class="form-label">Дата рождения</label>
<input
type="date"
th:field="*{birthday}"
id="birthday"
class="form-control"
/>
</div>
<div class="mb-3">
<label for="city" class="form-label">Место проживания</label>
<input
type="text"
th:field="*{city}"
id="city"
class="form-control"
/>
</div>
<div class="mb-3">
<label for="status" class="form-label">Статус</label>
<input
type="text"
th:field="*{status}"
id="status"
class="form-control"
/>
</div>
<button class="btn btn-success me-3" type="submit">Применить</button>
<a th:href="@{/admin/users(page=${page})}" class="btn btn-danger"
>Отмена</a
>
</form>
</main>
</body>
</html>

View File

@ -12,7 +12,7 @@
<th:block th:case="*">
<h2>Пользователи</h2>
<div>
<a th:href="@{/admin/users/create}" class="btn btn-primary">Добавить пользователя</a>
<a th:href="@{/admin/users/create}" class="btn btn-primary">Создать пользователя</a>
</div>
<table class="table">
<caption></caption>