From 2850911c260050b8b669dee832d7e6f1a937fce4 Mon Sep 17 00:00:00 2001 From: miker Date: Sun, 1 Oct 2006 18:09:17 +0000 Subject: [PATCH] going depth-first on from-pruning git-svn-id: svn://svn.open-ils.org/ILS/trunk@6308 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/reports/oils_rpt_builder.js | 36 ++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/Open-ILS/web/reports/oils_rpt_builder.js b/Open-ILS/web/reports/oils_rpt_builder.js index a67ab95f34..b6ccdee18e 100644 --- a/Open-ILS/web/reports/oils_rpt_builder.js +++ b/Open-ILS/web/reports/oils_rpt_builder.js @@ -199,6 +199,29 @@ function oilsRptPruneFromClause(relation, node) { if(!node) node = oilsRpt.def.from.join; for( var i in node ) { _debug("looking at node "+node[i].alias); + // first, descend into the tree, and prune leaves first + if( node[i].join ) { + oilsRptPruneFromClause(relation, node[i].join); + if(node[i].join && oilsRptObjectKeys(node[i].join).length == 0) + delete node[i].join; + + /* if there are no items in the select, where or having clauses with a relation + matching this nodes alias, we can safely remove this node from the tree */ + if( node[i].alias == relation ) { + if( !grep(oilsRpt.def.select, + function(i){ return (i.relation == node[i].alias)}) + && !grep(oilsRpt.def.where, + function(i){ return (i.relation == node[i].alias)}) + && !grep(oilsRpt.def.having, + function(i){ return (i.relation == node[i].alias)}) + ) { + delete node[i]; + return true; + } + } + } + + // now, if we're at the leaf to remove, remove it if( node[i].alias == relation ) { if( node[i].join ) { /* if we have subtrees, don't delete our tree node */ @@ -207,19 +230,6 @@ function oilsRptPruneFromClause(relation, node) { delete node[i]; return true; } - } else { - if( node[i].join ) { - if( oilsRptPruneFromClause(relation, node[i].join ) ) { - if(oilsRptObjectKeys(node[i].join).length == 0) { - delete node[i].join; - /* if there are no items in the select clause with a relation matching - this nodes alias, we can safely remove this node from the tree */ - if(!grep(oilsRpt.def.select,function(r){return (r.relation==node[i].alias)})) - delete node[i]; - return true; - } - } - } } } return false; -- 2.11.0