Merge branch '2-web-pages' into 'master'

Resolve "Добавить верстку нужных страниц"

Closes #2

See merge request romanov73/git-extractor!3
This commit is contained in:
BarminaA 2021-03-19 08:05:47 +00:00
commit ca75025d51
19 changed files with 253 additions and 94 deletions

View File

@ -1,15 +1,17 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.controller;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.extractor.model.Commit;
import ru.ulstu.extractor.service.GitRepositoryService;
import java.io.IOException;
import java.util.List;
import static ru.ulstu.extractor.RepoController.URL;
import static ru.ulstu.extractor.controller.RepoController.URL;
@RestController
@RequestMapping(URL)

View File

@ -3,7 +3,7 @@ package ru.ulstu.extractor.db;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import ru.ulstu.extractor.Commit;
import ru.ulstu.extractor.model.Commit;
import java.sql.ResultSet;
import java.sql.SQLException;

View File

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
import java.util.Date;

View File

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
public class LineChange {
private boolean added;

View File

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter;

View File

@ -5,22 +5,57 @@ 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 ru.ulstu.extractor.mvc.model.EmailForm;
import ru.ulstu.extractor.mvc.model.FilterForm;
import ru.ulstu.extractor.mvc.model.RepoForm;
import ru.ulstu.extractor.service.FilteringService;
import ru.ulstu.extractor.service.GitRepositoryService;
@Controller
public class GitExtractorController {
@GetMapping("/")
public String indexForm(Model model) {
model.addAttribute("emailForm", new EmailForm());
return "index";
private final FilteringService filteringService;
private final GitRepositoryService gitRepositoryService;
public GitExtractorController(FilteringService filteringService,
GitRepositoryService gitRepositoryService) {
this.filteringService = filteringService;
this.gitRepositoryService = gitRepositoryService;
}
@PostMapping("/sendEmail")
public String sendEmail(@ModelAttribute EmailForm emailForm, Model model) {
if (emailForm.getTo().isEmpty()) {
model.addAttribute("error", "'Кому' не должно быть пустым");
return "index";
@GetMapping("/newRepo")
public String indexNewRepo(Model model) {
model.addAttribute("repoForm", new RepoForm());
return "newRepo";
}
@GetMapping("/filtering")
public String filter(Model model) {
model.addAttribute("filterForm", new FilterForm());
return "filtering";
}
@PostMapping("/sendRepo")
public String sendRepo(@ModelAttribute RepoForm repoForm, Model model) {
if (repoForm.getRepo() == null || repoForm.getRepo().isEmpty()) {
model.addAttribute("error", "'Git' не должно быть пустым");
return "newRepo";
}
return "result";
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
try {
gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo());
} catch (Exception ex) {
model.addAttribute("error", ex.getMessage());
return "newRepo";
}
return "filtering";
}
@PostMapping("/sendFilter")
public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) {
if (filterForm.getFilter() == null || filterForm.getFilter().isEmpty()) {
model.addAttribute("error", "'Строка' не должно быть пустым");
return "filtering";
}
model.addAttribute("commits", filteringService.getCommits(filterForm.getFilter(), filterForm.getFilter()));
return "resultRepo";
}
}

View File

@ -10,7 +10,7 @@ public class MvcConfiguration implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/{articlename:\\w+}");
registry.addRedirectViewController("/", "/index");
registry.addRedirectViewController("/", "/newRepo");
registry.addRedirectViewController("/default", "/home");
}

View File

@ -1,40 +0,0 @@
package ru.ulstu.extractor.mvc.model;
public class EmailForm {
private String subject;
private String to;
private String message;
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return "EmailForm{" +
"subject='" + subject + '\'' +
", to='" + to + '\'' +
", message='" + message + '\'' +
'}';
}
}

View File

@ -0,0 +1,36 @@
package ru.ulstu.extractor.mvc.model;
public class FilterForm {
private String filter;
private String url;
public FilterForm() {
}
public FilterForm(String url) {
this.url = url;
}
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "FilterForm{" +
"subject='" + filter +
'}';
}
}

View File

@ -0,0 +1,20 @@
package ru.ulstu.extractor.mvc.model;
public class RepoForm {
private String repo;
public String getRepo() {
return repo;
}
public void setRepo(String repo) {
this.repo = repo;
}
@Override
public String toString() {
return "RepoForm{" +
"subject='" + repo +
'}';
}
}

View File

@ -0,0 +1,32 @@
package ru.ulstu.extractor.service;
import org.springframework.stereotype.Service;
import ru.ulstu.extractor.model.Commit;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class FilteringService {
private final GitRepositoryService gitRepositoryService;
public FilteringService(GitRepositoryService gitRepositoryService) {
this.gitRepositoryService = gitRepositoryService;
}
public List<Commit> getCommits(String urlRepo) {
return getCommits(urlRepo, null);
}
public List<Commit> getCommits(String urlRepo, String filterCommitMessage) {
if (filterCommitMessage != null) {
return getCommits(urlRepo)
.stream()
.filter(commit -> commit.getMessage().contains(filterCommitMessage))
.collect(Collectors.toList());
} else {
return getCommits(urlRepo);
}
}
}

View File

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.service;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
@ -8,6 +8,10 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import ru.ulstu.extractor.model.Changes;
import ru.ulstu.extractor.model.Commit;
import ru.ulstu.extractor.model.FileChange;
import ru.ulstu.extractor.model.LineChange;
import java.io.ByteArrayOutputStream;
import java.io.File;

View File

@ -32,14 +32,16 @@
</a>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
<div th:utext="'Failed URL: ' + ${url}" th:remove="tag">${url}</div>
<div th:utext="'Exception: ' + ${exception.message}" th:remove="tag">${exception.message}</div>
<ul th:remove="tag">
<li th:each="ste : ${exception.stackTrace}" th:remove="tag"><span
th:utext="${ste}" th:remove="tag">${ste}</span></li>
</ul>
</div>
<p class="card card-body">
<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>
<ul th:remove="tag">
<li th:each="ste : ${exception.stackTrace}" th:remove="tag"><span
th:utext="${ste}" th:remove="tag">${ste}</span></li>
</ul>
</div>
</div>
</div>
</html>

View File

@ -0,0 +1,53 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<body>
<form action="#" th:action="@{/sendFilter}" th:object="${filterForm}" method="post">
<p><b>Фильтровать данные:</b><Br></p>
По автору
<select class="selectpicker" data-live-search="true">
</select>
Дата с
<select class="selectpicker" data-live-search="true">
<option data-tokens="day">день</option>
<option data-tokens="month">месяц</option>
<option data-tokens="age">год</option>
</select>
по
<select class="selectpicker" data-live-search="true">
<option data-tokens="day">день</option>
<option data-tokens="month">месяц</option>
<option data-tokens="age">год</option>
</select>
<p>Строки:<br>
<input type="text" size="40" th:field="*{filter}">
<input type="hidden" th:field="*{url}">
</p>
<p style="color:red" th:text="${error}"></p>
<table>
<tr>
<th>Author</th>
<th>Date</th>
<th>Commit</th>
</tr>
<tr th:each="commit : ${commits}">
<td th:text="${commit.author}">Onions</td>
<td th:text="${commit.date}">2.41</td>
<td th:text="${commit.message}">yes</td>
</tr>
</table>
<p>
<input type="submit" value="Отправить"/>
</p>
</form>
</body>
</div>
</html>

View File

@ -0,0 +1,22 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<body>
<form action="#" th:action="@{/sendRepo}" 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" value="Отправить"/>
</p>
</form>
</body>
</div>
</html>

View File

@ -1,25 +0,0 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Результат обработки формы</h1>
<table>
<tr>
<td>Тема:</td>
<td><p th:text="${emailForm.subject}"/></td>
</tr>
<tr>
<td>Кому:</td>
<td><p th:text="${emailForm.to}"/></td>
</tr>
<tr>
<td>Сообщение:</td>
<td><p th:text="${emailForm.message}"/></td>
</tr>
</table>
<a href="/">Отправить другое сообщение</a>
</body>
</html>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<body>
<form oninput="result">
<p>Данные репозитория:</p>
<p>
<output name="result"></output>
</form>
</body>
</div>
</html>