show authors
This commit is contained in:
parent
8365cf825a
commit
ddd5bc504e
@ -16,7 +16,6 @@ import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.model.OffsetablePageRequest;
|
||||
import ru.ulstu.extractor.model.mvc.FilterForm;
|
||||
import ru.ulstu.extractor.service.FilteringService;
|
||||
import ru.ulstu.extractor.service.IndexService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -27,26 +26,13 @@ import static ru.ulstu.extractor.controller.Route.FILTER_COMMITS;
|
||||
|
||||
@Controller
|
||||
public class GitFilteringController {
|
||||
private final static int DEFAULT_PAGE_SIZE = 20;
|
||||
private final FilteringService filteringService;
|
||||
private final IndexService indexService;
|
||||
|
||||
public GitFilteringController(FilteringService filteringService,
|
||||
IndexService indexService) {
|
||||
public GitFilteringController(FilteringService filteringService) {
|
||||
this.filteringService = filteringService;
|
||||
this.indexService = indexService;
|
||||
}
|
||||
|
||||
/* @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";
|
||||
}*/
|
||||
|
||||
@RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
|
||||
public String listCommits(
|
||||
Model model,
|
||||
@ -56,9 +42,11 @@ public class GitFilteringController {
|
||||
@RequestParam String repositoryUrl,
|
||||
@RequestParam String branchName) {
|
||||
int currentPage = page.orElse(1);
|
||||
int pageSize = size.orElse(5);
|
||||
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
||||
|
||||
Page<Commit> commitsPage = indexService.getCommits(repositoryUrl, branchName, new OffsetablePageRequest(currentPage, pageSize));
|
||||
Page<Commit> commitsPage = filteringService.getCommits(repositoryUrl,
|
||||
branchName,
|
||||
new OffsetablePageRequest(currentPage, pageSize));
|
||||
int totalPages = commitsPage.getTotalPages();
|
||||
if (totalPages > 0) {
|
||||
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages - 1)
|
||||
@ -66,11 +54,11 @@ public class GitFilteringController {
|
||||
.collect(Collectors.toList());
|
||||
model.addAttribute("pageNumbers", pageNumbers);
|
||||
}
|
||||
filterForm = new FilterForm();
|
||||
filterForm.setCommitsPage(commitsPage);
|
||||
filterForm.setBranch(branchName);
|
||||
filterForm.setUrl(repositoryUrl);
|
||||
model.addAttribute("filterForm", filterForm);
|
||||
model.addAttribute("authors", filteringService.getRepositoryAuthors(repositoryUrl, branchName));
|
||||
return FILTER_COMMITS;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||
*/
|
||||
|
||||
package ru.ulstu.extractor.model.mvc;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
@ -7,11 +12,20 @@ public class FilterForm {
|
||||
private String filter;
|
||||
private String url;
|
||||
private String branch;
|
||||
private String author;
|
||||
private Page<Commit> commitsPage;
|
||||
|
||||
public FilterForm() {
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public FilterForm(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||
*/
|
||||
|
||||
package ru.ulstu.extractor.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@ -9,6 +14,6 @@ import ru.ulstu.extractor.model.Repository;
|
||||
import java.util.List;
|
||||
|
||||
public interface AuthorRepository extends JpaRepository<Author, Integer> {
|
||||
@Query("SELECT a FROM Commit c, Repository r, Branch b, Author a WHERE c.author = a AND c.branch = b AND r = b.repository AND r = :repository AND b.name = :branchName")
|
||||
List<Author> findByRepositoryAndBranch(@Param("repository") Repository repository, @Param("branchName") String branchName);
|
||||
@Query("SELECT DISTINCT a.name FROM Commit c, Repository r, Branch b, Author a WHERE c.author = a AND c.branch = b AND r = b.repository AND r = :repository AND b.name = :branchName AND a.name IS NOT NULL AND a.name <> '' ORDER BY a.name")
|
||||
List<String> findByRepositoryAndBranch(@Param("repository") Repository repository, @Param("branchName") String branchName);
|
||||
}
|
||||
|
@ -1,13 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||
*/
|
||||
|
||||
package ru.ulstu.extractor.service;
|
||||
|
||||
import com.sun.istack.NotNull;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.repository.AuthorRepository;
|
||||
import ru.ulstu.extractor.repository.CommitRepository;
|
||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FilteringService {
|
||||
private final AuthorRepository authorRepository;
|
||||
private final CommitRepository commitRepository;
|
||||
private final RepositoryRepository repositoryRepository;
|
||||
|
||||
private final IndexService indexService;
|
||||
public FilteringService(AuthorRepository authorRepository,
|
||||
CommitRepository commitRepository,
|
||||
RepositoryRepository repositoryRepository) {
|
||||
this.authorRepository = authorRepository;
|
||||
this.commitRepository = commitRepository;
|
||||
this.repositoryRepository = repositoryRepository;
|
||||
}
|
||||
|
||||
public FilteringService(IndexService indexService) {
|
||||
this.indexService = indexService;
|
||||
public List<String> getRepositoryAuthors(@NotNull String repositoryUrl,
|
||||
@NotNull String branchName) {
|
||||
return authorRepository.findByRepositoryAndBranch(
|
||||
repositoryRepository.findByUrl(repositoryUrl),
|
||||
branchName
|
||||
);
|
||||
}
|
||||
|
||||
public Page<Commit> getCommits(@NotNull String repositoryUrl,
|
||||
@NotNull String branchName,
|
||||
Pageable pageable) {
|
||||
return commitRepository.findByRepositoryAndBranch(
|
||||
pageable,
|
||||
repositoryRepository.findByUrl(repositoryUrl),
|
||||
branchName
|
||||
);
|
||||
}
|
||||
|
||||
/* @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";
|
||||
}*/
|
||||
}
|
||||
|
@ -7,15 +7,11 @@ package ru.ulstu.extractor.service;
|
||||
|
||||
import com.sun.istack.NotNull;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.extractor.model.Author;
|
||||
import ru.ulstu.extractor.model.Branch;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.model.Repository;
|
||||
import ru.ulstu.extractor.repository.AuthorRepository;
|
||||
import ru.ulstu.extractor.repository.BranchRepository;
|
||||
import ru.ulstu.extractor.repository.CommitRepository;
|
||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||
@ -29,19 +25,15 @@ public class IndexService {
|
||||
private final RepositoryRepository repositoryRepository;
|
||||
private final BranchRepository branchRepository;
|
||||
private final CommitRepository commitRepository;
|
||||
private final AuthorRepository authorRepository;
|
||||
|
||||
|
||||
public IndexService(GitRepositoryService gitRepositoryService,
|
||||
RepositoryRepository repositoryRepository,
|
||||
BranchRepository branchRepository,
|
||||
CommitRepository commitRepository,
|
||||
AuthorRepository authorRepository) {
|
||||
CommitRepository commitRepository) {
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
this.repositoryRepository = repositoryRepository;
|
||||
this.branchRepository = branchRepository;
|
||||
this.commitRepository = commitRepository;
|
||||
this.authorRepository = authorRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ -61,12 +53,4 @@ public class IndexService {
|
||||
branch.setCommits(commits);
|
||||
branchRepository.save(branch);
|
||||
}
|
||||
|
||||
public List<Author> getRepositoryAuthors(@NotNull String repositoryUrl, @NotNull String branchName) {
|
||||
return authorRepository.findByRepositoryAndBranch(repositoryRepository.findByUrl(repositoryUrl), branchName);
|
||||
}
|
||||
|
||||
public Page<Commit> getCommits(@NotNull String repositoryUrl, @NotNull String branchName, Pageable pageable) {
|
||||
return commitRepository.findByRepositoryAndBranch(pageable, repositoryRepository.findByUrl(repositoryUrl), branchName);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
<!--
|
||||
~ Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||
~ You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||
-->
|
||||
|
||||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
|
||||
<!--<head th:substituteby="header :: copy"></head>-->
|
||||
|
||||
<div class="container" layout:fragment="content">
|
||||
<h1>Ошибка</h1>
|
||||
|
||||
<!-- As we are using Thymeleaf, you might consider using
|
||||
${#httpServletRequest.requestURL}. But that returns the path
|
||||
to this error page. Hence we explicitly add the url to the
|
||||
Model in some of the example code. -->
|
||||
<p th:if="${url}">
|
||||
<b>Страница:</b> <span th:text="${url}">Page URL</span>
|
||||
</p>
|
||||
@ -34,11 +33,13 @@
|
||||
<div class="collapse" id="collapseExample">
|
||||
<p class="card card-body">
|
||||
<div th:utext="'Failed URL: ' + ${url}" th:remove="tag">${url}</div>
|
||||
<p th:if="${exception}">
|
||||
<div th:utext="'Exception: ' + ${exception.message}" th:remove="tag">${exception.message}</div>
|
||||
</p>
|
||||
<div th:if="${exception != null}" th:utext="'Exception: ' + ${exception.message}" th:remove="tag">
|
||||
${exception.message}
|
||||
</div>
|
||||
<ul th:remove="tag">
|
||||
<li th:each="ste : ${exception.stackTrace}" th:remove="tag"><span
|
||||
<li th:if="${exception != null && exception.stackTrace != null}" th:each="ste : ${exception.stackTrace}"
|
||||
th:remove="tag"><span
|
||||
th:utext="${ste}" th:remove="tag">${ste}</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -27,33 +27,59 @@
|
||||
}
|
||||
</style>
|
||||
<form action="#" th:action="${@route.FILTER_COMMITS}" th:object="${filterForm}" method="post">
|
||||
<p><b>Фильтровать данные:</b><Br></p>
|
||||
По автору
|
||||
<select class="selectpicker" data-live-search="true">
|
||||
<div class="row">
|
||||
<div class="col-md-1 col-sm-12">
|
||||
Автор
|
||||
</div>
|
||||
<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 th:each="author : ${authors}"
|
||||
th:value="${author}"
|
||||
th:utext="${author}">
|
||||
</option>
|
||||
</select>
|
||||
Дата с
|
||||
</div>
|
||||
<div class="col-md-1 col-sm-12">
|
||||
Дата:
|
||||
</div>
|
||||
<div class="col-md-3 col-sm-12">
|
||||
<select class="selectpicker" data-live-search="true">
|
||||
<option data-tokens="day">день</option>
|
||||
<option data-tokens="month">месяц</option>
|
||||
<option data-tokens="age">год</option>
|
||||
</select>
|
||||
по
|
||||
</div>
|
||||
<div class="col-md-1 col-sm-12">
|
||||
-
|
||||
</div>
|
||||
<div class="col-md-3 col-sm-12">
|
||||
<select class="selectpicker" data-live-search="true">
|
||||
<option data-tokens="day">день</option>
|
||||
<option data-tokens="month">месяц</option>
|
||||
<option data-tokens="age">год</option>
|
||||
</select>
|
||||
<p>Строки:<br>
|
||||
<input type="text" size="40" th:field="*{filter}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-2 col-sm-12">
|
||||
Искать по тексту:
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<input type="text" class="form-control" size="40" th:field="*{filter}">
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-12">
|
||||
<input type="submit" class="btn btn-outline-success w-100" value="Применить фильтр"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" th:field="*{url}">
|
||||
</p>
|
||||
<p style="color:red" th:text="${error}"></p>
|
||||
<table class="table table-striped">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col">Author</th>
|
||||
<th scope="col" style="width: 30%">Date</th>
|
||||
<th scope="col">Commit</th>
|
||||
<th scope="col">Автор</th>
|
||||
<th scope="col" style="width: 30%">Дата</th>
|
||||
<th scope="col">Сообщение</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -65,7 +91,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<input type="submit" value="Отправить"/>
|
||||
|
||||
</p>
|
||||
</form>
|
||||
Страницы:
|
||||
|
@ -46,7 +46,7 @@
|
||||
data-width="90%">
|
||||
<option th:each="branch : ${branches}"
|
||||
th:value="${branch.name}"
|
||||
th:utext="${branch.name}"/>
|
||||
th:utext="${branch.name}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user