[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm

bowersj2 lon-capa-cvs@mail.lon-capa.org
Tue, 26 Nov 2002 16:25:37 -0000


This is a MIME encoded message

--bowersj21038327937
Content-Type: text/plain

bowersj2		Tue Nov 26 11:25:37 2002 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  
  
--bowersj21038327937
Content-Type: text/plain
Content-Disposition: attachment; filename="bowersj2-20021126112537.txt"

Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.115 loncom/interface/lonnavmaps.pm:1.116
--- loncom/interface/lonnavmaps.pm:1.115	Tue Nov 26 09:45:24 2002
+++ loncom/interface/lonnavmaps.pm	Tue Nov 26 11:25:36 2002
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.115 2002/11/26 14:45:24 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.116 2002/11/26 16:25:36 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -208,8 +208,6 @@
     # Is this a new-style course? If so, we want to suppress showing the top-level
     # maps in their own folders, in favor of "inlining" them.
     my $topResource = $navmap->getById("0.0");
-    my $inlineTopLevelMaps = $topResource->src() =~ m|^/uploaded/.*default\.sequence$|;
-    my $inlinedelta = $inlineTopLevelMaps? -1 : 0;
 
     # Begin the HTML table
     # four cols: resource + indent, chat+feedback, icon, text string
@@ -232,8 +230,10 @@
     $mapIterator->next(); # discard the first BEGIN_MAP
     my $curRes = $mapIterator->next();
     my $counter = 0;
-    
-    while ($depth > 0) {
+
+    # We only need to do this if we need to open the maps to show the
+    # current position
+    while ($depth > 0 && !$ENV{'form.alreadyHere'}) {
         if ($curRes == $mapIterator->BEGIN_MAP()) { $depth++; }
         if ($curRes == $mapIterator->END_MAP()) { $depth--; }
 
@@ -262,17 +262,6 @@
             $ENV{'form.alreadyHere'} = 1;
         }
             
-        # Preprocessing: If we're inlining nav maps into the top-level display,
-        # make sure we show this map!
-        if ($inlineTopLevelMaps && ref($curRes) && $curRes->is_map && 
-            scalar(@{$mapStack}) == 1) {
-            if ($condition) {
-                undef $filterHash{$curRes->map_pc()};
-            } else {
-                $filterHash{$curRes->map_pc()} = 1;
-            }
-        }
-
         $curRes = $mapIterator->next();
     }
     
@@ -327,11 +316,11 @@
             next; # if yes, then just ignore this resource
         }
 
-        if (ref($curRes) && $curRes->src()) {
+        if (ref($curRes)) {
 
             my $deltalevel = $isNewBranch? 1 : 0; # reserves space for branch icon
 
-            if ($indentLevel - $deltalevel + $inlinedelta < 0) {
+            if ($indentLevel - $deltalevel < 0) {
                 # If this would be at a negative depth (top-level maps in
                 # new-style courses, we want to suppress their title display)
                 # then ignore it.
@@ -500,7 +489,7 @@
                 my $backgroundColor = $backgroundColors[$rowNum % scalar(@backgroundColors)];
 
                 # FIRST COL: The resource indentation, branch icon, name, and anchor
-                $r->print("  <tr bgcolor=\"$backgroundColor\"><td align=\"left\" valign=\"center\" width=\"60%\">\n");
+                $r->print("  <tr bgcolor=\"$backgroundColor\"><td align=\"left\" valign=\"center\">\n");
 
                 # Print the anchor if necessary
                 if ($counter == $currentUrlIndex - $currentUrlDelta) {
@@ -508,7 +497,7 @@
                 }
 
                 # print indentation
-                for (my $i = 0; $i < $indentLevel - $deltalevel + $inlinedelta; $i++) {
+                for (my $i = 0; $i < $indentLevel - $deltalevel; $i++) {
                     $r->print($indentString);
                 }
 
@@ -1276,7 +1265,7 @@
 
 =over 4
 
-=item * B<getIterator>(firstResource, finishResource, filterHash, condition): All parameters are optional. firstResource is a resource reference corresponding to where the iterator should start. It defaults to navmap->firstResource() for the corresponding nav map. finishResource corresponds to where you want the iterator to end, defaulting to navmap->finishResource(). filterHash is a hash used as a set containing strings representing the resource IDs, defaulting to empty. Condition is a 1 or 0 that sets what to do with the filter hash: If a 0, then only resource that exist IN the filterHash will be recursed on. If it is a 1, only resources NOT in the filterHash will be recursed on. Defaults to 0.
+=item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop): All parameters are optional. firstResource is a resource reference corresponding to where the iterator should start. It defaults to navmap->firstResource() for the corresponding nav map. finishResource corresponds to where you want the iterator to end, defaulting to navmap->finishResource(). filterHash is a hash used as a set containing strings representing the resource IDs, defaulting to empty. Condition is a 1 or 0 that sets what to do with the filter hash: If a 0, then only resource that exist IN the filterHash will be recursed on. If it is a 1, only resources NOT in the filterHash will be recursed on. Defaults to 0. forceTop is a boolean value. If it is false (default), the iterator will only return the first level of map that is not just a single, 'redirecting' map. If true, the iterator will return all information, starting with the top-level map, regardless of content.
 
 Thus, by default, only top-level resources will be shown. Change the condition to a 1 without changing the hash, and all resources will be shown. Changing the condition to 1 and including some values in the hash will allow you to selectively suppress parts of the navmap, while leaving it on 0 and adding things to the hash will allow you to selectively add parts of the nav map. See the handler code for examples.
 
@@ -1296,6 +1285,8 @@
 
 The tokens are retreivable via methods on the iterator object, i.e., $iterator->END_MAP.
 
+Maps can contain empty resources. The iterator will automatically skip over such resources, but will still treat the structure correctly. Thus, a complicated map with several branches, but consisting entirely of empty resources except for one beginning or ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs, but only one resource will be returned.
+
 =back
 
 =cut
@@ -1346,6 +1337,9 @@
     if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
     $self->{CONDITION} = shift;
 
+    # Do we want to automatically follow "redirection" maps?
+    $self->{FORCE_TOP} = shift;
+
     # Now, we need to pre-process the map, by walking forward and backward
     # over the parts of the map we're going to look at.
 
@@ -1361,6 +1355,11 @@
 
     my $maxDepth = 0; # tracks max depth
 
+    # If there is only one resource in this map, and it's a map, we
+    # want to remember that, so the user can ask for the first map
+    # that isn't just a redirector.
+    my $resource; my $resourceCount = 0;
+
     # **1**
 
     foreach my $pass (@iterations) {
@@ -1384,16 +1383,18 @@
             if ($curRes == $iterator->END_MAP()) { $depth--; }
         
             if (ref($curRes)) {
+                # If there's only one resource, this will save it
+                if($direction == FORWARD) { $resource = $curRes; $resourceCount++; }
                 my $resultingVal = $curRes->{DATA}->{$valName};
                 my $nextResources = $curRes->$nextResourceMethod();
-                my $resourceCount = scalar(@{$nextResources});
+                my $nextCount = scalar(@{$nextResources});
 
-                if ($resourceCount == 1) { # **3**
+                if ($nextCount == 1) { # **3**
                     my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;
                     $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);
                 }
                 
-                if ($resourceCount > 1) { # **4**
+                if ($nextCount > 1) { # **4**
                     foreach my $res (@{$nextResources}) {
                         my $current = $res->{DATA}->{$valName} || 999999999;
                         $res->{DATA}->{$valName} = min($current, $resultingVal + 1);
@@ -1413,6 +1414,18 @@
         }
     }
 
+    # Check: Was this only one resource, a map?
+    if ($resourceCount == 1 && $resource->is_map() && !$self->{FORCE_TOP}) { 
+        my $firstResource = $resource->map_start();
+        my $finishResource = $resource->map_finish();
+        return 
+            Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
+                                              $finishResource, $self->{FILTER},
+                                              $self->{ALREADY_SEEN}, 
+                                              $self->{CONDITION}, 0);
+        
+    }
+
     # Set up some bookkeeping information.
     $self->{CURRENT_DEPTH} = 0;
     $self->{MAX_DEPTH} = $maxDepth;
@@ -1562,6 +1575,11 @@
                                               $self->{ALREADY_SEEN}, $self->{CONDITION});
     }
 
+    # If this is a blank resource, don't actually return it.
+    if (!$self->{HERE}->src()) {
+        return $self->next();
+    }
+
     return $self->{HERE};
 
 }
@@ -1745,6 +1763,11 @@
                                              $self->{CONDITION}, $self->{DIRECTION});
     }
 
+    # If this is a blank resource, ignore it.
+    if (!$self->{HERE}->src()) {
+        return $self->next();
+    }
+    
     return $self->{HERE};
 }
 

--bowersj21038327937--