--- loncom/interface/lonnavmaps.pm 2003/04/04 21:36:01 1.174 +++ loncom/interface/lonnavmaps.pm 2003/07/21 20:25:42 1.217 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.174 2003/04/04 21:36:01 albertel Exp $ +# $Id: lonnavmaps.pm,v 1.217 2003/07/21 20:25:42 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -47,6 +47,7 @@ use Apache::Constants qw(:common :http); use Apache::loncommon(); use Apache::lonmenu(); use POSIX qw (floor strftime); +use Data::Dumper; # for debugging, not always used # symbolic constants sub SYMB { return 1; } @@ -71,7 +72,8 @@ my %statusIconMap = $resObj->TRIES_LEFT => 'navmap.open.gif', $resObj->INCORRECT => 'navmap.wrong.gif', $resObj->OPEN => 'navmap.open.gif', - $resObj->ATTEMPTED => 'navmap.open.gif' ); + $resObj->ATTEMPTED => 'navmap.ellipsis.gif', + $resObj->ANSWER_SUBMITTED => 'navmap.ellipsis.gif' ); my %iconAltTags = ( 'navmap.correct.gif' => 'Correct', @@ -90,7 +92,10 @@ my %colormap = $resObj->TRIES_LEFT => '', $resObj->INCORRECT => '', $resObj->OPEN => '', - $resObj->NOTHING_SET => '' ); + $resObj->NOTHING_SET => '', + $resObj->ATTEMPTED => '', + $resObj->ANSWER_SUBMITTED => '' + ); # And a special case in the nav map; what to do when the assignment # is not yet done and due in less then 24 hours my $hurryUpColor = "#FF0000"; @@ -159,7 +164,6 @@ sub real_handler { # Now that we've displayed some stuff to the user, init the navmap $navmap->init(); - $r->print('
 '); $r->rflush(); # Check that it's defined @@ -169,41 +173,125 @@ sub real_handler { return OK; } - # See if there's only one map in the top-level... if so, - # automatically display it - my $iterator = $navmap->getIterator(undef, undef, undef, 0); - my $depth = 1; - $iterator->next(); - my $curRes = $iterator->next(); - my $sequenceCount = 0; - my $sequenceId; - while ($depth > 0) { - if ($curRes == $iterator->BEGIN_MAP()) { $depth++; } - if ($curRes == $iterator->END_MAP()) { $depth--; } + # See if there's only one map in the top-level, if we don't + # already have a filter... if so, automatically display it + if ($ENV{QUERY_STRING} !~ /filter/) { + my $iterator = $navmap->getIterator(undef, undef, undef, 0); + my $depth = 1; + $iterator->next(); + my $curRes = $iterator->next(); + my $sequenceCount = 0; + my $sequenceId; + while ($depth > 0) { + if ($curRes == $iterator->BEGIN_MAP()) { $depth++; } + if ($curRes == $iterator->END_MAP()) { $depth--; } + + if (ref($curRes) && $curRes->is_sequence()) { + $sequenceCount++; + $sequenceId = $curRes->map_pc(); + } + + $curRes = $iterator->next(); + } + + if ($sequenceCount == 1) { + # The automatic iterator creation in the render call + # will pick this up. We know the condition because + # the defined($ENV{'form.filter'}) also ensures this + # is a fresh call. + $ENV{'form.filter'} = "$sequenceId"; + } + } + + my $jumpToFirstHomework = 0; + # Check to see if the student is jumping to next open, do-able problem + if ($ENV{QUERY_STRING} eq 'jumpToFirstHomework') { + $jumpToFirstHomework = 1; + # Find the next homework problem that they can do. + my $iterator = $navmap->getIterator(undef, undef, undef, 1); + my $depth = 1; + $iterator->next(); + my $curRes = $iterator->next(); + my $foundDoableProblem = 0; + my $problemRes; + + while ($depth > 0 && !$foundDoableProblem) { + if ($curRes == $iterator->BEGIN_MAP()) { $depth++; } + if ($curRes == $iterator->END_MAP()) { $depth--; } + + if (ref($curRes) && $curRes->is_problem()) { + my $status = $curRes->status(); + if ($curRes->completable()) { + $problemRes = $curRes; + $foundDoableProblem = 1; + + # Pop open all previous maps + my $stack = $iterator->getStack(); + pop @$stack; # last resource in the stack is the problem + # itself, which we don't need in the map stack + my @mapPcs = map {$_->map_pc()} @$stack; + $ENV{'form.filter'} = join(',', @mapPcs); - if (ref($curRes) && $curRes->is_sequence()) { - $sequenceCount++; - $sequenceId = $curRes->map_pc(); + # Mark as both "here" and "jump" + $ENV{'form.postsymb'} = $curRes->symb(); + } + } + } continue { + $curRes = $iterator->next(); } - $curRes = $iterator->next(); + # If we found no problems, print a note to that effect. + if (!$foundDoableProblem) { + $r->print("All homework assignments have been completed.

"); + } + } else { + $r->print("" . + "Go To My First Homework Problem    "); } - if ($sequenceCount == 1) { - # The automatic iterator creation in the render call - # will pick this up. - $ENV{'form.filter'} = "$sequenceId"; + my $suppressEmptySequences = 0; + my $filterFunc = undef; + my $resource_no_folder_link = 0; + + # Display only due homework. + my $showOnlyHomework = 0; + if ($ENV{QUERY_STRING} eq 'showOnlyHomework') { + $showOnlyHomework = 1; + $suppressEmptySequences = 1; + $filterFunc = sub { my $res = shift; + return $res->completable() || $res->is_map(); + }; + $r->print("

Uncompleted Homework

"); + $ENV{'form.filter'} = ''; + $ENV{'form.condition'} = 1; + $resource_no_folder_link = 1; + } else { + $r->print("" . + "Show Only Uncompleted Homework    "); } # renderer call - my $render = render({ 'cols' => [0,1,2,3], - 'url' => '/adm/navmaps', - 'navmap' => $navmap, - 'suppressNavmap' => 1, - 'r' => $r}); - + my $renderArgs = { 'cols' => [0,1,2,3], + 'url' => '/adm/navmaps', + 'navmap' => $navmap, + 'suppressNavmap' => 1, + 'suppressEmptySequences' => $suppressEmptySequences, + 'filterFunc' => $filterFunc, + 'resource_no_folder_link' => $resource_no_folder_link, + 'r' => $r}; + my $render = render($renderArgs); $navmap->untieHashes(); + # If no resources were printed, print a reassuring message so the + # user knows there was no error. + if ($renderArgs->{'counter'} == 0) { + if ($showOnlyHomework) { + $r->print("

All homework is currently completed.

"); + } else { # both jumpToFirstHomework and normal use the same: course must be empty + $r->print("

This course is empty.

"); + } + } + $r->print(""); $r->rflush(); @@ -267,7 +355,9 @@ sub getDescription { my $part = shift; my $status = $res->status($part); - if ($status == $res->NETWORK_FAILURE) { return ""; } + if ($status == $res->NETWORK_FAILURE) { + return "Having technical difficulties; please check status later"; + } if ($status == $res->NOTHING_SET) { return "Not currently assigned."; } @@ -294,7 +384,7 @@ sub getDescription { return "Excused by instructor"; } if ($status == $res->ATTEMPTED) { - return "Not yet graded."; + return "Answer submitted, not yet graded."; } if ($status == $res->TRIES_LEFT) { my $tries = $res->tries($part); @@ -313,6 +403,9 @@ sub getDescription { return "No due date $triesString"; } } + if ($status == $res->ANSWER_SUBMITTED) { + return 'Answer submitted'; + } } # Convenience function, so others can use it: Is the problem due in less then @@ -323,7 +416,7 @@ sub dueInLessThen24Hours { my $part = shift; my $status = $res->status($part); - return ($status == $res->OPEN() || $status == $res->ATTEMPTED() || + return ($status == $res->OPEN() || $status == $res->TRIES_LEFT()) && $res->duedate() && $res->duedate() < time()+(24*60*60) && $res->duedate() > time(); @@ -343,14 +436,9 @@ sub lastTry { } # This puts a human-readable name on the ENV variable. -# FIXME: This needs better logic: Who gets the advanced view of navmaps? -# As of 3-13-03, it's an open question. Guy doesn't want to check -# roles directly because it should be a check of capabilities for future -# role compatibity. There is no capability that matches this one for -# now, so this is done. (A hack for 1.0 might be to simply check roles -# anyhow.) + sub advancedUser { - return $ENV{'user.adv'}; + return $ENV{'request.role.adv'}; } @@ -464,29 +552,74 @@ sub timeToHumanString { =head1 NAME -Apache::lonnavmap - Subroutines to handle and render the navigation maps +Apache::lonnavmap - Subroutines to handle and render the navigation + maps =head1 SYNOPSIS The main handler generates the navigational listing for the course, the other objects export this information in a usable fashion for -other modules +other modules. + +=head1 OVERVIEW -=head1 Object: render +X When a user enters a course, LON-CAPA examines the + course structure and caches it in what is often referred to as the + "big hash" X. You can see it if you are logged into + LON-CAPA, in a course, by going to /adm/test. (You may need to + tweak the /home/httpd/lonTabs/htpasswd file to view it.) The + content of the hash will be under the heading "Big Hash". + +Big Hash contains, among other things, how resources are related +to each other (next/previous), what resources are maps, which +resources are being chosen to not show to the student (for random +selection), and a lot of other things that can take a lot of time +to compute due to the amount of data that needs to be collected and +processed. + +Apache::lonnavmaps provides an object model for manipulating this +information in a higher-level fashion then directly manipulating +the hash. It also provides access to several auxilary functions +that aren't necessarily stored in the Big Hash, but are a per- +resource sort of value, like whether there is any feedback on +a given resource. + +Apache::lonnavmaps also abstracts away branching, and someday, +conditions, for the times where you don't really care about those +things. + +Apache::lonnavmaps also provides fairly powerful routines for +rendering navmaps, and last but not least, provides the navmaps +view for when the user clicks the NAV button. + +B: Apache::lonnavmaps I works for the "currently +logged in user"; if you want things like "due dates for another +student" lonnavmaps can not directly retrieve information like +that. You need the EXT function. This module can still help, +because many things, such as the course structure, are constant +between users, and Apache::lonnavmaps can help by providing +symbs for the EXT call. + +The rest of this file will cover the provided rendering routines, +which can often be used without fiddling with the navmap object at +all, then documents the Apache::lonnavmaps::navmap object, which +is the key to accessing the Big Hash information, covers the use +of the Iterator (which provides the logic for traversing the +somewhat-complicated Big Hash data structure), documents the +Apache::lonnavmaps::Resource objects that are returned by + +=head1 Subroutine: render The navmap renderer package provides a sophisticated rendering of the standard navigation maps interface into HTML. The provided nav map handler is actually just a glorified call to this. -Because of the large number of parameters this function presents, +Because of the large number of parameters this function accepts, instead of passing it arguments as is normal, pass it in an anonymous -hash with the given options. This is because there is no obvious order -you may wish to override these in and a hash is easier to read and -understand then "undef, undef, undef, 1, undef, undef, renderButton, -undef, 0" when you mostly want default behaviors. +hash with the desired options. The package provides a function called 'render', called as -Apache::lonnavmaps::renderer->render({}). +Apache::lonnavmaps::render({}). =head2 Overview of Columns @@ -494,7 +627,7 @@ The renderer will build an HTML table fo it. The table is consists of several columns, and a row for each resource (or possibly each part). You tell the renderer how many columns to create and what to place in each column, optionally using -one or more of the preparent columns, and the renderer will assemble +one or more of the prepared columns, and the renderer will assemble the table. Any additional generally useful column types should be placed in the @@ -511,29 +644,33 @@ that takes a resource reference, a part argument hash passed to the renderer, and returns a string that will be inserted into the HTML representation as it. +All other parameters are ways of either changing how the columns +are printing, or which rows are shown. + The pre-packaged column names are refered to by constants in the -Apache::lonnavmaps::renderer namespace. The following currently exist: +Apache::lonnavmaps namespace. The following currently exist: =over 4 -=item * B: +=item * B: The general info about the resource: Link, icon for the type, etc. The -first column in the standard nav map display. This column also accepts -the following parameter in the renderer hash: +first column in the standard nav map display. This column provides the +indentation effect seen in the B