--- loncom/interface/lonnavmaps.pm 2004/07/21 19:54:43 1.268 +++ loncom/interface/lonnavmaps.pm 2004/08/20 20:14:27 1.277 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.268 2004/07/21 19:54:43 albertel Exp $ +# $Id: lonnavmaps.pm,v 1.277 2004/08/20 20:14:27 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -100,12 +100,38 @@ sub launch_win { } if ($mode eq 'link') { $result.='' - .&mt("Launch Navmaps in seperate window").""; + .&mt("Launch navigation window")."    "; } return $result; } - +sub close { + if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; } + return(< +window.status='Accessing Nav Control'; +menu=window.open("/adm/rat/empty.html","loncapanav", + "height=600,width=400,scrollbars=1"); +window.status='Closing Nav Control'; +menu.close(); +window.status='Done.'; + +ENDCLOSE +} + +sub update { + if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; } + if (!$ENV{'request.course.id'}) { return ''; } + if ($ENV{'REQUEST_URI'}=~m|^/adm/navmaps|) { return ''; } + return(< + +ENDUPDATE +} sub handler { my $r = shift; @@ -138,13 +164,24 @@ sub real_handler { if ($ENV{QUERY_STRING} eq 'collapseExternal') { &Apache::lonnet::put('environment',{'remotenavmap' => 'off'}); &Apache::lonnet::appenv('environment.remotenavmap' => 'off'); + my $menu=&Apache::lonmenu::reopenmenu(); + my $navstatus=&Apache::lonmenu::get_nav_status(); + if ($menu) { + $menu=(<print(<<"ENDSUBM"); @@ -169,7 +206,7 @@ ENDSUBM $r->print("\n"); $r->print("".&mt('Navigate Course Contents').""); # ------------------------------------------------------------ Get query string - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register']); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort','showOnlyHomework']); # ----------------------------------------------------- Force menu registration my $addentries=''; @@ -249,7 +286,7 @@ ENDSUBM if ($ENV{'environment.remotenavmap'} eq 'on') { # $r->print("" . $r->print("" . - &mt("Close external navmaps"). + &mt("Close navigation window"). "    "); } @@ -298,29 +335,45 @@ ENDSUBM # Display only due homework. my $showOnlyHomework = 0; - if ($ENV{QUERY_STRING} eq 'showOnlyHomework') { + if ($ENV{'form.showOnlyHomework'} eq "1") { $showOnlyHomework = 1; $suppressEmptySequences = 1; $filterFunc = sub { my $res = shift; return $res->completable() || $res->is_map(); }; + $r->print("" . + &mt("Show Everything")."    "); $r->print("

".&mt("Uncompleted Homework")."

"); $ENV{'form.filter'} = ''; $ENV{'form.condition'} = 1; $resource_no_folder_link = 1; } else { - $r->print("" . + $r->print("" . &mt("Show Only Uncompleted Homework")."    "); } + my %selected=($ENV{'form.sort'} => 'selected=on'); + my $sort_html=("
+ + + + + +
"); # renderer call - my $renderArgs = { 'cols' => [0,1,2,3], + my $renderArgs = { 'cols' => [0,2,3], + 'sort' => $ENV{'form.sort'}, 'url' => '/adm/navmaps', 'navmap' => $navmap, 'suppressNavmap' => 1, 'suppressEmptySequences' => $suppressEmptySequences, 'filterFunc' => $filterFunc, 'resource_no_folder_link' => $resource_no_folder_link, + 'sort_html'=> $sort_html, 'r' => $r}; my $render = render($renderArgs); $navmap->untieHashes(); @@ -1039,9 +1092,7 @@ sub render_resource { if ($resource->is_problem() && $part ne '0' && !$params->{'condensed'}) { - my $displaypart=&Apache::lonnet::EXT('resource.'.$part.'.display', - $resource->symb()); - unless ($displaypart) { $displaypart=$part; } + my $displaypart=$resource->part_display($part); $partLabel = " (Part: $displaypart)"; $link.='#'.&Apache::lonnet::escape($part); $title = ""; @@ -1489,6 +1540,9 @@ END $result .= '
'; } } + + if ($args->{'sort_html'}) { $result.=$args->{'sort_html'}; } + $result .= "
\n"; if ($r) { $r->print($result); @@ -1561,7 +1615,43 @@ END $args->{'here'} = $here; $args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0 - while ($curRes = $it->next($closeAllPages)) { + my @resources; + my $code='';# sub { !(shift->is_map();) }; + if ($args->{'sort'} eq 'title') { + my $oldFilterFunc = $filterFunc; + my $filterFunc= + sub { + my ($res)=@_; + if ($res->is_map()) { return 0;} + return &$oldFilterFunc($res); + }; + @resources=$navmap->retrieveResources(undef,$filterFunc); + @resources= sort {lc($a->compTitle) cmp lc($b->compTitle)} @resources; + } elsif ($args->{'sort'} eq 'duedate') { + @resources=$navmap->retrieveResources(undef, + sub { shift->is_problem(); }); + @resources= sort + { + if ($a->duedate ne $b->duedate) { + return $a->duedate cmp $b->duedate; + } else { + lc($a->compTitle) cmp lc($b->compTitle) + } + } @resources; + } else { + #unknow sort mechanism or default + undef($args->{'sort'}); + } + + + while (1) { + if ($args->{'sort'}) { + $curRes = shift(@resources); + } else { + $curRes = $it->next($closeAllPages); + } + if (!$curRes) { last; } + # Maintain indentation level. if ($curRes == $it->BEGIN_MAP() || $curRes == $it->BEGIN_BRANCH() ) { @@ -1675,10 +1765,15 @@ END # Set up some data about the parts that the cols might want my $filter = $it->{FILTER}; - my $stack = $it->getStack(); - my $src = getLinkForResource($stack); + my $src; + if ($args->{'sort'}) { + $src = $curRes->src(); # FIXME this is wrong for .pages + } else { + my $stack = $it->getStack(); + $src=getLinkForResource($stack); + } my $anchor=''; - if ($src=~s/(\#.*$)//) { + if ($src=~s/(\#.*)$//) { $anchor=$1; } my $srcHasQuestion = $src =~ /\?/; @@ -1686,7 +1781,7 @@ END ($srcHasQuestion?'&':'?') . 'symb=' . &Apache::lonnet::escape($curRes->symb()). $anchor; - + # Now, display each column. foreach my $col (@$cols) { my $colHTML = ''; @@ -2141,9 +2236,14 @@ sub getById { sub getBySymb { my $self = shift; my $symb = shift; + my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb); my $map = $self->getResourceByUrl($mapUrl); - return $self->getById($map->map_pc() . '.' . $id); + my $returnvalue = undef; + if (ref($map)) { + $returnvalue = $self->getById($map->map_pc() .'.'.$id); + } + return $returnvalue; } sub getByMapPc { @@ -2337,6 +2437,7 @@ in the filter function. =cut + sub getResourceByUrl { my $self = shift; my $resUrl = shift; @@ -3602,7 +3703,16 @@ sub weight { $self->symb(), $ENV{'user.domain'}, $ENV{'user.name'}, $ENV{'request.course.sec'}); - +} +sub part_display { + my $self= shift(); my $partID = shift(); + if (! defined($partID)) { $partID = '0'; } + my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display', + $self->symb); + if (! defined($display) || $display eq '') { + $display = $partID; + } + return $display; } # Multiple things need this @@ -4216,7 +4326,7 @@ sub status { if ($dateStatus == PAST_DUE_ANSWER_LATER || $dateStatus == PAST_DUE_NO_ANSWER ) { - return $dateStatus; + return $suppressFeedback ? ANSWER_SUBMITTED : $dateStatus; } if ($dateStatus == ANSWER_OPEN) {