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.OffsetablePageRequest;
|
||||||
import ru.ulstu.extractor.model.mvc.FilterForm;
|
import ru.ulstu.extractor.model.mvc.FilterForm;
|
||||||
import ru.ulstu.extractor.service.FilteringService;
|
import ru.ulstu.extractor.service.FilteringService;
|
||||||
import ru.ulstu.extractor.service.IndexService;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -27,26 +26,13 @@ import static ru.ulstu.extractor.controller.Route.FILTER_COMMITS;
|
|||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class GitFilteringController {
|
public class GitFilteringController {
|
||||||
|
private final static int DEFAULT_PAGE_SIZE = 20;
|
||||||
private final FilteringService filteringService;
|
private final FilteringService filteringService;
|
||||||
private final IndexService indexService;
|
|
||||||
|
|
||||||
public GitFilteringController(FilteringService filteringService,
|
public GitFilteringController(FilteringService filteringService) {
|
||||||
IndexService indexService) {
|
|
||||||
this.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)
|
@RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
|
||||||
public String listCommits(
|
public String listCommits(
|
||||||
Model model,
|
Model model,
|
||||||
@ -56,9 +42,11 @@ public class GitFilteringController {
|
|||||||
@RequestParam String repositoryUrl,
|
@RequestParam String repositoryUrl,
|
||||||
@RequestParam String branchName) {
|
@RequestParam String branchName) {
|
||||||
int currentPage = page.orElse(1);
|
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();
|
int totalPages = commitsPage.getTotalPages();
|
||||||
if (totalPages > 0) {
|
if (totalPages > 0) {
|
||||||
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages - 1)
|
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages - 1)
|
||||||
@ -66,11 +54,11 @@ public class GitFilteringController {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
model.addAttribute("pageNumbers", pageNumbers);
|
model.addAttribute("pageNumbers", pageNumbers);
|
||||||
}
|
}
|
||||||
filterForm = new FilterForm();
|
|
||||||
filterForm.setCommitsPage(commitsPage);
|
filterForm.setCommitsPage(commitsPage);
|
||||||
filterForm.setBranch(branchName);
|
filterForm.setBranch(branchName);
|
||||||
filterForm.setUrl(repositoryUrl);
|
filterForm.setUrl(repositoryUrl);
|
||||||
model.addAttribute("filterForm", filterForm);
|
model.addAttribute("filterForm", filterForm);
|
||||||
|
model.addAttribute("authors", filteringService.getRepositoryAuthors(repositoryUrl, branchName));
|
||||||
return FILTER_COMMITS;
|
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;
|
package ru.ulstu.extractor.model.mvc;
|
||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@ -7,11 +12,20 @@ public class FilterForm {
|
|||||||
private String filter;
|
private String filter;
|
||||||
private String url;
|
private String url;
|
||||||
private String branch;
|
private String branch;
|
||||||
|
private String author;
|
||||||
private Page<Commit> commitsPage;
|
private Page<Commit> commitsPage;
|
||||||
|
|
||||||
public FilterForm() {
|
public FilterForm() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthor(String author) {
|
||||||
|
this.author = author;
|
||||||
|
}
|
||||||
|
|
||||||
public FilterForm(String url) {
|
public FilterForm(String url) {
|
||||||
this.url = 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;
|
package ru.ulstu.extractor.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@ -9,6 +14,6 @@ import ru.ulstu.extractor.model.Repository;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface AuthorRepository extends JpaRepository<Author, Integer> {
|
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")
|
@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<Author> findByRepositoryAndBranch(@Param("repository") Repository repository, @Param("branchName") String branchName);
|
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;
|
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 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
|
@Service
|
||||||
public class FilteringService {
|
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) {
|
public List<String> getRepositoryAuthors(@NotNull String repositoryUrl,
|
||||||
this.indexService = indexService;
|
@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 com.sun.istack.NotNull;
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
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.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.ulstu.extractor.model.Author;
|
|
||||||
import ru.ulstu.extractor.model.Branch;
|
import ru.ulstu.extractor.model.Branch;
|
||||||
import ru.ulstu.extractor.model.Commit;
|
import ru.ulstu.extractor.model.Commit;
|
||||||
import ru.ulstu.extractor.model.Repository;
|
import ru.ulstu.extractor.model.Repository;
|
||||||
import ru.ulstu.extractor.repository.AuthorRepository;
|
|
||||||
import ru.ulstu.extractor.repository.BranchRepository;
|
import ru.ulstu.extractor.repository.BranchRepository;
|
||||||
import ru.ulstu.extractor.repository.CommitRepository;
|
import ru.ulstu.extractor.repository.CommitRepository;
|
||||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||||
@ -29,19 +25,15 @@ public class IndexService {
|
|||||||
private final RepositoryRepository repositoryRepository;
|
private final RepositoryRepository repositoryRepository;
|
||||||
private final BranchRepository branchRepository;
|
private final BranchRepository branchRepository;
|
||||||
private final CommitRepository commitRepository;
|
private final CommitRepository commitRepository;
|
||||||
private final AuthorRepository authorRepository;
|
|
||||||
|
|
||||||
|
|
||||||
public IndexService(GitRepositoryService gitRepositoryService,
|
public IndexService(GitRepositoryService gitRepositoryService,
|
||||||
RepositoryRepository repositoryRepository,
|
RepositoryRepository repositoryRepository,
|
||||||
BranchRepository branchRepository,
|
BranchRepository branchRepository,
|
||||||
CommitRepository commitRepository,
|
CommitRepository commitRepository) {
|
||||||
AuthorRepository authorRepository) {
|
|
||||||
this.gitRepositoryService = gitRepositoryService;
|
this.gitRepositoryService = gitRepositoryService;
|
||||||
this.repositoryRepository = repositoryRepository;
|
this.repositoryRepository = repositoryRepository;
|
||||||
this.branchRepository = branchRepository;
|
this.branchRepository = branchRepository;
|
||||||
this.commitRepository = commitRepository;
|
this.commitRepository = commitRepository;
|
||||||
this.authorRepository = authorRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -61,12 +53,4 @@ public class IndexService {
|
|||||||
branch.setCommits(commits);
|
branch.setCommits(commits);
|
||||||
branchRepository.save(branch);
|
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">
|
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
xmlns:th="http://www.thymeleaf.org"
|
xmlns:th="http://www.thymeleaf.org"
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
layout:decorate="~{default}">
|
layout:decorate="~{default}">
|
||||||
|
|
||||||
<!--<head th:substituteby="header :: copy"></head>-->
|
|
||||||
|
|
||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<h1>Ошибка</h1>
|
<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}">
|
<p th:if="${url}">
|
||||||
<b>Страница:</b> <span th:text="${url}">Page URL</span>
|
<b>Страница:</b> <span th:text="${url}">Page URL</span>
|
||||||
</p>
|
</p>
|
||||||
@ -34,11 +33,13 @@
|
|||||||
<div class="collapse" id="collapseExample">
|
<div class="collapse" id="collapseExample">
|
||||||
<p class="card card-body">
|
<p class="card card-body">
|
||||||
<div th:utext="'Failed URL: ' + ${url}" th:remove="tag">${url}</div>
|
<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>
|
</p>
|
||||||
|
<div th:if="${exception != null}" th:utext="'Exception: ' + ${exception.message}" th:remove="tag">
|
||||||
|
${exception.message}
|
||||||
|
</div>
|
||||||
<ul th:remove="tag">
|
<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>
|
th:utext="${ste}" th:remove="tag">${ste}</span></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,33 +27,59 @@
|
|||||||
}
|
}
|
||||||
</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="post">
|
||||||
<p><b>Фильтровать данные:</b><Br></p>
|
<div class="row">
|
||||||
По автору
|
<div class="col-md-1 col-sm-12">
|
||||||
<select class="selectpicker" data-live-search="true">
|
Автор
|
||||||
|
</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>
|
</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">
|
<select class="selectpicker" data-live-search="true">
|
||||||
<option data-tokens="day">день</option>
|
<option data-tokens="day">день</option>
|
||||||
<option data-tokens="month">месяц</option>
|
<option data-tokens="month">месяц</option>
|
||||||
<option data-tokens="age">год</option>
|
<option data-tokens="age">год</option>
|
||||||
</select>
|
</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">
|
<select class="selectpicker" data-live-search="true">
|
||||||
<option data-tokens="day">день</option>
|
<option data-tokens="day">день</option>
|
||||||
<option data-tokens="month">месяц</option>
|
<option data-tokens="month">месяц</option>
|
||||||
<option data-tokens="age">год</option>
|
<option data-tokens="age">год</option>
|
||||||
</select>
|
</select>
|
||||||
<p>Строки:<br>
|
</div>
|
||||||
<input type="text" size="40" th:field="*{filter}">
|
</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}">
|
<input type="hidden" th:field="*{url}">
|
||||||
</p>
|
|
||||||
<p style="color:red" th:text="${error}"></p>
|
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Author</th>
|
<th scope="col">Автор</th>
|
||||||
<th scope="col" style="width: 30%">Date</th>
|
<th scope="col" style="width: 30%">Дата</th>
|
||||||
<th scope="col">Commit</th>
|
<th scope="col">Сообщение</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -65,7 +91,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p>
|
<p>
|
||||||
<input type="submit" value="Отправить"/>
|
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
Страницы:
|
Страницы:
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
data-width="90%">
|
data-width="90%">
|
||||||
<option th:each="branch : ${branches}"
|
<option th:each="branch : ${branches}"
|
||||||
th:value="${branch.name}"
|
th:value="${branch.name}"
|
||||||
th:utext="${branch.name}"/>
|
th:utext="${branch.name}">
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user