From: ivan
Date: Thu, 27 Jan 2005 10:21:18 +0000 (+0000)
Subject: DHTML progress bar for glacial rate adding and editing, closes: Bug#1100
X-Git-Tag: BEFORE_FINAL_MASONIZE~728
X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=6cf964d0dc008621fb30fd2da28e2c44f29c6364;hp=e4ae5122522f2d45c68a38eaef337a82029f2fc1
DHTML progress bar for glacial rate adding and editing, closes: Bug#1100
---
diff --git a/CREDITS b/CREDITS
index 59edea610..02dd9a80c 100644
--- a/CREDITS
+++ b/CREDITS
@@ -113,7 +113,7 @@ Infostreet export.
Richard Siddall sent in Mason fixes and other
things I'm probably forgetting.
-Contains "JS Calendar" v0.9.3
+Contains "JS Calendar"
by Mihai Bazon licensed under the terms of the GNU LGPL.
Latex invoice template based on a template from eBills
@@ -137,5 +137,13 @@ released with 1.4.2beta1 and 1.5.0pre6.
Troy Hammonds sent in RADIUS session history viewing
code and other things I'm probably forgetting.
+Contains the "Javascript Remote Scripting (JSRS)" client library
+ by Brent Ashley
+licensed under the "No Nonsense Copyright and License" (see the included
+JSRS-LICENSE file).
+
+Contains the QLIB JavaScript library by
+Quazzle.com, Serge Dolgov, licensed under the terms of the GNU GPL.
+
Everything else is my (Ivan Kohler ) fault.
diff --git a/FS/FS/UID.pm b/FS/FS/UID.pm
index 3d893ee2f..c0c9f7af4 100644
--- a/FS/FS/UID.pm
+++ b/FS/FS/UID.pm
@@ -98,7 +98,7 @@ sub forksuidsetup {
}
sub myconnect {
- $dbh = DBI->connect( getsecrets, {'AutoCommit' => 0, 'ChopBlanks' => 1, } )
+ DBI->connect( getsecrets, {'AutoCommit' => 0, 'ChopBlanks' => 1, } )
or die "DBI->connect error: $DBI::errstr\n";
}
diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm
index dcac3c62b..f42d99837 100644
--- a/FS/FS/queue.pm
+++ b/FS/FS/queue.pm
@@ -3,7 +3,7 @@ package FS::queue;
use strict;
use vars qw( @ISA @EXPORT_OK $DEBUG $conf $jobnums);
use Exporter;
-use FS::UID;
+use FS::UID qw(myconnect);
use FS::Conf;
use FS::Record qw( qsearch qsearchs dbh );
#use FS::queue;
@@ -15,7 +15,6 @@ use FS::cust_svc;
@EXPORT_OK = qw( joblisting );
$DEBUG = 0;
-#$DEBUG = 1;
$FS::UID::callback{'FS::queue'} = sub {
$conf = new FS::Conf;
@@ -307,6 +306,38 @@ sub depended_delete {
}
}
+=item update_statustext VALUE
+
+Updates the statustext value of this job to supplied value, in the database.
+If there is an error, returns the error, otherwise returns false.
+
+=cut
+
+use vars qw($_update_statustext_dbh);
+sub update_statustext {
+ my( $self, $statustext ) = @_;
+ return '' if $statustext eq $self->statustext;
+ warn "updating statustext for $self to $statustext" if $DEBUG;
+
+ $_update_statustext_dbh ||= myconnect;
+
+ my $sth = $_update_statustext_dbh->prepare(
+ 'UPDATE queue set statustext = ? WHERE jobnum = ?'
+ ) or return $_update_statustext_dbh->errstr;
+
+ $sth->execute($statustext, $self->jobnum) or return $sth->errstr;
+ $_update_statustext_dbh->commit or die $_update_statustext_dbh->errstr;
+ $self->statustext($statustext);
+ '';
+
+ #my $new = new FS::queue { $self->hash };
+ #$new->statustext($statustext);
+ #my $error = $new->replace($self);
+ #return $error if $error;
+ #$self->statustext($statustext);
+ #'';
+}
+
=back
=head1 SUBROUTINES
diff --git a/FS/FS/rate.pm b/FS/FS/rate.pm
index b8a694041..7f625a6b1 100644
--- a/FS/FS/rate.pm
+++ b/FS/FS/rate.pm
@@ -1,12 +1,14 @@
package FS::rate;
use strict;
-use vars qw( @ISA );
-use FS::Record qw( qsearch qsearchs dbh );
+use vars qw( @ISA $DEBUG );
+use FS::Record qw( qsearch qsearchs dbh fields );
use FS::rate_detail;
@ISA = qw(FS::Record);
+$DEBUG = 1;
+
=head1 NAME
FS::rate - Object methods for rate records
@@ -94,13 +96,32 @@ sub insert {
}
if ( $options{'rate_detail'} ) {
+
+ my( $num, $last, $min_sec ) = (0, time, 5); #progressbar foo
+
foreach my $rate_detail ( @{$options{'rate_detail'}} ) {
+
$rate_detail->ratenum($self->ratenum);
$error = $rate_detail->insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
+
+ if ( $options{'job'} ) {
+ $num++;
+ if ( time - $min_sec > $last ) {
+ my $error = $options{'job'}->update_statustext(
+ int( 100 * $num / scalar( @{$options{'rate_detail'}} ) )
+ );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $last = time;
+ }
+ }
+
}
}
@@ -148,8 +169,8 @@ sub replace {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my @old_rate_detail = ();
- @old_rate_detail = $old->rate_detail if $options{'rate_detail'};
+# my @old_rate_detail = ();
+# @old_rate_detail = $old->rate_detail if $options{'rate_detail'};
my $error = $new->SUPER::replace($old);
if ($error) {
@@ -157,21 +178,67 @@ sub replace {
return $error;
}
- foreach my $old_rate_detail ( @old_rate_detail ) {
- my $error = $old_rate_detail->delete;
- if ($error) {
+# foreach my $old_rate_detail ( @old_rate_detail ) {
+#
+# my $error = $old_rate_detail->delete;
+# if ($error) {
+# $dbh->rollback if $oldAutoCommit;
+# return $error;
+# }
+#
+# if ( $options{'job'} ) {
+# $num++;
+# if ( time - $min_sec > $last ) {
+# my $error = $options{'job'}->update_statustext(
+# int( 50 * $num / scalar( @old_rate_detail ) )
+# );
+# if ( $error ) {
+# $dbh->rollback if $oldAutoCommit;
+# return $error;
+# }
+# $last = time;
+# }
+# }
+#
+# }
+ if ( $options{'rate_detail'} ) {
+ my $sth = $dbh->prepare('DELETE FROM rate_detail WHERE ratenum = ?') or do {
$dbh->rollback if $oldAutoCommit;
- return $error;
- }
- }
-
- foreach my $rate_detail ( @{$options{'rate_detail'}} ) {
- $rate_detail->ratenum($new->ratenum);
- $error = $rate_detail->insert;
- if ( $error ) {
+ return $dbh->errstr;
+ };
+
+ $sth->execute($old->ratenum) or do {
$dbh->rollback if $oldAutoCommit;
- return $error;
+ return $sth->errstr;
+ };
+
+ my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo
+# $num = 0;
+ foreach my $rate_detail ( @{$options{'rate_detail'}} ) {
+
+ $rate_detail->ratenum($new->ratenum);
+ $error = $rate_detail->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ if ( $options{'job'} ) {
+ $num++;
+ if ( time - $min_sec > $last ) {
+ my $error = $options{'job'}->update_statustext(
+ int( 100 * $num / scalar( @{$options{'rate_detail'}} ) )
+ );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $last = time;
+ }
+ }
+
}
+
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -230,6 +297,120 @@ sub rate_detail {
=back
+=head1 SUBROUTINES
+
+=over 4
+
+=item process
+
+Experimental job-queue processor for web interface adds/edits
+
+=cut
+
+sub process {
+ my $job = shift;
+
+ #my %param = @_;
+
+ my $param = shift;
+ my %param = split(/[;=]/, $param);
+
+ my $old = qsearchs('rate', { 'ratenum' => $param{'ratenum'} } )
+ if $param{'ratenum'};
+
+ my @rate_detail = map {
+
+ my $regionnum = $_->regionnum;
+ if ( $param{"sec_granularity$regionnum"} ) {
+
+ new FS::rate_detail {
+ 'dest_regionnum' => $regionnum,
+ map { $_ => $param{"$_$regionnum"} }
+ qw( min_included min_charge sec_granularity )
+ };
+
+ } else {
+
+ new FS::rate_detail {
+ 'dest_regionnum' => $regionnum,
+ 'min_included' => 0,
+ 'min_charge' => 0,
+ 'sec_granularity' => '60'
+ };
+
+ }
+
+ } qsearch('rate_region', {} );
+
+ my $rate = new FS::rate {
+ map { $_ => $param{$_} }
+ fields('rate')
+ };
+
+ my $error = '';
+ if ( $param{'ratenum'} ) {
+ warn "$rate replacing $old ($param{'ratenum'})\n" if $DEBUG;
+ $error = $rate->replace( $old,
+ 'rate_detail' => \@rate_detail,
+ 'job' => $job,
+ );
+ } else {
+ warn "inserting $rate\n" if $DEBUG;
+ $error = $rate->insert( 'rate_detail' => \@rate_detail,
+ 'job' => $job,
+ );
+ #$ratenum = $rate->getfield('ratenum');
+ }
+
+ die $error if $error;
+
+}
+
+# begin JSRPC code...
+
+package FS::rate::JSRPC;
+use vars qw(@ISA $DEBUG);
+use JavaScript::RPC::Server::CGI;
+use FS::UID;
+@ISA = qw( JavaScript::RPC::Server::CGI );
+$DEBUG = 1;
+
+sub process_rate {
+ my $self = shift;
+
+ my %param = @_;
+ warn "FS::rate::JSRPC::process_rate\n".
+ join('', map " $_ => $param{$_}\n", keys %param )
+ if $DEBUG;
+
+ #progressbar prototype code... should be generalized
+
+ #first get the CGI params shipped off to a job ASAP so an id can be returned
+ #to the caller
+
+ my $job = new FS::queue { 'job' => 'FS::rate::process' };
+
+ #too slow to insert all the cgi params as individual args..,?
+ #my $error = $queue->insert('_JOB', $cgi->Vars);
+
+ #my $bigstring = join(';', map { "$_=". scalar($cgi->param($_)) } $cgi->param );
+ my $bigstring = join(';', map { "$_=". $param{$_} } keys %param );
+ my $error = $job->insert('_JOB', $bigstring);
+
+ if ( $error ) {
+ $error;
+ } else {
+ $job->jobnum;
+ }
+
+}
+
+sub get_new_query {
+ FS::UID::cgi();
+}
+
+# end JSRPC code...
+
=head1 BUGS
=head1 SEE ALSO
diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued
index e14ddad8e..a3fb7e562 100644
--- a/FS/bin/freeside-queued
+++ b/FS/bin/freeside-queued
@@ -87,7 +87,7 @@ while (1) {
unless ( dbh && dbh->ping ) {
warn "WARNING: connection to database lost, reconnecting...\n";
- eval { myconnect; };
+ eval { $FS::UID::dbh = myconnect; };
unless ( !$@ && dbh && dbh->ping ) {
warn "WARNING: still no connection to database, sleeping for retry...\n";
@@ -162,6 +162,7 @@ while (1) {
#}
my @args = $ljob->args;
+ splice @args, 0, 1, $ljob if $args[0] eq '_JOB';
defined( my $pid = fork ) or do {
warn "WARNING: can't fork: $!\n";
@@ -184,8 +185,12 @@ while (1) {
forksuidsetup($user);
- #auto-use export classes...
- if ( $ljob->job =~ /(FS::part_export::\w+)::/ ) {
+ #auto-use classes...
+ #if ( $ljob->job =~ /(FS::part_export::\w+)::/ ) {
+ if ( $ljob->job =~ /(FS::part_export::\w+)::/
+ || $ljob->job =~ /(FS::\w+)::/
+ )
+ {
my $class = $1;
eval "use $class;";
if ( $@ ) {
diff --git a/JSRS-LICENSE b/JSRS-LICENSE
new file mode 100644
index 000000000..fd14984a9
--- /dev/null
+++ b/JSRS-LICENSE
@@ -0,0 +1,29 @@
+
+No Nonsense Copyright and License for JSRS JavaScript Remote Scripting
+======================================================================
+
+Copyright:
+
+This JSRS stuff was written by me. I find it useful. Others find it useful.
+You are welcome to use it, modify it to suit your needs, distribute it as you
+see fit. I'm happy if you use it for personal stuff or for commercial gain.
+
+The only thing you can't do is to restrict anyone else from using it however
+they see fit. You may not copyright it yourself or change the rules I have
+set on how it can be used.
+
+JSRS Javascript Remote Scripting Copyright (C) 2001 by Brent Ashley
+
+License:
+
+You can use this however you like. I make no guarantees whatsoever that it
+will suit your purpose. You take full responsibility for getting it working
+properly and for any implications of its failure or inability to satisfy your
+every need.
+
+======================================================================
+
+email inquiries: jsrs@megahuge.com
+
+
+
diff --git a/httemplate/docs/install.html b/httemplate/docs/install.html
index 86e2a6b8c..898eb9ef8 100644
--- a/httemplate/docs/install.html
+++ b/httemplate/docs/install.html
@@ -58,6 +58,7 @@ Before installing, you need:
NetAddr-IP
Chart
Crypt::PasswdMD5
+ JavaScript::RPC (JavaScript::RPC::Server::CGI)
Apache::DBI (optional but recommended for better webinterface performance)
diff --git a/httemplate/edit/process/rate.cgi b/httemplate/edit/process/rate.cgi
new file mode 100755
index 000000000..df7c4672e
--- /dev/null
+++ b/httemplate/edit/process/rate.cgi
@@ -0,0 +1,4 @@
+<%
+my $server = new FS::rate::JSRPC;
+$server->process;
+%>
diff --git a/httemplate/edit/rate.cgi b/httemplate/edit/rate.cgi
index 4a4b70ea3..3443f81d4 100644
--- a/httemplate/edit/rate.cgi
+++ b/httemplate/edit/rate.cgi
@@ -1,52 +1,7 @@
<%
-my($rate, $error);
-
-if ( $cgi->param('magic') eq 'process' ) {
-
- my $ratenum = $cgi->param('ratenum');
-
- my $old = qsearchs('rate', { 'ratenum' => $ratenum } ) if $ratenum;
-
- my @rate_detail = map {
- my $regionnum = $_->regionnum;
- if ( $cgi->param("sec_granularity$regionnum") ) {
- new FS::rate_detail {
- 'dest_regionnum' => $regionnum,
- map { $_ => scalar($cgi->param("$_$regionnum")) }
- qw( min_included min_charge sec_granularity )
- };
- } else {
- new FS::rate_detail {
- 'dest_regionnum' => $regionnum,
- 'min_included' => 0,
- 'min_charge' => 0,
- 'sec_granularity' => '60'
- };
- }
- } qsearch('rate_region', {} );
-
- $rate = new FS::rate ( {
- map {
- $_, scalar($cgi->param($_));
- } fields('rate')
- } );
-
- if ( $ratenum ) {
- warn "$rate replacing $old ($ratenum)\n";
- $error = $rate->replace($old, 'rate_detail' => \@rate_detail );
- } else {
- warn "inserting $rate\n";
- $error = $rate->insert( 'rate_detail' => \@rate_detail );
- $ratenum = $rate->getfield('ratenum');
- }
-
- unless ( $error ) {
- print $cgi->redirect("${p}browse/rate.cgi");
- myexit;
- }
-
-} elsif ( $cgi->keywords ) {
+my $rate;
+if ( $cgi->keywords ) {
my($query) = $cgi->keywords;
$query =~ /^(\d+)$/;
$rate = qsearchs( 'rate', { 'ratenum' => $1 } );
@@ -77,12 +32,41 @@ END
))
%>
-<% if ( $error ) { %>
-Error: <%= $error %>
-<% } %>
+
+
+
+
-
');
+ doc.write('