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

stredwic lon-capa-cvs@mail.lon-capa.org
Mon, 01 Jul 2002 21:12:06 -0000


This is a MIME encoded message

--stredwic1025557926
Content-Type: text/plain

stredwic		Mon Jul  1 17:12:06 2002 EDT

  Modified files:              
    /loncom/interface	lonchart.pm 
  Log:
  See bug 218.
  Lonchart now has the ability to remove columns from the chart.  When the check
  box is unchecked and any of the refreshing buttons (not recalculate) are hit,
  the column will be gone when the new page appears.  Selecting the column from
  the selection box and hitting a refreshing button, the column will reappear 
  when the new page is displayed.  The recalculate button sets all columns to
  appear.  The column selection box is only available when there are columns missing
  and only contain the names of missing columns.
  
  
--stredwic1025557926
Content-Type: text/plain
Content-Disposition: attachment; filename="stredwic-20020701171206.txt"

Index: loncom/interface/lonchart.pm
diff -u loncom/interface/lonchart.pm:1.48 loncom/interface/lonchart.pm:1.49
--- loncom/interface/lonchart.pm:1.48	Mon Jul  1 11:39:55 2002
+++ loncom/interface/lonchart.pm	Mon Jul  1 17:12:06 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonchart.pm,v 1.48 2002/07/01 15:39:55 stredwic Exp $
+# $Id: lonchart.pm,v 1.49 2002/07/01 21:12:06 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,16 +59,20 @@
 # ----- FORMAT PRINT DATA ----------------------------------------------
 
 sub FormatStudentInformation {
-    my ($cache,$name,$studentInformation,$spacePadding)=@_;
+    my ($cache,$name,$studentInformation,$reselected,$spacePadding)=@_;
     my $Str='<pre>';
 
-    foreach (@$studentInformation) {
-	my $data=$cache->{$name.':'.$_};
+    for(my $index=0; $index<(scalar @$studentInformation); $index++) {
+        if(!&ShouldShowColumn($reselected, 'heading', $index)) {
+            next;
+        }
+	my $data=$cache->{$name.':'.$studentInformation->[$index]};
 	$Str .= $data;
 
 	my @dataLength=split(//,$data);
 	my $length=scalar @dataLength;
-	$Str .= (' 'x($cache->{$_.'Length'}-$length));
+	$Str .= (' 'x($cache->{$studentInformation->[$index].'Length'}-
+                      $length));
 	$Str .= $spacePadding;
     }
 
@@ -76,7 +80,7 @@
 }
 
 sub FormatStudentData {
-    my ($name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_;
+    my ($reselected,$name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_;
     my ($sname,$sdom) = split(/\:/,$name);
     my $Str;
     my %CacheData;
@@ -87,7 +91,7 @@
     # Handle Student information ------------------------------------------
     # Handle user data
     $Str=&FormatStudentInformation(\%CacheData, $name, $studentInformation, 
-                                   $spacePadding);
+                                   $reselected, $spacePadding);
 
     # Handle errors
     if($CacheData{$name.':error'} =~ /environment/) {
@@ -116,6 +120,10 @@
     my $problemsSolved  = 0;
     my $numberOfParts   = 0;
     foreach my $sequence (split(/\:/,$CacheData{'orderedSequences'})) {
+        if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) {
+            next;
+        }
+
 	my $characterCount=0;
 	foreach my $problemID (split(/\:/,$CacheData{$sequence.':problems'})) {
 	    my $problem = $CacheData{$problemID.':problem'};
@@ -215,10 +223,14 @@
 }
 
 sub CreateTableHeadings {
-    my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
+    my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_;
     my $Str='<pre>';
 
     for(my $index=0; $index<(scalar @$headings); $index++) {
+        if(!&ShouldShowColumn($reselected, 'heading', $index)) {
+            next;
+        }
+
 	my $data=$$headings[$index];
 	$Str .= $data;
 
@@ -230,7 +242,12 @@
     }
 
     foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
-	$Str .= $CacheData->{$sequence.':title'};
+        if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) {
+            next;
+        }
+
+        my $name = $CacheData->{$sequence.':title'};
+	$Str .= $name;
 	my @titleLength=split(//,$CacheData->{$sequence.':title'});
 	my $leftover=$CacheData->{$sequence.':columnWidth'}-
                      (scalar @titleLength);
@@ -244,36 +261,90 @@
     return $Str;
 }
 
-sub CreateColumnSelectors {
-    my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
-    my $Str='';
+sub CreateColumnSelectionBox {
+    my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_;
 
-    $Str .= '<form name="stat" method="post" action="/adm/chart" >'."\n";
-    $Str .= '<input type="submit" name="sort" value="Refresh Chart"/>';
-    $Str .= '</form>'."\n";
-    return $Str;
+    my $missing=0;
+    my $notThere='<br><br><b>Select column to view:</b><br><br>';
+    my $name;
+    $notThere .= '&nbsp;&nbsp;&nbsp';
+    $notThere .= '<select name="reselect" size="4" multiple="true">'."\n";
 
     for(my $index=0; $index<(scalar @$headings); $index++) {
-	my $data=$$headings[$index];
-	$Str .= $data;
+        if(&ShouldShowColumn($reselected, 'heading', $index)) {
+            next;
+        }
+        $name = $headings->[$index];
+        $notThere .= '<option value="heading'.$index.'">';
+        $notThere .= $name.'</option>'."\n";
+        $missing++;
+    }
 
-	my @dataLength=split(//,$data);
-	my $length=scalar @dataLength;
-	$Str .= (' 'x($CacheData->{$$studentInformation[$index].'Length'}-
-                      $length));
-	$Str .= $spacePadding;
+    foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
+        if(&ShouldShowColumn($reselected, 'sequence', $sequence)) {
+            next;
+        }
+        $name = $CacheData->{$sequence.':title'};
+        $notThere .= '<option value="sequence'.$sequence.'">';
+        $notThere .= $name.'</option>'."\n";
+        $missing++;
+    }
+
+    if($missing) {
+        $notThere .= '</select><br><br>';
+    } else {
+        $notThere='';
+    }
+
+    return $notThere;
+}
+
+sub CreateColumnSelectors {
+    my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_;
+
+    my $found=0;
+    my ($name, $length, $position);
+    my $present='<pre>';
+    for(my $index=0; $index<(scalar @$headings); $index++) {
+        if(!&ShouldShowColumn($reselected, 'heading', $index)) {
+            next;
+        }
+        $name = $headings->[$index];
+        $length=$CacheData->{$$studentInformation[$index].'Length'};
+        $position=int($length/2);
+	$present .= (' 'x($position));
+        $present .= '<input type="checkbox" checked="on" ';
+        $present .= 'name="heading'.$index.'">';
+        $position+=2;
+	$present .= (' 'x($length-$position));
+	$present .= $spacePadding;
+        $found++;
     }
 
     foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
-	$Str .= $CacheData->{$sequence.':title'};
-	my @titleLength=split(//,$CacheData->{$sequence.':title'});
-	my $leftover=$CacheData->{$sequence.':columnWidth'}-
-                     (scalar @titleLength);
-	$Str .= (' 'x$leftover);
-	$Str .= $spacePadding;
+        if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) {
+            next;
+        }
+        $name = $CacheData->{$sequence.':title'};
+        $length=$CacheData->{$sequence.':columnWidth'};
+        $position=int($length/2);
+	$present .= (' 'x($position));
+        $present .= '<input type="checkbox" checked="on" ';
+        $present .= 'name="sequence'.$sequence.'">';
+        $position+=2;
+	$present .= (' 'x($length-$position));
+	$present .= $spacePadding;
+        $found++;
     }
 
-    return $Str;
+    if($found) {
+        $present .= '</pre>';
+        $present  = $present;
+    } else {
+        $present = '';
+    }
+
+    return $present.'</form>'."\n";;
 }
 
 sub CreateForm {
@@ -286,6 +357,12 @@
     else { $OpSel1 = 'selected'; }
 
     my $Ptr = '<form name="stat" method="post" action="/adm/chart" >'."\n";
+    $Ptr .= '<input type="submit" name="sort" value="Recalculate Chart"/>';
+    $Ptr .= "\n";
+    $Ptr .= '&nbsp;&nbsp;&nbsp;';
+    $Ptr .= '<input type="submit" name="refresh" value="Refresh Chart"/>';
+    $Ptr .= "\n";
+    $Ptr .= '<br><br>';
     $Ptr .= '<b> Sort by: &nbsp; </b>'."\n";
     $Ptr .= '&nbsp;&nbsp;&nbsp;';
     $Ptr .= '<input type="submit" name="sort" value="User Name" />'."\n";
@@ -295,17 +372,11 @@
     $Ptr .= '<input type="submit" name="sort" value="Section"/>'."\n";
     $Ptr .= '<br><br>';
     $Ptr .= '<b> Student Status: &nbsp; </b>'."\n".
+            '&nbsp;&nbsp;&nbsp;'.
             '<select name="status">'. 
             '<option '.$OpSel1.' >Active</option>'."\n".
             '<option '.$OpSel2.' >Expired</option>'."\n".
 	    '<option '.$OpSel3.' >Any</option> </select> '."\n";
-    $Ptr .= '<br><br>';
-    $Ptr .= '<input type="submit" name="sort" value="Recalculate Chart"/>';
-    $Ptr .= "\n";
-    $Ptr .= '&nbsp;&nbsp;&nbsp;';
-    $Ptr .= '<input type="submit" name="sort" value="Refresh Chart"/>';
-    $Ptr .= "\n";
-    $Ptr .= '</form>'."\n";
 
     return $Ptr;
 }
@@ -867,6 +938,31 @@
     return;
 }
 
+sub ShouldShowColumn {
+    my ($reselected,$type,$value)=@_;
+
+    if($ENV{'form.sort'} eq 'Recalculate Chart') {
+        return 1;
+    }
+
+    if(defined($ENV{'form.'.$type.$value})) {
+        return 1;
+    }
+
+    return &CheckForStringInArray($reselected, $type.$value);
+}
+
+sub CheckForStringInArray {
+    my ($inputArray,$checkString)=@_;
+    foreach (@$inputArray) {
+#        $jr->print('a:'.$_.' b:'.$checkString.'<br>');
+        if($_ eq $checkString) {
+            return 1;
+        }
+    }
+    return 0;
+}
+
 # ----- END HELPER FUNCTIONS --------------------------------------------
 
 sub BuildChart {
@@ -884,6 +980,10 @@
     my $cid=$ENV{'request.course.id'};
     my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
                   "_$ENV{'user.domain'}_$cid\_chart.db";
+    # $ENV{'form.domains'} can be either a scalar or an array reference.
+    # We need an array.
+    my @reselected = (ref($ENV{'form.reselect'}) ? @{$ENV{'form.reselect'}}
+                      : ($ENV{'form.reselect'}));
 
     $isCached=&TestCacheData($ChartDB);
     if($isCached < 0) {
@@ -928,20 +1028,29 @@
     if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_READER,0640)) {
         if(!$c->aborted()) { @students=&SortStudents(\@students,\%CacheData); }
 	if(!$c->aborted()) { $r->print(&CreateLegend()); }
+	if(!$c->aborted()) { $r->rflush(); }
 	if(!$c->aborted()) { $r->print(&CreateForm()); }
-	if(!$c->aborted()) { $r->print('<h3>'.(scalar @students).
+	if(!$c->aborted()) { $r->print(&CreateColumnSelectionBox(
+                                                       \%CacheData,
+                                                       \@studentInformation, 
+						       \@headings, 
+                                                       \@reselected,
+                                                       $spacePadding)); }
+        if(!$c->aborted()) { $r->print('<h3>'.(scalar @students).
                                        ' students</h3>'); }
-	if(!$c->aborted()) { $r->rflush(); }
-#	if(!$c->aborted()) { $r->print(&CreateColumnSelectors(
-#                                                         \%CacheData,
-#                                                         \@studentInformation, 
-#							 \@headings, 
-#							 $spacePadding)); }
+	if(!$c->aborted()) { $r->print(&CreateColumnSelectors(
+                                                       \%CacheData,
+                                                       \@studentInformation, 
+						       \@headings, 
+                                                       \@reselected,
+                                                       $spacePadding)); }
 	if(!$c->aborted()) { $r->print(&CreateTableHeadings(
                                                          \%CacheData,
                                                          \@studentInformation, 
 							 \@headings, 
+                                                         \@reselected,
 							 $spacePadding)); }
+	if(!$c->aborted()) { $r->rflush(); }
 	untie(%CacheData);
     } else {
 	$r->print("Init2: Unable to tie hash to db file");
@@ -968,7 +1077,8 @@
             push(@updateStudentList, $_);
             &ExtractStudentData($courseData, $_, $ChartDB);
         }
-        $r->print(&FormatStudentData($_, $cid, \@studentInformation,
+        $r->print(&FormatStudentData(\@reselected, $_, $cid, 
+                                     \@studentInformation,
                                      $spacePadding, $ChartDB));
         $r->rflush();
     }

--stredwic1025557926--