Merge branch '15-bootstrap' into 'master'

Resolve "Пофиксить bootstrap  интерфейс"

Closes #15

See merge request romanov73/git-extractor!10
This commit is contained in:
Anton Romanov 2021-03-27 08:00:26 +00:00
commit 0e371723c0
7 changed files with 113 additions and 69 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

@ -2,7 +2,6 @@ package ru.ulstu.extractor.mvc.model;
public class RepoForm {
private String repo;
private String branch;
public String getRepo() {
@ -24,7 +23,8 @@ public class RepoForm {
@Override
public String toString() {
return "RepoForm{" +
"subject='" + repo +
"repo='" + repo + '\'' +
", branch='" + branch + '\'' +
'}';
}
}

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

@ -19,14 +19,10 @@
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/" th:text="#{messages.menu.home}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" th:text="#{messages.menu.new-repo}">Link</a>
<a class="nav-link" href="/" th:text="#{messages.menu.new-repo}">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" th:text="#{messages.menu.indexed-repos}">Link</a>

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>

View File

@ -3,32 +3,61 @@
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<title>Индексировать новый репозиторий</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<form action="#" th:action="@{/newRepo}" th:object="${repoForm}" method="post">
<p style="color:red" th:text="${error}"></p>
<p><b>Ваш git репозиторий:</b><br>
<input type="text" size="40" th:field="*{repo}">
</p>
<p>
<input type="submit" name="send" value="Отправить"/>
</p>
<p>Ветки:<br>
<select id="select-branch" class="selectpicker" data-live-search="true" th:field="*{branch}">
<button class="btn btn-outline-dark dropdown-toggle" type="button" data-toggle="collapse"
data-target="#collapseOne" aria-expanded="false" aria-controls="collapseExample"
th:if="${repoForm.repo != null}"
th:text="${repoForm.repo == null ? 'Репозиторий' : repoForm.repo}">
Button with data-target
</button>
<div id="collapseOne" th:class="${repoForm.repo == null ? 'collapse show' : 'collapse'}"
aria-labelledby="headingOne">
<div class="card-body">
<div class="form-group">
<label for="repoUrl">Ваш git репозиторий (https url):</label>
<div class="row">
<div class="col-md-8 col-sm-12">
<input id="repoUrl" type="text" class="form-control"
aria-label="Ваш git репозиторий (https url)"
th:field="*{repo}">
</div>
<div class="col-md-4 col-sm-12">
<input type="submit" class="btn btn-outline-primary w-100" name="send"
value="Индексировать"/>
</div>
</div>
</div>
</div>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" th:if="${repoForm.repo != null}">
<div class="card-body">
<div class="form-group">
<label for="select-branch">Ветки:</label>
<div class="row">
<div class="col-md-8 col-sm-12">
<select id="select-branch" class="selectpicker" data-live-search="true" th:field="*{branch}"
data-width="90%">
<option th:each="branch : ${branches}"
th:value="${branch.name}"
th:utext="${branch.name}"/>
</option>
</select>
</p>
<p>
<input type="submit" name="next" value="Продолжить"/>
</p>
</div>
<div class="col-md-4 col-sm-12">
<input type="submit" class="btn btn-outline-success w-100" name="next" value="Продолжить"/>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<script>
<script language="JavaScript">
$('#select-branch').selectpicker('refresh');
</script>
</html>