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

Merged
BarminaA merged 1 commits from 2-web-pages into master 2021-03-19 12:05:48 +04:00
14 changed files with 128 additions and 11 deletions
Showing only changes of commit 97b3762c78 - Show all commits

View File

@ -1,15 +1,17 @@
package ru.ulstu.extractor; package ru.ulstu.extractor.controller;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; 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.io.IOException;
import java.util.List; import java.util.List;
import static ru.ulstu.extractor.RepoController.URL; import static ru.ulstu.extractor.controller.RepoController.URL;
@RestController @RestController
@RequestMapping(URL) @RequestMapping(URL)

View File

@ -3,7 +3,7 @@ package ru.ulstu.extractor.db;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import ru.ulstu.extractor.Commit; import ru.ulstu.extractor.model.Commit;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; 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.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package ru.ulstu.extractor; package ru.ulstu.extractor.model;
import java.util.Date; 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.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package ru.ulstu.extractor; package ru.ulstu.extractor.model;
public class LineChange { public class LineChange {
private boolean added; 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.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.DiffFormatter;

View File

@ -7,9 +7,19 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
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.mvc.model.RepoForm;
import ru.ulstu.extractor.service.FilteringService;
import ru.ulstu.extractor.service.GitRepositoryService;
@Controller @Controller
public class GitExtractorController { public class GitExtractorController {
private final FilteringService filteringService;
private final GitRepositoryService gitRepositoryService;
public GitExtractorController(FilteringService filteringService,
GitRepositoryService gitRepositoryService) {
this.filteringService = filteringService;
this.gitRepositoryService = gitRepositoryService;
}
@GetMapping("/newRepo") @GetMapping("/newRepo")
public String indexNewRepo(Model model) { public String indexNewRepo(Model model) {
@ -25,11 +35,17 @@ public class GitExtractorController {
@PostMapping("/sendRepo") @PostMapping("/sendRepo")
public String sendRepo(@ModelAttribute RepoForm repoForm, Model model) { public String sendRepo(@ModelAttribute RepoForm repoForm, Model model) {
model.addAttribute("filterForm", new FilterForm());
if (repoForm.getRepo() == null || repoForm.getRepo().isEmpty()) { if (repoForm.getRepo() == null || repoForm.getRepo().isEmpty()) {
model.addAttribute("error", "'Git' не должно быть пустым"); model.addAttribute("error", "'Git' не должно быть пустым");
return "newRepo"; return "newRepo";
} }
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
try {
gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo());
} catch (Exception ex) {
model.addAttribute("error", ex.getMessage());
return "newRepo";
}
return "filtering"; return "filtering";
} }
@ -39,6 +55,7 @@ public class GitExtractorController {
model.addAttribute("error", "'Строка' не должно быть пустым"); model.addAttribute("error", "'Строка' не должно быть пустым");
return "filtering"; return "filtering";
} }
model.addAttribute("commits", filteringService.getCommits(filterForm.getFilter(), filterForm.getFilter()));
return "resultRepo"; return "resultRepo";
} }
} }

View File

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

View File

@ -2,6 +2,14 @@ package ru.ulstu.extractor.mvc.model;
public class FilterForm { public class FilterForm {
private String filter; private String filter;
private String url;
public FilterForm() {
}
public FilterForm(String url) {
this.url = url;
}
public String getFilter() { public String getFilter() {
return filter; return filter;
@ -11,6 +19,14 @@ public class FilterForm {
this.filter = filter; this.filter = filter;
} }
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override @Override
public String toString() { public String toString() {
return "FilterForm{" + return "FilterForm{" +

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.Git;
import org.eclipse.jgit.api.errors.GitAPIException; 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.eclipse.jgit.revwalk.RevCommit;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; 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.ByteArrayOutputStream;
import java.io.File; import java.io.File;

View File

@ -27,8 +27,22 @@
</select> </select>
<p>Строки:<br> <p>Строки:<br>
<input type="text" size="40" th:field="*{filter}"> <input type="text" size="40" th:field="*{filter}">
<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>
<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> <p>
<input type="submit" value="Отправить"/> <input type="submit" value="Отправить"/>
</p> </p>

View File

@ -0,0 +1,32 @@
<!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">
<h1>Форма</h1>
<form action="#" th:action="@{/sendEmail}" th:object="${emailForm}" method="post">
<p style="color:red" th:text="${error}"></p>
<table>
<tr>
<td>Тема:</td>
<td><input type="text" th:field="*{subject}"/></td>
</tr>
<tr>
<td>Кому:</td>
<td><input type="text" th:field="*{to}"/></td>
</tr>
<tr>
<td>Сообщение:</td>
<td><textarea th:field="*{message}"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Отправить"/></td>
</tr>
</table>
</form>
</div>
</html>