[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm /localize/localize newphrases.txt
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 21 Apr 2004 18:04:55 -0000
This is a MIME encoded message
--matthew1082570695
Content-Type: text/plain
matthew Wed Apr 21 14:04:55 2004 EDT
Modified files:
/loncom/localize/localize newphrases.txt
/loncom/interface lonsearchcat.pm
Log:
Mostly interface changes and changes to translation strings.
Added &reset_timing, &time_left, and modified existing &update_seconds to
encapsulate the logic used to determine how long a search takes and when
to output an update to the search time counter. This makes &run_search
a little easier to digest.
&prev_next_buttons: reworked logic.
&display_results: Changed refresh from 1 second to 2 seconds.
--matthew1082570695
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040421140455.txt"
Index: loncom/localize/localize/newphrases.txt
diff -u loncom/localize/localize/newphrases.txt:1.47 loncom/localize/localize/newphrases.txt:1.48
--- loncom/localize/localize/newphrases.txt:1.47 Tue Apr 20 02:12:58 2004
+++ loncom/localize/localize/newphrases.txt Wed Apr 21 14:04:55 2004
@@ -90,3 +90,18 @@
The question can not be gotten correct, the following foils in the <optionresponse> have invalid correct options
#_1 is the foil name, _2 is the current value of the foil
[_1] with value [_2]
+
+# _1 is a selection dialog
+[_1] Records per Page
+# _1 is search string
+Search: [_1]
+# _1 is a server name
+contacting [_1]
+waiting on [_1]
+Receiving results from [_1]
+Reading results from [_1]
+Search Complete [_1]
+# _1, _3, and _5 are link anchors, _2,_4, and _6 are '</a>'
+[_1]prev[_2] [_3]reload[_4] [_5]next[_6]
+prev [_3]reload[_4] [_5]next[_6]
+[_1]prev[_2] [_3]reload[_4] next
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.213 loncom/interface/lonsearchcat.pm:1.214
--- loncom/interface/lonsearchcat.pm:1.213 Wed Apr 21 11:48:34 2004
+++ loncom/interface/lonsearchcat.pm Wed Apr 21 14:04:55 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.213 2004/04/21 15:48:34 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.214 2004/04/21 18:04:55 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -830,11 +830,12 @@
\&viewoptiontext,
sort(keys(%Views)));
$scrout.= ' ';
- $scrout.=&Apache::lonmeta::selectbox('show',
- $ENV{'form.show'},
- undef,
- (10,20,50,100,1000,10000));
- $scrout .= (' 'x2).&mt('Records per Page').'</nobr>'.$/;
+ my $countselect = &Apache::lonmeta::selectbox('show',
+ $ENV{'form.show'},
+ undef,
+ (10,20,50,100,1000,10000));
+ $scrout .= (' 'x2).&mt('[_1] Records per Page',$countselect).
+ '</nobr>'.$/;
return $scrout;
}
@@ -1801,12 +1802,39 @@
$r->rflush();
}
+{
+ my $max_time = 40; # seconds for the search to complete
+ my $start_time = 0;
+ my $last_time = 0;
+
+sub reset_timing {
+ $start_time = 0;
+ $last_time = 0;
+}
+
+sub time_left {
+ if ($start_time == 0) {
+ $start_time = time;
+ }
+ my $time_left = $max_time - (time - $start_time);
+ $time_left = 0 if ($time_left < 0);
+ return $time_left;
+}
+
sub update_seconds {
- my ($r,$text) = @_;
- $text =~ s/\'/\\\'/g;
- $r->print
- ("<script>document.statusform.seconds.value = ' $text'</script>\n");
- $r->rflush();
+ my ($r) = @_;
+ my $time = &time_left();
+ if (($last_time-$time) > 0) {
+ &Apache::lonnet::logthis('time left = '.$time.' last time = '.$time);
+ &Apache::lonnet::logthis('updating time');
+ $r->print("<script>".
+ "document.statusform.seconds.value = '$time'".
+ "</script>\n");
+ $r->rflush();
+ }
+ $last_time = $time;
+}
+
}
######################################################################
@@ -1855,11 +1883,6 @@
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
my $connection = $r->connection;
#
- # Timing variables
- #
- my $starttime = time;
- my $max_time = 30; # seconds for the search to complete
- #
# Print run_search header
#
$r->print(<<END);
@@ -1876,7 +1899,7 @@
if (@Lines > 2) {
$pretty_string = join '<br \>',(@Lines[0..2],'....<br />');
}
- $r->print(&mt("Search").": ".$pretty_string);
+ $r->print(&mt("Search: [_1]",$pretty_string));
$r->rflush();
#
# Determine the servers we need to contact.
@@ -1891,6 +1914,8 @@
@Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
}
my %Server_status;
+ #
+ # Check on the mysql table we will use to store results.
my $table =$ENV{'form.table'};
if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
$r->print("Unable to determine table id to store search results in.".
@@ -1935,20 +1960,18 @@
</form>
END
$r->rflush();
- my $time_remaining = $max_time - (time - $starttime) ;
- $time_remaining = 0 if ($time_remaining <0);
- my $last_time = $time_remaining;
- &update_seconds($r,$time_remaining);
- &update_status($r,'contacting '.$Servers_to_contact[0]);
- while (($time_remaining > 0) &&
+ &reset_timing();
+ &update_seconds($r);
+ &update_status($r,&mt('contacting [_1]',$Servers_to_contact[0]));
+ while (&time_left() &&
((@Servers_to_contact) || keys(%Server_status))) {
- $time_remaining = $max_time - (time - $starttime) ;
- &update_seconds($r,$time_remaining);
- # Send out a search request if it needs to be done.
+ &update_seconds($r);
+ #
+ # Send out a search request
if (@Servers_to_contact) {
# Contact one server
my $server = shift(@Servers_to_contact);
- &update_status($r,&mt('contacting').' '.$server);
+ &update_status($r,&mt('contacting [_1]',$server));
my $reply=&Apache::lonnet::metadata_query($query,$customquery,
$customshow,[$server]);
($server) = keys(%$reply);
@@ -1960,7 +1983,7 @@
# left to contact.
if (scalar (keys(%Server_status))) {
&update_status($r,
- &mt('waiting on').' '.(join(' ',keys(%Server_status))));
+ &mt('waiting on [_1]',join(' ',keys(%Server_status))));
}
sleep(1);
}
@@ -1969,12 +1992,7 @@
# have results from yet, looking for results.
while (my ($server,$status) = each(%Server_status)) {
last if ($connection->aborted());
- $time_remaining = $max_time - (time - $starttime) ;
- $time_remaining = 0 if ($time_remaining < 0);
- if ($last_time - $time_remaining > 0) {
- $last_time = $time_remaining;
- &update_seconds($r,$time_remaining);
- }
+ &update_seconds($r);
if ($status eq 'con_lost') {
delete ($Server_status{$server});
next;
@@ -1982,12 +2000,12 @@
$status=~/^([\.\w]+)$/;
my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1;
if (-e $datafile && ! -e "$datafile.end") {
- &update_status($r,&mt('Receiving results from').' '.$server);
+ &update_status($r,&mt('Receiving results from [_1]',$server));
next;
}
last if ($connection->aborted());
if (-e "$datafile.end") {
- &update_status($r,&mt('Reading results from').' '.$server);
+ &update_status($r,&mt('Reading results from [_1]',$server));
if (-z "$datafile") {
delete($Server_status{$server});
next;
@@ -2002,30 +2020,30 @@
# Read in the whole file.
while (my $result = <$fh>) {
last if ($connection->aborted());
- # handle custom fields? Someday we will!
+ #
+ # Records are stored one per line
chomp($result);
- next unless $result;
+ next if (! $result);
+ #
# Parse the result.
my %Fields = &parse_raw_result($result,$server);
$Fields{'hostname'} = $server;
+ #
+ # Skip based on copyright
next if (! ©right_check(\%Fields));
+ #
# Store the result in the mysql database
my $result = &Apache::lonmysql::store_row($table,\%Fields);
if (! defined($result)) {
$r->print(&Apache::lonmysql::get_error());
}
- # $r->print(&Apache::lonmysql::get_debug());
+ #
$hitcountsum ++;
- $time_remaining = $max_time - (time - $starttime) ;
- $time_remaining = 0 if ($time_remaining < 0);
- if ($last_time - $time_remaining > 0) {
- &update_seconds($r,$time_remaining);
- $last_time = $time_remaining;
- }
+ &update_seconds($r);
if ($hitcountsum % 50 == 0) {
&update_count_status($r,$hitcountsum);
}
- } # End of foreach (@results)
+ }
$fh->close();
# $server is only deleted if the results file has been
# found and (successfully) opened. This may be a bad idea.
@@ -2035,21 +2053,16 @@
&update_count_status($r,$hitcountsum);
}
last if ($connection->aborted());
- # Finished looping through the servers
- $starttime = time if (@Servers_to_contact);
- $time_remaining = $max_time - (time - $starttime) ;
- if ($last_time - $time_remaining > 0) {
- $last_time = $time_remaining;
- &update_seconds($r,$time_remaining);
- }
+ &update_seconds($r);
}
- &update_status($r,&mt('Search Complete').$server);
- &update_seconds($r,0);
+ &update_status($r,&mt('Search Complete [_1]',$server));
+ &update_seconds($r);
#
- &Apache::lonmysql::disconnect_from_db();
+ &Apache::lonmysql::disconnect_from_db(); # This is unneccessary
#
# We have run out of time or run out of servers to talk to and
- # results to get.
+ # results to get, so let the client know the top frame needs to be
+ # loaded from /adm/searchcat
$r->print("</body></html>");
if ($ENV{'form.catalogmode'} ne 'groupsearch') {
$r->print("<script>".
@@ -2077,37 +2090,32 @@
sub prev_next_buttons {
my ($current_min,$show,$total,$parms) = @_;
return '' if ($show eq 'all'); # No links if you get them all at once.
- my $links;
- ##
- ## Prev
+ #
+ # Create links
my $prev_min = $current_min - $show;
$prev_min = 1 if $prev_min < 1;
- if ($prev_min < $current_min) {
- $links .=
- qq{<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">}.
- &mt('prev').'</a>';
- } else {
- $links .= &mt('prev');
- }
- ##
- ## Pages.... Someday.
- ##
- $links .=
- qq{
- <a href="/adm/searchcat?$parms&start=$current_min&$show=$show">}.
- &mt('reload').'</a>';
- ##
- ## Next
+ my $prevlink =
+ qq{<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">};
+ #
my $next_min = $current_min + $show;
$next_min = $current_min if ($next_min > $total);
- if ($next_min != $current_min) {
- $links .=
- qq{
- <a href="/adm/searchcat?$parms&start=$next_min&show=$show">}.
- &mt('next').'</a>';
- } else {
- $links .= ' '.&mt('next');
- }
+ my $nextlink =
+ qq{<a href="/adm/searchcat?$parms&start=$next_min&show=$show">};
+ my $reloadlink =
+ qq{<a href="/adm/searchcat?$parms&start=$current_min&$show=$show">};
+ #
+ # Determine which parameters to pass
+ my $String = '[_1]prev[_2] [_3]reload[_4] [_5]next[_6]';
+ if ($prev_min == $current_min) {
+ $String =~ s:\[_[12]\]::g;
+ }
+ if ($next_min == $current_min) {
+ $String =~ s:\[_[56]\]::g;
+ }
+ my $links = &mt($String,
+ $prevlink, '</a>',
+ $reloadlink,'</a>',
+ $nextlink, '</a>');
return $links;
}
@@ -2192,7 +2200,7 @@
."</center>\n"
);
if ($total_results == 0) {
- $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="1">'.
+ $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2">'.
'<h3>'.&mt('There are currently no results').'.</h3>'.
"</form></body></html>");
return;
@@ -2218,7 +2226,6 @@
}
my $prefix=&catalogmode_output($Fields{'title'},$Fields{'url'},
$Fields{'id'},$checkbox_num++);
-
# Render the result into html
$output.= &$viewfunction($prefix,%Fields);
# Print them out as they come in.
--matthew1082570695--