From 9c757742e801ed6a0d3da9481db360c6786b9ce5 Mon Sep 17 00:00:00 2001 From: Dan Pearl Date: Thu, 4 Sep 2014 15:19:09 -0400 Subject: [PATCH] LP#1312699 - Add feature to allow user to edit their checkout history Signed-off-by: Dan Pearl Signed-off-by: Kathy Lussier --- Open-ILS/examples/fm_IDL.xml | 1 + .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 34 +++++++++++++- Open-ILS/src/sql/Pg/090.schema.action.sql | 4 +- .../Pg/upgrade/XXXX.editable_usr_circ_history.sql | 54 ++++++++++++++++++++++ .../src/templates/opac/myopac/circ_history.tt2 | 30 ++++++++++++ docs/RELEASE_NOTES_NEXT/OPAC/edit_circ_history | 10 ++++ 6 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.editable_usr_circ_history.sql create mode 100644 docs/RELEASE_NOTES_NEXT/OPAC/edit_circ_history diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 37aab837d2..7fa20721c4 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -4081,6 +4081,7 @@ SELECT usr, + 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 30e07561c0..154028bf4d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1522,6 +1522,10 @@ sub load_myopac_circ_history { my $ctx = $self->ctx; my $limit = $self->cgi->param('limit') || 15; my $offset = $self->cgi->param('offset') || 0; + my $action = $self->cgi->param('action') || ''; + + my $circ_handle_result; + $circ_handle_result = $self->handle_circ_update($action) if $action; $ctx->{circ_history_limit} = $limit; $ctx->{circ_history_offset} = $offset; @@ -1557,7 +1561,35 @@ sub load_myopac_circ_history { } $ctx->{circs} = $self->fetch_user_circs(1, [map { $_->{id} } @$circ_ids]); - return Apache2::Const::OK; + return defined($circ_handle_result) ? $circ_handle_result : Apache2::Const::OK; +} + +sub handle_circ_update { + my $self = shift; + my $action = shift; + my $circ_ids = shift; + my $e = $self->editor; + my $url; + + my @circ_ids = ($circ_ids) ? @$circ_ids : $self->cgi->param('circ_id'); # for non-_all actions + + my $cstore_ses = OpenSRF::AppSession->create('open-ils.cstore'); + $cstore_ses->connect(); + $cstore_ses->request('open-ils.cstore.transaction.begin')->gather(1); + + if($action =~ /delete/) { + for my $circ_id (@circ_ids) { + my $circ = $cstore_ses->request( + 'open-ils.cstore.direct.action.circulation.retrieve', $circ_id)->gather(1); + $circ->hide_from_usr_history(1); + my $resp = $cstore_ses->request( + 'open-ils.cstore.direct.action.circulation.update', $circ)->gather(1); + } + } + + $cstore_ses->request('open-ils.cstore.transaction.commit')->gather(1); + $cstore_ses->disconnect(); + return undef; } # TODO: action.usr_visible_holds does not return cancelled holds. Should it? diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index ca1e7f3894..44cce9ce37 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -147,7 +147,8 @@ CREATE TABLE action.circulation ( ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED, copy_location INT NOT NULL DEFAULT 1 REFERENCES asset.copy_location (id) DEFERRABLE INITIALLY DEFERRED, - checkin_scan_time TIMESTAMP WITH TIME ZONE + checkin_scan_time TIMESTAMP WITH TIME ZONE, + hide_from_usr_history BOOL NOT NULL DEFAULT FALSE ) INHERITS (money.billable_xact); ALTER TABLE action.circulation ADD PRIMARY KEY (id); ALTER TABLE action.circulation @@ -911,6 +912,7 @@ BEGIN WHERE usr = usr_id AND parent_circ IS NULL AND xact_start > NOW() - view_age + AND NOT hide_from_usr_history ORDER BY xact_start DESC LOOP RETURN NEXT c; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.editable_usr_circ_history.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.editable_usr_circ_history.sql new file mode 100644 index 0000000000..420bee25b7 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.editable_usr_circ_history.sql @@ -0,0 +1,54 @@ +BEGIN; + +ALTER TABLE action.circulation + ADD COLUMN hide_from_usr_history boolean not null default false; + +COMMIT; + +BEGIN; + +CREATE OR REPLACE FUNCTION action.usr_visible_circs(usr_id integer) + RETURNS SETOF action.circulation + LANGUAGE plpgsql +AS $function$ +DECLARE + c action.circulation%ROWTYPE; + view_age INTERVAL; + usr_view_age actor.usr_setting%ROWTYPE; + usr_view_start actor.usr_setting%ROWTYPE; +BEGIN + SELECT * INTO usr_view_age FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.circ.retention_age'; + SELECT * INTO usr_view_start FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.circ.retention_start'; + + IF usr_view_age.value IS NOT NULL AND usr_view_start.value IS NOT NULL THEN + -- User opted in and supplied a retention age + IF oils_json_to_text(usr_view_age.value)::INTERVAL > AGE(NOW(), oils_json_to_text(usr_view_start.value)::TIMESTAMPTZ) THEN + view_age := AGE(NOW(), oils_json_to_text(usr_view_start.value)::TIMESTAMPTZ); + ELSE + view_age := oils_json_to_text(usr_view_age.value)::INTERVAL; + END IF; + ELSIF usr_view_start.value IS NOT NULL THEN + -- User opted in + view_age := AGE(NOW(), oils_json_to_text(usr_view_start.value)::TIMESTAMPTZ); + ELSE + -- User did not opt in + RETURN; + END IF; + + FOR c IN + SELECT * + FROM action.circulation + WHERE usr = usr_id + AND parent_circ IS NULL + AND xact_start > NOW() - view_age + AND NOT hide_from_usr_history + ORDER BY xact_start DESC + LOOP +RETURN NEXT c; + END LOOP; + + RETURN; +END; +$function$ + +COMMIT; diff --git a/Open-ILS/src/templates/opac/myopac/circ_history.tt2 b/Open-ILS/src/templates/opac/myopac/circ_history.tt2 index 5339b25551..e686b8038f 100644 --- a/Open-ILS/src/templates/opac/myopac/circ_history.tt2 +++ b/Open-ILS/src/templates/opac/myopac/circ_history.tt2 @@ -58,11 +58,37 @@
[% l('There are no items in your circulation history.') %]
[% ELSE %] +
+ + + + + + +
+ + + +
+ @@ -136,6 +162,9 @@ FOR circ IN circ_items; %] + + [% END %] diff --git a/docs/RELEASE_NOTES_NEXT/OPAC/edit_circ_history b/docs/RELEASE_NOTES_NEXT/OPAC/edit_circ_history new file mode 100644 index 0000000000..ea4c60cd93 --- /dev/null +++ b/docs/RELEASE_NOTES_NEXT/OPAC/edit_circ_history @@ -0,0 +1,10 @@ +Editable Borrowing History +^^^^^^^^^^^^^^^^^^^^^^^^^^ +You can delete titles that you do not wish to appear in your Check Out History. + + * In "My Account", click on the "Items Checked Out" tab, then the "Check Out History" sub-tab. + * Check off the items you wish to conceal. + * Click the Go button next to the "Delete Selected Titles" drop-down box. + * Click OK in the pop-up to confirm your deletion. Choose carefully, as there is no "undo". + +Deleted titles will also not appear in the downloaded CSV file. -- 2.11.0
+ + [% sort_head("sort_title", l("Title")) %] [% sort_head("author", l("Author")) %] [% sort_head("checkout", l("Checkout Date")) %]
+ + [% circ.circ.target_copy.barcode | html %] [% circ.circ.target_copy.call_number.label | html %]