[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm

bowersj2 lon-capa-cvs@mail.lon-capa.org
Mon, 08 Sep 2003 22:44:36 -0000


bowersj2		Mon Sep  8 18:44:36 2003 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  Towards fixing bug 2048 (2^11), provide students information about 
  status on their printing screen so they can make intelligent choices 
  about printing. Somewhat more effort then I had hoped due to fighting 
  with Perl due to my own stupidity. (Momma said there'd be days like 
  this.)
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.224 loncom/interface/lonnavmaps.pm:1.225
--- loncom/interface/lonnavmaps.pm:1.224	Mon Sep  8 15:53:09 2003
+++ loncom/interface/lonnavmaps.pm	Mon Sep  8 18:44:36 2003
@@ -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.225 2003/09/08 22:44:36 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -655,13 +655,13 @@
 
 =back
 
-=item B<Apache::lonnavmaps::communication_status>:
+=item * B<Apache::lonnavmaps::communication_status>:
 
 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<Apache::lonnavmaps::quick_status>:
+=item * B<Apache::lonnavmaps::quick_status>:
 
 An icon for the status of a problem, with five possible states:
 Correct, incorrect, open, awaiting grading (for a problem where the
@@ -669,11 +669,24 @@
 essay problem), or none (not open yet, not a problem). The
 third column of the standard navmap.
 
-=item B<Apache::lonnavmaps::long_status>:
+=item * B<Apache::lonnavmaps::long_status>:
 
 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<Apache::lonnavmaps::part_status_summary>:
+
+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<not> showing parts. If 
+C<showParts> 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 +854,7 @@
 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 +1093,63 @@
     return $result;
 }
 
+my %statusColors = 
+    (
+     $resObj->CLOSED => '#000000',
+     $resObj->OPEN   => '#000000',
+     $resObj->CORRECT => '#000000',
+     $resObj->INCORRECT => '#000000',
+     $resObj->ATTEMPTED => '#000000',
+     $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 '<td></td>'; }
+    if ($params->{showParts}) { 
+	return '<td></td>';
+    }
+
+    my $td = "<td align='right'>\n";
+    my $endtd = "</td>\n";
+
+    # If there is a single part, just show the simple status
+    if ($resource->singlepart()) {
+	my $status = $resource->simpleStatus('0');
+	return $td . "<font color='" . $statusColors{$status} . "'>"
+	    . $statusStrings{$status} . "</font>" . $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, "<font color='" . $statusColors{$status} .
+		"'>" . $statusCount->[$slot] . ' '
+		. $statusStrings{$status} . "</font>";
+	}
+    }
+
+    return $td . 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) = @_;
@@ -3464,6 +3531,11 @@
     return $self->countParts() > 1;
 }
 
+sub singlepart {
+    my $self = shift;
+    return $self->countParts() == 1;
+}
+
 sub responseType {
     my $self = shift;
     my $part = shift;
@@ -3979,6 +4051,38 @@
     my $part = shift;
     my $status = $self->status($part);
     return $compositeToSimple{$status};
+}
+
+=pod
+
+B<simpleStatusCount> 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