Merge branch '8-navigation' into 'master'

Resolve "Создать утилитарный класс для навигации"

Closes #8

See merge request romanov73/git-extractor!15
This commit is contained in:
Anton Romanov 2021-04-02 11:05:27 +00:00
commit d2f4363b64
13 changed files with 146 additions and 96 deletions

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*/
package ru.ulstu.extractor.config;
import org.springframework.context.annotation.Configuration;
@ -5,12 +10,14 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import static ru.ulstu.extractor.controller.Route.LIST_INDEXED_REPOSITORIES;
@Configuration
public class MvcConfiguration implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/{articlename:\\w+}");
registry.addRedirectViewController("/", "/newRepo");
registry.addRedirectViewController("/", LIST_INDEXED_REPOSITORIES);
registry.addRedirectViewController("/default", "/home");
}

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*/
package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Controller;
@ -7,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.extractor.repository.BranchRepository;
import ru.ulstu.extractor.repository.RepositoryRepository;
import static ru.ulstu.extractor.controller.Route.LIST_REPOSITORY_BRANCHES;
@Controller
public class BranchController {
private final RepositoryRepository repositoryRepository;
@ -17,12 +24,12 @@ public class BranchController {
this.branchRepository = branchRepository;
}
@GetMapping("/details")
@GetMapping(LIST_REPOSITORY_BRANCHES)
public String indexBranch(
Model model,
@RequestParam int repositoryId) {
model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId));
model.addAttribute("repository", repositoryRepository.findById(repositoryId).get());
return "indexBranch";
return LIST_REPOSITORY_BRANCHES;
}
}

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*/
package ru.ulstu.extractor.controller;
import org.springframework.data.domain.Page;
@ -18,6 +23,8 @@ import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static ru.ulstu.extractor.controller.Route.FILTER_COMMITS;
@Controller
public class GitFilteringController {
private final FilteringService filteringService;
@ -40,7 +47,7 @@ public class GitFilteringController {
return "resultRepo";
}*/
@RequestMapping(value = "/filtering", method = RequestMethod.GET)
@RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
public String listCommits(
Model model,
@ModelAttribute FilterForm filterForm,
@ -54,7 +61,7 @@ public class GitFilteringController {
Page<Commit> commitsPage = indexService.getCommits(repositoryUrl, branchName, new OffsetablePageRequest(currentPage, pageSize));
int totalPages = commitsPage.getTotalPages();
if (totalPages > 0) {
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages - 1)
.boxed()
.collect(Collectors.toList());
model.addAttribute("pageNumbers", pageNumbers);
@ -64,6 +71,6 @@ public class GitFilteringController {
filterForm.setBranch(branchName);
filterForm.setUrl(repositoryUrl);
model.addAttribute("filterForm", filterForm);
return "filtering";
return FILTER_COMMITS;
}
}

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*/
package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Controller;
@ -15,6 +20,9 @@ import ru.ulstu.extractor.service.IndexService;
import java.util.List;
import static ru.ulstu.extractor.controller.Route.FILTER_COMMITS;
import static ru.ulstu.extractor.controller.Route.INDEXING_NEW_REPOSITORY;
@Controller
public class GitIndexingController {
private final GitRepositoryService gitRepositoryService;
@ -26,40 +34,39 @@ public class GitIndexingController {
this.indexService = indexService;
}
@GetMapping("/newRepo")
@GetMapping(INDEXING_NEW_REPOSITORY)
public String indexNewRepo(Model model) {
model.addAttribute(new RepoForm());
return "newRepo";
return INDEXING_NEW_REPOSITORY;
}
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "send")
@RequestMapping(value = INDEXING_NEW_REPOSITORY, 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";
}
return INDEXING_NEW_REPOSITORY;
}
@RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next")
@RequestMapping(value = INDEXING_NEW_REPOSITORY, 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";
return INDEXING_NEW_REPOSITORY;
} else {
try {
indexService.index(repoForm.getRepo(), repoForm.getBranch());
} catch (Exception ex) {
model.addAttribute("error", ex.getMessage());
return "newRepo";
return INDEXING_NEW_REPOSITORY;
}
redirectAttributes.addAttribute("repositoryUrl", repoForm.getRepo());
redirectAttributes.addAttribute("branchName", repoForm.getBranch());
return "redirect:/filtering";
return "redirect:/" + FILTER_COMMITS;
}
}
}

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*/
package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Controller;
@ -5,17 +10,19 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import ru.ulstu.extractor.repository.RepositoryRepository;
import static ru.ulstu.extractor.controller.Route.LIST_INDEXED_REPOSITORIES;
@Controller
public class BaseIndexingController {
public class RepositoryController {
private final RepositoryRepository repositoryRepository;
public BaseIndexingController(RepositoryRepository repositoryRepository) {
public RepositoryController(RepositoryRepository repositoryRepository) {
this.repositoryRepository = repositoryRepository;
}
@GetMapping("/indexRepo")
@GetMapping(LIST_INDEXED_REPOSITORIES)
public String indexNewRepo(Model model) {
model.addAttribute("repositories", repositoryRepository.findAll());
return "indexRepo";
return LIST_INDEXED_REPOSITORIES;
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*/
package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Component;
@Component
public class Route {
public static final String LIST_INDEXED_REPOSITORIES = "listRepositories";
public static final String LIST_REPOSITORY_BRANCHES = "listBranches";
public static final String INDEXING_NEW_REPOSITORY = "indexNewRepository";
public static final String FILTER_COMMITS = "filterCommits";
public static String getLIST_INDEXED_REPOSITORIES() {
return LIST_INDEXED_REPOSITORIES;
}
public static String getLIST_REPOSITORY_BRANCHES() {
return LIST_REPOSITORY_BRANCHES;
}
public static String getINDEXING_NEW_REPOSITORY() {
return INDEXING_NEW_REPOSITORY;
}
public static String getFILTER_COMMITS() {
return FILTER_COMMITS;
}
}

View File

@ -1,3 +1,8 @@
<!--
~ Copyright (C) 2021 Anton Romanov - All Rights Reserved
~ You may use, distribute and modify this code, please write to: romanov73@gmail.com.
-->
<!DOCTYPE html>
<html lang="ru"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml">
@ -22,10 +27,12 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/" th:text="#{messages.menu.new-repo}">Link</a>
<a class="nav-link" th:href="${@route.INDEXING_NEW_REPOSITORY}"
th:text="#{messages.menu.new-repo}">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/indexRepo" th:text="#{messages.menu.indexed-repos}">Link</a>
<a class="nav-link" th:href="${@route.LIST_INDEXED_REPOSITORIES}"
th:text="#{messages.menu.indexed-repos}">Link</a>
</li>
</ul>
</div>

View File

@ -1,13 +1,32 @@
<!--
~ Copyright (C) 2021 Anton Romanov - All Rights Reserved
~ You may use, distribute and modify this code, please write to: romanov73@gmail.com.
-->
<!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">
<form action="#" th:action="@{/sendFilter}" th:object="${filterForm}" method="post">
<style>
.pagination {
display: inline-block;
}
.pagination a {
color: black;
float: left;
padding: 5px 5px;
text-decoration: none;
}
.pagination a.active {
background-color: gray;
color: white;
border-radius: 2px;
}
</style>
<form action="#" th:action="${@route.FILTER_COMMITS}" th:object="${filterForm}" method="post">
<p><b>Фильтровать данные:</b><Br></p>
По автору
<select class="selectpicker" data-live-search="true">
@ -49,10 +68,12 @@
<input type="submit" value="Отправить"/>
</p>
</form>
</div>
<div th:if="${filterForm.commitPage.totalPages > 0}" class="pagination"
th:each="pageNumber : ${pageNumbers}">
<a th:href="@{/filtering.html(size=${commitPage.size}, page=${pageNumber})}"
th:class="${pageNumber==commitPage.number + 1} ? active"></a>
Страницы:
<div th:if="${filterForm.commitsPage.totalPages > 0}" class="pagination"
th:each="pageNumber : ${pageNumbers}">
<a th:href="@{/filterCommits(size=${filterForm.commitsPage.size}, page=${pageNumber}, repositoryUrl=${filterForm.url}, branchName=${filterForm.branch})}"
th:text=${pageNumber}
th:class="${pageNumber == filterForm.commitsPage.number} ? active"></a>
</div>
</div>
</html>

View File

@ -1,32 +0,0 @@
<!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>

View File

@ -1,13 +1,14 @@
<!--
~ Copyright (C) 2021 Anton Romanov - All Rights Reserved
~ You may use, distribute and modify this code, please write to: romanov73@gmail.com.
-->
<!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>Индексировать новый репозиторий</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">
<form action="#" th:action="${@route.INDEXING_NEW_REPOSITORY}" th:object="${repoForm}" method="post">
<p style="color:red" th:text="${error}"></p>
<button class="btn btn-outline-dark dropdown-toggle" type="button" data-toggle="collapse"
data-target="#collapseOne" aria-expanded="false" aria-controls="collapseExample"

View File

@ -1,11 +1,12 @@
<!--
~ Copyright (C) 2021 Anton Romanov - All Rights Reserved
~ You may use, distribute and modify this code, please write to: romanov73@gmail.com.
-->
<!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>Проиндексированные репозитории</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<table class="table table-striped">
<thead class="thead-dark">
@ -15,7 +16,8 @@
</thead>
<tbody>
<tr th:each="branch: ${branches}">
<td><a th:href="@{'/filtering?branchName='+${branch.name}+'&repositoryUrl='+${repository.url}}"
<td>
<a th:href="@{${@route.FILTER_COMMITS} + '?branchName='+${branch.name}+'&repositoryUrl='+${repository.url}}"
th:text="${branch.name}"/></td>
</tr>
</tbody>

View File

@ -1,11 +1,12 @@
<!--
~ Copyright (C) 2021 Anton Romanov - All Rights Reserved
~ You may use, distribute and modify this code, please write to: romanov73@gmail.com.
-->
<!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>Проиндексированные репозитории</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<table class="table table-striped">
<thead class="thead-dark">
@ -15,7 +16,8 @@
</thead>
<tbody>
<tr th:each="repo: ${repositories}">
<td><a th:href="@{'/details?repositoryId='+${repo.id}}" th:text="${repo.url}"></td>
<td><a th:href="@{${@route.LIST_REPOSITORY_BRANCHES} + '?repositoryId=' + ${repo.id}}"
th:text="${repo.url}"></a></td>
</tr>
</tbody>
</table>

View File

@ -1,18 +0,0 @@
<!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>