From f9d9f6ac709b0dfe1c1e3f711b2fee6a93f33d42 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Sun, 11 Dec 2016 13:53:59 +0700 Subject: bugfix: wrong help page are shows --- .../src/main/java/com/juick/www/HelpService.java | 2 +- .../com/juick/www/controllers/HelpController.java | 39 ++++++++++++---------- 2 files changed, 23 insertions(+), 18 deletions(-) (limited to 'juick-spring-www/src/main/java/com/juick') diff --git a/juick-spring-www/src/main/java/com/juick/www/HelpService.java b/juick-spring-www/src/main/java/com/juick/www/HelpService.java index a3bee60a..76b3582d 100644 --- a/juick-spring-www/src/main/java/com/juick/www/HelpService.java +++ b/juick-spring-www/src/main/java/com/juick/www/HelpService.java @@ -29,7 +29,7 @@ public class HelpService { if (canPage(page) && canLang(lang)) { try { Path file = Paths.get(helpPath, lang, page); - String path =file.toString(); + String path = file.toString(); file = Paths.get(new ClassPathResource(path).getURI()); if (Files.isReadable(file)) diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java index b5f0134c..22ecacf3 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java @@ -33,30 +33,35 @@ public class HelpController { String page = pageParam.orElse("index"); String lang = langParam.orElse(locale.getLanguage()); - model.addAttribute("visitor", UserUtils.getCurrentUser()); - model.addAttribute("help_nav", getContent("navigation", lang, Optional.empty())); - model.addAttribute("help_data", getContent(page, lang, langOrPageParam)); - - return "views/help"; - } - - private String getContent(String page, String lang, Optional langOrPageParam) { String content = null; + String navigation = null; if (langOrPageParam.isPresent()) { - String anything = langOrPageParam.get(); + String langOrPage = langOrPageParam.get(); - if (helpService.canLang(anything)) - content = helpService.getHelp(page, anything); + if (helpService.canLang(langOrPage)) { + navigation = helpService.getHelp("navigation", langOrPage); + if (navigation != null) + lang = langOrPage; + } - if (content == null && helpService.canPage(anything)) - content = helpService.getHelp(anything, lang); - } else + if (navigation == null && helpService.canPage(langOrPage)) + page = langOrPage; + } + + if (content == null) content = helpService.getHelp(page, lang); - if (content != null) - return content; + if (navigation == null) + navigation = helpService.getHelp("navigation", lang); + + if (content == null || navigation == null) + throw new HttpNotFoundException(); - throw new HttpNotFoundException(); + model.addAttribute("help_nav", navigation); + model.addAttribute("help_data", content); + model.addAttribute("visitor", UserUtils.getCurrentUser()); + + return "views/help"; } } -- cgit v1.2.3