Merge branch '10-create-author-table' into 'master'
Resolve "Создание и вывод таблицы с автором и датой" Closes #10 See merge request romanov73/git-extractor!7
This commit is contained in:
commit
7a9b174f3b
@ -48,6 +48,7 @@ dependencies {
|
|||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'
|
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
|
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
|
||||||
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect'
|
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect'
|
||||||
|
compile group: 'org.springframework.data', name: 'spring-data-commons'
|
||||||
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner'
|
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner'
|
||||||
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5'
|
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5'
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'
|
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package ru.ulstu.extractor.mvc;
|
package ru.ulstu.extractor.mvc;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
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;
|
||||||
@ -7,23 +10,34 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
|||||||
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.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
import ru.ulstu.extractor.model.Branch;
|
import ru.ulstu.extractor.model.Branch;
|
||||||
|
import ru.ulstu.extractor.model.Commit;
|
||||||
import ru.ulstu.extractor.mvc.model.FilterForm;
|
import ru.ulstu.extractor.mvc.model.FilterForm;
|
||||||
import ru.ulstu.extractor.mvc.model.RepoForm;
|
import ru.ulstu.extractor.mvc.model.RepoForm;
|
||||||
|
import ru.ulstu.extractor.service.CommitService;
|
||||||
import ru.ulstu.extractor.service.FilteringService;
|
import ru.ulstu.extractor.service.FilteringService;
|
||||||
import ru.ulstu.extractor.service.GitRepositoryService;
|
import ru.ulstu.extractor.service.GitRepositoryService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class GitExtractorController {
|
public class GitExtractorController {
|
||||||
private final FilteringService filteringService;
|
private final FilteringService filteringService;
|
||||||
private final GitRepositoryService gitRepositoryService;
|
private final GitRepositoryService gitRepositoryService;
|
||||||
|
private final CommitService commitService;
|
||||||
|
|
||||||
public GitExtractorController(FilteringService filteringService,
|
public GitExtractorController(FilteringService filteringService,
|
||||||
GitRepositoryService gitRepositoryService) {
|
GitRepositoryService gitRepositoryService,
|
||||||
|
CommitService commitService) {
|
||||||
this.filteringService = filteringService;
|
this.filteringService = filteringService;
|
||||||
this.gitRepositoryService = gitRepositoryService;
|
this.gitRepositoryService = gitRepositoryService;
|
||||||
|
this.commitService = commitService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/newRepo")
|
@GetMapping("/newRepo")
|
||||||
@ -32,14 +46,10 @@ public class GitExtractorController {
|
|||||||
return "newRepo";
|
return "newRepo";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/filtering")
|
|
||||||
public String filter(Model model) {
|
|
||||||
model.addAttribute("filterForm", new FilterForm());
|
|
||||||
return "filtering";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/sendFilter")
|
@PostMapping("/sendFilter")
|
||||||
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) {
|
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) throws GitAPIException, IOException {
|
||||||
|
List<Commit> list = gitRepositoryService.getCommits(filterForm.getUrl());
|
||||||
|
model.addAttribute("commits", list);
|
||||||
if (filterForm.getFilter() == null || filterForm.getFilter().isEmpty()) {
|
if (filterForm.getFilter() == null || filterForm.getFilter().isEmpty()) {
|
||||||
model.addAttribute("error", "'Строка' не должно быть пустым");
|
model.addAttribute("error", "'Строка' не должно быть пустым");
|
||||||
return "filtering";
|
return "filtering";
|
||||||
@ -61,12 +71,36 @@ public class GitExtractorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next")
|
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next")
|
||||||
public String setBranch(@ModelAttribute RepoForm repoForm, Model model) {
|
public String setBranch(@ModelAttribute RepoForm repoForm, Model model, RedirectAttributes redirectAttributes) {
|
||||||
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
|
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
|
||||||
if (repoForm.getBranch() == null) {
|
if (repoForm.getBranch() == null) {
|
||||||
return "newRepo";
|
return "newRepo";
|
||||||
} else {
|
} else {
|
||||||
|
redirectAttributes.addAttribute("url", repoForm.getRepo());
|
||||||
|
redirectAttributes.addAttribute("branch", repoForm.getBranch());
|
||||||
|
return "redirect:/filtering";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/filtering", method = RequestMethod.GET)
|
||||||
|
public String listCommits(
|
||||||
|
Model model,
|
||||||
|
@ModelAttribute FilterForm filterForm,
|
||||||
|
@RequestParam("page") Optional<Integer> page,
|
||||||
|
@RequestParam("size") Optional<Integer> size,
|
||||||
|
@RequestParam String url,
|
||||||
|
@RequestParam String branch) throws GitAPIException, IOException {
|
||||||
|
int currentPage = page.orElse(1);
|
||||||
|
int pageSize = size.orElse(5);
|
||||||
|
Page<Commit> commitPage = commitService.findPaginated(PageRequest.of(currentPage - 1, pageSize), url);
|
||||||
|
model.addAttribute("commitPage", commitPage);
|
||||||
|
int totalPages = commitPage.getTotalPages();
|
||||||
|
if (totalPages > 0) {
|
||||||
|
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
||||||
|
.boxed()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
model.addAttribute("pageNumbers", pageNumbers);
|
||||||
|
}
|
||||||
return "filtering";
|
return "filtering";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
40
src/main/java/ru/ulstu/extractor/service/CommitService.java
Normal file
40
src/main/java/ru/ulstu/extractor/service/CommitService.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package ru.ulstu.extractor.service;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.extractor.model.Commit;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CommitService {
|
||||||
|
private final GitRepositoryService gitRepositoryService;
|
||||||
|
|
||||||
|
public CommitService(GitRepositoryService gitRepositoryService) {
|
||||||
|
this.gitRepositoryService = gitRepositoryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<Commit> findPaginated(Pageable pageable, String url) throws GitAPIException, IOException {
|
||||||
|
int pageSize = pageable.getPageSize();
|
||||||
|
int currentPage = pageable.getPageNumber();
|
||||||
|
int startItem = currentPage * pageSize;
|
||||||
|
List<Commit> commits = gitRepositoryService.getCommits(url);
|
||||||
|
;
|
||||||
|
|
||||||
|
if (commits.size() < startItem) {
|
||||||
|
commits = Collections.emptyList();
|
||||||
|
} else {
|
||||||
|
int toIndex = Math.min(startItem + pageSize, commits.size());
|
||||||
|
commits = commits.subList(startItem, toIndex);
|
||||||
|
}
|
||||||
|
return new PageImpl<>(commits, PageRequest.of(currentPage, pageSize), commits.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
|||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
</head>
|
</head>
|
||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<body>
|
|
||||||
<form action="#" th:action="@{/sendFilter}" th:object="${filterForm}" method="post">
|
<form action="#" th:action="@{/sendFilter}" th:object="${filterForm}" method="post">
|
||||||
<p><b>Фильтровать данные:</b><Br></p>
|
<p><b>Фильтровать данные:</b><Br></p>
|
||||||
По автору
|
По автору
|
||||||
@ -30,23 +29,30 @@
|
|||||||
<input type="hidden" th:field="*{url}">
|
<input type="hidden" th:field="*{url}">
|
||||||
</p>
|
</p>
|
||||||
<p style="color:red" th:text="${error}"></p>
|
<p style="color:red" th:text="${error}"></p>
|
||||||
<!-- <table>-->
|
<table border="1">
|
||||||
<!-- <tr>-->
|
<thead>
|
||||||
<!-- <th>Author</th>-->
|
<tr>
|
||||||
<!-- <th>Date</th>-->
|
<th>Author</th>
|
||||||
<!-- <th>Commit</th>-->
|
<th>Date</th>
|
||||||
<!-- </tr>-->
|
<th>Commit</th>
|
||||||
<!-- <tr th:each="commit : ${commits}">-->
|
</tr>
|
||||||
<!-- <td th:text="${commit.author}">Onions</td>-->
|
</thead>
|
||||||
<!-- <td th:text="${commit.date}">2.41</td>-->
|
<tbody>
|
||||||
<!-- <td th:text="${commit.message}">yes</td>-->
|
<tr th:each="commit: ${commits}">
|
||||||
<!-- </tr>-->
|
<td th:text="${commit.author}"></td>
|
||||||
<!-- </table>-->
|
<td th:text="${commit.date}"></td>
|
||||||
|
<td th:text="${commit.message}"></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
<p>
|
<p>
|
||||||
<input type="submit" value="Отправить"/>
|
<input type="submit" value="Отправить"/>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</div>
|
||||||
|
<div th:if="${commitPage.totalPages > 0}" class="pagination"
|
||||||
|
th:each="pageNumber : ${pageNumbers}">
|
||||||
|
<a th:href="@{/filtering.html(size=${commitPage.size}, page=${pageNumber})}"
|
||||||
|
th:class="${pageNumber==commitPage.number + 1} ? active"></a>
|
||||||
</div>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
</head>
|
</head>
|
||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<body>
|
|
||||||
<form action="#" th:action="@{/newRepo}" th:object="${repoForm}" method="post">
|
<form action="#" th:action="@{/newRepo}" th:object="${repoForm}" method="post">
|
||||||
<p style="color:red" th:text="${error}"></p>
|
<p style="color:red" th:text="${error}"></p>
|
||||||
<p><b>Ваш git репозиторий:</b><br>
|
<p><b>Ваш git репозиторий:</b><br>
|
||||||
@ -28,7 +27,6 @@
|
|||||||
<input type="submit" name="next" value="Продолжить"/>
|
<input type="submit" name="next" value="Продолжить"/>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$('#select-branch').selectpicker('refresh');
|
$('#select-branch').selectpicker('refresh');
|
||||||
|
Loading…
Reference in New Issue
Block a user