Необходимо добавить пагинацию для новостей и изменить логику контроллера + 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 { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation' 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.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 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0' implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'org.webjars.npm:bootstrap:5.3.3'
implementation 'com.h2database:h2:2.2.224' 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' 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; package com.example.demo.entrysData.api;
public class EntrysDataGroupedDepartmentDto { public class EntrysDataGroupedDepartmentDto {
private String DepartmentName; private String departmentName;
private Long Id; private Long id;
private String Login; private String login;
private String Role; private String role;
public Long getId(){ public Long getId(){
return Id; return id;
} }
public void setId(Long Id){ public void setId(Long Id){
this.Id = Id; this.id = Id;
} }
public String getLogin(){ public String getLogin(){
return Login; return login;
} }
public void setLogin(String Login){ public void setLogin(String Login){
this.Login = Login; this.login = Login;
} }
public String getRole(){ public String getRole(){
return Role; return role;
} }
public void setRole(String Role){ public void setRole(String Role){
this.Role = Role; this.role = Role;
} }
public String getDepartmentName(){ public String getDepartmentName(){
return DepartmentName; return departmentName;
} }
public void setDepartmentName(String 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 { public interface EntrysDataGroupedDepartment {
Long getId(); Long getId();
String getLogin(); String getLogin();
String getRole(); String getRole();
String getDepartmentName(); String getDepartmentName();
} }

View File

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

View File

@ -127,7 +127,7 @@ td form {
height: 200px; height: 200px;
border: 2px solid #2582A3; border: 2px solid #2582A3;
border-radius: 8%; border-radius: 8%;
margin-left: 180; margin-left: 20%;
margin-top: 9px; margin-top: 9px;
margin-bottom: 25px; 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> <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/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="/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" /> <link rel="stylesheet" href="/css/style.css" />
</head> </head>

View File

@ -9,6 +9,9 @@
<body> <body>
<main class="text-center" layout:fragment="content"> <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"> <span class="mainSt">
<b>Кафедры</b> <b>Кафедры</b>
</span> </span>
@ -47,6 +50,8 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
</th:block>
</th:block>
</main> </main>
</body> </body>

View File

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

View File

@ -9,10 +9,14 @@
<body> <body>
<main class="text-center" layout:fragment="content"> <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 class="mainSt d-flex justify-content-center" for="direction">
Направление</label> <b>Направление</b>
</label>
<div> <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> </div>
<table class="table"> <table class="table">
<caption></caption> <caption></caption>
@ -54,9 +58,13 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
</th:block>
<th:block th:replace="~{ pagination :: pagination ( <th:block th:replace="~{ pagination :: pagination (
url=${'directions'}, url=${'directions'},
totalPages=${totalPages}, totalPages=${totalPages},
currentPage=${currentPage}) }" /> currentPage=${currentPage}) }" />
</th:block>
</main> </main>
</body> </body>
</html>

View File

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

View File

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