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

(-)a/Koha/REST/V1/Biblios.pm (+19 lines)
Lines 250-255 sub get_items { Link Here
250
    # Deletion of parameter to avoid filtering on the items table in the case of bookings on 'itemtype'
250
    # Deletion of parameter to avoid filtering on the items table in the case of bookings on 'itemtype'
251
    $c->req->params->remove('bookable');
251
    $c->req->params->remove('bookable');
252
252
253
    my $group_by_status = $c->param('group_by_status');
254
    $c->req->params->remove('group_by_status');
255
253
    return $c->render_resource_not_found("Bibliographic record")
256
    return $c->render_resource_not_found("Bibliographic record")
254
        unless $biblio;
257
        unless $biblio;
255
258
Lines 261-266 sub get_items { Link Here
261
        my $items_rs = $biblio->items( { host_items => 1 } )->search_ordered( {}, { join => 'biblioitem' } );
264
        my $items_rs = $biblio->items( { host_items => 1 } )->search_ordered( {}, { join => 'biblioitem' } );
262
        $items_rs = $items_rs->filter_by_bookable if $bookable_only;
265
        $items_rs = $items_rs->filter_by_bookable if $bookable_only;
263
266
267
        if ($group_by_status) {
268
            my @item_ids;
269
            for my $status (
270
                qw( available checked_out local_use in_transit lost withdrawn damaged not_for_loan on_hold recalled in_bundle restricted )
271
                )
272
            {
273
                push @item_ids, $items_rs->search( { _status => $status } )->get_column('itemnumber');
274
            }
275
            $items_rs = $items_rs->search(
276
                {},
277
                {
278
                    order_by => [ \[ sprintf( "field(me.itemnumber, %s)", join( ', ', map { qq{'$_'} } @item_ids ) ) ] ]
279
                }
280
            );
281
        }
282
264
        # FIXME We need to order_by serial.publisheddate if we have _order_by=+me.serial_issue_number
283
        # FIXME We need to order_by serial.publisheddate if we have _order_by=+me.serial_issue_number
265
        my $items = $c->objects->search($items_rs);
284
        my $items = $c->objects->search($items_rs);
266
285
(-)a/api/v1/swagger/paths/biblios.yaml (-1 / +6 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:
Lines 919-922 Link Here
919
      "503":
924
      "503":
920
        description: Under maintenance
925
        description: Under maintenance
921
        schema:
926
        schema:
922
          $ref: "../swagger.yaml#/definitions/error"
927
          $ref: "../swagger.yaml#/definitions/error"
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc (-3 / +29 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 249-255 Link Here
249
        [%# FIXME The X-Base-Total-Count will be the number of items of the biblios %]
250
        [%# FIXME The X-Base-Total-Count will be the number of items of the biblios %]
250
        [%# In case or SeparateHoldings we may need to display the number of biblios in each tab %]
251
        [%# In case or SeparateHoldings we may need to display the number of biblios in each tab %]
251
        [%# Do we need separate/new endpoints or do we hack the somewhere client-side? %]
252
        [%# Do we need separate/new endpoints or do we hack the somewhere client-side? %]
252
        let item_table_url = "/api/v1/biblios/[% biblio.biblionumber | uri %]/items?";
253
        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"];
253
        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"];
254
        [% IF Koha.Preference('LocalCoverImages') %]
254
        [% IF Koha.Preference('LocalCoverImages') %]
255
            embed.push('cover_image_ids');
255
            embed.push('cover_image_ids');
Lines 290-295 Link Here
290
            holdings: "[% PROCESS 'build_table' tab="holdings" | collapse | $tojson %]",
290
            holdings: "[% PROCESS 'build_table' tab="holdings" | collapse | $tojson %]",
291
            otherholdings: "[% PROCESS 'build_table' tab="otherholdings" | collapse | $tojson %]",
291
            otherholdings: "[% PROCESS 'build_table' tab="otherholdings" | collapse | $tojson %]",
292
        };
292
        };
293
294
        let group_by_status_values = {
295
            holdings: false,
296
            otherholdings: false,
297
        };
298
        $(".GroupByStatus").on("click",function(e){
299
            e.preventDefault();
300
            let tab_id = $(this).data("tab");
301
            let was_grouped = group_by_status_values[tab_id];
302
            group_by_status_values[tab_id] = !was_grouped;
303
304
            build_items_table(tab_id, true, { destroy: true }, build_items_table_drawncallback );
305
306
            if ( was_grouped ) {
307
                $(this).html('<i class="fa fa-object-group"></i> Group by status</button>');
308
            } else {
309
                $(this).html('<i class="fa fa-object-ungroup"></i> Ungroup by status</button>');
310
            }
311
        });
312
293
        function build_items_table (tab_id, add_filters, dt_options, drawcallback) {
313
        function build_items_table (tab_id, add_filters, dt_options, drawcallback) {
294
314
295
            let table_dt;
315
            let table_dt;
Lines 335-342 Link Here
335
                [offset+7] : () => all_statuses,
355
                [offset+7] : () => all_statuses,
336
            };
356
            };
337
357
358
            let group_by_status = function(){
359
                if ( group_by_status_values[tab_id] ) {
360
                    return 'group_by_status=1';
361
                }
362
                return '';
363
            }
364
338
            var items_table = $("#" + tab_id + '_table').kohaTable({
365
            var items_table = $("#" + tab_id + '_table').kohaTable({
339
                ajax: { url: item_table_url },
366
                ajax: { url: "/api/v1/biblios/[% biblio.biblionumber | uri %]/items?" + group_by_status() },
340
                order: [],
367
                order: [],
341
                embed,
368
                embed,
342
                autoWidth: false,
369
                autoWidth: false,
343
- 

Return to bug 38122