[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-web/release] Adapt format on News page from related events.



commit 494a2637df6f70fcc13919f7ac91bbc29f371911
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Thu Dec 21 17:10:44 2017 +0100

    Adapt format on News page from related events.
---
 .../org/torproject/metrics/web/NewsServlet.java    | 67 +---------------------
 src/main/resources/web/jsps/news.jsp               | 17 +++++-
 2 files changed, 16 insertions(+), 68 deletions(-)

diff --git a/src/main/java/org/torproject/metrics/web/NewsServlet.java b/src/main/java/org/torproject/metrics/web/NewsServlet.java
index 7840a40..15717bd 100644
--- a/src/main/java/org/torproject/metrics/web/NewsServlet.java
+++ b/src/main/java/org/torproject/metrics/web/NewsServlet.java
@@ -82,77 +82,14 @@ public class NewsServlet extends AnyServlet {
         .getStart()) > 0);
 
     /* Sort news into categories. */
-    Map<String[], List<String[]>> newsByCategory = new LinkedHashMap<>();
+    Map<String[], List<String>> newsByCategory = new LinkedHashMap<>();
     for (String[] category : cutOffDates.values()) {
       newsByCategory.put(category, new ArrayList<>());
     }
     for (News news : this.sortedNews) {
-      StringBuilder sb = new StringBuilder();
-      sb.append("<h3 class=\"media-heading\">").append(news.getStart());
-      if (news.getEnd() != null) {
-        sb.append(" to ").append(news.getEnd());
-      }
-      if (news.getPlaces() != null) {
-        boolean appendUnknownCountry = false;
-        for (String place : news.getPlaces()) {
-          if (this.countries.containsKey(place)) {
-            sb.append(" <span class=\"label label-warning\">")
-                .append(this.countries.get(place)).append("</span>");
-          } else {
-            appendUnknownCountry = true;
-          }
-        }
-        if (appendUnknownCountry) {
-          sb.append(" <span class=\"label label-warning\">"
-              + "Unknown country</span>");
-        }
-      }
-      if (news.getProtocols() != null) {
-        for (String protocol : news.getProtocols()) {
-          switch (protocol) {
-            case "relay":
-              sb.append(" <span class=\"label label-success\">"
-                  + "Relays</span>");
-              break;
-            case "bridge":
-              sb.append(" <span class=\"label label-primary\">"
-                  + "Bridges</span>");
-              break;
-            case "<OR>":
-              sb.append(" <span class=\"label label-info\">"
-                  + "&lt;OR&gt;</span>");
-              break;
-            default:
-              sb.append(" <span class=\"label label-info\">").append(protocol)
-                  .append("</span>");
-              break;
-          }
-        }
-      }
-      if (news.isUnknown()) {
-        sb.append(" <span class=\"label label-default\">"
-            + "Unknown</span>");
-      }
-      sb.append("</h3><p>").append(news.getDescription()).append("</p>");
-      if (news.getLinks() != null && news.getLinks().length > 0) {
-        int written = 0;
-        sb.append("<p class=\"links\">");
-        for (String link : news.getLinks()) {
-          if (written++ > 0) {
-            sb.append(" ");
-          }
-          if (link.startsWith("https://metrics.torproject.org/";)) {
-            sb.append(link);
-          } else {
-            sb.append(link.replaceFirst(">", " target=\"_blank\">"));
-          }
-        }
-        sb.append("</p>");
-      }
-      String[] formattedNews = new String[] { sb.toString() };
       for (Map.Entry<String, String[]> category : cutOffDates.entrySet()) {
         if (news.getStart().compareTo(category.getKey()) >= 0) {
-          newsByCategory.get(category.getValue()).add(formattedNews);
+          newsByCategory.get(category.getValue()).add(news.formatAsTableRow());
           break;
         }
       }
diff --git a/src/main/resources/web/jsps/news.jsp b/src/main/resources/web/jsps/news.jsp
index 68f1689..499eade 100644
--- a/src/main/resources/web/jsps/news.jsp
+++ b/src/main/resources/web/jsps/news.jsp
@@ -20,9 +20,20 @@
     <c:forEach var="category" items="${news}" varStatus="status">
     <div class="container">
       <h2>${category.key[0]} <a href="#${category.key[1]}" name="${category.key[1]}" class="anchor">#</a></h2>
-      <c:forEach var="entry" items="${category.value}">
-      <p>${entry[0]}<br></p>
-      </c:forEach>
+      <table class="table events">
+        <thead>
+          <tr>
+            <th class="dates">Dates</th>
+            <th class="tags">Places/Protocols</th>
+            <th class="description">Description and Links</th>
+          </tr>
+        </thead>
+        <tbody>
+          <c:forEach var="entry" items="${category.value}">
+          ${entry}
+          </c:forEach>
+        </tbody>
+      </table>
     </div>
     </c:forEach>
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits