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

bowersj2 lon-capa-cvs@mail.lon-capa.org
Wed, 14 May 2003 20:16:56 -0000


bowersj2		Wed May 14 16:16:56 2003 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm lonhelper.pm lonprintout.pm 
  Log:
  For bug 1306 and some other things.
  
  When filtering resources out of the nav maps, such as in printing when
  the user is allowed to select just problems out of the course, it is
  common that there are folders that contain no problems. Thus, before
  this patch those folders just sat there, empty and open, which is a
  visually confusing UI state, even to me, so I imagine the users would
  be even worse off.
  
  The navmaps part of this patch allows you to specify a parameter such
  that empty maps should be suppressed, so they don't display and confuse
  the user. The lonhelper part of this patch passes that parameter through
  for resource elements. The lonprintout part of this patch turns
  that feature on for "print problems from this course", so that empty
  folders no longer show up there.
  
  This turned out to require pleasently little code in lonnavmaps, by
  putting it in the right place. The real functionality is all in about 20
  lines (without comments).
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.189 loncom/interface/lonnavmaps.pm:1.190
--- loncom/interface/lonnavmaps.pm:1.189	Wed May 14 14:34:44 2003
+++ loncom/interface/lonnavmaps.pm	Wed May 14 16:16:56 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.189 2003/05/14 18:34:44 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.190 2003/05/14 20:16:56 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -737,6 +737,14 @@
 false, it is simply skipped in the display. By default, all resources
 are shown.
 
+=item * B<suppressEmptySequences>:
+
+If you're using a filter function, and displaying sequences to orient
+the user, then frequently some sequences will be empty. Setting this to
+true will cause those sequences not to display, so as not to confuse the
+user into thinking that if the sequence is there there should be things
+under it.
+
 =item * B<suppressNavmaps>:
 
 If true, will not display Navigate Content resources. Default to
@@ -1223,6 +1231,43 @@
     $args->{'indentString'} = setDefault($args->{'indentString'}, "<img src='/adm/lonIcons/whitespace1.gif' width='25' height='1' alt='' border='0' />");
     $args->{'displayedHereMarker'} = 0;
 
+    # If we're suppressing empty sequences, look for them here. Use DFS for speed,
+    # since structure actually doesn't matter, except what map has what resources.
+    if ($args->{'suppressEmptySequences'}) {
+        my $dfsit = Apache::lonnavmaps::DFSiterator->new($navmap,
+                                                         $it->{FIRST_RESOURCE},
+                                                         $it->{FINISH_RESOURCE},
+                                                         {}, undef, 1);
+        $depth = 0;
+        $dfsit->next();
+        my $curRes = $dfsit->next();
+        while ($depth > -1) {
+            if ($curRes == $dfsit->BEGIN_MAP()) { $depth++; }
+            if ($curRes == $dfsit->END_MAP()) { $depth--; }
+
+            if (ref($curRes)) { 
+                # Parallel pre-processing: Do sequences have non-filtered-out children?
+                if ($curRes->is_sequence()) {
+                    $curRes->{DATA}->{HAS_VISIBLE_CHILDREN} = 0;
+                    # Sequences themselves do not count as visible children,
+                    # unless those sequences also have visible children.
+                    # This means if a sequence appears, there's a "promise"
+                    # that there's something under it if you open it, somewhere.
+                } else {
+                    # Not a sequence: if it's filtered, ignore it, otherwise
+                    # rise up the stack and mark the sequences as having children
+                    if (&$filterFunc($curRes)) {
+                        for my $sequence (@{$dfsit->getStack()}) {
+                            $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} = 1;
+                        }
+                    }
+                }
+            }
+        } continue {
+            $curRes = $dfsit->next();
+        }
+    }
+
     my $displayedJumpMarker = 0;
     # Set up iteration.
     $depth = 1;
@@ -1266,6 +1311,12 @@
             next;
         } 
 
+        # If this is an empty sequence and we're filtering them, continue on
+        if ($curRes->is_sequence() && $args->{'suppressEmptySequences'} &&
+            !$curRes->{DATA}->{HAS_VISIBLE_CHILDREN}) {
+            next;
+        }
+
         # If we're suppressing navmaps and this is a navmap, continue on
         if ($suppressNavmap && $curRes->src() =~ /^\/adm\/navmaps/) {
             next;
@@ -2194,7 +2245,8 @@
                 
                 $curRes->{DATA}->{DISPLAY_DEPTH} = $finalDepth;
                 if ($finalDepth > $maxDepth) {$maxDepth = $finalDepth;}
-                }
+            }
+        } continue {
             $curRes = $iterator->next();
         }
     }
@@ -2569,6 +2621,31 @@
     }
 
     return $self->{HERE};
+}
+
+# Identical to the full iterator methods of the same name. Hate to copy/paste
+# but I also hate to "inherit" either iterator from the other.
+
+sub getStack {
+    my $self=shift;
+
+    my @stack;
+
+    $self->populateStack(\@stack);
+
+    return \@stack;
+}
+
+# Private method: Calls the iterators recursively to populate the stack.
+sub populateStack {
+    my $self=shift;
+    my $stack = shift;
+
+    push @$stack, $self->{HERE} if ($self->{HERE});
+
+    if ($self->{RECURSIVE_ITERATOR_FLAG}) {
+        $self->{RECURSIVE_ITERATOR}->populateStack($stack);
+    }
 }
 
 1;
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.28 loncom/interface/lonhelper.pm:1.29
--- loncom/interface/lonhelper.pm:1.28	Wed May 14 14:58:21 2003
+++ loncom/interface/lonhelper.pm	Wed May 14 16:16:56 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.28 2003/05/14 18:58:21 bowersj2 Exp $
+# $Id: lonhelper.pm,v 1.29 2003/05/14 20:16:56 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1419,7 +1419,10 @@
 which controls whether the user can select more then one resource. The 
 "toponly" attribute controls whether the resource display shows just the
 resources in that sequence, or recurses into all sub-sequences, defaulting
-to false.
+to false. The "suppressEmptySequences" attribute reflects the 
+suppressEmptySequences argument to the render routine, which will cause
+folders that have all of their contained resources filtered out to also
+be filtered out.
 
 B<SUB-TAGS>
 
@@ -1480,6 +1483,7 @@
     $paramHash->{'variable'} = $token->[2]{'variable'};
     $helper->declareVar($paramHash->{'variable'});
     $paramHash->{'multichoice'} = $token->[2]{'multichoice'};
+    $paramHash->{'suppressEmptySequences'} = $token->[2]{'suppressEmptySequences'};
     $paramHash->{'toponly'} = $token->[2]{'toponly'};
     return '';
 }
@@ -1648,6 +1652,7 @@
                                        'showParts' => 0,
                                        'filterFunc' => $filterFunc,
                                        'resource_no_folder_link' => 1,
+                                       'suppressEmptySequences' => $self->{'suppressEmptySequences'},
                                        'iterator_map' => $mapUrl }
                                        );
 
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.171 loncom/interface/lonprintout.pm:1.172
--- loncom/interface/lonprintout.pm:1.171	Wed May 14 14:15:03 2003
+++ loncom/interface/lonprintout.pm	Wed May 14 16:16:56 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.171 2003/05/14 18:15:03 sakharuk Exp $
+# $Id: lonprintout.pm,v 1.172 2003/05/14 20:16:56 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1835,7 +1835,7 @@
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
     <message>(mark them then click "next" button) <br /></message>
-    <resource variable="RESOURCES" multichoice="1">
+    <resource variable="RESOURCES" multichoice="1" suppressEmptySequences='1'>
       <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblemOrMap</filterfunc>
       <choicefunc>return $isProblem</choicefunc>