--- loncom/interface/lonnavmaps.pm 2002/09/24 01:18:50 1.51 +++ loncom/interface/lonnavmaps.pm 2002/09/24 02:41:21 1.52 @@ -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 @@ sub new_handle { 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
"); - } - if ($curRes == $mapIterator->END_BRANCH()) { - $r->print("End branch
"); + if ($curRes == $mapIterator->BEGIN_BRANCH()) { + $isNewBranch = 1; } if (ref($curRes) && $curRes->src()) { @@ -911,6 +907,14 @@ sub new_handle { '"'; 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 = ""; @@ -927,7 +931,7 @@ sub new_handle { my $nowOpen = !defined($filterHash{$mapId}); $icon = $nowOpen ? "folder_opened.gif" : "folder_closed.gif"; - $linkopen = "print(" ${newBranchText}${linkopen}\"\"${linkclose}\n"); if ($curRes->is_problem() && $part != "0") { $partLabel = " (Part $part)"; } @@ -1460,7 +1464,7 @@ sub next { 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 @@ sub next { # 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 @@ sub next { # 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 @@ sub next { # 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 @@ sub next { $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};