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.stereotype.Controller;
|
||||
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.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@ -36,16 +35,22 @@ public class GitFilteringController {
|
||||
@RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
|
||||
public String listCommits(
|
||||
Model model,
|
||||
@ModelAttribute FilterForm filterForm,
|
||||
@RequestParam("page") Optional<Integer> page,
|
||||
@RequestParam("size") Optional<Integer> size,
|
||||
@RequestParam String repositoryUrl,
|
||||
@RequestParam String branchName) {
|
||||
@RequestParam Optional<Integer> page,
|
||||
@RequestParam Optional<Integer> size,
|
||||
@RequestParam Optional<String> repositoryUrl,
|
||||
@RequestParam Optional<String> branchName,
|
||||
@RequestParam Optional<String> author,
|
||||
@RequestParam Optional<String> filter) {
|
||||
int currentPage = page.orElse(1);
|
||||
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
||||
|
||||
Page<Commit> commitsPage = filteringService.getCommits(repositoryUrl,
|
||||
branchName,
|
||||
String notEmptyRepositoryUrl = repositoryUrl.orElseThrow(() -> new RuntimeException("Url repository not present"));
|
||||
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));
|
||||
int totalPages = commitsPage.getTotalPages();
|
||||
if (totalPages > 0) {
|
||||
@ -54,11 +59,17 @@ public class GitFilteringController {
|
||||
.collect(Collectors.toList());
|
||||
model.addAttribute("pageNumbers", pageNumbers);
|
||||
}
|
||||
FilterForm filterForm = new FilterForm();
|
||||
filterForm.setCommitsPage(commitsPage);
|
||||
filterForm.setBranch(branchName);
|
||||
filterForm.setUrl(repositoryUrl);
|
||||
filterForm.setBranchName(notEmptyBranchName);
|
||||
filterForm.setRepositoryUrl(notEmptyRepositoryUrl);
|
||||
filterForm.setAuthor(author.orElse(null));
|
||||
filterForm.setFilter(filter.orElse(null));
|
||||
model.addAttribute("filterForm", filterForm);
|
||||
model.addAttribute("authors", filteringService.getRepositoryAuthors(repositoryUrl, branchName));
|
||||
model.addAttribute("authors", filteringService.getRepositoryAuthors(
|
||||
notEmptyRepositoryUrl,
|
||||
notEmptyBranchName
|
||||
));
|
||||
return FILTER_COMMITS;
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import ru.ulstu.extractor.model.Commit;
|
||||
|
||||
public class FilterForm {
|
||||
private String filter;
|
||||
private String url;
|
||||
private String branch;
|
||||
private String repositoryUrl;
|
||||
private String branchName;
|
||||
private String author;
|
||||
private Page<Commit> commitsPage;
|
||||
|
||||
@ -27,7 +27,7 @@ public class FilterForm {
|
||||
}
|
||||
|
||||
public FilterForm(String url) {
|
||||
this.url = url;
|
||||
this.repositoryUrl = url;
|
||||
}
|
||||
|
||||
public String getFilter() {
|
||||
@ -38,22 +38,6 @@ public class FilterForm {
|
||||
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() {
|
||||
return commitsPage;
|
||||
}
|
||||
@ -62,10 +46,30 @@ public class FilterForm {
|
||||
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
|
||||
public String toString() {
|
||||
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;
|
||||
|
||||
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")
|
||||
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String 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, @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")
|
||||
List<CommitAuthorStatistic> getCommitAuthorStatistic();
|
||||
|
@ -40,22 +40,15 @@ public class FilteringService {
|
||||
|
||||
public Page<Commit> getCommits(@NotNull String repositoryUrl,
|
||||
@NotNull String branchName,
|
||||
String author,
|
||||
String filter,
|
||||
Pageable pageable) {
|
||||
return commitRepository.findByRepositoryAndBranch(
|
||||
pageable,
|
||||
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;
|
||||
}
|
||||
</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="col-md-1 col-sm-12">
|
||||
Автор
|
||||
@ -34,11 +34,16 @@
|
||||
<div class="col-md-3 col-sm-12">
|
||||
<select id="select-author" class="selectpicker" data-live-search="true" th:field="*{author}"
|
||||
data-width="90%">
|
||||
<option value="">Все авторы</option>
|
||||
<option th:each="author : ${authors}"
|
||||
th:value="${author}"
|
||||
th:utext="${author}">
|
||||
</option>
|
||||
</select>
|
||||
<script th:inline="javascript">
|
||||
$('select[name=selValue]').val([[*{author}]]);
|
||||
$('#select-author').selectpicker('refresh');
|
||||
</script>
|
||||
</div>
|
||||
<div class="col-md-1 col-sm-12">
|
||||
Дата:
|
||||
@ -73,7 +78,8 @@
|
||||
</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">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
@ -90,14 +96,15 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
|
||||
</p>
|
||||
</form>
|
||||
Страницы:
|
||||
<div th:if="${filterForm.commitsPage.totalPages > 0}" class="pagination"
|
||||
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:class="${pageNumber == filterForm.commitsPage.number} ? active"></a>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user