[rhmessaging-commits] rhmessaging commits: r1286 - in mgmt/cumin: resources and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Nov 12 11:31:21 EST 2007


Author: justi9
Date: 2007-11-12 11:31:20 -0500 (Mon, 12 Nov 2007)
New Revision: 1286

Modified:
   mgmt/cumin/python/cumin/measurement.py
   mgmt/cumin/python/cumin/measurement.strings
   mgmt/cumin/resources/wooly.js
Log:
Simplifications and improvements to the javascript functions.



Modified: mgmt/cumin/python/cumin/measurement.py
===================================================================
--- mgmt/cumin/python/cumin/measurement.py	2007-11-12 15:36:33 UTC (rev 1285)
+++ mgmt/cumin/python/cumin/measurement.py	2007-11-12 16:31:20 UTC (rev 1286)
@@ -48,7 +48,7 @@
 
     def render_item_extra(self, session, measure):
         if measure.highlow:
-            return "<small>high</small>&nbsp;<span ph=\"1\">%i</span> <small>low</small>&nbsp;<span ph=\"2\">%i</span>" \
+            return "<small>high</small>&nbsp;<span>%i</span> <small>low</small>&nbsp;<span>%i</span>" \
                    % (measure.get_high() or 0, measure.get_low() or 0)
         else:
             unit = self.unit_abbrevs.get(measure.unit, measure.unit)

Modified: mgmt/cumin/python/cumin/measurement.strings
===================================================================
--- mgmt/cumin/python/cumin/measurement.strings	2007-11-12 15:36:33 UTC (rev 1285)
+++ mgmt/cumin/python/cumin/measurement.strings	2007-11-12 16:31:20 UTC (rev 1286)
@@ -9,17 +9,21 @@
 
         if (attr) {
             var m = object.measurement[attr];
+            var tds = tr.elems("td", null, null, 0, 2);
 
-            var tds = tr.elems("td");
             tds.next().text().set(m.value);
 
             var td = tds.next();
-            var ph1 = td.placeholder("1");
-            var ph2 = td.placeholder("2");
 
-            if (ph1 && ph2) {
-                ph1.set(m.high);
-                ph2.set(m.low);
+            var phs = td.elems("span", null, null, 0, 2);
+            var ph = phs.next();
+
+            if (ph) {
+                ph.set(m.high);
+
+                ph = phs.next();
+
+                ph.set(m.low);
             } else {
                 td.text().set(m.rate);
             }

Modified: mgmt/cumin/resources/wooly.js
===================================================================
--- mgmt/cumin/resources/wooly.js	2007-11-12 15:36:33 UTC (rev 1285)
+++ mgmt/cumin/resources/wooly.js	2007-11-12 16:31:20 UTC (rev 1286)
@@ -140,43 +140,46 @@
         return node;
     }
 
-    function find(nodeParent, nodeType, nodeName, attr, attrValue) {
+    function find(found, limit,
+                  nodeParent, nodeType, nodeName,
+                  attr, attrValue) {
+        /*
+        assert(found);
+        assert(found instanceof Array);
         assert(nodeParent);
         assert(nodeType);
+        */
 
         var children = nodeParent.childNodes;
-        var found;
 
         for (var i = 0; i < children.length; i++) {
-            if (found) {
-                break;
-            }
-
             var child = children[i];
             var candidate = child;
 
             if (child.nodeType != nodeType) {
                 candidate = null;
-            } else if (nodeName && child.nodeName.toLowerCase() != nodeName) {
+            } else if (nodeName != null && child.nodeName.toLowerCase() != nodeName) {
                 candidate = null;
-            } else if (attr && child.nodeType == 1) {
+            } else if (attr != null && child.nodeType == 1) {
                 var value = child.getAttribute(attr);
 
                 if (!value) {
                     candidate = null;
-                } else if (value != attrValue) {
+                } else if (attrValue != null && value != attrValue) {
                     candidate = null;
                 }
             }
 
             if (candidate) {
-                found = candidate;
+                found.push(candidate);
+
+                if (found.length == limit) {
+                    return;
+                }
             } else {
-                found = find(child, nodeType, nodeName, attr, attrValue);
+                find(found, limit, child, nodeType, nodeName, attr, attrValue);
             }
         }
-
-        return found;
     }
 
     function Wooly() {
@@ -252,7 +255,7 @@
             }
 
             var nodes = this.node.getElementsByTagName(name);
-            var iter = new WoolyIterator(this, WoolyElement, nodes, 1, name);
+            var iter = new WoolyIterator(this, nodes, WoolyElement);
 
             for (var i = 0; i < start; i++) {
                 iter.next();
@@ -266,39 +269,25 @@
         }
     }
 
-    function WoolyIterator(doc, nodeClass, nodes, nodeType, nodeName) {
+    function WoolyIterator(doc, nodes, nodeClass) {
         assert(doc);
-        assert(doc instanceof WoolyDocument);
-        assert(nodeClass);
         assert(nodes);
-        assert(nodes instanceof NodeList);
-        assert(nodeType);
-        assert(typeof nodeType == "number");
-        if (nodeName) assert(typeof nodeName == "string");
+        assert(nodeClass);
 
         this.doc = doc;
         this.nodes = nodes;
         this.nodeClass = nodeClass;
-        this.nodeType = nodeType;
-        this.nodeName = nodeName;
 
-        this.lastIndex = -1;
+        this.pos = 0;
 
         this.next = function() {
-            var node;
+            var node = nodes[this.pos++]
 
-            for (var i = this.lastIndex + 1; i < this.nodes.length; i++) {
-                node = this.nodes[i];
-
-                if ((this.nodeType == null || node.nodeType == this.nodeType)
-                    && (this.nodeName == null
-                            || node.nodeName.toLowerCase() == this.nodeName)) {
-                        this.lastIndex = i;
-                        return new this.nodeClass(this.doc, node);
-                }
+            if (node) {
+                return new this.nodeClass(this.doc, node);
+            } else {
+                return null;
             }
-
-            return null;
         }
     }
 
@@ -380,15 +369,17 @@
             return new WoolyElement(this.doc, node);
         }
 
-        this.elems = function(name, start) {
+        this.elems = function(name, attr, attrValue, start, limit) {
             if (start == null) {
                 start = 0;
             }
 
-            var iter = new WoolyIterator(this.doc, WoolyElement,
-                                         this.node.childNodes,
-                                         1, name);
+            var nodes = new Array();
 
+            find(nodes, limit, this.node, 1, name, attr, attrValue);
+
+            var iter = new WoolyIterator(this.doc, nodes, WoolyElement);
+
             for (var i = 0; i < start; i++) {
                 iter.next();
             }
@@ -396,29 +387,27 @@
             return iter;
         }
 
-        this.elem = function(name, n) {
-            return this.elems(name, n).next();
+        this.elem = function(name, attr, attrValue, n) {
+            return this.elems(name, attr, attrValue, n, n + 1).next();
         }
 
-        this.text = function() {
-            var text = find(this.node, 3);
+        this.texts = function(start, limit) {
+            var nodes = new Array();
 
-            if (text) {
-                return new WoolyText(this.doc, text);
-            } else {
-                return null;
-            }
-        }
+            find(nodes, limit, this.node, 3);
 
-        this.placeholder = function(name) {
-            var ph = find(this.node, 1, "span", "ph", name);
+            var iter = new WoolyIterator(this.doc, nodes, WoolyText);
 
-            if (ph) {
-                return new WoolyElement(this.doc, ph);
-            } else {
-                return null;
+            for (var i = 0; i < start; i++) {
+                iter.next();
             }
+
+            return iter;
         }
+
+        this.text = function() {
+            return this.texts(0, 1).next();
+        }
     }
 
     function WoolyText(doc, node) {




More information about the rhmessaging-commits mailing list