|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
package ru.ulstu.extractor.mvc;
|
|
|
|
|
|
|
|
|
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
@ -7,23 +10,34 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
import ru.ulstu.extractor.model.Branch;
|
|
|
|
|
import ru.ulstu.extractor.model.Commit;
|
|
|
|
|
import ru.ulstu.extractor.mvc.model.FilterForm;
|
|
|
|
|
import ru.ulstu.extractor.mvc.model.RepoForm;
|
|
|
|
|
import ru.ulstu.extractor.service.CommitService;
|
|
|
|
|
import ru.ulstu.extractor.service.FilteringService;
|
|
|
|
|
import ru.ulstu.extractor.service.GitRepositoryService;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
|
public class GitExtractorController {
|
|
|
|
|
private final FilteringService filteringService;
|
|
|
|
|
private final GitRepositoryService gitRepositoryService;
|
|
|
|
|
private final CommitService commitService;
|
|
|
|
|
|
|
|
|
|
public GitExtractorController(FilteringService filteringService,
|
|
|
|
|
GitRepositoryService gitRepositoryService) {
|
|
|
|
|
GitRepositoryService gitRepositoryService,
|
|
|
|
|
CommitService commitService) {
|
|
|
|
|
this.filteringService = filteringService;
|
|
|
|
|
this.gitRepositoryService = gitRepositoryService;
|
|
|
|
|
this.commitService = commitService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/newRepo")
|
|
|
|
@ -32,14 +46,16 @@ public class GitExtractorController {
|
|
|
|
|
return "newRepo";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/filtering")
|
|
|
|
|
public String filter(Model model) {
|
|
|
|
|
model.addAttribute("filterForm", new FilterForm());
|
|
|
|
|
return "filtering";
|
|
|
|
|
}
|
|
|
|
|
// @GetMapping("/filtering")
|
|
|
|
|
// public String filter(Model model) {
|
|
|
|
|
// model.addAttribute("filterForm", new FilterForm());
|
|
|
|
|
// return "filtering";
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@PostMapping("/sendFilter")
|
|
|
|
|
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) {
|
|
|
|
|
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) throws GitAPIException, IOException {
|
|
|
|
|
List<Commit> list = gitRepositoryService.getCommits(filterForm.getUrl());
|
|
|
|
|
model.addAttribute("commits", list);
|
|
|
|
|
if (filterForm.getFilter() == null || filterForm.getFilter().isEmpty()) {
|
|
|
|
|
model.addAttribute("error", "'Строка' не должно быть пустым");
|
|
|
|
|
return "filtering";
|
|
|
|
@ -61,12 +77,36 @@ public class GitExtractorController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next")
|
|
|
|
|
public String setBranch(@ModelAttribute RepoForm repoForm, Model model) {
|
|
|
|
|
public String setBranch(@ModelAttribute RepoForm repoForm, Model model, RedirectAttributes redirectAttributes) {
|
|
|
|
|
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
|
|
|
|
|
if (repoForm.getBranch() == null) {
|
|
|
|
|
return "newRepo";
|
|
|
|
|
} else {
|
|
|
|
|
return "filtering";
|
|
|
|
|
redirectAttributes.addAttribute("url", repoForm.getRepo());
|
|
|
|
|
redirectAttributes.addAttribute("branch", repoForm.getBranch());
|
|
|
|
|
return "redirect:/filtering";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/filtering", method = RequestMethod.GET)
|
|
|
|
|
public String listCommits(
|
|
|
|
|
Model model,
|
|
|
|
|
@ModelAttribute FilterForm filterForm,
|
|
|
|
|
@RequestParam("page") Optional<Integer> page,
|
|
|
|
|
@RequestParam("size") Optional<Integer> size,
|
|
|
|
|
@RequestParam String url,
|
|
|
|
|
@RequestParam String branch) throws GitAPIException, IOException {
|
|
|
|
|
int currentPage = page.orElse(1);
|
|
|
|
|
int pageSize = size.orElse(5);
|
|
|
|
|
Page<Commit> commitPage = commitService.findPaginated(PageRequest.of(currentPage - 1, pageSize), url);
|
|
|
|
|
model.addAttribute("commitPage", commitPage);
|
|
|
|
|
int totalPages = commitPage.getTotalPages();
|
|
|
|
|
if (totalPages > 0) {
|
|
|
|
|
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
|
|
|
|
.boxed()
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
model.addAttribute("pageNumbers", pageNumbers);
|
|
|
|
|
}
|
|
|
|
|
return "filtering";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|