diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt index 19b7f7a63f..343706cb2c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -351,6 +351,8 @@ actions: [% To.json(actions || []) | $raw %], interfaces: [% To.json(interfaces || []) | $raw %], object: "[% object | html %]", + object_type: "[% object_type | html %]", + biblio_itemnumbers: [% To.json(biblio_itemnumbers || []) | $raw %], info: "[% info | html %]", datefrom: "[% datefrom | html %]", dateto: "[% dateto | html %]", diff --git a/koha-tmpl/intranet-tmpl/prog/js/viewlog.js b/koha-tmpl/intranet-tmpl/prog/js/viewlog.js index e7bac21dda..1b11ceedf7 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/viewlog.js +++ b/koha-tmpl/intranet-tmpl/prog/js/viewlog.js @@ -419,11 +419,33 @@ function buildApiFilters(params) { filters.user = params.user; } - if (params.object) { + // Cataloguing modification log: object_type=biblio means we should + // surface biblio-level changes ("biblio%") on the biblionumber AND + // item-level changes ("item%") on each of the biblio's itemnumbers + // (computed server-side and passed in via biblio_itemnumbers). + var biblio_expansion = false; + if ( + params.object && + params.object_type === "biblio" && + params.modules && + params.modules.length === 1 && + params.modules[0] === "CATALOGUING" + ) { + var itemnumbers = params.biblio_itemnumbers || []; + var or_clauses = [{ object: params.object, info: { like: "biblio%" } }]; + if (itemnumbers.length) { + or_clauses.push({ + object: itemnumbers, + info: { like: "item%" }, + }); + } + filters["-or"] = or_clauses; + biblio_expansion = true; + } else if (params.object) { filters.object = params.object; } - if (params.info) { + if (params.info && !biblio_expansion) { filters.info = { like: "%" + params.info + "%" }; } diff --git a/tools/viewlog.pl b/tools/viewlog.pl index 8c711433a5..bb4f8adccf 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -30,6 +30,7 @@ use C4::Serials qw( CountSubscriptionFromBiblionumber ); use C4::Search qw( enabled_staff_search_views ); use Koha::ActionLogs; +use Koha::Biblios; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Items; @@ -91,18 +92,34 @@ $template->param( if ($do_it) { if ( $output eq "screen" ) { + # Cataloguing modification log opens with modules=CATALOGUING and + # object_type=biblio: surface item-level changes alongside the + # biblio ones by collecting the biblio's itemnumbers and asking + # the JS to filter on either object set. Mirrors the CSV export + # branch below. The biblio object is also exposed so that the + # biblio-view-menu sidebar can render its links. + my $biblio; + my @biblio_itemnumbers; + if ( @modules == 1 && $object_type eq 'biblio' && $object ) { + $biblio = Koha::Biblios->find($object); + @biblio_itemnumbers = $biblio->items->get_column('itemnumber') if $biblio; + } + # Screen output: pass search params to template, DataTable loads via REST API $template->param( - logview => 1, - do_it => 1, - datefrom => $datefrom, - dateto => $dateto, - user => $user, - info => $info, - src => $src, - modules => \@modules, - actions => \@actions, - interfaces => \@interfaces + logview => 1, + do_it => 1, + datefrom => $datefrom, + dateto => $dateto, + user => $user, + info => $info, + src => $src, + modules => \@modules, + actions => \@actions, + interfaces => \@interfaces, + object_type => $object_type, + biblio => $biblio, + biblio_itemnumbers => \@biblio_itemnumbers, ); # Used modules