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

bowersj2 lon-capa-cvs@mail.lon-capa.org
Sat, 08 Mar 2003 21:16:38 -0000


bowersj2		Sat Mar  8 16:16:38 2003 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  Implement suggestion in bug 1103: If there is only one sequence
  on the highest level of the map, automatically open it. This satisfies
  the use case where someone uses a sequence to build a course on, then
  uses DOCS to add stuff in front and behind it. This demotes the sequence
  from "top level" (via redirection, since there was nothing else in the
  top-level sequence) to "just another sequence", but the users still
  want to see the sequence open, since it is the bulk of the course.
  
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.154 loncom/interface/lonnavmaps.pm:1.155
--- loncom/interface/lonnavmaps.pm:1.154	Sat Mar  8 15:52:41 2003
+++ loncom/interface/lonnavmaps.pm	Sat Mar  8 16:16:38 2003
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.154 2003/03/08 20:52:41 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.155 2003/03/08 21:16:38 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -186,6 +186,32 @@
         $r->print('<font size="+2" color="red">Coursemap undefined.</font>' .
                   '</body></html>');
         return OK;
+    }
+
+    # See if there's only one map in the top-level... if so,
+    # automatically display it
+    my $iterator = $navmap->getIterator(undef, undef, undef, 0);
+    my $depth = 1;
+    $iterator->next();
+    my $curRes = $iterator->next();
+    my $sequenceCount = 0;
+    my $sequenceId;
+    while ($depth > 0) {
+        if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
+        if ($curRes == $iterator->END_MAP()) { $depth--; }
+
+        if (ref($curRes) && $curRes->is_sequence()) {
+            $sequenceCount++;
+            $sequenceId = $curRes->map_pc();
+        }
+
+        $curRes = $iterator->next();
+    }
+
+    if ($sequenceCount == 1) {
+        # The automatic iterator creation in the render call 
+        # will pick this up.
+        $ENV{'form.filter'} = "$sequenceId";
     }
 
     # renderer call