#15 -- Fix filtering table

This commit is contained in:
Anton Romanov 2021-03-27 11:58:07 +04:00
parent 11f3b93b9d
commit 4b56058835
4 changed files with 62 additions and 43 deletions

View File

@ -5,17 +5,13 @@ 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;
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;
@ -27,12 +23,12 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Controller
public class GitExtractorController {
public class GitFilteringController {
private final FilteringService filteringService;
private final GitRepositoryService gitRepositoryService;
private final CommitService commitService;
public GitExtractorController(FilteringService filteringService,
public GitFilteringController(FilteringService filteringService,
GitRepositoryService gitRepositoryService,
CommitService commitService) {
this.filteringService = filteringService;
@ -40,12 +36,6 @@ public class GitExtractorController {
this.commitService = commitService;
}
@GetMapping("/newRepo")
public String indexNewRepo(Model model) {
model.addAttribute("repoForm", new RepoForm());
return "newRepo";
}
@PostMapping("/sendFilter")
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) throws GitAPIException, IOException {
List<Commit> list = gitRepositoryService.getCommits(filterForm.getUrl());
@ -57,31 +47,6 @@ public class GitExtractorController {
return "resultRepo";
}
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "send")
public String getBranch(@ModelAttribute RepoForm repoForm, Model model) {
try {
gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo());
List<Branch> list = gitRepositoryService.getBranches(repoForm.getRepo());
model.addAttribute("branches", list);
return "newRepo";
} catch (Exception ex) {
model.addAttribute("error", ex.getMessage());
return "newRepo";
}
}
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next")
public String setBranch(@ModelAttribute RepoForm repoForm, Model model, RedirectAttributes redirectAttributes) {
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
if (repoForm.getBranch() == null) {
return "newRepo";
} else {
redirectAttributes.addAttribute("url", repoForm.getRepo());
redirectAttributes.addAttribute("branch", repoForm.getBranch());
return "redirect:/filtering";
}
}
@RequestMapping(value = "/filtering", method = RequestMethod.GET)
public String listCommits(
Model model,

View File

@ -0,0 +1,55 @@
package ru.ulstu.extractor.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
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.servlet.mvc.support.RedirectAttributes;
import ru.ulstu.extractor.model.Branch;
import ru.ulstu.extractor.mvc.model.FilterForm;
import ru.ulstu.extractor.mvc.model.RepoForm;
import ru.ulstu.extractor.service.GitRepositoryService;
import java.util.List;
@Controller
public class GitIndexingController {
private final GitRepositoryService gitRepositoryService;
public GitIndexingController(GitRepositoryService gitRepositoryService) {
this.gitRepositoryService = gitRepositoryService;
}
@GetMapping("/newRepo")
public String indexNewRepo(Model model) {
model.addAttribute(new RepoForm());
return "newRepo";
}
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "send")
public String getBranch(@ModelAttribute RepoForm repoForm, Model model) {
try {
gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo());
List<Branch> branches = gitRepositoryService.getBranches(repoForm.getRepo());
model.addAttribute("branches", branches);
return "newRepo";
} catch (Exception ex) {
model.addAttribute("error", ex.getMessage());
return "newRepo";
}
}
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next")
public String setBranch(@ModelAttribute RepoForm repoForm, Model model, RedirectAttributes redirectAttributes) {
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
if (repoForm.getBranch() == null) {
return "newRepo";
} else {
redirectAttributes.addAttribute("url", repoForm.getRepo());
redirectAttributes.addAttribute("branch", repoForm.getBranch());
return "redirect:/filtering";
}
}
}

View File

@ -25,7 +25,6 @@ public class CommitService {
int currentPage = pageable.getPageNumber();
int startItem = currentPage * pageSize;
List<Commit> commits = gitRepositoryService.getCommits(url);
;
if (commits.size() < startItem) {
commits = Collections.emptyList();

View File

@ -29,12 +29,12 @@
<input type="hidden" th:field="*{url}">
</p>
<p style="color:red" th:text="${error}"></p>
<table border="1">
<thead>
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th>Author</th>
<th>Date</th>
<th>Commit</th>
<th scope="col">Author</th>
<th scope="col" style="width: 30%">Date</th>
<th scope="col">Commit</th>
</tr>
</thead>
<tbody>