freeside/FS/FS queue.pm,1.19,1.20 rate.pm,1.1,1.2 UID.pm,1.24,1.25
ivan
ivan at pouncequick.420.am
Thu Jan 27 02:21:24 PST 2005
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv11805/FS/FS
Modified Files:
queue.pm rate.pm UID.pm
Log Message:
DHTML progress bar for glacial rate adding and editing, closes: Bug#1100
Index: UID.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/UID.pm,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- UID.pm 25 Jun 2004 10:25:02 -0000 1.24
+++ UID.pm 27 Jan 2005 10:21:17 -0000 1.25
@@ -98,7 +98,7 @@
}
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";
}
Index: rate.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/rate.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rate.pm 20 Nov 2004 17:26:53 -0000 1.1
+++ rate.pm 27 Jan 2005 10:21:17 -0000 1.2
@@ -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 @@
}
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 @@
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 @@
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;
@@ -229,6 +296,120 @@
=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;
+ at 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
Index: queue.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/queue.pm,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- queue.pm 26 Nov 2004 09:39:52 -0000 1.19
+++ queue.pm 27 Jan 2005 10:21:17 -0000 1.20
@@ -3,7 +3,7 @@
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 @@
@EXPORT_OK = qw( joblisting );
$DEBUG = 0;
-#$DEBUG = 1;
$FS::UID::callback{'FS::queue'} = sub {
$conf = new FS::Conf;
@@ -305,6 +304,38 @@
$error = $job->delete;
return $error if $error
}
+}
+
+=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
More information about the freeside-commits
mailing list