Merge branch '19-filtering-by-author' into 'master'
Resolve "Фильтр коммитов по авторам" Closes #19 See merge request romanov73/git-extractor!16
This commit is contained in:
commit
9d825e6e4b
@ -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;
|
||||||
@ -36,16 +35,22 @@ public class GitFilteringController {
|
|||||||
@RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
|
@RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
|
||||||
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,
|
||||||
|
@RequestParam Optional<String> filter) {
|
||||||
int currentPage = page.orElse(1);
|
int currentPage = page.orElse(1);
|
||||||
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
||||||
|
|
||||||
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"));
|
||||||
|
|
||||||
|
Page<Commit> commitsPage = filteringService.getCommits(notEmptyRepositoryUrl,
|
||||||
|
notEmptyBranchName,
|
||||||
|
author.orElse(null),
|
||||||
|
filter.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) {
|
||||||
@ -54,11 +59,17 @@ 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));
|
||||||
|
filterForm.setFilter(filter.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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,8 +19,8 @@ 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 WHERE c.branch = b AND r = b.repository AND r = :repository AND b.name = :branchName")
|
@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) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%')))")
|
||||||
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName);
|
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter);
|
||||||
|
|
||||||
@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")
|
||||||
List<CommitAuthorStatistic> getCommitAuthorStatistic();
|
List<CommitAuthorStatistic> getCommitAuthorStatistic();
|
||||||
|
@ -40,22 +40,15 @@ public class FilteringService {
|
|||||||
|
|
||||||
public Page<Commit> getCommits(@NotNull String repositoryUrl,
|
public Page<Commit> getCommits(@NotNull String repositoryUrl,
|
||||||
@NotNull String branchName,
|
@NotNull String branchName,
|
||||||
|
String author,
|
||||||
|
String filter,
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
return commitRepository.findByRepositoryAndBranch(
|
return commitRepository.findByRepositoryAndBranch(
|
||||||
pageable,
|
pageable,
|
||||||
repositoryRepository.findByUrl(repositoryUrl),
|
repositoryRepository.findByUrl(repositoryUrl),
|
||||||
branchName
|
branchName,
|
||||||
|
author,
|
||||||
|
filter
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @PostMapping("/sendFilter")
|
|
||||||
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) throws GitAPIException, IOException {
|
|
||||||
List<Commit> list = gitRepositoryService.getCommits(filterForm.getUrl(), filterForm.getBranch());
|
|
||||||
model.addAttribute("commits", list);
|
|
||||||
if (filterForm.getFilter() == null || filterForm.getFilter().isEmpty()) {
|
|
||||||
model.addAttribute("error", "'Строка' не должно быть пустым");
|
|
||||||
return "filtering";
|
|
||||||
}
|
|
||||||
return "resultRepo";
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
@ -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">
|
||||||
Автор
|
Автор
|
||||||
@ -34,11 +34,16 @@
|
|||||||
<div class="col-md-3 col-sm-12">
|
<div class="col-md-3 col-sm-12">
|
||||||
<select id="select-author" class="selectpicker" data-live-search="true" th:field="*{author}"
|
<select id="select-author" class="selectpicker" data-live-search="true" th:field="*{author}"
|
||||||
data-width="90%">
|
data-width="90%">
|
||||||
|
<option value="">Все авторы</option>
|
||||||
<option th:each="author : ${authors}"
|
<option th:each="author : ${authors}"
|
||||||
th:value="${author}"
|
th:value="${author}"
|
||||||
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,7 +78,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" th:field="*{url}">
|
<input type="hidden" th:field="*{repositoryUrl}">
|
||||||
|
<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>
|
||||||
@ -90,14 +96,15 @@
|
|||||||
</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},
|
||||||
|
filter=${filterForm.filter})}"
|
||||||
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