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

bowersj2 lon-capa-cvs@mail.lon-capa.org
Mon, 12 May 2003 19:33:57 -0000


This is a MIME encoded message

--bowersj21052768037
Content-Type: text/plain

bowersj2		Mon May 12 15:33:57 2003 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  This commit is to fix up the parameter helper. Fixed student name
  breakage. Now the parameter helper does a better job (i.e., it *does*
  a job) of showing the user where they would have entered the parameter
  with the advanced interface. Hopefully this won't cause too many
  problems...
  
  also included in this commit because it wasn't worth trying to mask it 
  out is the beginning of some more infrastructure I will be using for the
  course initialization wizard, that allow the helper writer to bundle
  the logic for selecting the default value, display the value, and
  finally set the value all in the same geographical place in the helper,
  putting all the logic for a single preference in the same place. Pretty 
  cool, if I do say so myself. ;-)
  
  
--bowersj21052768037
Content-Type: text/plain
Content-Disposition: attachment; filename="bowersj2-20030512153357.txt"

Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.26 loncom/interface/lonhelper.pm:1.27
--- loncom/interface/lonhelper.pm:1.26	Thu May  8 16:10:49 2003
+++ loncom/interface/lonhelper.pm	Mon May 12 15:33:57 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.26 2003/05/08 20:10:49 bowersj2 Exp $
+# $Id: lonhelper.pm,v 1.27 2003/05/12 19:33:57 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -234,6 +234,7 @@
     my $file;
     read $fh, $file, 100000000;
 
+
     # Send header, don't cache this page
     if ($r->header_only) {
         if ($ENV{'browser.mathml'}) {
@@ -2362,6 +2363,101 @@
 
 1;
 
+package Apache::lonhelper::final;
+
+=pod
+
+=head2 Element: final
+
+<final> is a special element that works with helpers that use the <finalcode>
+tag. It goes through all the states and elements, executing the <finalcode>
+snippets and collecting the results. Finally, it takes the user out of the
+helper, going to a provided page.
+
+=cut
+
+no strict;
+@ISA = ("Apache::lonhelper::element");
+use strict;
+
+BEGIN {
+    &Apache::lonhelper::register('Apache::lonhelper::final',
+                                 ('final', 'exitpage'));
+}
+
+sub new {
+    my $ref = Apache::lonhelper::element->new();
+    bless($ref);
+}
+
+sub start_final { return ''; }
+
+sub end_final {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+    if ($target ne 'helper') {
+        return '';
+    }
+
+    Apache::lonhelper::final->new();
+   
+    return '';
+}
+
+sub start_exitpage {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+    if ($target ne 'helper') {
+        return '';
+    }
+
+    $paramHash->{EXIT_PAGE} = &Apache::lonxml::get_all_text('/exitpage',
+                                                            $parser);
+
+    return '';
+}
+
+sub end_exitpage { return ''; }
+
+sub render {
+    my $self = shift;
+
+    my @results;
+
+    # Collect all the results
+    for my $stateName (keys %{$helper->{STATES}}) {
+        my $state = $helper->{STATES}->{$stateName};
+        
+        for my $element (@{$state->{ELEMENTS}}) {
+            if (defined($element->{FINAL_CODE})) {
+                # Compile the code.
+                my $code = 'sub { my $helper = shift; ' . $element->{FINAL_CODE} .
+                    '}';
+                $code = eval($code);
+                die 'Error while executing final code for element with var ' .
+                    $element->{'variable'} . ', Perl said: ' . $@ if $@;
+
+                my $result = &$code($helper);
+                if ($result) {
+                    push @results, $result;
+                }
+            }
+        }
+    }
+
+    if (scalar(@results) == 0) {
+        return '';
+    }
+
+    my $result = "<ul>\n";
+    for my $re (@results) {
+        $result .= '    <li>' . $re . "</li>\n";
+    }
+    return $result . '</ul>';
+}
+
+1;
+
 package Apache::lonhelper::parmwizfinal;
 
 # This is the final state for the parmwizard. It is not generally useful,
@@ -2409,60 +2505,72 @@
                         'due_date' => "0_duedate",
                         'answer_date' => "0_answerdate");
     
-    my $result = "<form name='helpform' method='get' action='/adm/parmset'>\n";
-    $result .= '<p>Confirm that this information is correct, then click &quot;Finish Wizard&quot; to complete setting the parameter.<ul>';
     my $affectedResourceId = "";
     my $parm_name = $parmTypeHash{$vars->{ACTION_TYPE}};
     my $level = "";
-    
-    # Print the type of manipulation:
-    $result .= '<li>Setting the <b>' . $dateTypeHash{$vars->{ACTION_TYPE}}
-               . "</b></li>\n";
-    if ($vars->{ACTION_TYPE} eq 'due_date' || 
-        $vars->{ACTION_TYPE} eq 'answer_date') {
-        # for due dates, we default to "date end" type entries
-        $result .= "<input type='hidden' name='recent_date_end' " .
-            "value='" . $vars->{PARM_DATE} . "' />\n";
-        $result .= "<input type='hidden' name='pres_value' " . 
-            "value='" . $vars->{PARM_DATE} . "' />\n";
-        $result .= "<input type='hidden' name='pres_type' " .
-            "value='date_end' />\n";
-    } elsif ($vars->{ACTION_TYPE} eq 'open_date') {
-        $result .= "<input type='hidden' name='recent_date_start' ".
-            "value='" . $vars->{PARM_DATE} . "' />\n";
-        $result .= "<input type='hidden' name='pres_value' " .
-            "value='" . $vars->{PARM_DATE} . "' />\n";
-        $result .= "<input type='hidden' name='pres_type' " .
-            "value='date_start' />\n";
-    } 
-    
+    my $resourceString;
+    my $symb;
+    my $paramlevel;
+
     # Print the granularity, depending on the action
     if ($vars->{GRANULARITY} eq 'whole_course') {
-        $result .= '<li>for <b>all resources in the course</b></li>';
+        $resourceString .= '<li>for <b>all resources in the course</b></li>';
         $level = 9; # general course, see lonparmset.pm perldoc
         $affectedResourceId = "0.0";
+        $symb = 'a';
+        $paramlevel = 'general';
     } elsif ($vars->{GRANULARITY} eq 'map') {
         my $navmap = Apache::lonnavmaps::navmap->new(
                            $ENV{"request.course.fn"}.".db",
                            $ENV{"request.course.fn"}."_parms.db", 0, 0);
         my $res = $navmap->getById($vars->{RESOURCE_ID});
         my $title = $res->compTitle();
+        $symb = $res->symb();
         $navmap->untieHashes();
-        $result .= "<li>for the map named <b>$title</b></li>";
+        $resourceString .= "<li>for the map named <b>$title</b></li>";
         $level = 8;
         $affectedResourceId = $vars->{RESOURCE_ID};
+        $paramlevel = 'map';
     } else {
         my $navmap = Apache::lonnavmaps::navmap->new(
                            $ENV{"request.course.fn"}.".db",
                            $ENV{"request.course.fn"}."_parms.db", 0, 0);
         my $res = $navmap->getById($vars->{RESOURCE_ID});
+        $symb = $res->symb();
         my $title = $res->compTitle();
         $navmap->untieHashes();
-        $result .= "<li>for the resource named <b>$title</b></li>";
+        $resourceString .= "<li>for the resource named <b>$title</b></li>";
         $level = 7;
         $affectedResourceId = $vars->{RESOURCE_ID};
+        $paramlevel = 'full';
     }
 
+    my $result = "<form name='helpform' method='get' action='/adm/parmset#$affectedResourceId&$parm_name&$level'>\n";
+    $result .= '<p>Confirm that this information is correct, then click &quot;Finish Wizard&quot; to complete setting the parameter.<ul>';
+    
+    # Print the type of manipulation:
+    $result .= '<li>Setting the <b>' . $dateTypeHash{$vars->{ACTION_TYPE}}
+               . "</b></li>\n";
+    if ($vars->{ACTION_TYPE} eq 'due_date' || 
+        $vars->{ACTION_TYPE} eq 'answer_date') {
+        # for due dates, we default to "date end" type entries
+        $result .= "<input type='hidden' name='recent_date_end' " .
+            "value='" . $vars->{PARM_DATE} . "' />\n";
+        $result .= "<input type='hidden' name='pres_value' " . 
+            "value='" . $vars->{PARM_DATE} . "' />\n";
+        $result .= "<input type='hidden' name='pres_type' " .
+            "value='date_end' />\n";
+    } elsif ($vars->{ACTION_TYPE} eq 'open_date') {
+        $result .= "<input type='hidden' name='recent_date_start' ".
+            "value='" . $vars->{PARM_DATE} . "' />\n";
+        $result .= "<input type='hidden' name='pres_value' " .
+            "value='" . $vars->{PARM_DATE} . "' />\n";
+        $result .= "<input type='hidden' name='pres_type' " .
+            "value='date_start' />\n";
+    } 
+
+    $result .= $resourceString;
+    
     # Print targets
     if ($vars->{TARGETS} eq 'course') {
         $result .= '<li>for <b>all students in course</b></li>';
@@ -2475,7 +2583,10 @@
     } else {
         # FIXME: This is probably wasteful! Store the name!
         my $classlist = Apache::loncoursedata::get_classlist();
-        my $name = $classlist->{$vars->{USER_NAME}}->[6];
+        my $username = $vars->{USER_NAME};
+        # Chop off everything after the last colon (section)
+        $username = substr($username, 0, rindex($username, ':'));
+        my $name = $classlist->{$username}->[6];
         $result .= "<li>for <b>$name</b></li>";
         $level -= 6;
         my ($uname, $udom) = split /:/, $vars->{USER_NAME};
@@ -2493,6 +2604,12 @@
     # print pres_marker
     $result .= "\n<input type='hidden' name='pres_marker'" .
         " value='$affectedResourceId&$parm_name&$level' />\n";
+    
+    # Make the table appear
+    $result .= "\n<input type='hidden' value='true' name='prevvisit' />";
+    $result .= "\n<input type='hidden' value='all' name='pschp' />";
+    $result .= "\n<input type='hidden' value='$symb' name='pssymb' />";
+    $result .= "\n<input type='hidden' value='$paramlevel' name='parmlev' />";
 
     $result .= "<br /><br /><center><input type='submit' value='Finish Helper' /></center></form>\n";
 

--bowersj21052768037--