[rhmessaging-commits] rhmessaging commits: r3277 - mgmt/trunk/cumin/python/cumin.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Apr 9 15:24:35 EDT 2009


Author: eallen
Date: 2009-04-09 15:24:35 -0400 (Thu, 09 Apr 2009)
New Revision: 3277

Modified:
   mgmt/trunk/cumin/python/cumin/stat.py
   mgmt/trunk/cumin/python/cumin/stat.strings
   mgmt/trunk/cumin/python/cumin/widgets.py
Log:
1st part of javascript powered duration switches for stat value charts.

Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py	2009-04-09 18:51:35 UTC (rev 3276)
+++ mgmt/trunk/cumin/python/cumin/stat.py	2009-04-09 19:24:35 UTC (rev 3277)
@@ -73,14 +73,19 @@
         #else:
 
         return stat.rate_html(object)
+
 class DurationSwitch(StateSwitch):
     def __init__(self, app, name):
         super(DurationSwitch, self).__init__(app, name)
 
-        self.add_state("m", "10 minutes")
-        self.add_state("h", "1 hour")
-        self.add_state("d", "1 day")
+        self.add_state("600", "10 minutes")
+        self.add_state("3600", "1 hour")
+        self.add_state("86400", "1 day")
 
+class JSDurationSwitch(DurationSwitch):
+    def get_click(self, state):
+        return "return changeDuration('%s', this, '%s')" % (state, self.parent.path)
+
 class StatValueChart(Widget):
     def __init__(self, app, name):
         super(StatValueChart, self).__init__(app, name)
@@ -91,7 +96,7 @@
 
         self.stats_tmpl = Template(self, "stat_html")
 
-        self.duration = DurationSwitch(app, "duration")
+        self.duration = JSDurationSwitch(app, "duration")
         self.add_child(self.duration)
 
     def get_args(self, session):
@@ -109,13 +114,8 @@
         for stat in self.stats:
             params.append("stat=%s" % stat)
 
-        duration = self.duration.get(session)
+        params.append("duration=%s" % self.duration.get(session))
 
-        if duration == "h":
-            params.append("duration=%i" % 3600)
-        elif duration == "d":
-            params.append("duration=%i" % 86400)
-
         if self.mode:
             params.append("mode=%s" % self.mode)
 
@@ -165,7 +165,7 @@
     def __init__(self, app, name):
         super(StatStackedChart, self).__init__(app, name)
 
-        self.duration = self.JSDurationSwitch(app, "duration")
+        self.duration = JSDurationSwitch(app, "duration")
         self.add_child(self.duration)
 
     def get_chart_name(self, session):
@@ -174,21 +174,6 @@
     def render_height(self, session, object):
         return 200
 
-    class JSDurationSwitch(DurationSwitch):
-        def render_item_link(self, session, state):
-            href = "javascript:void(0)"
-
-            title = self.get_title(state)
-            hover = self.get_hover(state)
-            class_ = self.get(session) == state and "selected"
-            duration = 600
-            if state == "h":
-                duration = 3600
-            elif state == "d":
-                duration = 86400
-            click = "stackedDuration('%s', this, %i)" % (state, duration)
-            return fmt_link(href, title, class_, link_title=hover, click=click)
-
 class ImageCache(object):
     def __init__(self):
         self.__files = dict() # {name: {"time": time_created, "file": file object, "cookie": (cookie values)}}

Modified: mgmt/trunk/cumin/python/cumin/stat.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.strings	2009-04-09 18:51:35 UTC (rev 3276)
+++ mgmt/trunk/cumin/python/cumin/stat.strings	2009-04-09 19:24:35 UTC (rev 3277)
@@ -72,6 +72,26 @@
     margin: 0 0 0 1em;
 }
 
+[JSDurationSwitch.javascript]
+function changeDuration(state, a, id) {
+    li = a.parentNode;
+    ul = li.parentNode;
+    as = ul.getElementsByTagName('a');
+    for (var i=0; i < as.length; i++) {
+        as[i].className = (as[i] == a) ?  "selected" : "";
+    }
+    var oImg = document.images[id];
+    if (oImg) {
+        var src = oImg.src;
+        var branch = wooly.session.branch(src);
+        branch.duration = state;
+        src = branch.marshal();
+        src = cumin.refreshTime(src);
+        oImg.src = src;
+    }
+    return false;
+}
+
 [StatValueChart.html]
 <div class="StatValueChart" id="{id}">
   <h2>{title}</h2>
@@ -127,23 +147,6 @@
         oImg.src = src;
     }
 }
-function stackedDuration(state, a, duration) {
-    li = a.parentNode;
-    ul = li.parentNode;
-    as = ul.getElementsByTagName('a');
-    for (var i=0; i < as.length; i++) {
-        as[i].className = (as[i].firstChild.nodeValue.indexOf(state) != -1) ?  "selected" : "";
-    }
-    var oImg = document.images['{id}'];
-    if (oImg) {
-        var src = oImg.src;
-        var branch = wooly.session.branch(src);
-        branch.duration = duration;
-        src = branch.marshal();
-        src = cumin.refreshTime(src);
-        oImg.src = src;
-    }
-}
     $('{id}').onfullpage = function (width, height) { stackedNotify(true, width, height); };
     $('{id}').onrestore = function () { stackedNotify(false, {width}, 100); };
     document.images['{id}'].onload = function () {this.style.visibility = "visible"};

Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py	2009-04-09 18:51:35 UTC (rev 3276)
+++ mgmt/trunk/cumin/python/cumin/widgets.py	2009-04-09 19:24:35 UTC (rev 3277)
@@ -560,6 +560,9 @@
     def get_bookmark(self, state):
         return state in self.__bookmark and self.__bookmark[state]
 
+    def get_click(self, state):
+        return ""
+
     def get_param_id(self):
         """ needed because the SubmitSwitch class uses
             a hidden input to set the param value instead
@@ -574,8 +577,9 @@
         hover = self.get_hover(state)
         class_ = self.get(session) == state and "selected"
         bm = self.get_bookmark(state)
+        click = self.get_click(state)
 
-        return fmt_link(branch.marshal(), title, class_, link_title=hover, bm=bm)
+        return fmt_link(branch.marshal(), title, class_, link_title=hover, bm=bm, click=click)
 
 class GroupSwitch(StateSwitch):
     def __init__(self, app, name):




More information about the rhmessaging-commits mailing list