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

bowersj2 lon-capa-cvs@mail.lon-capa.org
Thu, 17 Oct 2002 19:25:27 -0000


bowersj2		Thu Oct 17 15:25:27 2002 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  Fixes Netscape 4 ugly graphics issues. Corrects newly discovered 
  Perl warnings on startup. Adds caching to the parmval function to
  speed it up.
  
  Profiling now shows Apache::lonnet::allowed calls dominate the new
  navmaps, as the old ones do. Significant further speedup would need
  to concentrate there. Since it really only matters when the whole
  map is shown... it isn't worth worrying about further.
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.83 loncom/interface/lonnavmaps.pm:1.84
--- loncom/interface/lonnavmaps.pm:1.83	Tue Oct 15 16:05:35 2002
+++ loncom/interface/lonnavmaps.pm	Thu Oct 17 15:25:27 2002
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.83 2002/10/15 20:05:35 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.84 2002/10/17 19:25:27 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -849,10 +849,6 @@
         $r->print('<img src="/adm/lonMisc/chat.gif"> Discussions'.
                   '<br><img src="/adm/lonMisc/feedback.gif"> New message (click to open)<p>'); 
     }
-    #if (($currenturl=~/^\/res/) &&
-    #    ($currenturl!~/^\/res\/adm/)) {
-    #    $r->print('<a href="#curloc">Current Location</a><p>');
-    #}
 
     # Check that it's defined
     if (!($navmap->courseMapDefined())) {
@@ -929,7 +925,7 @@
 
     # Begin the HTML table
     # four cols: resource + indent, chat+feedback, icon, text string
-    $r->print('<table cellspacing="3" cellpadding="0" bgcolor="#FFFFFF">' ."\n");
+    $r->print('<table cellspacing="0" cellpadding="3" width="100%" border="0" bgcolor="#FFFFFF">' ."\n");
 
     my $condition = 0;
     if ($ENV{'form.condition'}) {
@@ -944,7 +940,7 @@
     if ($currenturl && !$ENV{'form.alreadyHere'}) {
         # Give me every resource...
         my $mapIterator = $navmap->getIterator(undef, undef, {}, 1);
-        my $found != 0;
+        my $found = 0;
         my $depth = 1;
         $mapIterator->next(); # discard the first BEGIN_MAP
         my $curRes = $mapIterator->next();
@@ -1075,7 +1071,7 @@
                 }
 
             } else {
-                @parts[0] = "0"; # this is to get past foreach loop below
+                $parts[0] = "0"; # this is to get past foreach loop below
                  # you can consider a non-problem resource as a resource
                   # with only one part without loss
             }
@@ -1186,7 +1182,7 @@
                 }
 
                 # FIRST COL: The resource indentation, branch icon, and name
-                $r->print("  <tr><td align=\"left\" valign=\"center\">\n");
+                $r->print("  <tr><td align=\"left\" valign=\"center\" width=\"60%\">\n");
 
                 # print indentation
                 for (my $i = 0; $i < $indentLevel - $deltalevel; $i++) {
@@ -1217,7 +1213,7 @@
 
                 if ($curRes->{RESOURCE_ERROR}) {
                     $r->print(&Apache::loncommon::help_open_topic ("Navmap_Host_Down",
-                                                  '<font size="-1">Host down</font>'));
+                                              '<font size="-1">Host down</font>'));
                     }
 
                 my $discussionHTML = ""; my $feedbackHTML = "";
@@ -1241,7 +1237,7 @@
                     }
                 }
 
-                $r->print("<td align=\"left\" valign=\"center\">$discussionHTML$feedbackHTML</td>");
+                $r->print("<td width=\"75\" align=\"left\" valign=\"center\">$discussionHTML$feedbackHTML&nbsp;</td>");
 
                 # Is this the first displayed part of a multi-part problem
                 # that has not been condensed, so we should suppress these two
@@ -1254,12 +1250,12 @@
                     my $icon = $statusIconMap{$curRes->status($part)};
                     my $alt = $iconAltTags{$icon};
                     if ($icon) {
-                        $r->print("<td valign=\"center\" width=\"50\" align=\"right\">$linkopen<img src=\"/adm/lonIcons/$icon\" border=\"0\" alt=\"$alt\" />$linkclose</td>\n");
+                        $r->print("<td width=\"30\" valign=\"center\" width=\"50\" align=\"right\">$linkopen<img width=\"25\" height=\"25\" src=\"/adm/lonIcons/$icon\" border=\"0\" alt=\"$alt\" />$linkclose</td>\n");
                     } else {
-                        $r->print("<td></td>\n");
+                        $r->print("<td width=\"30\">&nbsp;</td>\n");
                     }
                 } else { # not problem, no icon
-                    $r->print("<td></td>\n");
+                    $r->print("<td width=\"30\">&nbsp;</td>\n");
                 }
 
                 # FOURTH COL: Text description
@@ -1274,7 +1270,7 @@
                     $r->print('(randomly select ' . $curRes->randompick() .')');
                 }
 
-                $r->print("</td></tr>\n");
+                $r->print("&nbsp;</td></tr>\n");
             }
         }
         $curRes = $mapIterator->next();
@@ -1669,6 +1665,8 @@
         $self->{EMAIL_STATUS} = \%emailstatus;
         
     }    
+
+    $self->{PARM_CACHE} = {};
     
     bless($self);
         
@@ -1790,6 +1788,21 @@
 sub parmval {
     my $self = shift;
     my ($what,$symb)=@_;
+    my $hashkey = $what."|||".$symb;
+
+    if (defined($self->{PARM_CACHE}->{$hashkey})) {
+        return $self->{PARM_CACHE}->{$hashkey};
+    }
+
+    my $result = $self->parmval_real($what, $symb);
+    $self->{PARM_CACHE}->{$hashkey} = $result;
+    return $result;
+}
+
+sub parmval_real {
+    my $self = shift;
+    my ($what,$symb) = @_;
+
     my $cid=$ENV{'request.course.id'};
     my $csec=$ENV{'request.course.sec'};
     my $uname=$ENV{'user.name'};
@@ -2251,8 +2264,6 @@
 
 =item * B<to>: Returns the "to" value from the compiled nav map. (It is likely you want to use B<getNext> instead.)
 
-=item * B<type>: Returns the type of the resource, "start", "normal", or "finish". 
-
 =back
 
 =cut
@@ -2282,7 +2293,6 @@
 }
 sub title { my $self=shift; return $self->navHash("title_", 1); }
 sub to { my $self=shift; return $self->navHash("to_", 1); }
-sub type { my $self=shift; return $self->navHash("type_", 1); }
 
 =pod
 
@@ -2498,7 +2508,7 @@
     my $self = shift;
     
     if (!defined($self->{RETURN_HASH})) {
-        my %tmpHash = &Apache::lonnet::restore($self->symb());
+        my %tmpHash  = &Apache::lonnet::restore($self->symb());
         $self->{RETURN_HASH} = \%tmpHash;
     }
 }