From 0b02b2b552e25fee6104de200af621275d209396 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 22 Feb 2012 13:14:13 -0500 Subject: [PATCH] TPac: Circulation history CSV export This adds a new "Download CSV" button to the TPac circulation history interface. The CSV is generated from a new Action/Trigger event definition. Signed-off-by: Bill Erickson Conflicts: Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm Open-ILS/src/sql/Pg/950.data.seed-values.sql Signed-off-by: Dan Scott --- .../perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 1 + .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 32 +++++++++-- .../lib/OpenILS/WWW/EGCatLoader/Util.pm | 13 +++++ Open-ILS/src/sql/Pg/950.data.seed-values.sql | 45 +++++++++++++++ .../XXXX.data.circ_history_export_csv.sql | 55 +++++++++++++++++++ .../templates/opac/myopac/circ_history.tt2 | 10 +++- .../opac/myopac/circ_history/export.tt2 | 1 + 7 files changed, 149 insertions(+), 8 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.circ_history_export_csv.sql create mode 100644 Open-ILS/src/templates/opac/myopac/circ_history/export.tt2 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 14e076032c..755f403485 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -155,6 +155,7 @@ sub load { return $self->load_myopac_bookbags if $path =~ m|opac/myopac/lists|; return $self->load_myopac_bookbag_print if $path =~ m|opac/myopac/list/print|; return $self->load_myopac_bookbag_update if $path =~ m|opac/myopac/list/update|; + return $self->load_myopac_circ_history_export if $path =~ m|opac/myopac/circ_history/export|; return $self->load_myopac_circ_history if $path =~ m|opac/myopac/circ_history|; return $self->load_myopac_hold_history if $path =~ m|opac/myopac/hold_history|; return $self->load_myopac_prefs_notify if $path =~ m|opac/myopac/prefs_notify|; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 378bfd565b..8e1e931bac 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1907,8 +1907,6 @@ sub update_bookbag_item_notes { sub load_myopac_bookbag_print { my ($self) = @_; - $self->apache->content_type("text/plain; encoding=utf8"); - my $id = int($self->cgi->param("list")); my ($sorter, $modifier) = $self->_get_bookbag_sort_params("sort"); @@ -1950,12 +1948,34 @@ sub load_myopac_bookbag_print { # provoke browser download dialogs. (my $filename = $bbag->id . $bbag->name) =~ s/[^a-z0-9_ -]//gi; - $self->apache->headers_out->add( - "Content-Disposition", - "attachment;filename=$filename.csv" + return $self->set_file_download_headers("$filename.csv"); +} + +sub load_myopac_circ_history_export { + my $self = shift; + my $e = $self->editor; + my $filename = $self->cgi->param('filename') || 'circ_history.csv'; + + my $ids = $e->json_query({ + select => { + au => [{ + column => 'id', + transform => 'action.usr_visible_circs', + result_field => 'id' + }] + }, + from => 'au', + where => {id => $e->requestor->id} + }); + + $self->ctx->{csv} = $U->fire_object_event( + undef, + 'circ.format.history.csv', + $e->search_action_circulation({id => [map {$_->{id}} @$ids]}, {substream =>1}), + $self->editor->requestor->home_ou ); - return Apache2::Const::OK; + return $self->set_file_download_headers($filename); } sub load_password_reset { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index e672eac1f7..b7c015b649 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -392,6 +392,19 @@ sub load_copy_location_groups { $ctx->{copy_location_groups} = \%buckets; } +sub set_file_download_headers { + my $self = shift; + my $filename = shift; + my $ctype = shift || "text/plain; encoding=utf8"; + + $self->apache->content_type($ctype); + $self->apache->headers_out->add( + "Content-Disposition", + "attachment;filename=$filename" + ); + + return Apache2::Const::OK; +} 1; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index cec8061c80..3e6346b625 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -11401,4 +11401,49 @@ INSERT INTO config.org_unit_setting_type 'gui', 'integer' ); +-- circ export csv export -- + +INSERT INTO action_trigger.hook (key, core_type, description, passive) +VALUES ( + 'circ.format.history.csv', + 'circ', + oils_i18n_gettext( + 'circ.format.history.csv', + 'Produce CSV of circulation history', + 'ath', + 'description' + ), + FALSE +); + +INSERT INTO action_trigger.event_definition ( + active, owner, name, hook, reactor, validator, group_field, template) +VALUES ( + TRUE, 1, 'Circ History CSV', 'circ.format.history.csv', 'ProcessTemplate', 'NOOP_True', 'usr', +$$ +Title,Author,Call Number,Barcode,Format +[%- +FOR circ IN target; + bibxml = helpers.unapi_bre(circ.target_copy.call_number.record, {flesh => '{mra}'}); + title = ""; + FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]'); + title = title _ part.textContent; + END; + author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent; + item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value') %] + + [%- helpers.csv_datum(title) -%], + [%- helpers.csv_datum(author) -%], + [%- helpers.csv_datum(circ.target_copy.call_number.label) -%], + [%- helpers.csv_datum(circ.target_copy.barcode) -%], + [%- helpers.csv_datum(item_type) %] +[%- END -%] +$$ +); + +INSERT INTO action_trigger.environment (event_def, path) + VALUES ( + currval('action_trigger.event_definition_id_seq'), + 'target_copy.call_number' + ); diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.circ_history_export_csv.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.circ_history_export_csv.sql new file mode 100644 index 0000000000..47cad2cdb5 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.circ_history_export_csv.sql @@ -0,0 +1,55 @@ + +BEGIN; + +INSERT INTO action_trigger.hook (key, core_type, description, passive) +VALUES ( + 'circ.format.history.csv', + 'circ', + oils_i18n_gettext( + 'circ.format.history.csv', + 'Produce CSV of circulation history', + 'ath', + 'description' + ), + FALSE +); + +INSERT INTO action_trigger.event_definition ( + active, owner, name, hook, reactor, validator, group_field, template) +VALUES ( + TRUE, 1, 'Circ History CSV', 'circ.format.history.csv', 'ProcessTemplate', 'NOOP_True', 'usr', +$$ +Title,Author,Call Number,Barcode,Format +[%- +FOR circ IN target; + bibxml = helpers.unapi_bre(circ.target_copy.call_number.record, {flesh => '{mra}'}); + title = ""; + FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]'); + title = title _ part.textContent; + END; + author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent; + item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value') %] + + [%- helpers.csv_datum(title) -%], + [%- helpers.csv_datum(author) -%], + [%- helpers.csv_datum(circ.target_copy.call_number.label) -%], + [%- helpers.csv_datum(circ.target_copy.barcode) -%], + [%- helpers.csv_datum(item_type) %] +[%- END -%] +$$ +); + +INSERT INTO action_trigger.environment (event_def, path) + VALUES ( + currval('action_trigger.event_definition_id_seq'), + 'target_copy.call_number' + ); + +COMMIT; + +/* UNDO +DELETE FROM action_trigger.event WHERE event_def = ( + SELECT id FROM action_trigger.event_definition WHERE hook = 'circ.format.history.csv'); +DELETE FROM action_trigger.event_definition WHERE hook = 'circ.format.history.csv'); +DELETE FROM action_trigger.hook WHERE key = 'circ.format.history.csv'; +*/ diff --git a/Open-ILS/src/templates/opac/myopac/circ_history.tt2 b/Open-ILS/src/templates/opac/myopac/circ_history.tt2 index 0728245676..4e8c861325 100644 --- a/Open-ILS/src/templates/opac/myopac/circ_history.tt2 +++ b/Open-ILS/src/templates/opac/myopac/circ_history.tt2 @@ -26,8 +26,14 @@ limit, offset => (offset + limit)}) %]' [% IF ctx.circs.size < limit %] class='invisible' [% END %] >[% l('Next') %] - - [% l('Export List') %] + +
+
+ [%- INCLUDE "opac/parts/preserve_params.tt2" %] + + +
+
diff --git a/Open-ILS/src/templates/opac/myopac/circ_history/export.tt2 b/Open-ILS/src/templates/opac/myopac/circ_history/export.tt2 new file mode 100644 index 0000000000..fa3988f7f0 --- /dev/null +++ b/Open-ILS/src/templates/opac/myopac/circ_history/export.tt2 @@ -0,0 +1 @@ +[%- ctx.csv.template_output.data -%] -- 2.43.2