Необходимо добавить пагинацию для новостей и изменить логику контроллера + html

This commit is contained in:
DyCTaTOR 2024-05-24 01:43:09 +04:00
parent 90138ca93d
commit c36a2253f9
13 changed files with 1423 additions and 192 deletions

View File

@ -30,16 +30,19 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
// implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
implementation 'org.modelmapper:modelmapper:3.2.0'
implementation 'org.springframework.boot:spring-boot-devtools'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'org.webjars.npm:bootstrap:5.3.3'
implementation 'com.h2database:h2:2.2.224'
runtimeOnly 'org.webjars.npm:bootstrap:5.3.3'
runtimeOnly 'org.webjars.npm:bootstrap-icons:1.11.3'
runtimeOnly 'org.webjars.npm:font-awesome:4.7.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,40 +1,40 @@
package com.example.demo.entrysData.api;
public class EntrysDataGroupedDepartmentDto {
private String DepartmentName;
private Long Id;
private String Login;
private String Role;
private String departmentName;
private Long id;
private String login;
private String role;
public Long getId(){
return Id;
return id;
}
public void setId(Long Id){
this.Id = Id;
this.id = Id;
}
public String getLogin(){
return Login;
return login;
}
public void setLogin(String Login){
this.Login = Login;
this.login = Login;
}
public String getRole(){
return Role;
return role;
}
public void setRole(String Role){
this.Role = Role;
this.role = Role;
}
public String getDepartmentName(){
return DepartmentName;
return departmentName;
}
public void setDepartmentName(String DepartmentName){
this.DepartmentName = DepartmentName;
this.departmentName = DepartmentName;
}
}

View File

@ -2,7 +2,10 @@ package com.example.demo.entrysData.model;
public interface EntrysDataGroupedDepartment {
Long getId();
String getLogin();
String getRole();
String getDepartmentName();
}

View File

@ -27,8 +27,9 @@ public interface EntrysDataRepository extends CrudRepository<EntrysDataEntity, L
"FROM EntrysDataEntity e " +
"GROUP BY departmentName ORDER BY count DESC")
List<EntrysDataGrouped> getCountEntrysInDepartment();
@Query("select e.department.name as departmentName, e.login as login, e.role as role, e.id as id " +
"from EntrysDataEntity e " +
"group by departmentName order by id desc")
@Query("SELECT e.department.name AS departmentName, e.login AS login, e.role AS role, e.id AS id " +
"FROM EntrysDataEntity e " +
"ORDER BY id DESC")
Page<EntrysDataGroupedDepartment> findAllWithDepartment(Pageable pageable);
}

View File

@ -127,7 +127,7 @@ td form {
height: 200px;
border: 2px solid #2582A3;
border-radius: 8%;
margin-left: 180;
margin-left: 20%;
margin-top: 9px;
margin-bottom: 25px;
}

View File

@ -9,7 +9,7 @@
<script type="text/javascript" src="/webjars/bootstrap/5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="/webjars/bootstrap/5.3.3/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="/webjars/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/webjars/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/style.css" />
</head>

View File

@ -9,6 +9,9 @@
<body>
<main class="text-center" layout:fragment="content">
<th:block th:switch="${departments.size()}">
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<span class="mainSt">
<b>Кафедры</b>
</span>
@ -47,6 +50,8 @@
</tr>
</tbody>
</table>
</th:block>
</th:block>
</main>
</body>

View File

@ -7,8 +7,8 @@
<body>
<main layout:fragment="content">
<form action="#" th:action="@{/directions/edit/{id}(id=${directions.id},(page=${page}))}" th:object="${directions}"
method="post">
<form action="#" th:action="@{/directions/edit/{id}(id=${directions.id},(page=${page}))}"
th:object="${directions}" method="post">
<div class="mb-3">
<label for="id" class="form-label">ID</label>
<input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
@ -44,7 +44,7 @@
</div>
<div class="mb-3 d-flex flex-row">
<button class="btn btn-primary me-2 button-fixed-width" type="submit">Сохранить</button>
<a class="btn btn-secondary button-fixed-width" href="/directions(page=${page})">Отмена</a>
<a class="btn btn-secondary button-fixed-width" th:href="@{/directions(page=${page})}">Отмена</a>
</div>
</form>
</main>

View File

@ -9,10 +9,14 @@
<body>
<main class="text-center" layout:fragment="content">
<th:block th:switch="${items.size()}">
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<label class="mainSt d-flex justify-content-center" for="direction">
Направление</label>
<b>Направление</b>
</label>
<div>
<a href="/directions/edit/(page=${page})" class="btn btn-danger">Добавить направление</a>
<a th:href="@{/directions/edit/(page=${page})}" class="btn btn-danger">Добавить направление</a>
</div>
<table class="table">
<caption></caption>
@ -54,9 +58,13 @@
</tr>
</tbody>
</table>
</th:block>
<th:block th:replace="~{ pagination :: pagination (
url=${'directions'},
totalPages=${totalPages},
currentPage=${currentPage}) }" />
</th:block>
</main>
</body>
</html>

View File

@ -9,48 +9,93 @@
<body>
<main class="text-center" layout:fragment="content">
<th:block th:switch="${news.size()}">
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<span class="mainSt">
<b>Новости</b>
</span>
<div>
<a href="/news/edit/" class="btn btn-danger">Добавить новость</a>
</div>
<table class="table">
<caption></caption>
<thead>
<tr>
<th scope="col" class="w-5">ID</th>
<th scope="col" class="w-10">Дата публикации</th>
<th scope="col" class="w-25">Заголовок</th>
<th scope="col" class="w-50">Описание</th>
<th scope="col" class="w-10"></th>
<th scope="col" class="w-10"></th>
</tr>
</thead>
<tbody>
<tr th:each="newItem : ${news}">
<th scope="row" th:text="${newItem.id}"></th>
<td th:text="${newItem.date}"></td>
<td th:text="${newItem.name}"></td>
<td th:text="${newItem.description}"></td>
<td>
<th:block th:unless="${news.size() > 3}">
<div class="row">
<div class="col mt-4" th:each="newItem : ${news}">
<div class="rectNews d-flex flex-column">
<img class="imageNew1" src="./images/New1.png" alt th:alt="${newItem.name}"
width="100%">
<div class="rectNewsTextBox">
<span class="rectNewsText">
<b scope="row" th:text="${newItem.description}"></b>
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get">
<button type="submit" class="btn btn-link button-link">
<i class="fa fa-edit">Изменить</i>
</button>
<a type="submit" class="btn btn-link button-link">
<i class="fa fa-edit"></i>
</a>
</form>
</td>
<td>
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post">
<button type="submit" class="btn btn-link button-link"
<a type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">
<i class="fa fa-trash">Удалить</i>
</button>
<i class="fa fa-trash"></i>
</a>
</form>
</td>
</tr>
</tbody>
</table>
</span>
</div>
</div>
</div>
</div>
</th:block>
<th:block th:if="${news.size() > 3}">
<div class="row">
<div class="col mt-4" th:each="newItem : ${news}">
<div class="rectNews d-flex flex-column">
<img class="imageNew1" src="./images/New1.png" alt th:alt="${newItem.name}"
width="100%">
<div class="rectNewsTextBox">
<span class="rectNewsText">
<b scope="row" th:text="${newItem.description}"></b>
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get">
<a type="submit" class="btn btn-link button-link">
<i class="fa fa-edit"></i>
</a>
</form>
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post">
<a type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">
<i class="fa fa-trash"></i>
</a>
</form>
</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col mt-4" th:each="newItem : ${news}">
<div class="rectNews d-flex flex-column">
<img class="imageNew1" src="./images/New1.png" alt th:alt="${newItem.name}"
width="100%">
<div class="rectNewsTextBox">
<span class="rectNewsText">
<b scope="row" th:text="${newItem.description}"></b>
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get">
<a type="submit" class="btn btn-link button-link">
<i class="fa fa-edit"></i>
</a>
</form>
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post">
<a type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">
<i class="fa fa-trash"></i>
</a>
</form>
</span>
</div>
</div>
</div>
</div>
</th:block>
</th:block>
</th:block>
</main>
</body>

View File

@ -9,6 +9,9 @@
<body>
<main class="text-center" layout:fragment="content">
<th:block th:switch="${items.size()}">
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<span class="mainSt">
<b>Пользователи</b>
</span>
@ -28,20 +31,20 @@
</tr>
</thead>
<tbody>
<tr th:each="newItem : ${news}">
<th scope="row" th:text="${newItem.id}"></th>
<td th:text="${newItem.date}"></td>
<td th:text="${newItem.name}"></td>
<td th:text="${newItem.description}"></td>
<tr th:each="user : ${items}">
<th scope="row" th:text="${user.id}"></th>
<td th:text="${user.login}"></td>
<td th:text="${user.role}"></td>
<td th:text="${user.departmentName}"></td>
<td>
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get">
<form th:action="@{/users/edit/{id}(id=${user.id})}" method="get">
<button type="submit" class="btn btn-link button-link">
<i class="fa fa-edit">Изменить</i>
</button>
</form>
</td>
<td>
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post">
<form th:action="@{/users/delete/{id}(id=${user.id})}" method="post">
<button type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">
<i class="fa fa-trash">Удалить</i>
@ -51,6 +54,12 @@
</tr>
</tbody>
</table>
</th:block>
<th:block th:replace="~{ pagination :: pagination (
url=${'users'},
totalPages=${totalPages},
currentPage=${currentPage}) }" />
</th:block>
</main>
</body>