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

(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (-1 / +9 lines)
Lines 442-448 sub _convert_facets { Link Here
442
442
443
    return if !$es;
443
    return if !$es;
444
444
445
    my %type_to_label = map { $_->name => { order => $_->facet_order, label => $_->label } }
445
    my %type_to_label = map { $_->name => { order => $_->facet_order, av_cat => $_->authorised_value_category, label => $_->label } }
446
        Koha::SearchEngine::Elasticsearch->get_facet_fields;
446
        Koha::SearchEngine::Elasticsearch->get_facet_fields;
447
447
448
    # We also have some special cases, e.g. itypes that need to show the
448
    # We also have some special cases, e.g. itypes that need to show the
Lines 471-477 sub _convert_facets { Link Here
471
            label => $type_to_label{$type}{label},
471
            label => $type_to_label{$type}{label},
472
            type_link_value                    => $type,
472
            type_link_value                    => $type,
473
            order      => $type_to_label{$type}{order},
473
            order      => $type_to_label{$type}{order},
474
            av_cat     => $type_to_label{$type}{av_cat},
474
        };
475
        };
476
        my %authorised_values;
477
        if ( $type_to_label{$type}{av_cat} ) {
478
            %authorised_values = map {$_->{authorised_value} => $_->{lib}} @{C4::Koha::GetAuthorisedValues($type_to_label{$type}{av_cat}, $opac)};
479
        }
475
        $limit = @{ $data->{buckets} } if ( $limit > @{ $data->{buckets} } );
480
        $limit = @{ $data->{buckets} } if ( $limit > @{ $data->{buckets} } );
476
        foreach my $term ( @{ $data->{buckets} }[ 0 .. $limit - 1 ] ) {
481
        foreach my $term ( @{ $data->{buckets} }[ 0 .. $limit - 1 ] ) {
477
            my $t = $term->{key};
482
            my $t = $term->{key};
Lines 481-486 sub _convert_facets { Link Here
481
            if ( exists( $special{$type} ) ) {
486
            if ( exists( $special{$type} ) ) {
482
                $label = $special{$type}->{$t} // $t;
487
                $label = $special{$type}->{$t} // $t;
483
            }
488
            }
489
            elsif ( $type_to_label{$type}{av_cat} ) {
490
                $label = $authorised_values{$t};
491
            }
484
            else {
492
            else {
485
                $label = $t;
493
                $label = $t;
486
            }
494
            }
(-)a/admin/searchengine/elasticsearch/mappings.pl (+5 lines)
Lines 28-33 use Koha::SearchEngine::Elasticsearch::QueryBuilder; Link Here
28
use Koha::SearchMarcMaps;
28
use Koha::SearchMarcMaps;
29
use Koha::SearchFields;
29
use Koha::SearchFields;
30
use Koha::Caches;
30
use Koha::Caches;
31
use Koha::AuthorisedValueCategories;
31
32
32
use Try::Tiny qw( catch try );
33
use Try::Tiny qw( catch try );
33
use Module::Load::Conditional qw( can_load );
34
use Module::Load::Conditional qw( can_load );
Lines 118-123 if ( $op eq 'cud-edit' ) { Link Here
118
            my $field_weight       = $field_weight[$i];
119
            my $field_weight       = $field_weight[$i];
119
            my $field_staff_client = $field_staff_client[$i];
120
            my $field_staff_client = $field_staff_client[$i];
120
            my $field_opac         = $field_opac[$i];
121
            my $field_opac         = $field_opac[$i];
122
            my $av_category = $input->param('facet_av_cat_' . $field_name);
121
123
122
            my $search_field = Koha::SearchFields->find_or_create(
124
            my $search_field = Koha::SearchFields->find_or_create(
123
                {
125
                {
Lines 139-144 if ( $op eq 'cud-edit' ) { Link Here
139
141
140
            my $facet_order = first { $faceted_field_names[$_] eq $field_name } 0 .. $#faceted_field_names;
142
            my $facet_order = first { $faceted_field_names[$_] eq $field_name } 0 .. $#faceted_field_names;
141
            $search_field->facet_order( defined $facet_order ? $facet_order + 1 : undef );
143
            $search_field->facet_order( defined $facet_order ? $facet_order + 1 : undef );
144
            $search_field->authorised_value_category($av_category);
142
            $search_field->store;
145
            $search_field->store;
143
        }
146
        }
144
147
Lines 297-308 while ( my $search_field = $search_fields->next ) { Link Here
297
    push @all_search_fields, $search_field_unblessed;
300
    push @all_search_fields, $search_field_unblessed;
298
}
301
}
299
302
303
my @authorised_value_categories = Koha::AuthorisedValueCategories->search->get_column('category_name');
300
push @messages, @errors;
304
push @messages, @errors;
301
$template->param(
305
$template->param(
302
    indexes           => \@indexes,
306
    indexes           => \@indexes,
303
    all_search_fields => \@all_search_fields,
307
    all_search_fields => \@all_search_fields,
304
    facetable_fields  => \@facetable_fields,
308
    facetable_fields  => \@facetable_fields,
305
    messages          => \@messages,
309
    messages          => \@messages,
310
    authorised_value_categories => \@authorised_value_categories,
306
);
311
);
307
312
308
output_html_with_http_headers $input, $cookie, $template->output;
313
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc (-2 / +1 lines)
Lines 88-95 Link Here
88
                                [% FOREACH facet IN facets_loo.facets %]
88
                                [% FOREACH facet IN facets_loo.facets %]
89
                                    [% IF facets_loo.type_label_CollectionCodes %]
89
                                    [% IF facets_loo.type_label_CollectionCodes %]
90
                                        [% SET facet.facet_label_value = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => facet.facet_label_value ) || facet.facet_label_value %]
90
                                        [% SET facet.facet_label_value = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => facet.facet_label_value ) || facet.facet_label_value %]
91
                                    [% END %]
91
                                    [% ELSIF facets_loo.type_label_Language %]
92
                                    [% IF facets_loo.type_label_Language %]
93
                                        [% SET facet.facet_label_value = Languages.GetByISOCode(lang,facet.facet_label_value) || facet.facet_label_value %]
92
                                        [% SET facet.facet_label_value = Languages.GetByISOCode(lang,facet.facet_label_value) || facet.facet_label_value %]
94
                                    [% END %]
93
                                    [% END %]
95
                                    [% IF loop.count > 5 && !facet.active %]
94
                                    [% IF loop.count > 5 && !facet.active %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (+24 lines)
Lines 1-5 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE AuthorisedValues %]
3
[% SET footerjs = 1 %]
4
[% SET footerjs = 1 %]
4
[% PROCESS 'i18n.inc' %]
5
[% PROCESS 'i18n.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
[% INCLUDE 'doc-head-open.inc' %]
Lines 498-503 a.add, a.delete { Link Here
498
                                            <th>Order</th>
499
                                            <th>Order</th>
499
                                            <th class="NoSort">Search field</th>
500
                                            <th class="NoSort">Search field</th>
500
                                            <th class="NoSort">Label</th>
501
                                            <th class="NoSort">Label</th>
502
                                            <th class="NoSort">Authorized value category</th>
501
                                            <th class="NoSort">&nbsp;</th>
503
                                            <th class="NoSort">&nbsp;</th>
502
                                        </tr>
504
                                        </tr>
503
                                    </thead>
505
                                    </thead>
Lines 524-529 a.add, a.delete { Link Here
524
                                                    [% END %]
526
                                                    [% END %]
525
                                                    <input type="hidden" name="facet_name" value="[% f.name | html %]" />
527
                                                    <input type="hidden" name="facet_name" value="[% f.name | html %]" />
526
                                                </td>
528
                                                </td>
529
                                                <td>
530
                                                    <select name="facet_av_cat_[% f.name | html %]">
531
                                                        [% FOR av_cat IN authorised_value_categories %]
532
                                                            [% IF f.authorised_value_category == av_cat %]
533
                                                                <option value="[% av_cat | html %]" selected="selected">[% av_cat | html %]</option>
534
                                                            [% ELSE %]
535
                                                                <option value="[% av_cat | html %]">[% av_cat | html %]</option>
536
                                                            [% END %]
537
                                                        [% END %]
538
                                                    </select>
539
                                                </td>
527
                                                <td>
540
                                                <td>
528
                                                    <a class="btn btn-default btn-xs delete-facet" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
541
                                                    <a class="btn btn-default btn-xs delete-facet" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
529
                                                </td>
542
                                                </td>
Lines 541-546 a.add, a.delete { Link Here
541
                                                </select>
554
                                                </select>
542
                                            </td>
555
                                            </td>
543
                                            <td></td>
556
                                            <td></td>
557
                                            <td>
558
                                                <select data-id="facet-av-cat">
559
                                                    [% FOR av_cat IN authorised_value_categories %]
560
                                                        [% IF f.authorised_value_category == av_cat %]
561
                                                            <option value="[% av_cat | html %]" selected="selected">[% av_cat | html %]</option>
562
                                                        [% ELSE %]
563
                                                            <option value="[% av_cat | html %]">[% av_cat | html %]</option>
564
                                                        [% END %]
565
                                                    [% END %]
566
                                                </select>
567
                                            </td>
544
                                            <td><a class="btn btn-default btn-xs add-facet"><i class="fa fa-plus"></i> Add</a></td>
568
                                            <td><a class="btn btn-default btn-xs add-facet"><i class="fa fa-plus"></i> Add</a></td>
545
                                        </tr>
569
                                        </tr>
546
                                    </tfoot>
570
                                    </tfoot>
(-)a/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js (-2 / +2 lines)
Lines 177-183 $(document).ready(function () { Link Here
177
        if (search_field_name.length > 0) {
177
        if (search_field_name.length > 0) {
178
            const next_id = Math.max.apply(null, dt_data.map(row => row[0])) + 1;
178
            const next_id = Math.max.apply(null, dt_data.map(row => row[0])) + 1;
179
            const label = selected_option.data('label');
179
            const label = selected_option.data('label');
180
            new_line = [next_id, search_field_name, '<span>%s</span><input type="hidden" name="facet_name" value="%s" />'.format(label.escapeHtml(), search_field_name.escapeHtml()), build_delete_link('delete-facet')]
180
            const av_cat_select = $(clone_line(line).find('td')[2]).find('select').attr({name: 'facet_av_cat_%s'.format(search_field_name.escapeHtml())});
181
            new_line = [next_id, search_field_name, '<span>%s</span><input type="hidden" name="facet_name" value="%s" />'.format(label.escapeHtml(), search_field_name.escapeHtml()), av_cat_select[0].outerHTML, build_delete_link()]
181
            dt.row.add(new_line).draw();
182
            dt.row.add(new_line).draw();
182
183
183
            clean_line(line);
184
            clean_line(line);
184
- 

Return to bug 36396