[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Tue, 24 Sep 2002 02:41:21 -0000
bowersj2 Mon Sep 23 22:41:21 2002 EDT
Modified files:
/loncom/interface lonnavmaps.pm
Log:
Branches are now detected correctly, I think. At least it looks that way
on my branching test map from heck. Temporarily denoting them with "NB
->", for "New Branch". We probably want to discuss how to *actually*
display them, but that's now an implementation detail, rather then the
algorithmic show-stopper it was as of a few hours ago.
Also, the *last* commit made the new nav maps the default. The old nav
map can still be obtained with the "jtest=1" flag on the querystring.
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.51 loncom/interface/lonnavmaps.pm:1.52
--- loncom/interface/lonnavmaps.pm:1.51 Mon Sep 23 21:18:50 2002
+++ loncom/interface/lonnavmaps.pm Mon Sep 23 22:41:21 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.51 2002/09/24 01:18:50 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.52 2002/09/24 02:41:21 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -870,19 +870,15 @@
while ($curRes != $mapIterator->END_NAV_MAP) {
if ($curRes == $mapIterator->BEGIN_MAP() ||
- $curRes == $mapIterator->BEGIN_BRANCH()) {
+ $curRes == $mapIterator->BEGIN_BRANCH()) {
$indentLevel++;
}
if ($curRes == $mapIterator->END_MAP() ||
- $curRes == $mapIterator->END_BRANCH()) {
+ $curRes == $mapIterator->END_BRANCH()) {
$indentLevel--;
}
-
- if ($curRes == $mapIterator->BEGIN_BRANCH()) {
- $r->print("Begin branch<br/>");
- }
- if ($curRes == $mapIterator->END_BRANCH()) {
- $r->print("End branch<br/>");
+ if ($curRes == $mapIterator->BEGIN_BRANCH()) {
+ $isNewBranch = 1;
}
if (ref($curRes) && $curRes->src()) {
@@ -911,6 +907,14 @@
'"';
my $title = $curRes->title();
my $partLabel = "";
+ my $newBranchText = "";
+
+ # If this is a new branch, label it so
+ # (temporary, this should be an icon w/ alt text)
+ if ($isNewBranch) {
+ $newBranchText = "NB -> ";
+ $isNewBranch = 0;
+ }
# links to open and close the folders
my $linkopen = "<a href=\"$link\">";
@@ -927,7 +931,7 @@
my $nowOpen = !defined($filterHash{$mapId});
$icon = $nowOpen ?
"folder_opened.gif" : "folder_closed.gif";
- $linkopen = "<a href=\"/adm/navmaps?jtest=1&filter=";
+ $linkopen = "<a href=\"/adm/navmaps?filter=";
$linkopen .= $nowOpen ?
addToFilter(\%filterHash, $mapId) :
removeFromFilter(\%filterHash, $mapId);
@@ -952,7 +956,7 @@
$r->print($indentString);
}
- $r->print(" ${linkopen}<img border=\"0\" src=\"" .
+ $r->print(" ${newBranchText}${linkopen}<img border=\"0\" src=\"" .
"/adm/lonIcons/$icon\" alt=\"\">${linkclose}\n");
if ($curRes->is_problem() && $part != "0") { $partLabel = " (Part $part)"; }
@@ -1460,7 +1464,7 @@
if (scalar(@{$self->{BRANCH_STACK}}) == 0) {
if ($self->{BRANCH_DEPTH} > 0) {
$self->{FORCE_NEXT} = $self->END_MAP();
- $self->{BRANCH_DEPTH}--;
+ $self->{BRANCH_DEPTH}--;
return $self->END_BRANCH();
} else {
return $self->END_MAP();
@@ -1479,13 +1483,32 @@
# to start a new one. (We know because we already checked to see
# if the stack was empty.)
if ( scalar (@{$self->{BRANCH_STACK}}) < $self->{BRANCH_STACK_SIZE}) {
- $self->{BRANCH_STACK_SIZE} = scalar(@{$self->{BRANCH_STACK}});
- $self->{BRANCH_DEPTH}++;
- return $self->BEGIN_BRANCH();
+ $self->{BRANCH_STACK_SIZE} = scalar(@{$self->{BRANCH_STACK}});
+ $self->{BRANCH_DEPTH}++;
+ return $self->BEGIN_BRANCH();
}
+ # Remember the size for comparision next time.
+ $self->{BRANCH_STACK_SIZE} = scalar(@{$self->{BRANCH_STACK}});
+
+ # If the next resource we mean to return is going to need
+ # a lower branch level, terminate branches until we get
+ # there.
+
# Get the next resource in the branch
$self->{HERE} = pop @{$self->{BRANCH_STACK}};
+
+ # Are we at the right depth? If not, close a branch and return
+ # the current resource onto the branch stack
+ if (defined($self->{HERE}->{DATA}->{ITERATOR_DEPTH})
+ && $self->{HERE}->{DATA}->{ITERATOR_DEPTH} <
+ $self->{BRANCH_DEPTH} ) {
+ $self->{BRANCH_DEPTH}--;
+ # return it so we can pick it up eventually
+ push @{$self->{BRANCH_STACK}}, $self->{HERE};
+ return $self->END_BRANCH();
+ }
+
# We always return it after this point and never before
# (proof: look at just the return statements), so we
# remember that we've seen this.
@@ -1493,23 +1516,23 @@
# Are we at the utter end? If so, return the END_NAV_MAP marker.
if ($self->{HERE} == $self->{NAV_MAP}->finishResource() ) {
- $self->{FORCE_NEXT} = $self->END_NAV_MAP;
+ $self->{FORCE_NEXT} = $self->END_NAV_MAP;
return $self->{HERE};
}
- # Remember the size for comparision next time.
- $self->{BRANCH_STACK_SIZE} = scalar(@{$self->{BRANCH_STACK}});
-
# Get the next possible resources
my $nextUnfiltered = $self->{HERE}->getNext();
my $next = [];
# filter the next possibilities to remove things we've
- # already seen
+ # already seen. Also, remember what branch depth they should
+ # be displayed at, since there's no other reliable way to tell.
foreach (@$nextUnfiltered) {
- if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
- push @$next, $_;
- }
+ if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
+ push @$next, $_;
+ $_->{DATA}->{ITERATOR_DEPTH} =
+ $self->{BRANCH_DEPTH} + 1;
+ }
}
# Handle branch cases:
@@ -1518,24 +1541,24 @@
# 2+ things next: have some branches
my $nextCount = scalar(@$next);
if ($nextCount == 0) {
- # Return this and on the next run, close the branch up if we're
- # in a branch
- if ($self->{BRANCH_DEPTH} > 0 ) {
- $self->{FORCE_NEXT} = $self->END_BRANCH();
- $self->{BRANCH_DEPTH}--;
- }
+ # Return this and on the next run, close the branch up if we're
+ # in a branch
+ if ($self->{BRANCH_DEPTH} > 0 ) {
+ $self->{FORCE_NEXT} = $self->END_BRANCH();
+ $self->{BRANCH_DEPTH}--;
+ }
return $self->{HERE};
}
while (@$next) {
# copy the next possibilities over to the branch stack
# in the right order
- push @{$self->{BRANCH_STACK}}, shift @$next;
+ push @{$self->{BRANCH_STACK}}, shift @$next;
}
if ($nextCount >= 2) {
- $self->{FORCE_NEXT} = $self->BEGIN_BRANCH();
- $self->{BRANCH_DEPTH}++;
+ $self->{FORCE_NEXT} = $self->BEGIN_BRANCH();
+ $self->{BRANCH_DEPTH}++;
return $self->{HERE};
}
@@ -1552,8 +1575,8 @@
$self->{RECURSIVE_ITERATOR} =
Apache::lonnavmaps::iterator->new ($self->{NAV_MAP}, $firstResource,
$finishResource, $self->{FILTER}, $self->{ALREADY_SEEN});
- # prime the new iterator with the first resource
- #push @{$self->{RECURSIVE_ITERATOR}->{BRANCH_STACK}}, $firstResource;
+ # prime the new iterator with the first resource
+ #push @{$self->{RECURSIVE_ITERATOR}->{BRANCH_STACK}}, $firstResource;
}
return $self->{HERE};