View | Details | Raw Unified | Return to bug 38122
Collapse All | Expand All

(-)a/Koha/REST/V1/Biblios.pm (+19 lines)
Lines 255-260 sub get_items { Link Here
255
    # Deletion of parameter to avoid filtering on the items table in the case of bookings on 'itemtype'
255
    # Deletion of parameter to avoid filtering on the items table in the case of bookings on 'itemtype'
256
    $c->req->params->remove('bookable');
256
    $c->req->params->remove('bookable');
257
257
258
    my $group_by_status = $c->param('group_by_status');
259
    $c->req->params->remove('group_by_status');
260
258
    return $c->render_resource_not_found("Bibliographic record")
261
    return $c->render_resource_not_found("Bibliographic record")
259
        unless $biblio;
262
        unless $biblio;
260
263
Lines 266-271 sub get_items { Link Here
266
        my $items_rs = $biblio->items( { host_items => 1 } )->search_ordered( {}, { join => 'biblioitem' } );
269
        my $items_rs = $biblio->items( { host_items => 1 } )->search_ordered( {}, { join => 'biblioitem' } );
267
        $items_rs = $items_rs->filter_by_bookable if $bookable_only;
270
        $items_rs = $items_rs->filter_by_bookable if $bookable_only;
268
271
272
        if ($group_by_status) {
273
            my @item_ids;
274
            for my $status (
275
                qw( available checked_out local_use in_transit lost withdrawn damaged not_for_loan on_hold recalled in_bundle restricted )
276
                )
277
            {
278
                push @item_ids, $items_rs->search( { _status => $status } )->get_column('itemnumber');
279
            }
280
            $items_rs = $items_rs->search(
281
                {},
282
                {
283
                    order_by => [ \[ sprintf( "field(me.itemnumber, %s)", join( ', ', map { qq{'$_'} } @item_ids ) ) ] ]
284
                }
285
            );
286
        }
287
269
        # FIXME We need to order_by serial.publisheddate if we have _order_by=+me.serial_issue_number
288
        # FIXME We need to order_by serial.publisheddate if we have _order_by=+me.serial_issue_number
270
        my $items = $c->objects->search($items_rs);
289
        my $items = $c->objects->search($items_rs);
271
290
(-)a/api/v1/swagger/paths/biblios.yaml (+5 lines)
Lines 499-504 Link Here
499
        description: Limit to items that are bookable
499
        description: Limit to items that are bookable
500
        required: false
500
        required: false
501
        type: boolean
501
        type: boolean
502
      - name: group_by_status
503
        in: query
504
        description: Return the items grouped by status
505
        required: false
506
        type: boolean
502
    consumes:
507
    consumes:
503
      - application/json
508
      - application/json
504
    produces:
509
    produces:
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc (-11 / +26 lines)
Lines 61-66 Link Here
61
        </span>
61
        </span>
62
        <button class="btn btn-link SelectAll" data-tab="[% tab | html %]"><i class="fa fa-check"></i> Select all</button>
62
        <button class="btn btn-link SelectAll" data-tab="[% tab | html %]"><i class="fa fa-check"></i> Select all</button>
63
        <button class="btn btn-link ClearAll" data-tab="[% tab | html %]"><i class="fa fa-times"></i> Clear all</button>
63
        <button class="btn btn-link ClearAll" data-tab="[% tab | html %]"><i class="fa fa-times"></i> Clear all</button>
64
        <button class="btn btn-link GroupByStatus" data-tab="[% tab | html %]"><i class="fa fa-object-group"></i> Group by status</button>
64
        <span class="itemselection_actions">
65
        <span class="itemselection_actions">
65
            | Actions:
66
            | Actions:
66
            [% IF CAN_user_tools_items_batchdel %]
67
            [% IF CAN_user_tools_items_batchdel %]
Lines 255-261 Link Here
255
        [%# FIXME The X-Base-Total-Count will be the number of items of the biblios %]
256
        [%# FIXME The X-Base-Total-Count will be the number of items of the biblios %]
256
        [%# In case or SeparateHoldings we may need to display the number of biblios in each tab %]
257
        [%# In case or SeparateHoldings we may need to display the number of biblios in each tab %]
257
        [%# Do we need separate/new endpoints or do we hack the somewhere client-side? %]
258
        [%# Do we need separate/new endpoints or do we hack the somewhere client-side? %]
258
        let item_table_url = "/api/v1/biblios/[% biblio.biblionumber | uri %]/items?";
259
        let embed = ["+strings,_status,home_library,holding_library,checkout,checkout.patron,transfer,transfer+strings,first_hold,first_hold+strings,first_hold.patron,first_hold.desk"];
259
        let embed = ["+strings,_status,home_library,holding_library,checkout,checkout.patron,transfer,transfer+strings,first_hold,first_hold+strings,first_hold.patron,first_hold.desk"];
260
        [% IF Koha.Preference('LocalCoverImages') %]
260
        [% IF Koha.Preference('LocalCoverImages') %]
261
            embed.push('cover_image_ids');
261
            embed.push('cover_image_ids');
Lines 297-311 Link Here
297
            otherholdings: "[% PROCESS 'build_table' tab="otherholdings" | collapse | $tojson %]",
297
            otherholdings: "[% PROCESS 'build_table' tab="otherholdings" | collapse | $tojson %]",
298
        };
298
        };
299
299
300
        const branchcodes = {
300
        let group_by_status_values = {
301
          [% FOREACH key IN branchcodes.keys %]
301
            holdings: false,
302
            "[% key | html %]": [
302
            otherholdings: false,
303
              [% FOREACH code IN branchcodes.$key %]
304
                "[% code | html %]"[% UNLESS loop.last %], [% END %]
305
              [% END %]
306
            ][% UNLESS loop.last %], [% END %]
307
          [% END %]
308
        };
303
        };
304
        $(".GroupByStatus").on("click",function(e){
305
            e.preventDefault();
306
            let tab_id = $(this).data("tab");
307
            let was_grouped = group_by_status_values[tab_id];
308
            group_by_status_values[tab_id] = !was_grouped;
309
310
            build_items_table(tab_id, true, { destroy: true }, build_items_table_drawncallback );
311
312
            if ( was_grouped ) {
313
                $(this).html('<i class="fa fa-object-group"></i> Group by status</button>');
314
            } else {
315
                $(this).html('<i class="fa fa-object-ungroup"></i> Ungroup by status</button>');
316
            }
317
        });
309
318
310
        function build_items_table (tab_id, add_filters, dt_options, drawcallback) {
319
        function build_items_table (tab_id, add_filters, dt_options, drawcallback) {
311
320
Lines 358-365 Link Here
358
                return $("#" + tab_id + "_status select").val();
367
                return $("#" + tab_id + "_status select").val();
359
            };
368
            };
360
369
370
            let group_by_status = function(){
371
                if ( group_by_status_values[tab_id] ) {
372
                    return 'group_by_status=1';
373
                }
374
                return '';
375
            }
376
361
            var items_table = $("#" + tab_id + '_table').kohaTable({
377
            var items_table = $("#" + tab_id + '_table').kohaTable({
362
                ajax: { url: item_table_url },
378
                ajax: { url: "/api/v1/biblios/[% biblio.biblionumber | uri %]/items?" + group_by_status() },
363
                order: [],
379
                order: [],
364
                embed,
380
                embed,
365
                autoWidth: false,
381
                autoWidth: false,
366
- 

Return to bug 38122