#19 -- Fix filtering
This commit is contained in:
parent
3cdc712a2c
commit
1770de91c8
@ -8,7 +8,6 @@ package ru.ulstu.extractor.controller;
|
|||||||
import org.springframework.data.domain.Page;
|
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.ModelAttribute;
|
|
||||||
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.bind.annotation.RequestParam;
|
||||||
@ -34,21 +33,23 @@ public class GitFilteringController {
|
|||||||
this.filteringService = filteringService;
|
this.filteringService = filteringService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
|
@RequestMapping(value = FILTER_COMMITS, method = {RequestMethod.GET, RequestMethod.POST})
|
||||||
public String listCommits(
|
public String listCommits(
|
||||||
Model model,
|
Model model,
|
||||||
@ModelAttribute FilterForm filterForm,
|
@RequestParam Optional<Integer> page,
|
||||||
@RequestParam("page") Optional<Integer> page,
|
@RequestParam Optional<Integer> size,
|
||||||
@RequestParam("size") Optional<Integer> size,
|
@RequestParam Optional<String> repositoryUrl,
|
||||||
@RequestParam String repositoryUrl,
|
@RequestParam Optional<String> branchName,
|
||||||
@RequestParam String branchName) {
|
@RequestParam Optional<String> author) {
|
||||||
int currentPage = page.orElse(1);
|
int currentPage = page.orElse(1);
|
||||||
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
||||||
String author = "Anton Romanov";
|
|
||||||
|
|
||||||
Page<Commit> commitsPage = filteringService.getCommits(repositoryUrl,
|
String notEmptyRepositoryUrl = repositoryUrl.orElseThrow(() -> new RuntimeException("Url repository not present"));
|
||||||
branchName,
|
String notEmptyBranchName = branchName.orElseThrow(() -> new RuntimeException("Branch name not present"));
|
||||||
author,
|
|
||||||
|
Page<Commit> commitsPage = filteringService.getCommits(notEmptyRepositoryUrl,
|
||||||
|
notEmptyBranchName,
|
||||||
|
author.orElse(null),
|
||||||
new OffsetablePageRequest(currentPage - 1, pageSize));
|
new OffsetablePageRequest(currentPage - 1, pageSize));
|
||||||
int totalPages = commitsPage.getTotalPages();
|
int totalPages = commitsPage.getTotalPages();
|
||||||
if (totalPages > 0) {
|
if (totalPages > 0) {
|
||||||
@ -57,31 +58,16 @@ public class GitFilteringController {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
model.addAttribute("pageNumbers", pageNumbers);
|
model.addAttribute("pageNumbers", pageNumbers);
|
||||||
}
|
}
|
||||||
|
FilterForm filterForm = new FilterForm();
|
||||||
filterForm.setCommitsPage(commitsPage);
|
filterForm.setCommitsPage(commitsPage);
|
||||||
filterForm.setBranch(branchName);
|
filterForm.setBranchName(notEmptyBranchName);
|
||||||
filterForm.setUrl(repositoryUrl);
|
filterForm.setRepositoryUrl(notEmptyRepositoryUrl);
|
||||||
|
filterForm.setAuthor(author.orElse(null));
|
||||||
model.addAttribute("filterForm", filterForm);
|
model.addAttribute("filterForm", filterForm);
|
||||||
model.addAttribute("authors", filteringService.getRepositoryAuthors(repositoryUrl, branchName));
|
model.addAttribute("authors", filteringService.getRepositoryAuthors(
|
||||||
|
notEmptyRepositoryUrl,
|
||||||
|
notEmptyBranchName
|
||||||
|
));
|
||||||
return FILTER_COMMITS;
|
return FILTER_COMMITS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @RequestMapping(value = FILTER_COMMITS, method = RequestMethod.POST)
|
|
||||||
// public ModelAndView listFilterCommits(
|
|
||||||
// Model model,
|
|
||||||
// @ModelAttribute FilterForm filterForm) {
|
|
||||||
// Page<Commit> commitsPage = filteringService.getCommits(filterForm.getUrl(),
|
|
||||||
// filterForm.getBranch(),
|
|
||||||
// new OffsetablePageRequest(0, DEFAULT_PAGE_SIZE));
|
|
||||||
// int totalPages = commitsPage.getTotalPages();
|
|
||||||
// if (totalPages > 0) {
|
|
||||||
// List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
|
||||||
// .boxed()
|
|
||||||
// .collect(Collectors.toList());
|
|
||||||
// model.addAttribute("pageNumbers", pageNumbers);
|
|
||||||
// }
|
|
||||||
// filterForm.setCommitsPage(commitsPage);
|
|
||||||
// model.addAttribute("filterForm", filterForm);
|
|
||||||
// model.addAttribute("authors", filteringService.getRepositoryAuthors(filterForm.getUrl(), filterForm.getBranch()));
|
|
||||||
// return new ModelAndView()FILTER_COMMITS + "?repositoryUrl="+filterForm.getUrl() + "&branchName=" +filterForm.getBranch() ;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ import ru.ulstu.extractor.model.Commit;
|
|||||||
|
|
||||||
public class FilterForm {
|
public class FilterForm {
|
||||||
private String filter;
|
private String filter;
|
||||||
private String url;
|
private String repositoryUrl;
|
||||||
private String branch;
|
private String branchName;
|
||||||
private String author;
|
private String author;
|
||||||
private Page<Commit> commitsPage;
|
private Page<Commit> commitsPage;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public class FilterForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FilterForm(String url) {
|
public FilterForm(String url) {
|
||||||
this.url = url;
|
this.repositoryUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFilter() {
|
public String getFilter() {
|
||||||
@ -38,22 +38,6 @@ public class FilterForm {
|
|||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBranch() {
|
|
||||||
return branch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBranch(String branch) {
|
|
||||||
this.branch = branch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Page<Commit> getCommitsPage() {
|
public Page<Commit> getCommitsPage() {
|
||||||
return commitsPage;
|
return commitsPage;
|
||||||
}
|
}
|
||||||
@ -62,10 +46,30 @@ public class FilterForm {
|
|||||||
this.commitsPage = commitsPage;
|
this.commitsPage = commitsPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRepositoryUrl() {
|
||||||
|
return repositoryUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepositoryUrl(String repositoryUrl) {
|
||||||
|
this.repositoryUrl = repositoryUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBranchName() {
|
||||||
|
return branchName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBranchName(String branchName) {
|
||||||
|
this.branchName = branchName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "FilterForm{" +
|
return "FilterForm{" +
|
||||||
"subject='" + filter +
|
"filter='" + filter + '\'' +
|
||||||
|
", repositoryUrl='" + repositoryUrl + '\'' +
|
||||||
|
", branchName='" + branchName + '\'' +
|
||||||
|
", author='" + author + '\'' +
|
||||||
|
", commitsPage=" + commitsPage +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import ru.ulstu.extractor.model.Repository;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface CommitRepository extends JpaRepository<Commit, Integer> {
|
public interface CommitRepository extends JpaRepository<Commit, Integer> {
|
||||||
@Query("SELECT c FROM Commit c, Repository r, Branch b, Author a WHERE c.branch = b AND r = b.repository AND a = c.author AND r = :repository AND b.name = :branchName AND a.name = :author")
|
@Query("SELECT c FROM Commit c, Repository r, Branch b, Author a WHERE c.branch = b AND r = b.repository AND a = c.author AND r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author)")
|
||||||
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author);
|
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author);
|
||||||
|
|
||||||
@Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.author.name")
|
@Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.author.name")
|
||||||
|
@ -40,7 +40,7 @@ public class FilteringService {
|
|||||||
|
|
||||||
public Page<Commit> getCommits(@NotNull String repositoryUrl,
|
public Page<Commit> getCommits(@NotNull String repositoryUrl,
|
||||||
@NotNull String branchName,
|
@NotNull String branchName,
|
||||||
@NotNull String author,
|
String author,
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
return commitRepository.findByRepositoryAndBranch(
|
return commitRepository.findByRepositoryAndBranch(
|
||||||
pageable,
|
pageable,
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<form action="#" th:action="${@route.FILTER_COMMITS}" th:object="${filterForm}" method="post">
|
<form action="#" th:action="${@route.FILTER_COMMITS}" th:object="${filterForm}" method="get">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-1 col-sm-12">
|
<div class="col-md-1 col-sm-12">
|
||||||
Автор
|
Автор
|
||||||
@ -39,6 +39,11 @@
|
|||||||
th:utext="${author}">
|
th:utext="${author}">
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
<script th:inline="javascript">
|
||||||
|
$('select[name=selValue]').val([[*{author}]]);
|
||||||
|
$('#select-author').selectpicker('refresh');
|
||||||
|
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-1 col-sm-12">
|
<div class="col-md-1 col-sm-12">
|
||||||
Дата:
|
Дата:
|
||||||
@ -73,8 +78,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" th:field="*{url}">
|
<input type="hidden" th:field="*{repositoryUrl}">
|
||||||
<input type="hidden" th:field="*{branch}">
|
<input type="hidden" th:field="*{branchName}">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<tr>
|
<tr>
|
||||||
@ -91,14 +96,14 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p>
|
|
||||||
|
|
||||||
</p>
|
|
||||||
</form>
|
</form>
|
||||||
Страницы:
|
Страницы:
|
||||||
<div th:if="${filterForm.commitsPage.totalPages > 0}" class="pagination"
|
<div th:if="${filterForm.commitsPage.totalPages > 0}" class="pagination"
|
||||||
th:each="pageNumber : ${pageNumbers}">
|
th:each="pageNumber : ${pageNumbers}">
|
||||||
<a th:href="@{/filterCommits(size=${filterForm.commitsPage.size}, page=${pageNumber}, repositoryUrl=${filterForm.url}, branchName=${filterForm.branch})}"
|
<a th:href="@{/filterCommits(size=${filterForm.commitsPage.size}, page=${pageNumber},
|
||||||
|
repositoryUrl=${filterForm.repositoryUrl},
|
||||||
|
branchName=${filterForm.branchName},
|
||||||
|
author=${filterForm.author})}"
|
||||||
th:text=${pageNumber}
|
th:text=${pageNumber}
|
||||||
th:class="${pageNumber == filterForm.commitsPage.number} ? active"></a>
|
th:class="${pageNumber == filterForm.commitsPage.number} ? active"></a>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user