fixed a bug that caused from-clause pruning to fail in some cases...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 1 Nov 2006 02:53:04 +0000 (02:53 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 1 Nov 2006 02:53:04 +0000 (02:53 +0000)
basically just refactored and cleaned up the method the method

git-svn-id: svn://svn.open-ils.org/ILS/trunk@6536 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/reports/oils_rpt_builder.js
Open-ILS/web/reports/oils_rpt_folder_window.js
Open-ILS/web/reports/oils_rpt_utils.js

index 31790e1..7623980 100644 (file)
@@ -349,6 +349,8 @@ function oilsRptPruneFromList(pathlist) {
                                !grep(oilsRpt.def.where, func) && 
                                !grep(oilsRpt.def.having, func) ) {
 
+                       debug('looks like we can prune ' + path);
+
                        oilsRptPruneFromClause(oilsRptPathRel(pathlist[j]));
                }
        }
@@ -359,35 +361,46 @@ function oilsRptPruneFromList(pathlist) {
        from the "from" clause */
 
 function oilsRptPruneFromClause(relation, node) {
-       _debug("removing relation from 'from' clause: " + relation);
+
+       var keys = oilsRptObjectKeys(node);
+       _debug("trying to remove relation: " + relation+'\n\tthis object has keys: '+keys);
+
        if(!node) node = oilsRpt.def.from.join;
        if(!node) return false;
 
        for( var i in node ) {
-               _debug("from prune looking at node "+node[i].path);
-               // first, descend into the tree, and prune leaves first
-               if( node[i].join ) {
-                       oilsRptPruneFromClause(relation, node[i].join); 
-                       if(oilsRptObjectKeys(node[i].join).length == 0) 
-                               delete node[i].join;
-               }
-       }
+               var child_node = node[i];
+               _debug("\tanalyzing child node: "+child_node.path);
 
-       if(!node.join) {
+               // first, descend into the tree, and prune leaves 
+               if( child_node.join ) {
 
-               var key = oilsRptObjectKeys(node)[0];
-               var from_alias = node[key].alias;
-               var func = function(n){ return (n.relation == from_alias)};
+                       oilsRptPruneFromClause(relation, child_node.join); 
+                       var join_keys = oilsRptObjectKeys(child_node.join);
+                       _debug("\tchild has a sub-join for items : ["+ join_keys+"]");
 
-               _debug("pruning from clause with alias "+ from_alias);
+                       if(join_keys.length == 0) {
+                               _debug("\tdeleting join for object "+i);
+                               delete child_node.join;
+                       }
+               }
 
-               if(     !grep(oilsRpt.def.select, func) &&
-                               !grep(oilsRpt.def.where, func) &&
-                               !grep(oilsRpt.def.having, func) ) {
+               if( !child_node.join ) {
 
-                       // if we're at an unused empty leaf, remove it
-                       delete node[i];
-                       return true;
+                       _debug("\tchild node has no sub-join, seeing if we should delete it");
+
+                       var from_alias = child_node.alias;
+                       var func = function(n){ return (n.relation == from_alias)};
+       
+                       if(     !grep(oilsRpt.def.select, func) &&
+                                       !grep(oilsRpt.def.where, func) &&
+                                       !grep(oilsRpt.def.having, func) ) {
+       
+                               /* we are not used by any other clauses */
+                               _debug("\tdeleting node with relation: "+ from_alias);
+                               delete node[i];
+                               return true;
+                       }
                }
        }
 
index 3efef31..b007476 100644 (file)
@@ -33,7 +33,10 @@ oilsRptFolderWindow.prototype.draw = function() {
 
        var mine = ( this.folderNode.folder.owner().id() == USER.id() );
 
-       if( mine  && this.type == 'template') 
+       _debug('drawing folder window with type '+this.type);
+       if(mine) _debug('folder is mine...');
+
+       if( mine && this.type == 'template') 
                unHideMe(DOM.oils_rpt_folder_window_contents_new_template.parentNode);
        else hideMe(DOM.oils_rpt_folder_window_contents_new_template.parentNode);
 
@@ -473,7 +476,7 @@ oilsRptFolderWindow.prototype.fetchFolderData = function(callback) {
                        var res = r.getResultObject();
 
                        if( res.length == 0 ) {
-                               hideMe(DOM.oils_rpt_content_count_row);
+                               //hideMe(DOM.oils_rpt_content_count_row); /* this also hides the new-template link.. fix me */
                                hideMe(DOM.oils_rpt_content_row);
                                unHideMe(DOM.oils_rpt_content_row_empty);
                        } else {
index 6cf1aef..794229e 100644 (file)
@@ -117,14 +117,6 @@ function nodeText(id) {
        return "";
 }
 
-/*
-function print_tabs(t) {
-       var r = '';
-       for (var j = 0; j < t; j++ ) { r = r + "  "; }
-       return r;
-}
-*/
-
 
 function oilsRptDebug() {
        if(!oilsRptDebugEnabled) return;
@@ -141,27 +133,6 @@ function oilsRptDebug() {
 }
 
 
-
-/* pretty print JSON */
-/*
-function formatJSON(s) {
-       var r = ''; var t = 0;
-       for (var i in s) {
-               if (s[i] == '{' || s[i] == '[' ) {
-                       r = r + s[i] + "\n" + print_tabs(++t);
-               } else if (s[i] == '}' || s[i] == ']') {
-                       t--; r = r + "\n" + print_tabs(t) + s[i];
-               } else if (s[i] == ',') {
-                       r = r + s[i] + "\n" + print_tabs(t);
-               } else {
-                       r = r + s[i];
-               }
-       }
-       return r;
-}
-*/
-
-
 function print_tabs_html(t) {
        var r = '';
        for (var j = 0; j < t; j++ ) { r = r + "&nbsp;&nbsp;"; }
@@ -311,14 +282,6 @@ function oilsRptDoGenericUpdate( method, arg, callback ) {
        req.send();
 }
 
-/*
-function oilsRptFetchReport(id, callback) {
-       var req = new Request(OILS_RPT_FETCH_REPORT, SESSION, id);
-       req.callback(function(r){ callback(r.getResultObject());});
-       req.send();
-}
-*/
-
 function oilsRptFetchReport(id, callback) {
        var r = oilsRptGetCache('rr', id);
        if(r) return callback(r);