Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#91] fix pagenation #95

Merged
merged 2 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath /> <!-- lookup parent from repository -->
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.hexlet.typoreporter</groupId>
<artifactId>hexlet-typo-reporter</artifactId>
Expand Down Expand Up @@ -116,6 +116,11 @@
<artifactId>prettytime</artifactId>
<version>${prettytime.version}</version>
</dependency>
<dependency>
<groupId>io.github.jpenren</groupId>
<artifactId>thymeleaf-spring-data-dialect</artifactId>
<version>3.5.0</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.hexlet.typoreporter.config.thymeleaf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.dialect.springdata.SpringDataDialect;

@Configuration
public class ThymeleafAutoConfiguration {

@Bean
public SpringDataDialect springDataDialect() {
return new SpringDataDialect();
}
}
17 changes: 0 additions & 17 deletions src/main/java/io/hexlet/typoreporter/web/WorkspaceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,7 @@ public String getWorkspaceTyposPage(Model model,
.stream()
.findFirst()
.orElseGet(() -> asc(DEFAULT_SORT_FIELD));
var pageNumber = typoPage.getNumber() + 1;
var pageNumbers = IntStream.of(1, pageNumber - 1, pageNumber, pageNumber + 1, typoPage.getTotalPages())
.filter(n -> n > 0)
.filter(n -> n <= typoPage.getTotalPages())
.distinct()
.boxed()
.collect(toList());

if (pageNumbers.size() > 1) {
if (pageNumbers.get(0) != pageNumbers.get(1) - 1) {
pageNumbers.add(1, null);
}
if (pageNumbers.get(pageNumbers.size() - 2) != pageNumbers.get(pageNumbers.size() - 1) - 1) {
pageNumbers.add(pageNumbers.size() - 1, null);
}
}

model.addAttribute("pageNumbers", pageNumbers);
model.addAttribute("typoPage", typoPage);
model.addAttribute("availableSizes", availableSizes);
model.addAttribute("sortProp", sort.getProperty());
Expand Down
38 changes: 4 additions & 34 deletions src/main/resources/templates/workspace/wks-typos.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sd="http://www.w3.org/1999/xhtml">
<head th:replace="fragments/header :: head"></head>
<body style="padding-top: 4.5rem">
<nav th:replace="fragments/panels :: mainNavbarTop"></nav>
Expand Down Expand Up @@ -46,39 +46,9 @@
</div>
</div>
<!-- Page pagination -->
<nav class="col">
<ul class="pagination">
<li class="page-item" th:classappend="${typoPage.first}? 'disabled'">
<a aria-label="Previous" class="page-link"
th:aria-disabled="${typoPage.first}"
th:href="@{'/workspace/' + ${wksName} + '/typos'(page=${typoPage.number - 1},size=${typoPage.size},sort=|${sortProp},${sortDir}|)}"
th:tabindex="${typoPage.first}? -1">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li class="page-item"
th:attrappend="aria-current=${isCurrent}?'page'"
th:classappend="${isCurrent}?'active'"
th:each="number, stat : ${pageNumbers}"
th:with="isCurrent = ${number == typoPage.number + 1}">
<a class="page-link"
th:href="@{'/workspace/' + ${wksName} + '/typos'(page=${number - 1},size=${typoPage.size},sort=|${sortProp},${sortDir}|)}"
th:text="${number}"
th:unless="${isCurrent || number == null }"></a>
<span class="page-link" th:if="${isCurrent && number != null}"
th:text="${number}"></span>
<span class="page-link" th:if="${number == null}">...</span>
</li>
<li class="page-item" th:classappend="${typoPage.last}? 'disabled'">
<a aria-label="Next" class="page-link"
th:aria-disabled="${typoPage.last}"
th:href="@{'/workspace/' + ${wksName} + '/typos'(page=${typoPage.number + 1},size=${typoPage.size},sort=|${sortProp},${sortDir}|)}"
th:tabindex="${typoPage.last}?-1">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
<div class="col-sm-6">
<ul class="pagination" sd:pagination="full"></ul>
</div>
</div>
<!-- Workspace typo table -->
<div class="row">
Expand Down