From caae6eae5a5e389a0c0debf2f9d1febe12520c56 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 1 Apr 2021 16:16:54 +0400 Subject: [PATCH 01/28] #18 - Create statistic --- src/main/resources/templates/statistic.html | 55 +++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/resources/templates/statistic.html diff --git a/src/main/resources/templates/statistic.html b/src/main/resources/templates/statistic.html new file mode 100644 index 0000000..9d53245 --- /dev/null +++ b/src/main/resources/templates/statistic.html @@ -0,0 +1,55 @@ + + + + Простая обработка формы на Spring MVC + + +
+ + + +
+
+
+ From 33bf0bd8f31992c3ff8b2b4bc5e79f4050bfbf63 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 2 Apr 2021 11:05:33 +0400 Subject: [PATCH 02/28] #8 -- Add router component. You can access to url's in mvc controllers also in web page templates. --- .../extractor/config/MvcConfiguration.java | 9 +++++- .../controller/BranchController.java | 11 +++++-- .../controller/GitFilteringController.java | 11 +++++-- .../controller/GitIndexingController.java | 25 +++++++++------ ...troller.java => RepositoryController.java} | 15 ++++++--- .../ru/ulstu/extractor/controller/Route.java | 32 +++++++++++++++++++ src/main/resources/templates/default.html | 11 +++++-- .../{filtering.html => filterCommits.html} | 9 ++++-- src/main/resources/templates/index.html | 32 ------------------- .../{newRepo.html => indexNewRepository.html} | 7 +++- .../{indexBranch.html => listBranches.html} | 8 ++++- .../{indexRepo.html => listRepositories.html} | 8 ++++- src/main/resources/templates/resultRepo.html | 18 ----------- 13 files changed, 121 insertions(+), 75 deletions(-) rename src/main/java/ru/ulstu/extractor/controller/{BaseIndexingController.java => RepositoryController.java} (54%) create mode 100644 src/main/java/ru/ulstu/extractor/controller/Route.java rename src/main/resources/templates/{filtering.html => filterCommits.html} (87%) delete mode 100644 src/main/resources/templates/index.html rename src/main/resources/templates/{newRepo.html => indexNewRepository.html} (92%) rename src/main/resources/templates/{indexBranch.html => listBranches.html} (72%) rename src/main/resources/templates/{indexRepo.html => listRepositories.html} (70%) delete mode 100644 src/main/resources/templates/resultRepo.html diff --git a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java index 2355ca1..035f359 100644 --- a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java @@ -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"); } diff --git a/src/main/java/ru/ulstu/extractor/controller/BranchController.java b/src/main/java/ru/ulstu/extractor/controller/BranchController.java index 8254210..031dc48 100644 --- a/src/main/java/ru/ulstu/extractor/controller/BranchController.java +++ b/src/main/java/ru/ulstu/extractor/controller/BranchController.java @@ -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; } } diff --git a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java index 85ef6aa..3d945dd 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java +++ b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java @@ -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, @@ -64,6 +71,6 @@ public class GitFilteringController { filterForm.setBranch(branchName); filterForm.setUrl(repositoryUrl); model.addAttribute("filterForm", filterForm); - return "filtering"; + return FILTER_COMMITS; } } diff --git a/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java b/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java index 18ddb48..5ad0083 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java +++ b/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java @@ -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 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; } } } diff --git a/src/main/java/ru/ulstu/extractor/controller/BaseIndexingController.java b/src/main/java/ru/ulstu/extractor/controller/RepositoryController.java similarity index 54% rename from src/main/java/ru/ulstu/extractor/controller/BaseIndexingController.java rename to src/main/java/ru/ulstu/extractor/controller/RepositoryController.java index e2a154a..9401504 100644 --- a/src/main/java/ru/ulstu/extractor/controller/BaseIndexingController.java +++ b/src/main/java/ru/ulstu/extractor/controller/RepositoryController.java @@ -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; } } diff --git a/src/main/java/ru/ulstu/extractor/controller/Route.java b/src/main/java/ru/ulstu/extractor/controller/Route.java new file mode 100644 index 0000000..34853a5 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/controller/Route.java @@ -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; + } +} diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 04f7459..8c20522 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -1,3 +1,8 @@ + + @@ -22,10 +27,12 @@ diff --git a/src/main/resources/templates/filtering.html b/src/main/resources/templates/filterCommits.html similarity index 87% rename from src/main/resources/templates/filtering.html rename to src/main/resources/templates/filterCommits.html index 365ac17..eca26f5 100644 --- a/src/main/resources/templates/filtering.html +++ b/src/main/resources/templates/filterCommits.html @@ -1,13 +1,18 @@ + + - Простая обработка формы на Spring MVC + Фильтрация коммитов репозитория
-
+

Фильтровать данные:

По автору - - - Кому: - - - - Сообщение: -