Koha/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt
Jonathan Druart 424aca3d56 Bug 28445: Use the task queue for the batch delete and update items tool
Here we go!

Disclaimer: this patch is huge and does many things, but splitting it in
several chunks would be time consuming and painful to rebase. However it
adds many tests and isolate/refactor code to make it way more reusable.

This patchset will make the "batch item modification" and "batch item
deletion" features use the task queue (reminder: Since bug 28158, and so
21.05.00, we do no longer use the old "background job" functionality and
the user does not get any info about the progress of the job).

More than that, more of the code to build an item form and a list of
items is now isolated in module (.pm) and include files (.inc)

We are reusing the changes made by bug 27526 that simplifies the way we
edit/create items (no more unecessary serialization Koha > MARC > MARCXML
> XML > HTML)

New module:
* Koha::BackgroundJob::BatchDeleteItem
    Subclass for process item deletion in batch
* Koha::BackgroundJob::BatchUpdateItem
    Subclass for process item modification in batch
* Koha::Item::Attributes
    We needed an object to represent item's attributes that are not
    mapped with a koha field (aka "more subfields xml")
    This module will help us to create the marcxml from a hashref and the
    reverse.
* Koha::UI::Form::Builder::Item
    The code that was used to build the add/edit item form is
    centralised in this module. In conjunction with the
    subfields_for_item BLOCK (from html_helpers.inc) it will be really
    easy to reuse this code in other places where the item form is used
    (acquisition and serials modules)
* Koha::UI::Table::Builder::Items
    Same as previously for the table. We are now using this table from 3
    different places (batch item mod, batch item del, backgroung job
    detail view) and the code is only in one place.
    To use with items_table_batchmod BLOCK (still from html_helpers.inc)

This patch is fixing some bugs about repeatable subfields and regex. A UI
change will reflect the limitation: if you want to apply a regex on a
subfield you cannot add several subfields for the same subfield code.

Test plan:

Prepare the ground:
- Make sure you are always using a bibliographic/item record using the framework
you are modifying!
- Add some subfields for items that are not mapped with a koha field
(note that you can use 'é' for more fun, don't try more funny
characters)
- Make some subfields (mapped and not mapped with a kohafield)
repeatable
- Add default values to some of your subfields

There are 4 main screens to test:
1. Add/edit item form
The behaviour should be the same before and after this patch.
See test plan from bug 27526.
Those 2 prefs must be tested:
    * SubfieldsToAllowForRestrictedEditing
    * SubfieldsToUseWhenPrefill

2. Batch modification
a. Fill some values, play with repeatable and regex.
Note that the behaviour in master was buggy, only the first value was modified by the regex:
    * With subfield = "a | b"
    1 value added with "new"
    => "new | b"

    * With subfield = "a | b"
    2 new fields "new1","new2"
    => "new2 | b"

Important note: For repeatable subfields, a regex will apply on the subfields in
the "concatenated form". To apply the regex on all the different subfields of a given
subfield code you must use the "g" modifier.
This could be improved later, but keep in mind that it's not a regression or behaviour
change.

b. Play with the "Populate fields with default values from default framework" checkbox

c. Use this tool to modify items and play with the different sysprefs that
interfer with it:
    * NewItemsDefaultLocation
    * SubfieldsToAllowForRestrictedBatchmod
    * MaxItemsToDisplayForBatchMod
    * MaxItemsToProcessForBatchMod

3. Batch deletion
a. Batch delete some items
b. Check items out and try to delete them
c. Use the "Delete records if no items remain" checkbox to delete
bibliographic records without remaining items.
d. Play with the following sysprefs and confirm that it works as
expected:
    * MaxItemsToDisplayForBatchDel
e. Stress the tool: Go to the confirmation screen with items that can be
deleted, don't request the job to be processed right away, but check the
item out before.

4. Background job detail view
You must have seen it already if you are curious and tested the above.
When a new modification or deletion batch is requested, the confirmation
screen will tell you that the job has enqueued. A link to the progress
of the job can be followed.
On this screen you will be able to see the result of the job once it's
fully processed.

QA notes:
* There are some FIXME's that are not blocker in my opinion. Feel free to
discuss them if you have suggestions.
* Do we still need MaxItemsToProcessForBatchMod?
* Prior to this patchset we had a "Return to the cataloging module" link
if we went from the cataloguing module and that the biblio was deleted.
We cannot longer know if the biblio will be deleted but we could display
a "Go to the cataloging module" link on the "job has been enqueued"
screen regardless from where we were coming from.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-10-18 11:28:40 +02:00

229 lines
7.3 KiB
Text

[% USE raw %]
[% USE KohaDates %]
[% USE Asset %]
[% USE KohaDates %]
[% SET footerjs = 1 %]
[% BLOCK show_job_status %]
[% SWITCH job.status %]
[% CASE "new" %]
New
[% CASE "cancelled" %]
Cancelled
[% CASE "finished" %]
Finished
[% CASE "started" %]
Started
[% CASE "running" %]
Running
[% CASE # Default case %]
[% job.status | html %]
[% END -%]
[% END %]
[% BLOCK show_job_type %]
[% SWITCH job_type %]
[% CASE 'batch_biblio_record_modification' %]
Batch bibliographic record modification
[% CASE 'batch_biblio_record_deletion' %]
Batch bibliographic record record deletion
[% CASE 'batch_authority_record_modification' %]
Batch authority record modification
[% CASE 'batch_authority_record_deletion' %]
Batch authority record deletion
[% CASE 'batch_item_record_modification' %]
Batch item record modification
[% CASE 'batch_item_record_deletion' %]
Batch item record deletion
[% CASE "batch_hold_cancel" %]
Batch hold cancellation
[% CASE %]Unknown job type '[% job_type | html %]'
[% END %]
[% END %]
[% INCLUDE 'doc-head-open.inc' %]
<title>
[% IF op == 'view' %]
Details of job #[% job.id | html %] &rsaquo;
[% END %]
Background jobs &rsaquo;
Administration &rsaquo; Koha
</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body id="admin_background_jobs" class="admin">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'prefs-admin-search.inc' %]
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
<ol>
<li>
<a href="/cgi-bin/koha/mainpage.pl">Home</a>
</li>
[% IF CAN_user_parameters_manage_background_jobs %]
<li>
<a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
</li>
[% IF op == 'view' %]
<li>
<a href="/cgi-bin/koha/admin/background_jobs.pl">Background jobs</a>
</li>
<li>
<a href="#" aria-current="page">Details of job #[% job.id | html %]</a>
</li>
[% ELSE %]
<li>
<a href="#" aria-current="page">Background jobs</a>
</li>
[% END %]
[% ELSE %]
<li>
<a href="#" aria-current="page">Administration</a>
</li>
[% END %]
</ol>
</nav>
<div class="main container-fluid">
<div class="row">
<div class="col-sm-10 col-sm-push-2">
<main>
[% FOR m IN messages %]
<div class="dialog message">
[% SWITCH m.code %]
[% CASE 'cannot_view_job' %]
<div><i class="fa fa-exclamation error"></i>Insufficient permission to see this job.</div>
[% CASE %]
[% m.code | html %]
[% END %]
</div>
[% END %]
[% IF op == 'view' %]
<h1>Details of job #[% job.id | html %]</h1>
[% PROCESS "background_jobs/${job.type}.inc" %]
<fieldset class="rows">
<ol>
<li><span class="label">Job ID: </span>[% job.id | html %]</li>
<li>
<label for="job_status">Status: </label>
[% PROCESS show_job_status %]
</li>
<li><label for="job_progress">Progress: </label>[% job.progress || 0 | html %] / [% job.size | html %]</li>
<li>
<label for="job_type">Type: </label>
[% PROCESS show_job_type job_type => job.type %]
</li>
<li>
<label for="job_enqueued_on">Queued: </label>
[% job.enqueued_on | $KohaDates with_hours = 1 %]
</li>
<li>
<label for="job_started_on">Started: </label>
[% job.started_on | $KohaDates with_hours = 1 %]
</li>
<li>
<label for="job_ended_on">Ended: </label>
[% job.ended_on | $KohaDates with_hours = 1 %]
</li>
<li><label for="job_data">Report: </label>
[% PROCESS 'report' %]
</li>
<li><label for="job_data">Detailed messages: </label>
[% PROCESS 'detail' %]
</li>
</ol>
</fieldset>
[% IF CAN_user_parameters_manage_background_jobs %]
<fieldset class="action">
<a href="/cgi-bin/koha/admin/background_jobs.pl">Return to the job list</a>
</fieldset>
[% END %]
[% END %]
[% IF op == 'list' %]
<h2>Background jobs</h2>
[% IF jobs.count %]
<table id="table_background_jobs">
<thead>
<tr>
<th>Job ID</th>
<th>Status</th>
<th>Progress</th>
<th>Type</th>
<th>Queued</th>
<th>Started</th>
<th>Ended</th>
<th class="noExport">Actions</th>
</tr>
</thead>
<tbody>
[% FOREACH job IN jobs %]
<tr>
<td>[% job.id | html %]</td>
<td>
[% PROCESS show_job_status %]
</td>
<td>[% job.progress || 0 | html %] / [% job.size | html %]</td>
<td>
[% PROCESS show_job_type job_type => job.type %]
</td>
<td>[% job.enqueued_on | $KohaDates with_hours = 1 %]</td>
<td>[% job.started_on| $KohaDates with_hours = 1 %]</td>
<td>[% job.ended_on| $KohaDates with_hours = 1 %]</td>
<td class="actions">
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&amp;id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a>
[% IF job.status == 'new' || job.status == 'started' %]
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&amp;id=[% job.id | html %]"><i class="fa fa-trash"></i> Cancel</a>
[% END %]
</td>
</tr>
[% END %]
</tbody>
</table>
[% ELSE %]
<div class="dialog message">
There are no background jobs yet.
</div>
[% END %]
[% END %]
</main>
</div> <!-- /.col-sm-10.col-sm-push-2 -->
<div class="col-sm-2 col-sm-pull-10">
<aside>
[% INCLUDE 'admin-menu.inc' %]
</aside>
</div> <!-- /.col-sm-2.col-sm-pull-10 -->
</div> <!-- /.row -->
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/admin-menu.js") | $raw %]
[% INCLUDE 'datatables.inc' %]
<script>
$(document).ready(function() {
$("#table_background_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
"aoColumnDefs": [
{ "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
],
"aaSorting": [[ 0, "desc" ]],
"iDisplayLength": 10,
"sPaginationType": "full_numbers"
}));
});
</script>
[% IF op == 'view' %]
[% PROCESS 'js' %]
[% END %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]