--- loncom/interface/lonnavmaps.pm 2003/09/08 19:53:09 1.224 +++ loncom/interface/lonnavmaps.pm 2003/09/17 18:15:54 1.229 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Navigate Maps Handler # -# $Id: lonnavmaps.pm,v 1.224 2003/09/08 19:53:09 bowersj2 Exp $ +# $Id: lonnavmaps.pm,v 1.229 2003/09/17 18:15:54 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,7 @@ use strict; use Apache::Constants qw(:common :http); use Apache::loncommon(); use Apache::lonmenu(); +use Apache::lonlocal; use POSIX qw (floor strftime); use Data::Dumper; # for debugging, not always used @@ -134,7 +135,7 @@ sub real_handler { } $r->print("\n"); - $r->print("Navigate Course Contents"); + $r->print("".&mt('Navigate Course Contents').""); # ------------------------------------------------------------ Get query string &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register']); @@ -221,7 +222,7 @@ sub real_handler { } } else { $r->print("" . - "Go To My First Homework Problem    "); + &mt("Go To My First Homework Problem")."    "); } my $suppressEmptySequences = 0; @@ -236,13 +237,13 @@ sub real_handler { $filterFunc = sub { my $res = shift; return $res->completable() || $res->is_map(); }; - $r->print("

Uncompleted Homework

"); + $r->print("

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

"); $ENV{'form.filter'} = ''; $ENV{'form.condition'} = 1; $resource_no_folder_link = 1; } else { $r->print("" . - "Show Only Uncompleted Homework    "); + &mt("Show Only Uncompleted Homework")."    "); } # renderer call @@ -261,7 +262,7 @@ sub real_handler { # user knows there was no error. if ($renderArgs->{'counter'} == 0) { if ($showOnlyHomework) { - $r->print("

All homework is currently completed.

"); + $r->print("

".&mt("All homework is currently completed").".

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

This course is empty.

"); } @@ -331,35 +332,35 @@ sub getDescription { my $status = $res->status($part); if ($status == $res->NETWORK_FAILURE) { - return "Having technical difficulties; please check status later"; + return &mt("Having technical difficulties; please check status later"); } if ($status == $res->NOTHING_SET) { - return "Not currently assigned."; + return &mt("Not currently assigned."); } if ($status == $res->OPEN_LATER) { return "Open " . timeToHumanString($res->opendate($part)); } if ($status == $res->OPEN) { if ($res->duedate($part)) { - return "Due " . timeToHumanString($res->duedate($part)); + return &mt("Due")." " .timeToHumanString($res->duedate($part)); } else { - return "Open, no due date"; + return &mt("Open, no due date"); } } if ($status == $res->PAST_DUE_ANSWER_LATER) { - return "Answer open " . timeToHumanString($res->answerdate($part)); + return &mt("Answer open")." " . timeToHumanString($res->answerdate($part)); } if ($status == $res->PAST_DUE_NO_ANSWER) { - return "Was due " . timeToHumanString($res->duedate($part)); + return &mt("Was due")." " . timeToHumanString($res->duedate($part)); } if ($status == $res->ANSWER_OPEN) { - return "Answer available"; + return &mt("Answer available"); } if ($status == $res->EXCUSED) { - return "Excused by instructor"; + return &mt("Excused by instructor"); } if ($status == $res->ATTEMPTED) { - return "Answer submitted, not yet graded."; + return &mt("Answer submitted, not yet graded"); } if ($status == $res->TRIES_LEFT) { my $tries = $res->tries($part); @@ -372,14 +373,14 @@ sub getDescription { } } if ($res->duedate()) { - return "Due " . timeToHumanString($res->duedate($part)) . + return &mt("Due")." " . timeToHumanString($res->duedate($part)) . " $triesString"; } else { - return "No due date $triesString"; + return &mt("No due date")." $triesString"; } } if ($status == $res->ANSWER_SUBMITTED) { - return 'Answer submitted'; + return &mt('Answer submitted'); } } @@ -429,9 +430,11 @@ sub timeToHumanString { my ($time) = @_; # zero, '0' and blank are bad times if (!$time) { - return 'never'; + return &mt('never'); } - + unless (&Apache::loncommon::current_language()=~/^en/) { + return localtime($time); + } my $now = time(); my @time = localtime($time); @@ -655,13 +658,13 @@ can't close or open folders when this is =back -=item B: +=item * B: Whether there is discussion on the resource, email for the user, or (lumped in here) perl errors in the execution of the problem. This is the second column in the main nav map. -=item B: +=item * B: An icon for the status of a problem, with five possible states: Correct, incorrect, open, awaiting grading (for a problem where the @@ -669,11 +672,24 @@ computer's grade is suppressed, or the c essay problem), or none (not open yet, not a problem). The third column of the standard navmap. -=item B: +=item * B: A text readout of the details of the current status of the problem, such as "Due in 22 hours". The fourth column of the standard navmap. +=item * B: + +A text readout summarizing the status of the problem. If it is a +single part problem, will display "Correct", "Incorrect", +"Not yet open", "Open", "Attempted", or "Error". If there are +multiple parts, this will output a string that in HTML will show a +status of how many parts are in each status, in color coding, trying +to match the colors of the icons within reason. + +Note this only makes sense if you are I showing parts. If +C is true (see below), this column will not output +anything. + =back If you add any others please be sure to document them here. @@ -841,8 +857,7 @@ sub resource { return 0; } sub communication_status { return 1; } sub quick_status { return 2; } sub long_status { return 3; } - -# Data for render_resource +sub part_status_summary { return 4; } sub render_resource { my ($resource, $part, $params) = @_; @@ -1081,8 +1096,66 @@ sub render_long_status { return $result; } +# Colors obtained by taking the icons, matching the colors, and +# possibly reducing the Value (HSV) of the color, if it's too bright +# for text, generally by one third or so. +my %statusColors = + ( + $resObj->CLOSED => '#000000', + $resObj->OPEN => '#998b13', + $resObj->CORRECT => '#26933f', + $resObj->INCORRECT => '#c48207', + $resObj->ATTEMPTED => '#a87510', + $resObj->ERROR => '#000000' + ); +my %statusStrings = + ( + $resObj->CLOSED => 'Not yet open', + $resObj->OPEN => 'Open', + $resObj->CORRECT => 'Correct', + $resObj->INCORRECT => 'Incorrect', + $resObj->ATTEMPTED => 'Attempted', + $resObj->ERROR => 'Network Error' + ); +my @statuses = ($resObj->CORRECT, $resObj->ATTEMPTED, $resObj->INCORRECT, $resObj->OPEN, $resObj->CLOSED, $resObj->ERROR); + +use Data::Dumper; +sub render_parts_summary_status { + my ($resource, $part, $params) = @_; + if (!$resource->is_problem()) { return ''; } + if ($params->{showParts}) { + return ''; + } + + my $td = "\n"; + my $endtd = "\n"; + + # If there is a single part, just show the simple status + if ($resource->singlepart()) { + my $status = $resource->simpleStatus('0'); + return $td . "" + . $statusStrings{$status} . "" . $endtd; + } + + # Now we can be sure the $part doesn't really matter. + my $statusCount = $resource->simpleStatusCount(); + my @counts; + foreach my $status(@statuses) { + # decouple display order from the simpleStatusCount order + my $slot = Apache::lonnavmaps::resource::statusToSlot($status); + if ($statusCount->[$slot]) { + push @counts, "" . $statusCount->[$slot] . ' ' + . $statusStrings{$status} . ""; + } + } + + return $td . $resource->countParts() . ' parts: ' . join (', ', @counts) . $endtd; +} + my @preparedColumns = (\&render_resource, \&render_communication_status, - \&render_quick_status, \&render_long_status); + \&render_quick_status, \&render_long_status, + \&render_parts_summary_status); sub setDefault { my ($val, $default) = @_; @@ -1905,7 +1978,7 @@ sub getById { sub getBySymb { my $self = shift; my $symb = shift; - my ($mapUrl, $id, $filename) = split (/___/, $symb); + my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb); my $map = $self->getResourceByUrl($mapUrl); return $self->getById($map->map_pc() . '.' . $id); } @@ -1981,7 +2054,7 @@ sub parmval_real { unless ($symb) { return ''; } my $result=''; - my ($mapname,$id,$fn)=split(/\_\_\_/,$symb); + my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb); # ----------------------------------------------------- Cascading lookup scheme my $rwhat=$what; @@ -3464,6 +3537,11 @@ sub multipart { return $self->countParts() > 1; } +sub singlepart { + my $self = shift; + return $self->countParts() == 1; +} + sub responseType { my $self = shift; my $part = shift; @@ -3982,6 +4060,38 @@ sub simpleStatus { } =pod + +B will return an array reference containing, in +this order, the number of OPEN, CLOSED, CORRECT, INCORRECT, ATTEMPTED, +and ERROR parts the given problem has. + +=cut + +# This maps the status to the slot we want to increment +my %statusToSlotMap = + ( + OPEN() => 0, + CLOSED() => 1, + CORRECT() => 2, + INCORRECT() => 3, + ATTEMPTED() => 4, + ERROR() => 5 + ); + +sub statusToSlot { return $statusToSlotMap{shift()}; } + +sub simpleStatusCount { + my $self = shift; + + my @counts = (0, 0, 0, 0, 0, 0, 0); + foreach my $part (@{$self->parts()}) { + $counts[$statusToSlotMap{$self->simpleStatus($part)}]++; + } + + return \@counts; +} + +=pod B