Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372232 )

Change subject: Add feature to collapse deeper levels of hierarchy to show 
maximum of  nodes
......................................................................

Add feature to collapse deeper levels of hierarchy to show maximum of  nodes

Change-Id: Iabed8a2d18d3a34cc07f43ecfdcbaf9569272d1e
---
M drilldown/CargoDrilldownHierarchy.php
M drilldown/CargoSpecialDrilldown.php
2 files changed, 55 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/32/372232/1

diff --git a/drilldown/CargoDrilldownHierarchy.php 
b/drilldown/CargoDrilldownHierarchy.php
index 07f889b..9b384d0 100644
--- a/drilldown/CargoDrilldownHierarchy.php
+++ b/drilldown/CargoDrilldownHierarchy.php
@@ -64,9 +64,9 @@
                $stack->push( $node );
                while ( !$stack->isEmpty() ) {
                        $node = $stack->pop();
+                       CargoDrilldownHierarchy::computeNodeCountByFilter( 
$node, $f, $fullTextSearchTerm, $appliedFilters );
                        if ( $node->mLeft !== 1 ) {
                                // check if its not __pseudo_root__ node, then 
only add count
-                               
CargoDrilldownHierarchy::computeNodeCountByFilter( $node, $f, 
$fullTextSearchTerm, $appliedFilters );
                                $filter_values[$node->mRootValue] = 
$node->mWithinTreeMatchCount;
                        }
                        if ( count( $node->mChildren ) > 0 ) {
@@ -80,4 +80,43 @@
                }
                return $filter_values;
        }
+
+       /*
+       * Finds maximum permissible depth for listing nodes in Drilldown such 
that total nodes appearing on the Filter line
+       * is less than or equal to $wgCargoMaxHierarchyDrilldownValues
+       */
+       static function findMaxDrilldownDepth( $node ) {
+               global $wgCargoMaxHierarchyDrilldownValues;
+               if ( !isset( $wgCargoMaxHierarchyDrilldownValues ) ) {
+                       return PHP_INT_MAX;
+               }
+               $maxDepth = 0;
+               $nodeCount = 0;
+               $queue = new SplQueue();
+               $queue->enqueue( $node );
+               $queue->enqueue( null );
+               while ( !$queue->isEmpty() ) {
+                       $node = $queue->dequeue();
+                       if ( $node == null ) {
+                               if ( !$queue->isEmpty() ) {
+                                       if ( $flag != 0 ) {
+                                               $maxDepth++;
+                                       }
+                                       $queue->enqueue( null );
+                               }
+                       } else {
+                               foreach ( $node->mChildren as $child ) {
+                                       if ( $child->mWithinTreeMatchCount > 0 
) {
+                                               if ( $nodeCount >= 
$wgCargoMaxHierarchyDrilldownValues ) {
+                                                       break(2);
+                                               }
+                                               $queue->enqueue( $child );
+                                               $nodeCount++;
+                                               $flag = 1;
+                                       }
+                               }
+                       }
+               }
+               return max(1, $maxDepth);
+       }
 }
\ No newline at end of file
diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index b89561a..775620a 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -504,6 +504,8 @@
                // compute counts
                $filter_values = 
CargoDrilldownHierarchy::computeNodeCountForTreeByFilter( 
$drilldownHierarchyTreeRoot,
                        $f, $fullTextSearchTerm, $applied_filters );
+               $maxDepth = CargoDrilldownHierarchy::findMaxDrilldownDepth( 
$drilldownHierarchyTreeRoot );
+               $depth = 0;
                $num_printed_values = 0;
                $stack = new SplStack();
                // preorder traversal of the tree
@@ -511,7 +513,7 @@
                while ( !$stack->isEmpty() ) {
                        $node = $stack->pop();
                        if ( $node != ")" ) {
-                               if ( $node->mLeft !== 1 ) {
+                               if ( $node->mLeft !== 1 && 
$node->mWithinTreeMatchCount > 0 ) {
                                        // check if its not __pseudo_root__ 
node, then only print
                                        if ( $num_printed_values++ > 0 ) {
                                                $results_line .= " · ";
@@ -523,24 +525,26 @@
                                        $results_line .= 
$this->printFilterValueLink( $f, $node->mRootValue,
                                                $node->mWithinTreeMatchCount, 
$filter_url, $filter_values );
                                }
-                               if ( count( $node->mChildren ) > 0 ) {
+                               if ( count( $node->mChildren ) > 0 && 
$node->mWithinTreeMatchCount > 0 && $depth + 1 <= $maxDepth ) {
+                                       $depth++;
                                        if ( $node->mLeft !== 1 ) {
-                                               $filter_url = $cur_url . 
urlencode( str_replace( ' ', '_', $f->name ) ) . '=' .
-                                                       urlencode( str_replace( 
' ', '_', $node->mRootValue ) );
-                                               $results_line .= " · ";
-                                               $results_line .= "(" . 
$this->printFilterValueLink( $f,
-                                                       wfMessage( 
'cargo-drilldown-hierarchy-only', $node->mRootValue )->parse() ,
-                                                       
$node->mExactRootMatchCount, $filter_url, $filter_values );
+                                               $results_line .= " · (";
+                                               if ( 
$node->mExactRootMatchCount > 0 ) {
+                                                       $filter_url = $cur_url 
. urlencode( str_replace( ' ', '_', $f->name ) ) . '=' .
+                                                               urlencode( 
str_replace( ' ', '_', $node->mRootValue ) );
+                                                       $results_line .= 
$this->printFilterValueLink( $f,
+                                                               wfMessage( 
'cargo-drilldown-hierarchy-only', $node->mRootValue )->parse() ,
+                                                               
$node->mExactRootMatchCount, $filter_url, $filter_values );
+                                               }
                                                $stack->push( ")" );
                                        }
-                                       $i = count( $node->mChildren ) - 1;
-                                       while ( $i >= 0 ) {
+                                       for( $i = count( $node->mChildren ) - 
1; $i >= 0; $i--) {
                                                $stack->push( 
$node->mChildren[$i] );
-                                               $i = $i - 1;
                                        }
                                }
                        } else {
                                $results_line .= " ) ";
+                               $depth--;
                        }
                }
                return $results_line;

-- 
To view, visit https://gerrit.wikimedia.org/r/372232
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iabed8a2d18d3a34cc07f43ecfdcbaf9569272d1e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 <f29ah...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to