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; package ru.ulstu.extractor.config;
import org.springframework.context.annotation.Configuration; 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.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import static ru.ulstu.extractor.controller.Route.LIST_INDEXED_REPOSITORIES;
@Configuration @Configuration
public class MvcConfiguration implements WebMvcConfigurer { 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("/", "/newRepo"); registry.addRedirectViewController("/", LIST_INDEXED_REPOSITORIES);
registry.addRedirectViewController("/default", "/home"); 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; package ru.ulstu.extractor.controller;
import org.springframework.stereotype.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.BranchRepository;
import ru.ulstu.extractor.repository.RepositoryRepository; import ru.ulstu.extractor.repository.RepositoryRepository;
import static ru.ulstu.extractor.controller.Route.LIST_REPOSITORY_BRANCHES;
@Controller @Controller
public class BranchController { public class BranchController {
private final RepositoryRepository repositoryRepository; private final RepositoryRepository repositoryRepository;
@ -17,12 +24,12 @@ public class BranchController {
this.branchRepository = branchRepository; this.branchRepository = branchRepository;
} }
@GetMapping("/details") @GetMapping(LIST_REPOSITORY_BRANCHES)
public String indexBranch( public String indexBranch(
Model model, Model model,
@RequestParam int repositoryId) { @RequestParam int repositoryId) {
model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId)); model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId));
model.addAttribute("repository", repositoryRepository.findById(repositoryId).get()); 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; package ru.ulstu.extractor.controller;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -18,6 +23,8 @@ import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static ru.ulstu.extractor.controller.Route.FILTER_COMMITS;
@Controller @Controller
public class GitFilteringController { public class GitFilteringController {
private final FilteringService filteringService; private final FilteringService filteringService;
@ -40,7 +47,7 @@ public class GitFilteringController {
return "resultRepo"; return "resultRepo";
}*/ }*/
@RequestMapping(value = "/filtering", method = RequestMethod.GET) @RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
public String listCommits( public String listCommits(
Model model, Model model,
@ModelAttribute FilterForm filterForm, @ModelAttribute FilterForm filterForm,
@ -54,7 +61,7 @@ public class GitFilteringController {
Page<Commit> commitsPage = indexService.getCommits(repositoryUrl, branchName, new OffsetablePageRequest(currentPage, pageSize)); Page<Commit> commitsPage = indexService.getCommits(repositoryUrl, branchName, new OffsetablePageRequest(currentPage, pageSize));
int totalPages = commitsPage.getTotalPages(); int totalPages = commitsPage.getTotalPages();
if (totalPages > 0) { if (totalPages > 0) {
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages) List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages - 1)
.boxed() .boxed()
.collect(Collectors.toList()); .collect(Collectors.toList());
model.addAttribute("pageNumbers", pageNumbers); model.addAttribute("pageNumbers", pageNumbers);
@ -64,6 +71,6 @@ public class GitFilteringController {
filterForm.setBranch(branchName); filterForm.setBranch(branchName);
filterForm.setUrl(repositoryUrl); filterForm.setUrl(repositoryUrl);
model.addAttribute("filterForm", filterForm); 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; package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -15,6 +20,9 @@ import ru.ulstu.extractor.service.IndexService;
import java.util.List; import java.util.List;
import static ru.ulstu.extractor.controller.Route.FILTER_COMMITS;
import static ru.ulstu.extractor.controller.Route.INDEXING_NEW_REPOSITORY;
@Controller @Controller
public class GitIndexingController { public class GitIndexingController {
private final GitRepositoryService gitRepositoryService; private final GitRepositoryService gitRepositoryService;
@ -26,40 +34,39 @@ public class GitIndexingController {
this.indexService = indexService; this.indexService = indexService;
} }
@GetMapping("/newRepo") @GetMapping(INDEXING_NEW_REPOSITORY)
public String indexNewRepo(Model model) { public String indexNewRepo(Model model) {
model.addAttribute(new RepoForm()); 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) { public String getBranch(@ModelAttribute RepoForm repoForm, Model model) {
try { try {
gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo()); gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo());
List<Branch> branches = gitRepositoryService.getBranches(repoForm.getRepo()); List<Branch> branches = gitRepositoryService.getBranches(repoForm.getRepo());
model.addAttribute("branches", branches); model.addAttribute("branches", branches);
return "newRepo";
} catch (Exception ex) { } catch (Exception ex) {
model.addAttribute("error", ex.getMessage()); 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) { public String setBranch(@ModelAttribute RepoForm repoForm, Model model, RedirectAttributes redirectAttributes) {
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo())); model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
if (repoForm.getBranch() == null) { if (repoForm.getBranch() == null) {
return "newRepo"; return INDEXING_NEW_REPOSITORY;
} else { } else {
try { try {
indexService.index(repoForm.getRepo(), repoForm.getBranch()); indexService.index(repoForm.getRepo(), repoForm.getBranch());
} catch (Exception ex) { } catch (Exception ex) {
model.addAttribute("error", ex.getMessage()); model.addAttribute("error", ex.getMessage());
return "newRepo"; return INDEXING_NEW_REPOSITORY;
} }
redirectAttributes.addAttribute("repositoryUrl", repoForm.getRepo()); redirectAttributes.addAttribute("repositoryUrl", repoForm.getRepo());
redirectAttributes.addAttribute("branchName", repoForm.getBranch()); 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; package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -5,17 +10,19 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import ru.ulstu.extractor.repository.RepositoryRepository; import ru.ulstu.extractor.repository.RepositoryRepository;
import static ru.ulstu.extractor.controller.Route.LIST_INDEXED_REPOSITORIES;
@Controller @Controller
public class BaseIndexingController { public class RepositoryController {
private final RepositoryRepository repositoryRepository; private final RepositoryRepository repositoryRepository;
public BaseIndexingController(RepositoryRepository repositoryRepository) { public RepositoryController(RepositoryRepository repositoryRepository) {
this.repositoryRepository = repositoryRepository; this.repositoryRepository = repositoryRepository;
} }
@GetMapping("/indexRepo") @GetMapping(LIST_INDEXED_REPOSITORIES)
public String indexNewRepo(Model model) { public String indexNewRepo(Model model) {
model.addAttribute("repositories", repositoryRepository.findAll()); 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> <!DOCTYPE html>
<html lang="ru" <html lang="ru"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"> 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"> <div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto"> <ul class="navbar-nav mr-auto">
<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" th:href="${@route.INDEXING_NEW_REPOSITORY}"
th:text="#{messages.menu.new-repo}">Link</a>
</li> </li>
<li class="nav-item"> <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> </li>
</ul> </ul>
</div> </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"> <!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org" <html xmlns:th="http://www.thymeleaf.org"
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>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content"> <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> <p><b>Фильтровать данные:</b><Br></p>
По автору По автору
<select class="selectpicker" data-live-search="true"> <select class="selectpicker" data-live-search="true">
@ -49,10 +68,12 @@
<input type="submit" value="Отправить"/> <input type="submit" value="Отправить"/>
</p> </p>
</form> </form>
</div> Страницы:
<div th:if="${filterForm.commitPage.totalPages > 0}" class="pagination" <div th:if="${filterForm.commitsPage.totalPages > 0}" class="pagination"
th:each="pageNumber : ${pageNumbers}"> th:each="pageNumber : ${pageNumbers}">
<a th:href="@{/filtering.html(size=${commitPage.size}, page=${pageNumber})}" <a th:href="@{/filterCommits(size=${filterForm.commitsPage.size}, page=${pageNumber}, repositoryUrl=${filterForm.url}, branchName=${filterForm.branch})}"
th:class="${pageNumber==commitPage.number + 1} ? active"></a> th:text=${pageNumber}
th:class="${pageNumber == filterForm.commitsPage.number} ? active"></a>
</div>
</div> </div>
</html> </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"> <!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org" <html xmlns:th="http://www.thymeleaf.org"
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>
<title>Индексировать новый репозиторий</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</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="${@route.INDEXING_NEW_REPOSITORY}" th:object="${repoForm}" method="post">
<p style="color:red" th:text="${error}"></p> <p style="color:red" th:text="${error}"></p>
<button class="btn btn-outline-dark dropdown-toggle" type="button" data-toggle="collapse" <button class="btn btn-outline-dark dropdown-toggle" type="button" data-toggle="collapse"
data-target="#collapseOne" aria-expanded="false" aria-controls="collapseExample" 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"> <!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org" <html xmlns:th="http://www.thymeleaf.org"
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>
<title>Проиндексированные репозитории</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content"> <div class="container" layout:fragment="content">
<table class="table table-striped"> <table class="table table-striped">
<thead class="thead-dark"> <thead class="thead-dark">
@ -15,7 +16,8 @@
</thead> </thead>
<tbody> <tbody>
<tr th:each="branch: ${branches}"> <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> th:text="${branch.name}"/></td>
</tr> </tr>
</tbody> </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"> <!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org" <html xmlns:th="http://www.thymeleaf.org"
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>
<title>Проиндексированные репозитории</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content"> <div class="container" layout:fragment="content">
<table class="table table-striped"> <table class="table table-striped">
<thead class="thead-dark"> <thead class="thead-dark">
@ -15,7 +16,8 @@
</thead> </thead>
<tbody> <tbody>
<tr th:each="repo: ${repositories}"> <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> </tr>
</tbody> </tbody>
</table> </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>