You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chukwa.apache.org by ey...@apache.org on 2009/05/22 03:09:15 UTC
svn commit: r777346 - in /hadoop/chukwa/trunk/src:
java/org/apache/hadoop/chukwa/hicc/TimeHandler.java web/hicc/js/time.js
web/hicc/jsp/time_range.jsp
Author: eyang
Date: Fri May 22 01:09:15 2009
New Revision: 777346
URL: http://svn.apache.org/viewvc?rev=777346&view=rev
Log:
CHUKWA-251. Added per widget Time range input. (Terence Kwan via Eric Yang)
Modified:
hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java
hadoop/chukwa/trunk/src/web/hicc/js/time.js
hadoop/chukwa/trunk/src/web/hicc/jsp/time_range.jsp
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java?rev=777346&r1=777345&r2=777346&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java Fri May 22 01:09:15 2009
@@ -105,6 +105,50 @@
return l;
}
+ public void parsePeriodValue(String period) {
+ Calendar now = Calendar.getInstance();
+ this.start = now.getTimeInMillis();
+ this.end = now.getTimeInMillis();
+ if (period.equals("last1hr")) {
+ start = end - (60 * 60 * 1000);
+ } else if (period.equals("last2hr")) {
+ start = end - (2 * 60 * 60 * 1000);
+ } else if (period.equals("last3hr")) {
+ start = end - (3 * 60 * 60 * 1000);
+ } else if (period.equals("last6hr")) {
+ start = end - (6 * 60 * 60 * 1000);
+ } else if (period.equals("last12hr")) {
+ start = end - (12 * 60 * 60 * 1000);
+ } else if (period.equals("last24hr")) {
+ start = end - (24 * 60 * 60 * 1000);
+ } else if (period.equals("last7d")) {
+ start = end - (7 * 24 * 60 * 60 * 1000);
+ } else if (period.equals("last30d")) {
+ start = end - (30L * 24 * 60 * 60 * 1000);
+ } else if (period.startsWith("custom;")) {
+
+ // default value is between 2 days ago and now
+ String startString="2 days ago";
+ String endString="now";
+
+ // tokenize the value to "custom;2 days ago;now"
+ StringTokenizer st=new StringTokenizer(period,";");
+ if (st.hasMoreTokens()) {
+ st.nextToken(); // skip the first token
+ if (st.hasMoreTokens()) {
+ startString=st.nextToken();
+ if (st.hasMoreTokens()) {
+ endString=st.nextToken();
+ }
+ }
+ }
+
+ // parse the parameter strings
+ start = parseDateShorthand(startString);
+ end = parseDateShorthand(endString);
+ }
+ }
+
public void init(HttpServletRequest request) {
xf = new XssFilter(request);
Calendar now = Calendar.getInstance();
@@ -125,46 +169,7 @@
} else if (request.getParameter("period") != null
&& !request.getParameter("period").equals("")) {
String period = xf.getParameter("period");
- this.start = now.getTimeInMillis();
- this.end = now.getTimeInMillis();
- if (period.equals("last1hr")) {
- start = end - (60 * 60 * 1000);
- } else if (period.equals("last2hr")) {
- start = end - (2 * 60 * 60 * 1000);
- } else if (period.equals("last3hr")) {
- start = end - (3 * 60 * 60 * 1000);
- } else if (period.equals("last6hr")) {
- start = end - (6 * 60 * 60 * 1000);
- } else if (period.equals("last12hr")) {
- start = end - (12 * 60 * 60 * 1000);
- } else if (period.equals("last24hr")) {
- start = end - (24 * 60 * 60 * 1000);
- } else if (period.equals("last7d")) {
- start = end - (7 * 24 * 60 * 60 * 1000);
- } else if (period.equals("last30d")) {
- start = end - (30 * 24 * 60 * 60 * 1000);
- } else if (period.startsWith("custom;")) {
-
- // default value is between 2 days ago and now
- String startString="2 days ago";
- String endString="now";
-
- // tokenize the value to "custom;2 days ago;now"
- StringTokenizer st=new StringTokenizer(period,";");
- if (st.hasMoreTokens()) {
- st.nextToken(); // skip the first token
- if (st.hasMoreTokens()) {
- startString=st.nextToken();
- if (st.hasMoreTokens()) {
- endString=st.nextToken();
- }
- }
- }
-
- // parse the parameter strings
- start = parseDateShorthand(startString);
- end = parseDateShorthand(endString);
- }
+ parsePeriodValue(period);
} else if (request.getParameter("start") != null
&& request.getParameter("end") != null) {
start = Long.parseLong(request.getParameter("start"));
@@ -175,25 +180,7 @@
} else if (session.getAttribute("time_type").equals("last")
&& session.getAttribute("period") != null) {
String period = (String) session.getAttribute("period");
- this.start = now.getTimeInMillis();
- this.end = now.getTimeInMillis();
- if (period.equals("last1hr")) {
- start = end - (60 * 60 * 1000);
- } else if (period.equals("last2hr")) {
- start = end - (2 * 60 * 60 * 1000);
- } else if (period.equals("last3hr")) {
- start = end - (3 * 60 * 60 * 1000);
- } else if (period.equals("last6hr")) {
- start = end - (6 * 60 * 60 * 1000);
- } else if (period.equals("last12hr")) {
- start = end - (12 * 60 * 60 * 1000);
- } else if (period.equals("last24hr")) {
- start = end - (24 * 60 * 60 * 1000);
- } else if (period.equals("last7d")) {
- start = end - (7 * 24 * 60 * 60 * 1000);
- } else if (period.equals("last30d")) {
- start = end - (30L * 24 * 60 * 60 * 1000);
- }
+ parsePeriodValue(period);
}
// if((request.getParameter("period")==null ||
// request.getParameter("period").equals("")) &&
Modified: hadoop/chukwa/trunk/src/web/hicc/js/time.js
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/js/time.js?rev=777346&r1=777345&r2=777346&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/js/time.js (original)
+++ hadoop/chukwa/trunk/src/web/hicc/js/time.js Fri May 22 01:09:15 2009
@@ -89,6 +89,11 @@
var time_machine="last";
var obj=document.getElementById(boxId+"period").options;
var period=obj[document.getElementById(boxId+"period").selectedIndex].value;
+ if (period == 'custom') {
+ var start_string = $F(boxId+"_start_time");
+ var end_string = $F(boxId+"_end_time");
+ period="custom;"+start_string+";"+end_string;
+ }
var myAjax=new Ajax.Request(
'/hicc/jsp/session.jsp',
{
Modified: hadoop/chukwa/trunk/src/web/hicc/jsp/time_range.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/time_range.jsp?rev=777346&r1=777345&r2=777346&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/time_range.jsp (original)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/time_range.jsp Fri May 22 01:09:15 2009
@@ -17,7 +17,7 @@
* limitations under the License.
*/
%>
-<%@ page import = "java.util.Hashtable, java.util.Enumeration, java.util.Calendar, java.util.Date, java.text.SimpleDateFormat, org.apache.hadoop.chukwa.hicc.TimeHandler, java.text.NumberFormat, org.apache.hadoop.chukwa.util.XssFilter" %>
+<%@ page import = "java.util.Hashtable, java.util.StringTokenizer, java.util.Enumeration, java.util.Calendar, java.util.Date, java.text.SimpleDateFormat, org.apache.hadoop.chukwa.hicc.TimeHandler, java.text.NumberFormat, org.apache.hadoop.chukwa.util.XssFilter" %>
<%
XssFilter xf = new XssFilter(request);
response.setHeader("boxId", xf.getParameter("boxId"));
@@ -25,10 +25,12 @@
<% String boxId = xf.getParameter("boxId");
TimeHandler time = new TimeHandler(request, (String)session.getAttribute("time_zone")); %>
Time Period
-<select id="<%= boxId %>period" name="<%= boxId %>time_period" class="formSelect">
+<select class="timeWidgetPeriodControl" id="<%= boxId %>period" name="<%= boxId %>time_period" class="formSelect">
<%
+ boolean fCustom=false;
+
String period = (String) session.getAttribute("period");
- String[][] periodMap = new String[8][2];
+ String[][] periodMap = new String[9][2];
periodMap[0][0]="last1hr";
periodMap[0][1]="Last 1 Hour";
periodMap[1][0]="last2hr";
@@ -45,13 +47,95 @@
periodMap[6][1]="Last 7 Days";
periodMap[7][0]="last30d";
periodMap[7][1]="Last 30 Days";
+ periodMap[8][0]="custom";
+ periodMap[8][1]="Custom Period";
for (int i=0;i<periodMap.length;i++) {
String meta = "";
- if(period!=null && period.equals(periodMap[i][0])) {
+ if (period!=null && period.equals(periodMap[i][0])) {
meta = "selected";
+ } else if (period.startsWith("custom;") && (periodMap[i][0].equals("custom"))) {
+ meta = "selected";
+ fCustom = true;
}
+
out.println("<option value='"+periodMap[i][0]+"' "+meta+">"+periodMap[i][1]+"</option>");
}
%>
</select>
+<div id="<%= boxId %>period_custom_block" style="display:<%= (fCustom?"block":"none") %>;">
+<%
+ String start_string="2 days ago";
+ String end_string="now";
+ if (period.startsWith("custom;")) {
+ // the string should be custom;<start>;<end>
+ StringTokenizer st=new StringTokenizer(period,";");
+ if (st.hasMoreTokens()) {
+ st.nextToken(); // skip custom;
+ if (st.hasMoreTokens()) {
+ start_string=st.nextToken();
+ if (st.hasMoreTokens()) {
+ end_string=st.nextToken();
+ }
+ }
+ }
+ }
+%>
+ <br/>
+ <fieldset>
+ <legend>Custom Period</legend>
+ <table>
+ <tr><td>
+ <label for="start_period">Start Period:</label>
+ </td><td>
+ <input type="edit" name="<%= boxId %>_start_time" id="<%= boxId %>_start_time" value="<%= start_string %>"/>
+ </td><td>
+ <a href="#" id="help_edit_start_time" class="<%= boxId %>help_control">?</a>
+ </td></tr>
+ <tr><td>
+ <label for="end_period">End Period:</label>
+ </td><td>
+ <input type="edit" name="<%= boxId %>_end_time" id="<%= boxId %>_end_time" value="<%= end_string %>"/>
+ </td><td>
+ <a href="#" id="help_edit_start_time" class="<%= boxId %>help_control">?</a>
+ </td></tr>
+ </table>
+ </fieldset>
+
+ </div>
<input type="button" name="<%= boxId %>apply" value="Apply" onclick="save_time_range('<%= boxId %>')" class="formButton">
+
+<script>
+/*
+ * popup the online help
+ */
+function popup_help(event) {
+ var element = Event.element(event);
+ window.open("/hicc/jsp/help.jsp?id="+element.id,
+ "Help",
+ "width=500,height=400");
+}
+
+/*
+ * toggle the custom period control
+ */
+function togglePeriodControl(event) {
+ var element = Event.element(event);
+ value=$F(element.id);
+ if (value=='custom') {
+ $(element.id+'_custom_block').show();
+ } else {
+ $(element.id+'_custom_block').hide();
+ }
+}
+
+
+period_control = document.getElementById("<%= boxId %>period");
+
+if (period_control != null) {
+ period_control.observe('change',togglePeriodControl);
+ help_controls=document.getElementsByClassName("<%= boxId %>help_control");
+ for (i=0;i<help_controls.length;i++) {
+ help_controls[i].observe("click",popup_help);
+ }
+}
+</script>