From 3e529db79b64f6da698fbe25b037bc94e1b236ac Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Thu, 30 Aug 2012 18:41:14 -0400 Subject: [PATCH] Verification sorta works but doesn't report progress correctly Signed-off-by: Lebbeous Fogle-Weekley --- .../perlmods/lib/OpenILS/Application/URLVerify.pm | 50 +++++++++----- Open-ILS/src/templates/url_verify/select_urls.tt2 | 25 ++++--- .../web/js/dojo/openils/URLVerify/SelectURLs.js | 79 +++++++++++++++++++--- .../web/js/dojo/openils/URLVerify/nls/URLVerify.js | 8 ++- 4 files changed, 125 insertions(+), 37 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm index ebe79ead20..7fbe2d628a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm @@ -19,8 +19,8 @@ my $U = 'OpenILS::Application::AppUtils'; __PACKAGE__->register_method( - method => 'validate_session', - api_name => 'open-ils.url_verify.session.validate', + method => 'verify_session', + api_name => 'open-ils.url_verify.session.verify', stream => 1, signature => { desc => q/ @@ -29,7 +29,7 @@ __PACKAGE__->register_method( params => [ {desc => 'Authentication token', type => 'string'}, {desc => 'Session ID (url_verify.session.id)', type => 'number'}, - {desc => 'URL ID list (optional). An empty list will result in no URLs being processed', type => 'array'}, + {desc => 'URL ID list (optional). An empty list will result in no URLs being processed, but null will result in all the URLs for the session being processed', type => 'array'}, { desc => q/ Options (optional). @@ -58,10 +58,10 @@ __PACKAGE__->register_method( } ); -# "validate_session" sounds like something to do with authentication, but it -# actually means for a given session, validate all the URLs associated with +# "verify_session" sounds like something to do with authentication, but it +# actually means for a given session, verify all the URLs associated with # that session. -sub validate_session { +sub verify_session { my ($self, $client, $auth, $session_id, $url_ids, $options) = @_; $options ||= {}; @@ -152,6 +152,7 @@ sub validate_session { $e->create_url_verify_verification_attempt($attempt) or return $e->die_event; + $attempt = $e->data; $e->commit; } @@ -163,7 +164,8 @@ sub validate_session { $session->owning_lib, 'url_verify.verification_batch_size', $e) || 5; - my $num_processed = 0; # total number processed, including redirects + my $total_excluding_redirects = 0; + my $total_processed = 0; # total number processed, including redirects my $resp_window = 1; # before we start the real work, let the caller know @@ -171,7 +173,8 @@ sub validate_session { $client->respond({ url_count => $url_count, - total_processed => $num_processed, + total_processed => $total_processed, + total_excluding_redirects => $total_excluding_redirects, attempt => $attempt }); @@ -191,19 +194,20 @@ sub validate_session { if ($content) { - $num_processed++; + $total_processed++; - if ($options->{report_all} or ($num_processed % $resp_window == 0)) { + if ($options->{report_all} or ($total_processed % $resp_window == 0)) { $client->respond({ url_count => $url_count, current_verification => $content, - total_processed => $num_processed + total_excluding_redirects => $total_excluding_redirects, + total_processed => $total_processed }); } # start off responding quickly, then throttle # back to only relaying every 256 messages. - $resp_window *= 2 unless $resp_window == 256; + $resp_window *= 2 unless $resp_window >= 256; } } }, @@ -216,7 +220,9 @@ sub validate_session { } ); - sort_and_fire_domains($e, $auth, $attempt, $url_ids, $multises); + sort_and_fire_domains( + $e, $auth, $attempt, $url_ids, $multises, \$total_excluding_redirects + ); # Wait for all requests to be completed $multises->session_wait(1); @@ -225,12 +231,22 @@ sub validate_session { $attempt->finish_time('now'); $e->xact_begin; - $e->update_url_verify_verification_attempt($attempt) or return $e->die_event; + $e->update_url_verify_verification_attempt($attempt) or + return $e->die_event; + $e->xact_commit; + # This way the caller gets an actual timestamp in the "finish_time" field + # instead of the string "now". + $attempt = $e->retrieve_url_verify_verification_attempt($e->data) or + return $e->die_event; + + $e->disconnect; + return { url_count => $url_count, - total_processed => $num_processed, + total_processed => $total_processed, + total_excluding_redirects => $total_excluding_redirects, attempt => $attempt }; } @@ -244,7 +260,7 @@ sub validate_session { # # * local data structures, not container.* buckets sub sort_and_fire_domains { - my ($e, $auth, $attempt, $url_ids, $multises) = @_; + my ($e, $auth, $attempt, $url_ids, $multises, $count) = @_; # there is potential here for data sets to be too large # for delivery, but it's not likely, since we're only @@ -275,6 +291,8 @@ sub sort_and_fire_domains { $multises->request( 'open-ils.url_verify.verify_url', $auth, $attempt->id, $url_id); + + $$count++; # sic, a reference to a scalar } } } diff --git a/Open-ILS/src/templates/url_verify/select_urls.tt2 b/Open-ILS/src/templates/url_verify/select_urls.tt2 index 4c79124b62..b3985d95ef 100644 --- a/Open-ILS/src/templates/url_verify/select_urls.tt2 +++ b/Open-ILS/src/templates/url_verify/select_urls.tt2 @@ -3,6 +3,7 @@ +
[% ctx.page_title %]
- +
+
+
+
+
@@ -58,4 +60,7 @@
+ [% END %] diff --git a/Open-ILS/web/js/dojo/openils/URLVerify/SelectURLs.js b/Open-ILS/web/js/dojo/openils/URLVerify/SelectURLs.js index e1c4938ff5..b8992ac3f8 100644 --- a/Open-ILS/web/js/dojo/openils/URLVerify/SelectURLs.js +++ b/Open-ILS/web/js/dojo/openils/URLVerify/SelectURLs.js @@ -1,5 +1,7 @@ if (!dojo._hasResource["openils.URLVerify.SelectURLs"]) { + dojo.require("dojo.string"); dojo.require("openils.CGI"); + dojo.require("openils.Util"); dojo.requireLocalization("openils.URLVerify", "URLVerify"); @@ -17,29 +19,86 @@ if (!dojo._hasResource["openils.URLVerify.SelectURLs"]) { var localeStrings = dojo.i18n.getLocalization("openils.URLVerify", "URLVerify"); - module.setup = function(grid) { + module.setup = function(grid, progress_dialog) { var cgi = new openils.CGI(); + module.session_id = cgi.param("session_id"); + module.grid = grid; - module.grid.attr("query", {"session_id": cgi.param("session_id")}); + module.grid.attr("query", {"session_id": module.session_id}); module.grid.refresh(); // Alternative to grid.refresh() once filter is set up //module.grid.fetchLock = false; //module.grid.filterUi.doApply(); }; - module.validate_selected = function() { - if (module.grid.everythingSeemsSelected()) { - if (confirm(localeStrings.VALIDATE_ALL)) { - return module.validate_all(); + module.verify_selected = function() { + var really_everything = false; + + if (module.grid.everythingSeemsSelected()) + really_everything = confirm(localeStrings.VERIFY_ALL); + + module.clear_attempt_display(); + progress_dialog.attr("title", localeStrings.VERIFICATION_BEGIN); + progress_dialog.show(); + + fieldmapper.standardRequest( + ["open-ils.url_verify", "open-ils.url_verify.session.verify"], { + "params": [ + openils.User.authtoken, + module.session_id, + really_everything ? null : module.grid.getSelectedIDs() + ], + "async": true, + "onresponse": function(r) { + if (r = openils.Util.readResponse(r)) { + progress_dialog.attr( + "title", + dojo.string.substitute( + localeStrings.VERIFICATION_PROGRESS, + [r.total_processed] + ) + ); + progress_dialog.update({ + "maximum": r.url_count, + "progress": r.total_excluding_redirects + }); + + if (r.attempt) + module.update_attempt_display(r.attempt); + } + } } - } + ) + + module.grid.getSelectedIDs(); + }; - console.info("module.validate_selected() sees IDs: " + dojo.toJson(module.grid.getSelectedIDs())); + module.clear_attempt_display = function() { + dojo.empty(dojo.byId("url-verify-attempt-id")); + dojo.empty(dojo.byId("url-verify-attempt-start")); + dojo.empty(dojo.byId("url-verify-attempt-finish")); }; - module.validate_all = function() { - console.info("module.validate_all() called"); + module.update_attempt_display = function(attempt) { + dojo.byId("url-verify-attempt-id").innerHTML = + dojo.string.substitute( + localeStrings.VERIFICATION_ATTEMPT_ID, + [attempt.id()] + ); + dojo.byId("url-verify-attempt-start").innerHTML = + dojo.string.substitute( + localeStrings.VERIFICATION_ATTEMPT_START, + [attempt.start_time()] + ); + + if (attempt.finish_time()) { + dojo.byId("url-verify-attempt-finish").innerHTML = + dojo.string.substitute( + localeStrings.VERIFICATION_ATTEMPT_FINISH, + [attempt.finish_time()] + ); + } }; }()); diff --git a/Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js b/Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js index 5b00a3e6e4..d0b6f3de7d 100644 --- a/Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js +++ b/Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js @@ -5,5 +5,11 @@ "EXTRACTING_URLS": "Extracting URLs ...", "NEED_UVUS": "You must add some tag and subfield combinations", "REDIRECTING": "Loading next interface ...", - "INTERFACE_SETUP": "Setting up interface ..." + "INTERFACE_SETUP": "Setting up interface ...", + "VERIFY_ALL": "Click 'OK' to verify ALL the URLs found in this session. Click 'Cancel' if the selected, visible URLs are the only ones you want verified.", + "VERIFICATION_BEGIN": "Verifying URLs. This can take a moment ...", + "VERIFICATION_PROGRESS": "Verifying URLs: ${0} URLs processed ...", + "VERIFICATION_ATTEMPT_ID": "Last verification attempt ID: ${0}", + "VERIFICATION_ATTEMPT_START": "Attempt start time: ${0}", + "VERIFICATION_ATTEMPT_FINISH": "Attempt finish time: ${0}" } -- 2.11.0