accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject svn commit: r1461914 - in /accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets: BasicServlet.java trace/ShowTrace.java
Date Thu, 28 Mar 2013 01:23:56 GMT
Author: elserj
Date: Thu Mar 28 01:23:56 2013
New Revision: 1461914

URL: http://svn.apache.org/r1461914
Log:
ACCUMULO-1205 Stub in an onload for the "Show Trace" page which display:table-row's any trace
line which has the 'addl data' checkbox already checked.

Modified:
    accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java
    accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTrace.java

Modified: accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java?rev=1461914&r1=1461913&r2=1461914&view=diff
==============================================================================
--- accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java
(original)
+++ accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java
Thu Mar 28 01:23:56 2013
@@ -153,7 +153,7 @@ abstract public class BasicServlet exten
     sb.append("</head>\n");
     
     // BEGIN BODY OPENING
-    sb.append("\n<body>\n");
+    sb.append("\n<body ").append(getBodyAttributes()).append(">\n");
     sb.append("<div id='content-wrapper'>\n");
     sb.append("<div id='content'>\n");
     sb.append("<div id='header'>");
@@ -222,6 +222,16 @@ abstract public class BasicServlet exten
     sb.append("</body>\n");
     sb.append("</html>\n");
   }
+
+  /**
+   * Allow the concrete servlet implementation to provide attributes on the body HTML tag,
+   * such as 'onload', which can be used to call Javascript methods on page load.
+   * By default, nothing is specified.
+   * @return
+   */
+  protected String getBodyAttributes() {
+    return "";
+  }
   
   public static String encode(String s) {
     try {

Modified: accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTrace.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTrace.java?rev=1461914&r1=1461913&r2=1461914&view=diff
==============================================================================
--- accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTrace.java
(original)
+++ accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTrace.java
Thu Mar 28 01:23:56 2013
@@ -41,6 +41,8 @@ import org.apache.hadoop.io.Text;
 public class ShowTrace extends Basic {
   
   private static final long serialVersionUID = 1L;
+  private static final String checkboxIdSuffix = "_checkbox";
+  private static final String pageLoadFunctionName = "pageload";
   
   String getTraceId(HttpServletRequest req) {
     return getStringParameter(req, "id", null);
@@ -87,6 +89,18 @@ public class ShowTrace extends Basic {
     sb.append("    elt.style.display='none';\n ");
     sb.append(" }\n");
     sb.append("}\n");
+
+    sb.append("function ").append(pageLoadFunctionName).append("() {\n");
+    sb.append("  var checkboxes = document.getElementsByTagName('input');\n");
+    sb.append("  for (var i = 0; i < checkboxes.length; i++) {\n");
+    sb.append("    if (checkboxes[i].checked) {\n");
+    sb.append("      var idSuffixOffset = checkboxes[i].id.indexOf('").append(checkboxIdSuffix).append("');\n");
+    sb.append("      var id = checkboxes[i].id.substring(0, idSuffixOffset);\n");
+    sb.append("      document.getElementById(id).style.display='table-row';\n");
+    sb.append("    }\n");
+    sb.append("  }\n");
+    sb.append("}\n");
+
     sb.append("</script>\n");
     sb.append("<div>");
     sb.append("<table><caption>");
@@ -102,10 +116,15 @@ public class ShowTrace extends Basic {
         sb.append(String.format("<td style='text-indent: %dpx'>%s@%s</td>%n",
level * 5, node.svc, node.sender));
         sb.append("<td>" + node.description + "</td>");
         boolean hasData = node.data != null && !node.data.isEmpty();
-        if (hasData)
-          sb.append("<td><input type='checkbox' onclick='toggle(\"" + Long.toHexString(node.spanId)
+ "\")'></td>\n");
-        else
+        if (hasData) {
+          String hexSpanId = Long.toHexString(node.spanId);
+          sb.append("<td><input type='checkbox' id=\"");
+          sb.append(hexSpanId);
+          sb.append(checkboxIdSuffix);
+          sb.append("\" onclick='toggle(\"" + Long.toHexString(node.spanId) + "\")'></td>\n");
+        } else {
           sb.append("<td></td>\n");
+        }
         sb.append("</tr>\n");
         sb.append("<tr id='" + Long.toHexString(node.spanId) + "' style='display:none'>");
         sb.append("<td colspan='5'>\n");
@@ -133,4 +152,9 @@ public class ShowTrace extends Basic {
     sb.append("</table>\n");
     sb.append("</div>\n");
   }
+  
+  @Override
+  protected String getBodyAttributes() {
+    return " onload=\"" + pageLoadFunctionName + "()\" ";
+  }
 }



Mime
View raw message