--- loncom/interface/lonnavmaps.pm 2002/10/28 13:58:58 1.87 +++ loncom/interface/lonnavmaps.pm 2002/10/28 19:10:35 1.88 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.87 2002/10/28 13:58:58 www Exp $ +# $Id: lonnavmaps.pm,v 1.88 2002/10/28 19:10:35 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -910,6 +910,11 @@ sub new_handle { } } + # 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 $currenturl = $ENV{'form.postdata'}; $currenturl=~s/^http\:\/\///; $currenturl=~s/^[^\/]+//; @@ -936,35 +941,53 @@ sub new_handle { # instead of uris. The changes to this and the main rendering # loop should be obvious. # Here's a simple example of the iterator. - # If there is a current resource - if ($currenturl && !$ENV{'form.alreadyHere'}) { - # Give me every resource... - my $mapIterator = $navmap->getIterator(undef, undef, {}, 1); - my $found = 0; - my $depth = 1; - $mapIterator->next(); # discard the first BEGIN_MAP - my $curRes = $mapIterator->next(); - - while ($depth > 0 && !$found) { - if (ref($curRes) && $curRes->src() eq $currenturl) { - # If this is the correct resource, be sure to - # show it by making sure the containing maps - # are open. - - my $mapStack = $mapIterator->getStack(); - for my $map (@{$mapStack}) { - if ($condition) { - undef $filterHash{$map->map_pc()}; - } else { - $filterHash{$map->map_pc()} = 1; - } + # Preprocess the map: Look for current URL, force inlined maps to display + + my $mapIterator = $navmap->getIterator(undef, undef, {}, 1); + my $found = 0; + my $depth = 1; + $mapIterator->next(); # discard the first BEGIN_MAP + my $curRes = $mapIterator->next(); + + while ($depth > 0) { + if ($curRes == $mapIterator->BEGIN_MAP()) { + $depth++; + } + if ($curRes == $mapIterator->END_MAP()) { + $depth--; + } + + my $mapStack = $mapIterator->getStack(); + if ($currenturl && !$ENV{'form.alreadyHere'} && ref($curRes) && + $curRes->src() eq $currenturl) { + # If this is the correct resource, be sure to + # show it by making sure the containing maps + # are open. + + for my $map (@{$mapStack}) { + if ($condition) { + undef $filterHash{$map->map_pc()}; + } else { + $filterHash{$map->map_pc()} = 1; } - $found = 1; } - $curRes = $mapIterator->next(); + $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(); + } + undef $res; # so we don't accidentally use it later my $indentLevel = 0; my $indentString = "\"\""; @@ -974,15 +997,32 @@ sub new_handle { my $in24Hours = $now + 24 * 60 * 60; my $depth = 1; my $displayedHereMarker = 0; - + # We know the first thing is a BEGIN_MAP (see "$self->{STARTED}" # code in iterator->next), so ignore the first one my $mapIterator = $navmap->getIterator(undef, undef, \%filterHash, $condition); $mapIterator->next(); my $curRes = $mapIterator->next(); + my $deltadepth = 0; + + my @backgroundColors = ("#FFFFFF", "#F6F6F6"); + my $rowNum = 0; while ($depth > 0) { + # If we're in a new style course, and this is a BEGIN_MAP, END_MAP, or + # map resource and the stack depth is only one, just plain ignore this resource + # entirely. (This has the effect of inlining the resources in that map + # in the nav map.) + if ($inlineTopLevelMaps && scalar(@{$mapIterator->getStack()}) == 1 && + ref($curRes) && $curRes->is_map()) { + # We let the normal depth stuff occur, but we need to shift everything + # over by one to the left to make it look right. + $deltadepth = -1; + $curRes = $mapIterator->next(); + next; + } + if ($curRes == $mapIterator->BEGIN_MAP() || $curRes == $mapIterator->BEGIN_BRANCH()) { $indentLevel++; @@ -1001,6 +1041,9 @@ sub new_handle { $depth--; } + if ($depth == 1) { $deltadepth = 0; } # we're done shifting, because we're + # out of the inlined map + # Is this resource being blotted out? if (ref($curRes) && !advancedUser() && $curRes->randomout()) { $curRes = $mapIterator->next(); @@ -1168,11 +1211,12 @@ sub new_handle { $color = $hurryUpColor; } # Special case: If this is the last try, and there is - # more then one available, give a bit of urgency + # more then one available, and it's not due yet, give a bit of urgency my $tries = $curRes->tries($part); my $maxtries = $curRes->maxtries($part); if ($tries && $maxtries && $maxtries > 1 && - $maxtries - $tries == 1) { + $maxtries - $tries == 1 && $curRes->duedate() && + $curRes->duedate() > time()) { $color = $hurryUpColor; } if ($color ne "") { @@ -1184,11 +1228,14 @@ sub new_handle { $nonLinkedText .= ' (hidden) '; } + $rowNum++; + my $backgroundColor = $backgroundColors[$rowNum % scalar(@backgroundColors)]; + # FIRST COL: The resource indentation, branch icon, and name - $r->print(" \n"); + $r->print(" \n"); # print indentation - for (my $i = 0; $i < $indentLevel - $deltalevel; $i++) { + for (my $i = 0; $i < $indentLevel - $deltalevel + $deltadepth; $i++) { $r->print($indentString); } @@ -2174,7 +2221,7 @@ sub populateStack { my $self=shift; my $stack = shift; - push @$stack, $self->{HERE}; + push @$stack, $self->{HERE} if ($self->{HERE}); if ($self->{RECURSIVE_ITERATOR_FLAG}) { $self->{RECURSIVE_ITERATOR}->populateStack($stack);