Mercurial Hosting > nabble
comparison src/nabble/view/web/user/UserPendingNodes.java @ 0:7ecd1a4ef557
add content
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Thu, 21 Mar 2019 19:15:52 -0600 |
| parents | |
| children | 18cf4872fd7f |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7ecd1a4ef557 |
|---|---|
| 1 | |
| 2 package nabble.view.web.user; | |
| 3 | |
| 4 import nabble.model.Node; | |
| 5 import nabble.model.User; | |
| 6 import nabble.view.lib.Jtp; | |
| 7 import nabble.view.lib.Shared; | |
| 8 import nabble.view.lib.HtmlViewUtils; | |
| 9 | |
| 10 import javax.servlet.ServletException; | |
| 11 import javax.servlet.http.HttpServlet; | |
| 12 import javax.servlet.http.HttpServletRequest; | |
| 13 import javax.servlet.http.HttpServletResponse; | |
| 14 import java.io.IOException; | |
| 15 import java.io.PrintWriter; | |
| 16 import java.util.ArrayList; | |
| 17 import java.util.List; | |
| 18 | |
| 19 | |
| 20 public final class UserPendingNodes extends HttpServlet { | |
| 21 | |
| 22 private static final int MAX_ROWS = 20; | |
| 23 | |
| 24 protected void service(HttpServletRequest request, HttpServletResponse response) | |
| 25 throws ServletException, IOException | |
| 26 { | |
| 27 PrintWriter out = response.getWriter(); | |
| 28 User user = Jtp.getUser(request, response); | |
| 29 | |
| 30 if ( user == null ) { | |
| 31 Jtp.login("You must register/login to edit your profile.", request, response); | |
| 32 return; | |
| 33 } | |
| 34 | |
| 35 String iRecS = request.getParameter("i"); | |
| 36 int iRec = iRecS == null? 0 : Integer.valueOf(iRecS); | |
| 37 | |
| 38 List<Node> nodeArray = user.getPendingPosts().get(0, 1000); | |
| 39 SearchResults searchResults = cutResults(nodeArray, iRec); | |
| 40 | |
| 41 String title = "Pending Posts of "; | |
| 42 title += user.getName(); | |
| 43 | |
| 44 String url = "/user/UserPendingNodes.jtp"; | |
| 45 HtmlViewUtils.GenericPagingPath pagingPath = new HtmlViewUtils.GenericPagingPath(url); | |
| 46 | |
| 47 out.print( "\r\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\r\n<html>\r\n <head>\r\n " ); | |
| 48 Shared.title(request, response, title); | |
| 49 out.print( "\r\n </head>\r\n <body>\r\n " ); | |
| 50 Shared.minHeaderGlobal(request, response); | |
| 51 out.print( "\r\n <table>\r\n <tr valign=\"top\">\r\n <td><img src=\"" ); | |
| 52 out.print( (Shared.getAvatarImageURL(user, false)) ); | |
| 53 out.print( "\" class=\"avatar light-border-color\" width=100 height=100/></td>\r\n <td style=\"width:100%\">\r\n <div class=\"second-font\" style=\"font-size:170%\">\r\n " ); | |
| 54 out.print( (user.getNameHtml()) ); | |
| 55 out.print( "\r\n </div>\r\n <div style=\"margin-top:.5em\">\r\n <a href=\"/template/NamlServlet.jtp?macro=user_profile\">Account Settings</a>\r\n </div>\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n <table style=\"border-collapse:collapse;width:100%;margin-top:.5em\">\r\n <tr>\r\n <td class=\"title-row light-border-color\" colspan=3>\r\n <div style=\"float:left;padding-top:.2em\">\r\n <b>Pending Messages</b>\r\n </div>\r\n " ); | |
| 56 HtmlViewUtils.genericPaging(request, response, searchResults.getCount(), iRec, MAX_ROWS, pagingPath, ".4em 0 0 0"); | |
| 57 out.print( "\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n <style type=\"text/css\">\r\n table.nodes {\r\n width:100%;\r\n border-width: 1px;\r\n border-style: solid;\r\n border-collapse:collapse;\r\n margin-top:.5em;\r\n }\r\n\r\n table.nodes td {\r\n padding:.1em;\r\n }\r\n\r\n table.nodes td.header {\r\n padding: .2em .3em;\r\n border-bottom-width: 1px;\r\n border-bottom-style: solid;\r\n }\r\n </style>\r\n\r\n " ); | |
| 58 | |
| 59 String[] columns = new String[] { "Message", "Pending Since", "Forum" }; | |
| 60 | |
| 61 out.print( "\r\n\r\n<table class=\"nodes medium-border-color\">\r\n <tr class=\"shaded-bg-color\" style=\"font-weight: bold\">\r\n <td class=\"header\" style=\"width:16px\"></td>\r\n <td class=\"header\">" ); | |
| 62 out.print( (columns[0]) ); | |
| 63 out.print( "</td>\r\n <td class=\"header\">" ); | |
| 64 out.print( (columns[1]) ); | |
| 65 out.print( "</td>\r\n <td class=\"header\">" ); | |
| 66 out.print( (columns[2]) ); | |
| 67 out.print( "</td>\r\n </tr>\r\n " ); | |
| 68 | |
| 69 Node[] nodes = searchResults.getNodes(); | |
| 70 int i = 0; | |
| 71 if (nodes.length > 0) { | |
| 72 for (Node node : nodes) { | |
| 73 | |
| 74 out.print( "\r\n<tr " ); | |
| 75 out.print( (i++%2==1?"class=\"light-bg-color\"":"") ); | |
| 76 out.print( ">\r\n <td align=\"center\">\r\n " ); | |
| 77 Shared.showPending(out, node); | |
| 78 out.print( "\r\n </td>\r\n <td style=\"padding:.3em .4em;\">\r\n <a href=\"" ); | |
| 79 out.print( (Jtp.url(node)) ); | |
| 80 out.print( "\">" ); | |
| 81 out.print( (node.getSubjectHtml()) ); | |
| 82 out.print( "</a>\r\n </td>\r\n <td style=\"padding:.2em\">\r\n " ); | |
| 83 out.print( (node.getMailToList() == null? "" : Jtp.formatDateLong(node.getMailToList().getWhenSent())) ); | |
| 84 out.print( "\r\n </td>\r\n <td style=\"padding:.2em\">\r\n " ); | |
| 85 out.print( (Jtp.link(node.getApp())) ); | |
| 86 out.print( "\r\n </td>\r\n</tr>\r\n" ); | |
| 87 | |
| 88 } | |
| 89 } else { | |
| 90 | |
| 91 out.print( "\r\n<tr><td colspan=4 style=\"padding:.3em\">None</td></tr>\r\n" ); | |
| 92 | |
| 93 } | |
| 94 | |
| 95 out.print( "\r\n</table>\r\n" ); | |
| 96 HtmlViewUtils.genericPaging(request, response, searchResults.getCount(), iRec, MAX_ROWS, pagingPath, ".5em 0 0 0"); | |
| 97 out.print( "\r\n\r\n" ); | |
| 98 Shared.footer(request,response); | |
| 99 out.print( "\r\n" ); | |
| 100 Shared.analytics(request,response); | |
| 101 out.print( "\r\n</body>\r\n</html>\r\n" ); | |
| 102 | |
| 103 } | |
| 104 | |
| 105 private class SearchResults { | |
| 106 private int count; | |
| 107 private Node[] nodes; | |
| 108 | |
| 109 public SearchResults() {} | |
| 110 | |
| 111 public SearchResults(int count, Node[] nodes) { | |
| 112 this.count = count; | |
| 113 this.nodes = nodes; | |
| 114 } | |
| 115 | |
| 116 public int getCount() { return count; } | |
| 117 public void setCount(int count) { this.count = count; } | |
| 118 public Node[] getNodes() { return nodes; } | |
| 119 public void setNodes(Node[] nodes) { this.nodes = nodes; } | |
| 120 } | |
| 121 | |
| 122 private SearchResults cutResults(List<Node> array, int iRec) { | |
| 123 int i = iRec; | |
| 124 int count = 0; | |
| 125 List<Node> nodes = new ArrayList<Node>(); | |
| 126 while (count < MAX_ROWS) { | |
| 127 if (array.size()-1 < i) | |
| 128 break; | |
| 129 nodes.add(array.get(i++)); | |
| 130 count++; | |
| 131 } | |
| 132 Node[] nodesArray = nodes.toArray(new Node[0]); | |
| 133 return new SearchResults(array.size(), nodesArray); | |
| 134 } | |
| 135 } | |
| 136 |
