Author: [log in to unmask] Date: Fri Feb 12 14:36:56 2016 New Revision: 4218 Log: Run web app updates; change fields shown in dataset list; display human readable file size in dataset list; make initial pager sizes larger. Added: webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/ByteFormat.java webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/Util.java webapps/trunk/run-webapp/src/main/webapp/WEB-INF/tags/ webapps/trunk/run-webapp/src/main/webapp/WEB-INF/tags/functions.tld Modified: webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/DatacatHelper.java webapps/trunk/run-webapp/src/main/webapp/html/pager.html webapps/trunk/run-webapp/src/main/webapp/showDatasets.jsp webapps/trunk/run-webapp/src/main/webapp/showEpics.jsp webapps/trunk/run-webapp/src/main/webapp/showRunTable.jsp webapps/trunk/run-webapp/src/main/webapp/showScalers.jsp Added: webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/ByteFormat.java ============================================================================= --- webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/ByteFormat.java (added) +++ webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/ByteFormat.java Fri Feb 12 14:36:56 2016 @@ -0,0 +1,67 @@ +package org.hps.webapps.run; + +import java.text.DecimalFormat; +import java.text.FieldPosition; +import java.text.Format; +import java.text.ParsePosition; + +/** + * A formatter for formatting byte sizes. For example, formatting 12345 byes results in "12.1 kB" + * and 1234567 results in "1.18 MB". + * <p> + * Copied from datacat webapp. + * + * @author Bill Lynch + * @author Tony Johnson + */ +public class ByteFormat extends Format { + + private final static String[] mags = {" B", " kB", " MB", " GB", " TB", " PB"}; + private final static DecimalFormat formatter = new DecimalFormat("#,##0.0"); + + /** + * Formats a long which represent a number of bytes. + */ + public String format(long bytes){ + return format(new Long(bytes)); + } + + /** + * Format the given object (must be a Long). + * + * @param obj assumed to be the number of bytes as a Long. + * @param buf the StringBuffer to append to. + * @param pos + * @return A formatted string representing the given bytes in more human-readable form. + */ + public StringBuffer format(Object obj, StringBuffer buf, FieldPosition pos){ + if(obj instanceof Long){ + long numBytes = ((Long) obj).longValue(); + if(numBytes > 1024){ + int mag = 1; + for(; mag < mags.length; mag++){ + if(numBytes < 1024 * 1024) { + break; + } + numBytes /= 1024; + } + + buf.append(formatter.format((double) numBytes / 1024.0)).append(mags[mag]); + } else { + buf.append(numBytes).append(mags[0]); + } + } + return buf; + } + + /** + * In this implementation, returns null always. + * + * @param source + * @param pos + * @return returns null in this implementation. + */ + public Object parseObject(String source, ParsePosition pos){ + return null; + } +} Modified: webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/DatacatHelper.java ============================================================================= --- webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/DatacatHelper.java (original) +++ webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/DatacatHelper.java Fri Feb 12 14:36:56 2016 @@ -44,5 +44,5 @@ } return datasets; - } + } } Added: webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/Util.java ============================================================================= --- webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/Util.java (added) +++ webapps/trunk/run-webapp/src/main/java/org/hps/webapps/run/Util.java Fri Feb 12 14:36:56 2016 @@ -0,0 +1,51 @@ +package org.hps.webapps.run; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Locale; +import java.util.TimeZone; + +/** + * Copied from datacat webapp. + * + * @author bvan + */ +public class Util { + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.US); + private static final ByteFormat byteFormat = new ByteFormat(); + + static { + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + } + + public static String formatTimestamp(Timestamp timestamp){ + synchronized(byteFormat) { + return timestamp == null ? "" : dateFormat.format(timestamp); + } + } + + public static String formatBytes(long bytes){ + synchronized(byteFormat) { + return byteFormat.format(bytes); + } + } + + public static String formatEvents(long events){ + return String.format("%,d", events); + } + + public static String getValueType(Object value){ + if(value instanceof Long || value instanceof Integer || value instanceof BigInteger) { + return "integer"; + } + if(value instanceof Double || value instanceof Float || value instanceof BigDecimal) { + return "decimal"; + } + if(value instanceof Timestamp){ + return "timestamp"; + } + return "string"; + } +} Added: webapps/trunk/run-webapp/src/main/webapp/WEB-INF/tags/functions.tld ============================================================================= --- webapps/trunk/run-webapp/src/main/webapp/WEB-INF/tags/functions.tld (added) +++ webapps/trunk/run-webapp/src/main/webapp/WEB-INF/tags/functions.tld Fri Feb 12 14:36:56 2016 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"> + <tlib-version>1.0</tlib-version> + <short-name>datacat</short-name> + <uri>http://hpsweb.jlab.org/datacat</uri> + <function> + <description>Format bytes</description> + <name>formatBytes</name> + <function-class>org.hps.webapps.run.Util</function-class> + <function-signature>java.lang.String formatBytes(long)</function-signature> + </function> +</taglib> Modified: webapps/trunk/run-webapp/src/main/webapp/html/pager.html ============================================================================= --- webapps/trunk/run-webapp/src/main/webapp/html/pager.html (original) +++ webapps/trunk/run-webapp/src/main/webapp/html/pager.html Fri Feb 12 14:36:56 2016 @@ -9,10 +9,10 @@ <select class="pagesize"> <option selected="selected" value="10">10</option> <option value="20">20</option> - <option value="30">30</option> - <option value="40">40</option> <option value="50">50</option> <option value="100">100</option> + <option value="200">200</option> + <option value="500">500</option> <option value="1000">1000</option> <option value="10000">10000</option> </select> Modified: webapps/trunk/run-webapp/src/main/webapp/showDatasets.jsp ============================================================================= --- webapps/trunk/run-webapp/src/main/webapp/showDatasets.jsp (original) +++ webapps/trunk/run-webapp/src/main/webapp/showDatasets.jsp Fri Feb 12 14:36:56 2016 @@ -1,6 +1,11 @@ <%@ page contentType="text/html"%> -<%@page import="java.util.*,org.hps.run.database.RunSummary,java.text.SimpleDateFormat"%> +<%@page import="java.util.*"%> +<%@page import="java.io.File"%> +<%@page import="org.hps.run.database.RunSummary"%> +<%@page import="org.hps.webapps.run.DatacatHelper"%> +<%@page import="org.apache.commons.io.FileUtils"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="/WEB-INF/tags/functions.tld" prefix="f"%> <html> @@ -31,28 +36,32 @@ <table id="dataset-table" class="tablesorter-blue"> <thead> <tr> - <th>Path</th> - <th>Type</th> + <th>Name</th> + <th>Size</th> <th>Created</th> </tr> </thead> <tbody> <c:forEach var="dataset" items="${datasets}"> + <c:forEach var="location" items="${dataset.viewInfo.locations}"> + <c:if test="${location.isMaster().booleanValue()}"> + <c:set var="master" value="${location}"/> + </c:if> + </c:forEach> <tr> - <!-- onclick="document.location.href='<%=getServletContext().getInitParameter("datacat")%>/display/datasets/<c:out value="${dataset.path}"/>';"> --> <td> + <!-- Link to external datacat site. --> <a href="<%=getServletContext().getInitParameter("datacat")%>/display/datasets/<c:out value="${dataset.path}"/>"> - <c:out value="${dataset.path}" /> + <c:out value="${dataset.name}" /> </a> + <!-- Link to plot display if file is AIDA DQM. --> <c:if test="${dataType == 'DQM' && dataFormat == 'AIDA'}"> - <c:forEach var="location" items="${dataset.viewInfo.locations}" begin="0" end="0"> - <a target="_blank" style="font-size: 80%" - href="<%=getServletContext().getInitParameter("dqm")%>/show_plots?file=<c:out value="${location.resource}"/>">Show Plots</a> - </c:forEach> + <a target="_blank" style="font-size: 80%" + href="<%=getServletContext().getInitParameter("dqm")%>/show_plots?file=<c:out value="${master.resource}"/>">Show Plots</a> </c:if> </td> <td> - <c:out value="${dataset.dataType}" /> + <c:out value="${f:formatBytes(master.size)}" /> </td> <td> <c:out value="${dataset.dateCreated}" /> @@ -60,7 +69,6 @@ </tr> </c:forEach> </tbody> - </table> - + </table> </body> </html> Modified: webapps/trunk/run-webapp/src/main/webapp/showEpics.jsp ============================================================================= --- webapps/trunk/run-webapp/src/main/webapp/showEpics.jsp (original) +++ webapps/trunk/run-webapp/src/main/webapp/showEpics.jsp Fri Feb 12 14:36:56 2016 @@ -15,7 +15,7 @@ widgets : [ 'zebra' ] }).tablesorterPager({ container : $("#pager"), - size : 50 + size : 100 }); }); </script> Modified: webapps/trunk/run-webapp/src/main/webapp/showRunTable.jsp ============================================================================= --- webapps/trunk/run-webapp/src/main/webapp/showRunTable.jsp (original) +++ webapps/trunk/run-webapp/src/main/webapp/showRunTable.jsp Fri Feb 12 14:36:56 2016 @@ -21,7 +21,7 @@ widgets : [ 'zebra' ] }).tablesorterPager({ container : $("#pager"), - size : 20 + size : 100 }); }); </script> Modified: webapps/trunk/run-webapp/src/main/webapp/showScalers.jsp ============================================================================= --- webapps/trunk/run-webapp/src/main/webapp/showScalers.jsp (original) +++ webapps/trunk/run-webapp/src/main/webapp/showScalers.jsp Fri Feb 12 14:36:56 2016 @@ -14,7 +14,7 @@ widgets : [ 'zebra' ] }).tablesorterPager({ container : $("#pager"), - size : 50 + size : 100 }); }); </script>