From ebfae6637d88c9d444f39c7fbe43ce4b7ffc130f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 20 Dec 2016 15:28:54 +0300 Subject: juick-spring-www: WIP --- .../com/juick/www/controllers/IndexController.java | 20 ++++--- .../www/controllers/ShowMessageController.java | 22 ++----- .../juick/www/controllers/ThreadController.java | 67 ++++++++++++++++++++++ .../templates/views/partial/thread_message.html | 57 ++++++++++++++++++ .../webapp/WEB-INF/templates/views/thread.html | 17 ++++++ 5 files changed, 158 insertions(+), 25 deletions(-) create mode 100644 juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java create mode 100644 juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/thread_message.html create mode 100644 juick-spring-www/src/main/webapp/WEB-INF/templates/views/thread.html diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java index 54d83b61..87540795 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java @@ -7,7 +7,6 @@ import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.UserUtils; import com.juick.www.util.EncodeUtils; -import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.context.MessageSource; @@ -20,7 +19,6 @@ import org.springframework.web.bind.annotation.RequestParam; import javax.inject.Inject; import java.io.IOException; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -48,17 +46,23 @@ public class IndexController { @RequestParam(value = "search", required = false) String paramSearch, ModelMap model) throws IOException { - if (paramTagStr.isPresent()) - return "redirect:/tag/" + URLEncoder.encode(paramTagStr.get(), CharEncoding.UTF_8); + int before = paramBefore.orElse(0); + String tag = paramTagStr.orElse(StringUtils.EMPTY); + + if (StringUtils.isNotEmpty(tag)) { + StringBuilder builder = new StringBuilder(); + builder.append("redirect:").append("/tag/").append(tag); + if (before > 0) + builder.append("?before=").append(before); + return builder.toString(); + } if (StringUtils.isNotEmpty(paramSearch) && paramSearch.length() > 64) - paramSearch = ""; + paramSearch = StringUtils.EMPTY; User visitor = UserUtils.getCurrentUser(); - String title = ""; - - int before = paramBefore.orElse(0); + String title = StringUtils.EMPTY; List mids = new ArrayList<>(); diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java index 406c27ed..93039a37 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java @@ -30,20 +30,8 @@ public class ShowMessageController { public String parseAnything( @PathVariable String anything, @RequestParam(required = false, defaultValue = "0") int before, - @RequestParam(required = false) String tag, Model model) { - if (StringUtils.isNotEmpty(tag)) { - StringBuilder builder = new StringBuilder(); - - builder.append("redirect:/").append(anything).append("/tag/").append(tag); - - if (before > 0) - builder.append("?before=").append(before); - - return builder.toString(); - } - if (before == 0) { boolean isPostNumber = WebUtils.isPostNumber(anything); int messageId = isPostNumber ? @@ -65,7 +53,7 @@ public class ShowMessageController { return showUserMessages(anything, null, before, model); } - @RequestMapping("/{userName}/tag/{tagName}") + //@RequestMapping("/{userName}/tag/{tagName}") public String showUserMessagesByTag( @PathVariable String userName, @PathVariable String tagName, @@ -95,7 +83,7 @@ public class ShowMessageController { return "views/index"; } - @RequestMapping("/{userName}/friends") + //@RequestMapping("/{userName}/friends") public String getFriends( @PathVariable String userName, Model model) { @@ -114,7 +102,7 @@ public class ShowMessageController { return "views/index"; } - @RequestMapping("/{userName}/readers") + //@RequestMapping("/{userName}/readers") public String getReaders( @PathVariable String userName, Model model) { @@ -152,7 +140,7 @@ public class ShowMessageController { return "views/index"; } - @RequestMapping("/{userName}/{postNumber}") + //@RequestMapping("/{userName}/{postNumber}") public String checkShowPost( @PathVariable String userName, @PathVariable String postNumber, @@ -176,6 +164,6 @@ public class ShowMessageController { } - return "index"; + return "views/thread"; } } diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java new file mode 100644 index 00000000..f8693e13 --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java @@ -0,0 +1,67 @@ +package com.juick.www.controllers; + +import com.juick.server.util.HttpForbiddenException; +import com.juick.service.MessagesService; +import com.juick.service.UserService; +import com.juick.util.UserUtils; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import javax.inject.Inject; + +/** + * Created by vitalyster on 20.12.2016. + */ +@Controller +public class ThreadController { + @Inject + MessagesService messagesService; + @Inject + UserService userService; + + @RequestMapping(value = "/{userName}/{mid}") + public String doGetThread( + @PathVariable int mid, + @RequestParam(required = false, value = "view") String paramView, + ModelMap modelMap) { + com.juick.User visitor = UserUtils.getCurrentUser(); + + if (!messagesService.canViewThread(mid, visitor.getUid())) { + throw new HttpForbiddenException(); + } + + com.juick.Message msg = messagesService.getMessage(mid); + + boolean listview = false; + if (paramView != null) { + if (paramView.equals("list")) { + listview = true; + if (visitor.getUid() > 0) { + userService.setUserOptionInt(visitor.getUid(), "repliesview", 1); + } + } else if (paramView.equals("tree") && visitor.getUid() > 0) { + userService.setUserOptionInt(visitor.getUid(), "repliesview", 0); + } + } else if (visitor.getUid() > 0 && userService.getUserOptionInt(visitor.getUid(), "repliesview", 0) == 1) { + listview = true; + } + + String title = msg.getUser().getName() + ": " + msg.getTagsString(); + + modelMap.put("title", title); + String headers = ""; + if (paramView != null) { + headers += ""; + } + if (msg.Hidden) { + headers += ""; + } + modelMap.put("headers", headers); + modelMap.put("msg", msg); + modelMap.put("listview", listview); + return "views/thread"; + } +} diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/thread_message.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/thread_message.html new file mode 100644 index 00000000..159eebf5 --- /dev/null +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/thread_message.html @@ -0,0 +1,57 @@ + \ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/thread.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/thread.html new file mode 100644 index 00000000..ac7da17f --- /dev/null +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/thread.html @@ -0,0 +1,17 @@ + + + + Page title + + + +
+ + + +
+ + + -- cgit v1.2.3