[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Mon, 28 Oct 2002 19:10:35 -0000
bowersj2 Mon Oct 28 14:10:35 2002 EDT
Modified files:
/loncom/interface lonnavmaps.pm
Log:
* Fixes urgency case where all but one try was used up, but it's past the
due date so who cares?
* Inlines maps on the top-level for course docs. Lightly tested. Ensures
these inlined maps can't be accidentally suppressed, potentially making
the whole course disappear.
* Gerd observes it's hard to follow the rows across and tell what corresponds
to what. This will alternate white and ultra-light-grey rows, so the
eye can follow the grey or white across easily. This should be accessible
to everyone who can see, unless they're still using 256 color displays.
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.87 loncom/interface/lonnavmaps.pm:1.88
--- loncom/interface/lonnavmaps.pm:1.87 Mon Oct 28 08:58:58 2002
+++ loncom/interface/lonnavmaps.pm Mon Oct 28 14:10:35 2002
@@ -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 @@
}
}
+ # 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 @@
# 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 = "<img src=\"/adm/lonIcons/whitespace1.gif\" width=\"25\" height=\"1\" alt=\"\" border=\"0\" />";
@@ -974,15 +997,32 @@
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 @@
$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 @@
$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 @@
$nonLinkedText .= ' <i>(hidden)</i> ';
}
+ $rowNum++;
+ my $backgroundColor = $backgroundColors[$rowNum % scalar(@backgroundColors)];
+
# FIRST COL: The resource indentation, branch icon, and name
- $r->print(" <tr><td align=\"left\" valign=\"center\" width=\"60%\">\n");
+ $r->print(" <tr bgcolor=\"$backgroundColor\"><td align=\"left\" valign=\"center\" width=\"60%\">\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 @@
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);