From be30d843aab467aa628f1c3f3c7d194bfda54284 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 23 May 2017 14:47:38 +0300 Subject: fix style --- .../main/java/com/juick/www/controllers/User.java | 99 +++++++++------------- .../pebble/extension/FormatterExtension.java | 2 + .../pebble/extension/filters/TagsListFilter.java | 23 +++++ 3 files changed, 63 insertions(+), 61 deletions(-) create mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TagsListFilter.java (limited to 'juick-www/src/main/java/com') diff --git a/juick-www/src/main/java/com/juick/www/controllers/User.java b/juick-www/src/main/java/com/juick/www/controllers/User.java index b66c6fa1..8e22c654 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/User.java +++ b/juick-www/src/main/java/com/juick/www/controllers/User.java @@ -39,10 +39,7 @@ import org.springframework.web.util.UriComponents; import ru.sape.Sape; import javax.inject.Inject; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.PrintWriter; import java.net.URLEncoder; import java.util.List; import java.util.stream.Collectors; @@ -152,7 +149,7 @@ public class User { model.addAttribute("statsReplies", userService.getStatsReplies(user.getUid())); model.addAttribute("iread", userService.getUserReadLeastPopular(user.getUid(), 8)); model.addAttribute("tagStats", tagService.getUserTagStats(user.getUid()) - .stream().map(t -> t.getTag().getName()).collect(Collectors.toList())); + .stream().sorted((e1, e2) -> Integer.compare(e2.getUsageCount(), e1.getUsageCount())).limit(20).map(t -> t.getTag().getName()).collect(Collectors.toList())); model.addAttribute("paramTag", paramTag); List msgs = messagesService.getMessages(mids); @@ -218,76 +215,56 @@ public class User { } @GetMapping("/{uname}/friends") - protected void doGetFriends(HttpServletRequest request, HttpServletResponse response, - @PathVariable String uname) throws IOException { + protected String doGetFriends(@PathVariable String uname, ModelMap model) throws IOException { com.juick.User user = userService.getUserByName(uname); com.juick.User visitor = UserUtils.getCurrentUser(); if (visitor.isBanned()) { - throw new HttpForbiddenException(); + throw new HttpNotFoundException(); } + model.addAttribute("title", "Подписки " + user.getName()); + model.addAttribute("headers", ""); + model.addAttribute("visitor", visitor); + model.addAttribute("user", user); + model.addAttribute("readonly", messagesService.isReadonly()); + model.addAttribute("isSubscribed", userService.isSubscribed(visitor.getUid(), user.getUid())); + model.addAttribute("isInBL", userService.isInBL(visitor.getUid(), user.getUid())); + model.addAttribute("isInBLAny", userService.isInBLAny(user.getUid(), visitor.getUid())); + model.addAttribute("statsIRead", userService.getStatsIRead(user.getUid())); + model.addAttribute("statsMyReaders", userService.getStatsMyReaders(user.getUid())); + model.addAttribute("statsMessages", userService.getStatsMessages(user.getUid())); + model.addAttribute("statsReplies", userService.getStatsReplies(user.getUid())); + model.addAttribute("iread", userService.getUserReadLeastPopular(user.getUid(), 8)); + model.addAttribute("tagStats", tagService.getUserTagStats(user.getUid()) + .stream().map(t -> t.getTag().getName()).collect(Collectors.toList())); + model.addAttribute("users", userService.getUserFriends(user.getUid())); - response.setContentType("text/html; charset=UTF-8"); - try (PrintWriter out = response.getWriter()) { - String head = ""; - templates.pageHead(out, visitor, "Подписки " + user.getName(), head); - templates.pageNavigation(out, visitor, null); - //pageUserColumn(out, user, visitor); - - out.println("
"); - out.println(""); - - List friends = userService.getUserFriends(user.getUid()); - for (int i = 0; i < friends.size(); i++) { - if (i % 3 == 0 && i > 0) { - out.print(""); - } - out.print(""); - } - - out.println("
" - + friends.get(i).getName() + "
"); - out.println("
"); - - templates.pageFooter(request, out, visitor, false); - templates.pageEnd(out); - } + return "views/users"; } @GetMapping("/{uname}/readers") - protected void doGetReaders(HttpServletRequest request, HttpServletResponse response, - @PathVariable String uname) throws IOException { + protected String doGetReaders(@PathVariable String uname, ModelMap model) throws IOException { com.juick.User user = userService.getUserByName(uname); com.juick.User visitor = UserUtils.getCurrentUser(); if (visitor.isBanned()) { throw new HttpForbiddenException(); } + model.addAttribute("title", "Читатели " + user.getName()); + model.addAttribute("headers", ""); + model.addAttribute("visitor", visitor); + model.addAttribute("user", user); + model.addAttribute("readonly", messagesService.isReadonly()); + model.addAttribute("isSubscribed", userService.isSubscribed(visitor.getUid(), user.getUid())); + model.addAttribute("isInBL", userService.isInBL(visitor.getUid(), user.getUid())); + model.addAttribute("isInBLAny", userService.isInBLAny(user.getUid(), visitor.getUid())); + model.addAttribute("statsIRead", userService.getStatsIRead(user.getUid())); + model.addAttribute("statsMyReaders", userService.getStatsMyReaders(user.getUid())); + model.addAttribute("statsMessages", userService.getStatsMessages(user.getUid())); + model.addAttribute("statsReplies", userService.getStatsReplies(user.getUid())); + model.addAttribute("iread", userService.getUserReadLeastPopular(user.getUid(), 8)); + model.addAttribute("tagStats", tagService.getUserTagStats(user.getUid()) + .stream().map(t -> t.getTag().getName()).collect(Collectors.toList())); + model.addAttribute("users", userService.getUserReaders(user.getUid())); - response.setContentType("text/html; charset=UTF-8"); - try (PrintWriter out = response.getWriter()) { - String head = ""; - templates.pageHead(out, visitor, "Читатели " + user.getName(), head); - templates.pageNavigation(out, visitor, null); - //pageUserColumn(out, user, visitor); - - out.println("
"); - out.println(""); - - List readers = userService.getUserReaders(user.getUid()); - for (int i = 0; i < readers.size(); i++) { - if (i % 3 == 0 && i > 0) { - out.print(""); - } - out.print(""); - } - - out.println("
" - + readers.get(i).getName() + "
"); - out.println("
"); - - templates.pageFooter(request, out, visitor, false); - templates.pageEnd(out); - } + return "views/users"; } } diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java index 220e0460..198e9668 100644 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java @@ -2,6 +2,7 @@ package com.mitchellbosecke.pebble.extension; import com.mitchellbosecke.pebble.extension.filters.FormatMessageFilter; import com.mitchellbosecke.pebble.extension.filters.PrettyTimeFilter; +import com.mitchellbosecke.pebble.extension.filters.TagsListFilter; import java.util.HashMap; import java.util.Map; @@ -15,6 +16,7 @@ public class FormatterExtension extends AbstractExtension { Map filters = new HashMap<>(); filters.put("formatMessage", new FormatMessageFilter()); filters.put("prettyTime", new PrettyTimeFilter()); + filters.put("tagsList", new TagsListFilter()); return filters; } } diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TagsListFilter.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TagsListFilter.java new file mode 100644 index 00000000..55c98307 --- /dev/null +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TagsListFilter.java @@ -0,0 +1,23 @@ +package com.mitchellbosecke.pebble.extension.filters; + +import com.juick.Tag; +import com.mitchellbosecke.pebble.extension.Filter; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Created by vitalyster on 23.05.2017. + */ +public class TagsListFilter implements Filter { + @Override + public Object apply(Object input, Map args) { + return ((List) input).stream().map(Tag::getName).collect(Collectors.toList()); + } + + @Override + public List getArgumentNames() { + return null; + } +} -- cgit v1.2.3