Merge branch '15-bootstrap' into 'master'

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

Closes #15

See merge request romanov73/git-extractor!10
merge-requests/11/merge
Anton Romanov 3 years ago
commit 0e371723c0

@ -5,17 +5,13 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; 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.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; 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.model.Commit;
import ru.ulstu.extractor.mvc.model.FilterForm; 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.CommitService;
import ru.ulstu.extractor.service.FilteringService; import ru.ulstu.extractor.service.FilteringService;
import ru.ulstu.extractor.service.GitRepositoryService; import ru.ulstu.extractor.service.GitRepositoryService;
@ -27,12 +23,12 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@Controller @Controller
public class GitExtractorController { public class GitFilteringController {
private final FilteringService filteringService; private final FilteringService filteringService;
private final GitRepositoryService gitRepositoryService; private final GitRepositoryService gitRepositoryService;
private final CommitService commitService; private final CommitService commitService;
public GitExtractorController(FilteringService filteringService, public GitFilteringController(FilteringService filteringService,
GitRepositoryService gitRepositoryService, GitRepositoryService gitRepositoryService,
CommitService commitService) { CommitService commitService) {
this.filteringService = filteringService; this.filteringService = filteringService;
@ -40,12 +36,6 @@ public class GitExtractorController {
this.commitService = commitService; this.commitService = commitService;
} }
@GetMapping("/newRepo")
public String indexNewRepo(Model model) {
model.addAttribute("repoForm", new RepoForm());
return "newRepo";
}
@PostMapping("/sendFilter") @PostMapping("/sendFilter")
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) throws GitAPIException, IOException { public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) throws GitAPIException, IOException {
List<Commit> list = gitRepositoryService.getCommits(filterForm.getUrl()); List<Commit> list = gitRepositoryService.getCommits(filterForm.getUrl());
@ -57,31 +47,6 @@ public class GitExtractorController {
return "resultRepo"; 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) @RequestMapping(value = "/filtering", method = RequestMethod.GET)
public String listCommits( public String listCommits(
Model model, Model model,

@ -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";
}
}
}

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

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

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

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

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

Loading…
Cancel
Save