[Koha-patches] [PATCH] bug 5309: Adjust progres bar

Robin Sheat robin at catalyst.net.nz
Fri Oct 15 02:53:11 CEST 2010


From: Srdjan Jankovic <srdjan at catalyst.net.nz>

Also added some test facilities
wr73785
---
 .../prog/en/includes/background-job.inc            |    4 +-
 .../intranet-tmpl/prog/en/modules/test/README      |    1 +
 .../prog/en/modules/test/progressbar.tmpl          |   43 ++++++++
 test/README                                        |    3 +
 test/progressbar.pl                                |   55 ++++++++++
 test/progressbarsubmit.pl                          |  104 ++++++++++++++++++++
 test/search.pl                                     |   74 ++++++++++++++
 7 files changed, 282 insertions(+), 2 deletions(-)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/test/README
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/test/progressbar.tmpl
 create mode 100644 test/README
 create mode 100755 test/progressbar.pl
 create mode 100755 test/progressbarsubmit.pl
 create mode 100755 test/search.pl

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc
index 9d257f4..ff37876 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc
@@ -15,7 +15,7 @@
             if (json.job_status == 'completed') {
                 percentage = 100;
             }
-				var bgproperty = (parseInt(percentage)*2-300)+"px 0px";
+				var bgproperty = (parseInt(percentage/2)*3-300)+"px 0px";
                 $("#jobprogress").css("background-position",bgproperty);
 				$("#jobprogresspercent").text(percentage);
 
@@ -66,7 +66,7 @@
                 data: inputs.join('&'),
                 url: f.action,
                 dataType: 'json',
-		type: 'post',
+		        type: 'post',
                 success: function(json) {
                     jobID = json.jobID;
                     inBackgroundJobProgressTimer = false;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/test/README b/koha-tmpl/intranet-tmpl/prog/en/modules/test/README
new file mode 100644
index 0000000..20fe504
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/test/README
@@ -0,0 +1 @@
+Test templates, to be used with test scripts
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/test/progressbar.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/test/progressbar.tmpl
new file mode 100644
index 0000000..73f148f
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/test/progressbar.tmpl
@@ -0,0 +1,43 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha &rsaquo; Tools &rsaquo; Stage MARC Records For Import</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<!-- TMPL_INCLUDE NAME="file-upload.inc" -->
+<!-- TMPL_INCLUDE NAME="background-job.inc" -->
+<style type="text/css">
+	#uploadpanel,#fileuploadstatus,#fileuploadfailed,#jobpanel,#jobstatus,#jobfailed { display : none; }
+	#fileuploadstatus,#jobstatus { margin:.4em; }
+	#fileuploadprogress,#jobprogress{ width:150px;height:10px;border:1px solid #666;background:url('/intranet-tmpl/prog/img/progress.png') -300px 0px no-repeat; }</style>
+<script type="text/javascript">
+//<![CDATA[
+$(document).ready(function(){
+});
+function CheckForm(f) {
+    submitBackgroundJob(f);
+    return false;
+}
+
+//]]>
+</script>
+</head>
+<body>
+<div id="doc3" class="yui-t2">
+   
+<form method="post" action="progressbarsubmit.pl">
+<input type="hidden" name="submitted" id="submitted" value="1" />
+<input type="hidden" name="runinbackground" id="runinbackground" value="" />
+<input type="hidden" name="completedJobID" id="completedJobID" value="" />
+
+<input type="button" id="mainformsubmit" onclick="return CheckForm(this.form);" value="Start" />
+ 
+       <div id="jobpanel">
+           <div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
+           <div id="jobfailed"></div>
+       </div>
+  
+</form>
+</div>
+
+<div>
+Completed: <span id="completed"><!-- TMPL_VAR NAME="completedJobID" --> </span>
+</div>
+</body>
diff --git a/test/README b/test/README
new file mode 100644
index 0000000..fe2895c
--- /dev/null
+++ b/test/README
@@ -0,0 +1,3 @@
+A collection of cgi and command line scripts that are useful for some testing,
+but for one reason or another cannot be made into automated test in t.
+Use with templates in koha-tmpl/intranet-tmpl/prog/en/modules/test
diff --git a/test/progressbar.pl b/test/progressbar.pl
new file mode 100755
index 0000000..142184b
--- /dev/null
+++ b/test/progressbar.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+
+# Script for testing progressbar, part 1 - initial screem
+# it is split into two scripts so we can use firebug to debug it
+
+# Koha library project  www.koha.org
+
+# Licensed under the GPL
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use strict;
+#use warnings; FIXME - Bug 2505
+
+# standard or CPAN modules used
+use CGI;
+use CGI::Cookie;
+
+# Koha modules used
+use C4::Context;
+use C4::Auth;
+use C4::Output;
+use C4::BackgroundJob;
+
+my $input = new CGI;
+my $dbh = C4::Context->dbh;
+$dbh->{AutoCommit} = 0;
+
+my ($template, $loggedinuser, $cookie)
+	= get_template_and_user({template_name => "test/progressbar.tmpl",
+					query => $input,
+					type => "intranet",
+					debug => 1,
+					});
+
+output_html_with_http_headers $input, $cookie, $template->output;
+
+exit 0;
+
+
diff --git a/test/progressbarsubmit.pl b/test/progressbarsubmit.pl
new file mode 100755
index 0000000..a0dbde1
--- /dev/null
+++ b/test/progressbarsubmit.pl
@@ -0,0 +1,104 @@
+#!/usr/bin/perl
+
+# Script for testing progressbar, part 2 - json submit handler
+#   and Z39.50 lookups
+
+# Koha library project  www.koha.org
+
+# Licensed under the GPL
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use strict;
+#use warnings; FIXME - Bug 2505
+
+# standard or CPAN modules used
+use CGI;
+use CGI::Cookie;
+
+# Koha modules used
+use C4::Context;
+use C4::Auth;
+use C4::Output;
+use C4::BackgroundJob;
+
+my $input = new CGI;
+
+my $submitted=$input->param('submitted');
+my $runinbackground = $input->param('runinbackground');
+my $jobID = $input->param('jobID');
+my $completedJobID = $input->param('completedJobID');
+
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "test/progressbar.tmpl",
+                    query => $input,
+                    type => "intranet",
+                    debug => 1,
+                    });
+
+my %cookies = parse CGI::Cookie($cookie);
+my $sessionID = $cookies{'CGISESSID'}->value;
+if ($completedJobID) {
+} elsif ($submitted) {
+    my $job = undef;
+    if ($runinbackground) {
+        my $job_size = 100;
+        $job = C4::BackgroundJob->new($sessionID, undef, $ENV{'SCRIPT_NAME'}, $job_size);
+        $jobID = $job->id();
+
+        # fork off
+        if (my $pid = fork) {
+            # parent
+            # return job ID as JSON
+            
+            # prevent parent exiting from
+            # destroying the kid's database handle
+            # FIXME: according to DBI doc, this may not work for Oracle
+
+            my $reply = CGI->new("");
+            print $reply->header(-type => 'text/html');
+            print "{ jobID: '$jobID' }";
+            exit 0;
+        } elsif (defined $pid) {
+        # if we get here, we're a child that has detached
+        # itself from Apache
+
+            # close STDOUT to signal to Apache that
+            # we're now running in the background
+            close STDOUT;
+            close STDERR;
+
+            foreach (1..100) {
+                sleep 1;
+                $job->progress( $_ );
+            }
+            $job->finish();
+        } else {
+            # fork failed, so exit immediately
+            die "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
+        }
+
+    }
+} else {
+    # initial form
+    die "We should not be here";
+}
+
+exit 0;
+
+
diff --git a/test/search.pl b/test/search.pl
new file mode 100755
index 0000000..4362791
--- /dev/null
+++ b/test/search.pl
@@ -0,0 +1,74 @@
+#!/usr/bin/perl -w
+
+use C4::Search;
+
+my @SEARCH = (
+    { operators => [
+          'and',
+          'and'
+      ],
+      operands => [
+          'shakespeare, "(william)"',
+          'dream'
+      ],
+      indexes => [
+          'au,wrdl',
+          'ti',
+          'kw'
+      ],
+      limits => [
+          'yr,st-numeric=2000-'
+      ],
+      sort_by => [
+          'relevance'
+      ],
+      lang => 'en',
+    },
+);
+
+
+foreach ( @SEARCH ) {
+    my ($expected, @mismatch);
+    my( $error,
+        $query,
+        $simple_query,
+        $query_cgi,
+        $query_desc,
+        $limit,
+        $limit_cgi,
+        $limit_desc,
+        $stopwords_removed,
+        $query_type )
+      = buildQuery( $_->{operators}, $_->{operands}, $_->{indexes}, $_->{limits}, $_->{sort_by}, 0,  $_->{lang} );
+
+    die $error if $error;
+
+    $expected = $_->{query};
+    push @mismatch, "Query: $query (not: $expected)" unless $query eq $expected;
+
+    $expected = $_->{simple_query};
+    push @mismatch, "Simple Query: $simple_query (not: $expected)" unless $simple_query eq $expected;
+
+    $expected = $_->{query_cgi};
+    push @mismatch, "Query CGI: $query_cgi (not: $expected)" unless $query_cgi eq $expected;
+
+    $expected = $_->{query_desc};
+    push @mismatch, "Query desc: $query_desc (not: $expected)" unless $query_desc eq $expected;
+
+    $expected = $_->{limit};
+    push @mismatch, "Limit: $limit (not: $expected)" unless $limit eq $expected;
+
+    $expected = $_->{limit_cgi};
+    push @mismatch, "Limit CGI: $limit_cgi (not: $expected)" unless $limit_cgi eq $expected;
+
+    $expected = $_->{limit_desc};
+    push @mismatch, "Limit desc: $limit_desc (not: $expected)" unless $limit_desc eq $expected;
+
+    $expected = $_->{stopwords_removed};
+    push @mismatch, "Stopwords removed: $stopwords_removed (not: $expected)" unless $stopwords_removed eq $expected;
+
+    $expected = $_->{query_type};
+    push @mismatch, "Query Type: $query_type (not: $expected)" unless $query_type eq $expected;
+
+    die map "$_\n", @mismatch if @mismatch;
+}
-- 
1.7.1



More information about the Koha-patches mailing list