[Repoze-checkins] r1160 - repoze.debug/trunk/repoze/debug/static
Paul Everitt
paul at agendaless.com
Sat Jun 28 13:06:58 EDT 2008
Author: Paul Everitt <paul at agendaless.com>
Date: Sat Jun 28 13:06:58 2008
New Revision: 1160
Log:
Clicking in the tree grabs the right @href and sets the right-hand-sides browser. Currently only works for top-level nodes. Still need to think about how the relationships will be assembled.
Modified:
repoze.debug/trunk/repoze/debug/static/debugui-xul.js
repoze.debug/trunk/repoze/debug/static/debugui-xul.xsl
repoze.debug/trunk/repoze/debug/static/debugui.xul
repoze.debug/trunk/repoze/debug/static/samplefeed.xml
Modified: repoze.debug/trunk/repoze/debug/static/debugui-xul.js
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/debugui-xul.js (original)
+++ repoze.debug/trunk/repoze/debug/static/debugui-xul.js Sat Jun 28 13:06:58 2008
@@ -1,12 +1,25 @@
var gm;
+var cl = console.log;
-function GuiModel (treeid, atomurl) {
- this.treeid = treeid;
- this.atomurl = atomurl;
- this.tree = document.getElementById(treeid);
+function GuiModel (tree_id, atom_url) {
+ this.tree_id = tree_id;
+ this.atom_url = atom_url;
+ this.tree = document.getElementById(tree_id);
this.processor = null;
- this.atomdoc = null;
+ this.atom_doc = null;
+ this.curr_tree_selection = 0;
+ this.ns = {
+ 'xhtml' : 'http://www.w3.org/1999/xhtml',
+ 'mathml': 'http://www.w3.org/1998/Math/MathML',
+ 'atom' : 'http://www.w3.org/2005/Atom',
+ };
+
+
+ // Register handlers
+ this.tree.addEventListener("select", this.selectEntry, false);
+ var btn = document.getElementById("reloadEntries");
+ btn.addEventListener("command", this.reloadModel, false);
}
GuiModel.prototype.tostring = function (node) {
@@ -26,6 +39,7 @@
return xmlhttp.responseXML;
}
+
GuiModel.prototype.loadProcessor = function (xslurl) {
/* Load the XSLT that massages Atom-data into XML datasources */
@@ -35,6 +49,7 @@
}
+
GuiModel.prototype.reloadModel = function () {
/* Fetch the atom data, then update various trees */
@@ -42,26 +57,42 @@
var target = this.tree.builder.datasource.documentElement;
// Get new data, transform it, and import into the document
- var atomdoc = this.loadURL(this.atomurl);
- var result = this.processor.transformToDocument(atomdoc);
+ this.atom_doc = this.loadURL(this.atom_url);
+ var result = this.processor.transformToDocument(this.atom_doc);
var iresult = document.importNode(result.documentElement, true);
// Update the tree datasource and rebuild
Sarissa.moveChildNodes(iresult, target);
this.tree.builder.rebuild();
+
+ // Reset the selection to the last-known selection
+ this.tree.view.selection.select(this.curr_tree_selection);
+ this.tree.view.toggleOpenState(this.curr_tree_selection);
}
-function documentLoaded (e) {
- var tree = document.getElementById(treeid);
- tree.builder.rebuild();
-
- // Mark the first item as selected
- tree.view.selection.select(0);
- tree.view.toggleOpenState(0);
+
+GuiModel.prototype.selectEntry = function (e) {
+ /* Activate the right-hand side */
+
+ var item = gm.tree.view.getItemAtIndex(gm.tree.currentIndex);
+ var entrynode = item.getElementsByClassName("entryid")[0];
+ var entryid = entrynode.getAttribute("label");
+ gm.curr_entryid = entryid;
+ gm.curr_tree_selection = gm.tree.view.selection.currentIndex;
+
+ // Change the browser url on the right
+ var this_id = "urn:uuid:32736";
+ var xp = "/*/atom:entry[atom:id='" + entryid + "']/atom:link";
+ var href= selectSingleNode(xp).getAttribute("href");
+ var iframe = document.getElementById("selected-entry");
+ iframe.setAttribute("src", href);
+
}
function initGuiModel () {
+ /* Run on document load by the DOMContentLoaded listener below */
+
if (window.location.host.indexOf(":") == -1){
// Running from FS, not dynamicall via WSGI, use dummy data
var atom_url = "samplefeed.xml";
@@ -76,15 +107,41 @@
document.addEventListener("DOMContentLoaded", initGuiModel, false);
-function selectEntry () {
- var tree = document.getElementById(treeid);
- var item = tree.view.getItemAtIndex(tree.currentIndex);
- var hrefcell = item.childNodes[0].childNodes[2];
- if (hrefcell.hasAttribute("label")) {
- // Change the browser url on the right
- var href = hrefcell.getAttribute("label");
- var iframe = document.getElementById("selected-entry");
- iframe.setAttribute("src", href);
+
+/* Companion functions, stolen from Sarissa */
+
+function selectNodes (sExpr, returnSingle) {
+ var nsDoc = gm.atom_doc;
+ function nsresolver(prefix) {
+ return gm.ns[prefix] || null;
}
-}
+ var result = null;
+ if(!returnSingle){
+ var oResult = nsDoc.evaluate(sExpr,
+ nsDoc,
+ nsresolver,
+ XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+ var nodeList = new SarissaNodeList(oResult.snapshotLength);
+ nodeList.expr = sExpr;
+ for(var i=0;i<nodeList.length;i++){
+ nodeList[i] = oResult.snapshotItem(i);
+ }
+ result = nodeList;
+ }
+ else {
+ var xf = XPathResult.FIRST_ORDERED_NODE_TYPE;
+ result = nsDoc.evaluate(sExpr,
+ nsDoc,
+ nsresolver,
+ xf, null).singleNodeValue;
+ }
+ return result;
+};
+function selectSingleNode (sExpr) {
+ return selectNodes(sExpr, true);
+}
+
+function SarissaNodeList (i) {
+ this.length = i;
+};
Modified: repoze.debug/trunk/repoze/debug/static/debugui-xul.xsl
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/debugui-xul.xsl (original)
+++ repoze.debug/trunk/repoze/debug/static/debugui-xul.xsl Sat Jun 28 13:06:58 2008
@@ -6,10 +6,10 @@
<xsl:template match="/">
<log>
<xsl:for-each select="/atom:feed/atom:entry">
- <entry id="n32432" name="/somerequest.html">
- <item id="n32432" name="xxApp Result"/>
- <item id="n32432" name="Siteconfig"/>
- <item id="n32432" name="User"/>
+ <entry entryid="{atom:id}" name="/somerequest.html" elapsed="22.0">
+ <item entryid="{atom:id}-1" name="App Result" elapsed="4.3"/>
+ <item entryid="{atom:id}-2" name="Siteconfig" elapsed="3.9"/>
+ <item entryid="{atom:id}-3" name="User" elapsed="0.8"/>
</entry>
</xsl:for-each>
</log>
Modified: repoze.debug/trunk/repoze/debug/static/debugui.xul
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/debugui.xul (original)
+++ repoze.debug/trunk/repoze/debug/static/debugui.xul Sat Jun 28 13:06:58 2008
@@ -7,11 +7,11 @@
<script src="debugui-xul.js"/>
<vbox flex="1">
<tree id="xui-logtree" datasources="samplelogentries.xml" ref="*" querytype="xml"
- seltype="single" rows="10" flex="1" onselect="selectEntry();">
+ seltype="single" rows="10" flex="1">
<treecols>
<treecol id="title" primary="true" label="Title" flex="1"/>
<treecol id="elapsed" label="Elapsed"/>
- <treecol id="href" label="href" hidden="true"/>
+ <treecol id="entryid" label="Entry ID" hidden="true"/>
</treecols>
<template>
<query expr="*"/>
@@ -20,15 +20,15 @@
<treeitem uri="?">
<treerow>
<treecell label="?name"/>
- <treecell label="?name"/>
- <treecell label="?name"/>
+ <treecell label="?elapsed"/>
+ <treecell class="entryid" label="?entryid"/>
</treerow>
</treeitem>
</treechildren>
</action>
</template>
</tree>
- <button id="normal" label="Reload" oncommand="reloadSummary();"/>
+ <button id="reloadEntries" label="Reload"/>
</vbox>
<vbox flex="4">
<iframe id="selected-entry" flex="1"/>
Modified: repoze.debug/trunk/repoze/debug/static/samplefeed.xml
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/samplefeed.xml (original)
+++ repoze.debug/trunk/repoze/debug/static/samplefeed.xml Sat Jun 28 13:06:58 2008
@@ -10,14 +10,14 @@
<entry>
<id>urn:uuid:20323</id>
<title>My Entry</title>
- <link href="http://example.org/2003/12/13/atom03"/>
+ <link href="http://www.google.com/"/>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
<entry>
<id>urn:uuid:32736</id>
<title>Second Entry</title>
- <link href="http://example.org/2003/12/13/atom03"/>
+ <link href="http://www.mozilla.org/"/>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
More information about the Repoze-checkins
mailing list