#21 -- Fix report page
This commit is contained in:
parent
0fee0ab9ce
commit
0ec47113d1
@ -1,50 +0,0 @@
|
|||||||
package ru.ulstu.aspirant.controller;
|
|
||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import ru.ulstu.aspirant.service.AspirantService;
|
|
||||||
import ru.ulstu.indicator.model.Indicator;
|
|
||||||
import ru.ulstu.model.OffsetablePageRequest;
|
|
||||||
import ru.ulstu.report.model.Report;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("aspirant")
|
|
||||||
public class AspirantController {
|
|
||||||
private static final Integer DEFAULT_PAGE_SIZE = 1;
|
|
||||||
private static final Integer DEFAULT_PAGE_NUMBER = 1;
|
|
||||||
private final AspirantService aspirantService;
|
|
||||||
|
|
||||||
public AspirantController(AspirantService aspirantService) {
|
|
||||||
this.aspirantService = aspirantService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("aspirantReport")
|
|
||||||
public String createReport(Model model,
|
|
||||||
@RequestParam Optional<Integer> page,
|
|
||||||
@RequestParam Optional<Integer> size) {
|
|
||||||
int currentPage = page.orElse(DEFAULT_PAGE_NUMBER);
|
|
||||||
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
|
||||||
|
|
||||||
Page<Indicator> indicators = aspirantService.getIndicatorsByCourse(new OffsetablePageRequest(currentPage - 1, pageSize));
|
|
||||||
model.addAttribute("indicators", indicators);
|
|
||||||
int totalPages = indicators.getTotalPages();
|
|
||||||
if (totalPages > 0) {
|
|
||||||
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
|
||||||
.boxed()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
model.addAttribute("pageNumbers", pageNumbers);
|
|
||||||
}
|
|
||||||
|
|
||||||
model.addAttribute("report", new Report());
|
|
||||||
return "aspirant/editReport";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +1,40 @@
|
|||||||
package ru.ulstu.report.controller;
|
package ru.ulstu.report.controller;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import ru.ulstu.aspirant.service.AspirantService;
|
||||||
|
import ru.ulstu.indicator.model.Indicator;
|
||||||
|
import ru.ulstu.model.OffsetablePageRequest;
|
||||||
|
import ru.ulstu.report.model.Report;
|
||||||
import ru.ulstu.report.model.ReportListForm;
|
import ru.ulstu.report.model.ReportListForm;
|
||||||
import ru.ulstu.report.service.ReportPeriodService;
|
import ru.ulstu.report.service.ReportPeriodService;
|
||||||
import ru.ulstu.report.service.ReportService;
|
import ru.ulstu.report.service.ReportService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("report")
|
@RequestMapping("report")
|
||||||
public class ReportController {
|
public class ReportController {
|
||||||
|
private static final Integer DEFAULT_PAGE_SIZE = 1;
|
||||||
|
private static final Integer DEFAULT_PAGE_NUMBER = 1;
|
||||||
|
|
||||||
|
private final AspirantService aspirantService;
|
||||||
private final ReportService reportService;
|
private final ReportService reportService;
|
||||||
private final ReportPeriodService reportPeriodService;
|
private final ReportPeriodService reportPeriodService;
|
||||||
|
|
||||||
public ReportController(ReportService reportService,
|
public ReportController(AspirantService aspirantService,
|
||||||
|
ReportService reportService,
|
||||||
ReportPeriodService reportPeriodService) {
|
ReportPeriodService reportPeriodService) {
|
||||||
|
this.aspirantService = aspirantService;
|
||||||
this.reportService = reportService;
|
this.reportService = reportService;
|
||||||
this.reportPeriodService = reportPeriodService;
|
this.reportPeriodService = reportPeriodService;
|
||||||
}
|
}
|
||||||
@ -37,4 +55,26 @@ public class ReportController {
|
|||||||
model.addAttribute("canCreate", reportService.canCreateReport(reportListForm.getReportPeriod()));
|
model.addAttribute("canCreate", reportService.canCreateReport(reportListForm.getReportPeriod()));
|
||||||
return "report/reportList";
|
return "report/reportList";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("editReport/{reportId}")
|
||||||
|
public String createReport(@PathVariable("reportId") Integer reportId,
|
||||||
|
Model model,
|
||||||
|
@RequestParam Optional<Integer> page,
|
||||||
|
@RequestParam Optional<Integer> size) {
|
||||||
|
int currentPage = page.orElse(DEFAULT_PAGE_NUMBER);
|
||||||
|
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
||||||
|
|
||||||
|
Page<Indicator> indicators = aspirantService.getIndicatorsByCourse(new OffsetablePageRequest(currentPage - 1, pageSize));
|
||||||
|
model.addAttribute("indicators", indicators);
|
||||||
|
int totalPages = indicators.getTotalPages();
|
||||||
|
if (totalPages > 0) {
|
||||||
|
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
||||||
|
.boxed()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
model.addAttribute("pageNumbers", pageNumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.addAttribute("report", new Report());
|
||||||
|
return "report/editReport";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"
|
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"
|
||||||
aria-haspopup="true" aria-expanded="false">Аспиранту</a>
|
aria-haspopup="true" aria-expanded="false">Аспиранту</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
<a class="dropdown-item" href="/aspirant/aspirantReport">Новый отчет аспиранта по БРС</a>
|
|
||||||
<a class="dropdown-item" href="/report/reportList">Список отчетов</a>
|
<a class="dropdown-item" href="/report/reportList">Список отчетов</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
|
||||||
<html
|
<html
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
|
||||||
layout:decorate="~{default}">
|
layout:decorate="~{default}">
|
||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<h3 th:text="${'Редактирование отчета аспиранта '} +${report.createDate}"></h3>
|
<h3 th:text="${'Редактирование отчета аспиранта '} +${report.createDate}"></h3>
|
||||||
<form action="#" th:action="@{/aspirant/saveReport}"
|
<form action="#" th:action="@{/report/saveReport}"
|
||||||
th:object="${report}"
|
th:object="${report}"
|
||||||
method="post">
|
method="post">
|
||||||
<input type="hidden" th:field="*{id}">
|
<input type="hidden" th:field="*{id}">
|
||||||
@ -97,14 +96,14 @@
|
|||||||
onclick="return confirm('Удалить запись?')">
|
onclick="return confirm('Удалить запись?')">
|
||||||
Удалить
|
Удалить
|
||||||
</button>
|
</button>
|
||||||
<a href="/aspirant/reports" class="btn btn-outline-dark">Отмена</a>
|
<a href="/report/reportList" class="btn btn-outline-dark">Отмена</a>
|
||||||
</form>
|
</form>
|
||||||
<div th:if="${indicators.totalPages > 0}" class="pagination">
|
<div th:if="${indicators.totalPages > 0}" class="pagination">
|
||||||
<span style="float: left; padding: 5px 5px;">Страницы:</span>
|
<span style="float: left; padding: 5px 5px;">Страницы:</span>
|
||||||
</div>
|
</div>
|
||||||
<div th:if="${indicators.totalPages > 0}" class="pagination"
|
<div th:if="${indicators.totalPages > 0}" class="pagination"
|
||||||
th:each="pageNumber : ${pageNumbers}">
|
th:each="pageNumber : ${pageNumbers}">
|
||||||
<a th:href="@{/aspirant/aspirantReport(size=${indicators.size}, page=${pageNumber})}"
|
<a th:href="@{/report/editReport(size=${indicators.size}, page=${pageNumber})}"
|
||||||
th:text=${pageNumber}
|
th:text=${pageNumber}
|
||||||
th:class="${pageNumber == indicators.number+1} ? active"></a>
|
th:class="${pageNumber == indicators.number+1} ? active"></a>
|
||||||
</div>
|
</div>
|
Loading…
x
Reference in New Issue
Block a user