--- loncom/interface/lonnavdisplay.pm 2010/03/29 14:50:46 1.17 +++ loncom/interface/lonnavdisplay.pm 2015/03/01 20:47:54 1.30 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA -# Navigate Maps Handler +# Navigate Maps Display Handler # -# $Id: lonnavdisplay.pm,v 1.17 2010/03/29 14:50:46 raeburn Exp $ +# $Id: lonnavdisplay.pm,v 1.30 2015/03/01 20:47:54 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,14 +30,14 @@ package Apache::lonnavdisplay; use strict; -use Apache::Constants qw(:common :http); +use Apache::Constants qw(:common :http REDIRECT); use Apache::lonmenu(); use Apache::loncommon(); use Apache::lonnavmaps(); use Apache::lonhtmlcommon(); use Apache::lonnet; use Apache::lonlocal; -use Time::HiRes qw( gettimeofday tv_interval ); +use Apache::londocs(); sub handler { my $r = shift; @@ -46,27 +46,20 @@ sub handler { sub real_handler { my $r = shift; - #my $t0=[&gettimeofday()]; # Handle header-only request if ($r->header_only) { - if ($env{'browser.mathml'}) { - &Apache::loncommon::content_type($r,'text/xml'); - } else { - &Apache::loncommon::content_type($r,'text/html'); - } + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK; } - # Send header, don't cache this page - if ($env{'browser.mathml'}) { - &Apache::loncommon::content_type($r,'text/xml'); - } else { + # Check for critical messages and redirect if present. + my ($redirect,$url) = &Apache::loncommon::critical_redirect(300); + if ($redirect) { &Apache::loncommon::content_type($r,'text/html'); + $r->header_out(Location => $url); + return REDIRECT; } - &Apache::loncommon::no_cache($r); - - my %toplinkitems=(); # Create the nav map my $navmap = Apache::lonnavmaps::navmap->new(); @@ -77,6 +70,9 @@ sub real_handler { $env{'user.reinit'} = 1; return HTTP_NOT_ACCEPTABLE; } + + # Send header, don't cache this page + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; # ------------------------------------------------------------ Get query string @@ -99,7 +95,12 @@ sub real_handler { $start_page = &Apache::loncommon::start_page($title,undef,$args); } $r->print($start_page. - ''); + ''); + &startContentScreen($r,'navmaps'); $r->rflush(); # Check that it's defined @@ -111,21 +112,32 @@ sub real_handler { return OK; } - # See if there's only one map in the top-level, if we don't - # already have a filter... if so, automatically display it - # (older code; should use retrieveResources) - if ($ENV{QUERY_STRING} !~ /filter/) { - my $iterator = $navmap->getIterator(undef, undef, undef, 0); - my $curRes; - my $sequenceCount = 0; - my $sequenceId; - while ($curRes = $iterator->next()) { - if (ref($curRes) && $curRes->is_sequence()) { + my %toplinkitems=(); + my @resources = $navmap->retrieveResources(); + my $sequenceCount = 0; + my $problemCount = 0; + my $notaprobCount = 0; + my $sequenceId; + my $notools; + foreach my $curRes (@resources) { + if (ref($curRes)) { + if ($curRes->is_sequence()) { $sequenceCount++; $sequenceId = $curRes->map_pc(); + } elsif ($curRes->is_problem()) { + $problemCount ++; + } else { + $notaprobCount ++; } } - + } + if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) { + $notools = 1; + } + + # If there's only one map in the top-level and we don't + # already have a filter, automatically display it + if ($ENV{QUERY_STRING} !~ /filter/) { if ($sequenceCount == 1) { # The automatic iterator creation in the render call # will pick this up. We know the condition because @@ -181,9 +193,11 @@ sub real_handler { if ($env{'form.register'}) { $link .= '&register='.$env{'form.register'}; } - &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework', - 'location.href="'.$link.'"', - "Show my first due problem"); + unless ($notools) { + &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework', + 'location.href="'.$link.'"', + "Show my first due problem"); + } } my $suppressEmptySequences = 0; @@ -214,25 +228,31 @@ sub real_handler { if ($env{'form.register'}) { $link .= '&register='.$env{'form.register'}; } - &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted', - 'location.href="'.$link.'"', - 'Show only uncompleted problems'); + unless ($notools) { + &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted', + 'location.href="'.$link.'"', + 'Show only uncompleted problems'); + } } my %selected=($env{'form.sort'} => ' selected="selected"'); - my $sort_html=('
+ my $sort_html; + unless ($notools) { + $sort_html=( + ' '.&mt('Sort by:').' - - +
'); + } # renderer call my $renderArgs = { 'cols' => [0,1,2,3], 'sort' => $env{'form.sort'}, @@ -245,7 +265,9 @@ sub real_handler { 'sort_html'=> $sort_html, 'r' => $r, 'caller' => 'navmapsdisplay', - 'linkitems' => \%toplinkitems}; + 'linkitems' => \%toplinkitems, + 'notools' => $notools}; + my $render = &Apache::lonnavmaps::render($renderArgs); # If no resources were printed, print a reassuring message so the @@ -257,15 +279,39 @@ sub real_handler { $r->print("

".&mt("This course is empty.")."

"); } } - #my $td=&tv_interval($t0); - #$r->print("
$td"); - + &endContentScreen($r); $r->print(&Apache::loncommon::end_page()); $r->rflush(); return OK; } +sub startContentScreen { + my ($r,$mode)=@_; + + $r->print("\n".''."\n"); + $r->print('
'); +} + +sub endContentScreen { + my ($r)=@_; + $r->print('
'); +} + 1; __END__