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

www lon-capa-cvs@mail.lon-capa.org
Mon, 26 Jan 2004 19:55:45 -0000


This is a MIME encoded message

--www1075146945
Content-Type: text/plain

www		Mon Jan 26 14:55:45 2004 EDT

  Modified files:              
    /loncom/interface	lonhtmlcommon.pm lonindexer.pm 
  Log:
  Work in progress:
  * fixed caching of RES directory listings
  * reduced number of clicks when selecting view options
  * implemented list of recent folders as pulldown (I believe better than bookmarks)
  
  
--www1075146945
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20040126145545.txt"

Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.40 loncom/interface/lonhtmlcommon.pm:1.41
--- loncom/interface/lonhtmlcommon.pm:1.40	Thu Jan 15 15:22:47 2004
+++ loncom/interface/lonhtmlcommon.pm	Mon Jan 26 14:55:44 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.40 2004/01/15 20:22:47 www Exp $
+# $Id: lonhtmlcommon.pm,v 1.41 2004/01/26 19:55:44 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -90,6 +90,51 @@
 ##############################################
 ##############################################
 
+sub recent_filename {
+    my $area=shift;
+    return 'nohist_recent_'.&Apache::lonnet::escape($area);
+}
+
+sub store_recent {
+    my ($area,$name,$value)=@_;
+    my $file=&recent_filename($area);
+    my %recent=&Apache::lonnet::dump($file);
+    if (scalar(keys(%recent))>10) {
+# remove oldest value
+	my $oldest=time;
+	my $delkey='';
+	foreach (keys %recent) {
+	    my $thistime=(split(/\&/,$recent{$_}))[0];
+	    if ($thistime<$oldest) {
+		$oldest=$thistime;
+		$delkey=$_;
+	    }
+	}
+	&Apache::lonnet::del($file,[$delkey]);
+    }
+# store new value
+    &Apache::lonnet::put($file,{ $name => 
+				 time.'&'.&Apache::lonnet::escape($value) });
+}
+
+sub select_recent {
+    my ($area,$fieldname,$event)=@_;
+    my %recent=&Apache::lonnet::dump(&recent_filename($area));
+    my $return="\n<select name='$fieldname'".
+	($event?" onChange='$event'":'').
+	">\n<option value=''>--- ".&mt('Recent')." ---</option>";
+    foreach (sort keys %recent) {
+	unless ($_=~/^error\:/) {
+	    $return.="\n<option value='$_'>".
+		&Apache::lonnet::unescape((split(/\&/,$recent{$_}))[1]).
+		'</option>';
+	}
+    }
+    $return.="\n</select>\n";
+    return $return;
+}
+
+
 =pod
 
 =item textbox
@@ -876,14 +921,18 @@
 # ------------------------------------------------------- Puts directory header
 
 sub crumbs {
-    my ($uri,$target,$prefix)=@_;
+    my ($uri,$target,$prefix,$form)=@_;
     my $output='<br /><tt><b><font size="+2">'.$prefix.'/';
     if ($ENV{'user.adv'}) {
 	my $path=$prefix;
 	foreach (split('/',$uri)) {
 	    unless ($_) { next; }
 	    $path.='/'.$_;
-	    $output.='<a href="'.$path.'"'.($target?' target="'.$target.'"':'').'>'.$_.'</a>/';
+	    my $linkpath=$path;
+	    if ($form) {
+		$linkpath="javascript:$form.action='$path';$form.submit();";
+	    }
+	    $output.='<a href="'.$linkpath.'"'.($target?' target="'.$target.'"':'').'>'.$_.'</a>/';
 	}
     } else {
 	$output.=$uri;
Index: loncom/interface/lonindexer.pm
diff -u loncom/interface/lonindexer.pm:1.86 loncom/interface/lonindexer.pm:1.87
--- loncom/interface/lonindexer.pm:1.86	Mon Jan  5 10:02:43 2004
+++ loncom/interface/lonindexer.pm	Mon Jan 26 14:55:44 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Directory Indexer
 #
-# $Id: lonindexer.pm,v 1.86 2004/01/05 15:02:43 www Exp $
+# $Id: lonindexer.pm,v 1.87 2004/01/26 19:55:44 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -54,7 +54,7 @@
 use GDBM_File;
 
 # ---------------------------------------- variables used throughout the module
-my %hash; # tied to a user-specific gdbm file
+my %hash; # global user-specific gdbm file
 my %dirs; # keys are directories, values are the open/close status
 my %language; # has the reference information present in language.tab
 
@@ -116,7 +116,7 @@
     %hash = ();
     {
 	my %dbfile;
-	if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
+	if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_READER(),0640)) {
 	    while(my($key,$value)=each(%dbfile)) {
 		$hash{$key}=$value;
 	    }
@@ -360,7 +360,7 @@
 		$achash{$ref}=$ac;
 		$ac++;
 	    }
-	    # sorting through the actions and changing the tied database hash
+	    # sorting through the actions and changing the global database hash
 	    foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
 		my $key=$_;
 		if ($ahash{$key} eq '1') {
@@ -389,7 +389,7 @@
 	}
 	
 # ---------------------------------- get state of file attributes to be showing
-	if ($ENV{'form.attrs'} ne '') {
+	if ($ENV{'form.attrs'}) {
 	    for (my $i=0; $i<=9; $i++) {
 		delete $hash{'display_attrs_'.$i};
 		if ($ENV{'form.attr'.$i} == 1) {
@@ -402,6 +402,7 @@
 		$attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
 	    }
 	}
+
 # ------------------------------- output state of file attributes to be showing
 #                                 All versions has to the last item
 #                                 since it does not take an extra col
@@ -424,30 +425,34 @@
  enctype="application/x-www-form-urlencoded">
 <b><font color="#666666">$Displayfileattributes</font></b><br />
 <table border=0><tr>
-<td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> $lt{'ti'}</td>
-<td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> $lt{'si'}</td>
-<td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> $lt{'la'}</td>
-<td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> $lt{'lm'}</td>
-<td><input type="checkbox" name="attr8" value="1" $attrchk[8] /> $lt{'st'}</td>
+<td><input type="checkbox" name="attr0" value="1" $attrchk[0] onClick="this.form.submit();" /> $lt{'ti'}</td>
+<td><input type="checkbox" name="attr1" value="1" $attrchk[1] onClick="this.form.submit();" /> $lt{'si'}</td>
+<td><input type="checkbox" name="attr2" value="1" $attrchk[2] onClick="this.form.submit();" /> $lt{'la'}</td>
+<td><input type="checkbox" name="attr3" value="1" $attrchk[3] onClick="this.form.submit();" /> $lt{'lm'}</td>
+<td><input type="checkbox" name="attr8" value="1" $attrchk[8] onClick="this.form.submit();" /> $lt{'st'}</td>
 </tr><tr>
-<td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> $lt{'au'}</td>
-<td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> $lt{'kw'}</td>
-<td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> $lt{'ln'}</td>
-<td><input type="checkbox" name="attr7" value="1" $attrchk[7] /> $lt{'sr'}</td>
-<td><input type="checkbox" name="attr9" value="1" $attrchk[9] /> $lt{'av'}</td>
+<td><input type="checkbox" name="attr4" value="1" $attrchk[4] onClick="this.form.submit();" /> $lt{'au'}</td>
+<td><input type="checkbox" name="attr5" value="1" $attrchk[5] onClick="this.form.submit();" /> $lt{'kw'}</td>
+<td><input type="checkbox" name="attr6" value="1" $attrchk[6] onClick="this.form.submit();" /> $lt{'ln'}</td>
+<td><input type="checkbox" name="attr7" value="1" $attrchk[7] onClick="this.form.submit();" /> $lt{'sr'}</td>
+<td><input type="checkbox" name="attr9" value="1" $attrchk[9] onClick="this.form.submit();" /> $lt{'av'}</td>
 <td>&nbsp;</td>
 </tr></table>
-<input type="hidden" name="dirPointer" value="on" />
+<input type="hidden" name="attrs" value="1" />
+<input type="submit" name="updatedisplay" value="$lt{'ud'}" />
 <input type="hidden" name="acts" value="" />
-<input type="submit" name="attrs" value="$lt{'ud'}" />
-$closebutton
-$groupimportbutton
-</form>
+$closebutton $groupimportbutton
 END
 # ---------------------------------------------------------------- Bread crumbs
-        $r->print(&Apache::lonhtmlcommon::crumbs($uri));
+        $r->print(&Apache::lonhtmlcommon::crumbs($uri,'','',
+				(($ENV{'form.catalogmode'} eq 'groupimport')?
+				 'document.forms.fileattr':'')).
+		  &Apache::lonhtmlcommon::select_recent('residx','resrecent',
+'this.form.action=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.submit();').
+		  '</form>');
 # ------------------------------------------------------ Remember where we were
 	&Apache::loncommon::storeresurl($uri);
+	&Apache::lonhtmlcommon::store_recent('residx',$uri,$uri);
 # ----------------- output starting row to the indexed file/directory hierarchy
         my $titleclr="#ddffff";
 #        $r->print(&initdebug());
@@ -502,18 +507,13 @@
 	    }
 	}
 	
-	my $bredir = $ENV{'form.dirPointer'};
 	my $toplevel;
 	my $indent = 0;
 	$uri = $uri.'/' if $uri !~ /.*\/$/;
 
-	if ($bredir ne 'on') {
-	    $hash{'top.level'} = $uri;
-	    $toplevel = $uri;
 
-	} else {
-	    $toplevel = $hash{'top.level'};
-	}
+	$hash{'top.level'} = $uri;
+	$toplevel = $uri;
 
 # -------------------------------- if not at top level, provide an uplink arrow
 	if ($toplevel ne '/res/'){
@@ -538,12 +538,9 @@
 
 # --------------------------------------------------- end the output and return
 	$r->print('</body></html>'."\n");
-#    } else {
-#	$r->print('<html><head></head><body>Unable to tie hash to db '.
-#		  'file</body></html>');
-#	return OK;
     }
     if(! $c->aborted()) {
+# write back into the temporary file
 	my %dbfile;
         if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
             while (my($key,$value) = each(%hash)) {
@@ -610,18 +607,17 @@
     my ($r,$uri)=@_;
     my @list;
     (my $luri = $uri) =~ s/\//_/g;
-
-    if ($ENV{'form.attrs'} eq &mt('Update Display')) {
+    if ($ENV{'form.updatedisplay'}) {
 	foreach (keys %hash) {
 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
-	    }
+	}
     }
 
-    if ($hash{'dirlist_files'.$luri}) {
+    if ($hash{'dirlist_files_'.$luri}) {
 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
     } else {
 	@list = &Apache::lonnet::dirlist($uri);
-	$hash{'dirlist_files_'.$luri} = join('\n',@list);
+	$hash{'dirlist_files_'.$luri} = join("\n",@list);
     }
     return @list=&match_ext($r,@list);
 }
@@ -729,8 +725,6 @@
 
 # display domain
     if ($filecom[1] eq 'domain') {
-	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
-	    if ($ENV{'form.dirPointer'} eq "on");
 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
 	$r->print("<td>");
 	&begin_form ($r,$filecom[0]);
@@ -1015,7 +1009,6 @@
 	       'enctype="application/x-www-form-urlencoded">'."\n");
     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
 	       "\n");
-    $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
     $dnum++;
 }
 

--www1075146945--