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

(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (-1 / +9 lines)
Lines 441-447 sub _convert_facets { Link Here
441
441
442
    return if !$es;
442
    return if !$es;
443
443
444
    my %type_to_label = map { $_->name => { order => $_->facet_order, label => $_->label } }
444
    my %type_to_label = map { $_->name => { order => $_->facet_order, av_cat => $_->authorised_value_category, label => $_->label } }
445
        Koha::SearchEngine::Elasticsearch->get_facet_fields;
445
        Koha::SearchEngine::Elasticsearch->get_facet_fields;
446
446
447
    # We also have some special cases, e.g. itypes that need to show the
447
    # We also have some special cases, e.g. itypes that need to show the
Lines 470-476 sub _convert_facets { Link Here
470
            label => $type_to_label{$type}{label},
470
            label => $type_to_label{$type}{label},
471
            type_link_value                    => $type,
471
            type_link_value                    => $type,
472
            order      => $type_to_label{$type}{order},
472
            order      => $type_to_label{$type}{order},
473
            av_cat     => $type_to_label{$type}{av_cat},
473
        };
474
        };
475
        my %authorised_values;
476
        if ( $type_to_label{$type}{av_cat} ) {
477
            %authorised_values = map {$_->{authorised_value} => $_->{lib}} @{C4::Koha::GetAuthorisedValues($type_to_label{$type}{av_cat}, $opac)};
478
        }
474
        $limit = @{ $data->{buckets} } if ( $limit > @{ $data->{buckets} } );
479
        $limit = @{ $data->{buckets} } if ( $limit > @{ $data->{buckets} } );
475
        foreach my $term ( @{ $data->{buckets} }[ 0 .. $limit - 1 ] ) {
480
        foreach my $term ( @{ $data->{buckets} }[ 0 .. $limit - 1 ] ) {
476
            my $t = $term->{key};
481
            my $t = $term->{key};
Lines 480-485 sub _convert_facets { Link Here
480
            if ( exists( $special{$type} ) ) {
485
            if ( exists( $special{$type} ) ) {
481
                $label = $special{$type}->{$t} // $t;
486
                $label = $special{$type}->{$t} // $t;
482
            }
487
            }
488
            elsif ( $type_to_label{$type}{av_cat} ) {
489
                $label = $authorised_values{$t};
490
            }
483
            else {
491
            else {
484
                $label = $t;
492
                $label = $t;
485
            }
493
            }
(-)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
                name => $field_name,
125
                name => $field_name,
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 294-305 while ( my $search_field = $search_fields->next ) { Link Here
294
    push @all_search_fields, $search_field_unblessed;
297
    push @all_search_fields, $search_field_unblessed;
295
}
298
}
296
299
300
my @authorised_value_categories = Koha::AuthorisedValueCategories->search->get_column('category_name');
297
push @messages, @errors;
301
push @messages, @errors;
298
$template->param(
302
$template->param(
299
    indexes           => \@indexes,
303
    indexes           => \@indexes,
300
    all_search_fields => \@all_search_fields,
304
    all_search_fields => \@all_search_fields,
301
    facetable_fields  => \@facetable_fields,
305
    facetable_fields  => \@facetable_fields,
302
    messages          => \@messages,
306
    messages          => \@messages,
307
    authorised_value_categories => \@authorised_value_categories,
303
);
308
);
304
309
305
output_html_with_http_headers $input, $cookie, $template->output;
310
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 493-498 a.add, a.delete { Link Here
493
                                            <th>Order</th>
494
                                            <th>Order</th>
494
                                            <th class="NoSort">Search field</th>
495
                                            <th class="NoSort">Search field</th>
495
                                            <th class="NoSort">Label</th>
496
                                            <th class="NoSort">Label</th>
497
                                            <th class="NoSort">Authorized value category</th>
496
                                            <th class="NoSort">&nbsp;</th>
498
                                            <th class="NoSort">&nbsp;</th>
497
                                        </tr>
499
                                        </tr>
498
                                    </thead>
500
                                    </thead>
Lines 519-524 a.add, a.delete { Link Here
519
                                                    [% END %]
521
                                                    [% END %]
520
                                                    <input type="hidden" name="facet_name" value="[% f.name | html %]" />
522
                                                    <input type="hidden" name="facet_name" value="[% f.name | html %]" />
521
                                                </td>
523
                                                </td>
524
                                                <td>
525
                                                    <select name="facet_av_cat_[% f.name | html %]">
526
                                                        [% FOR av_cat IN authorised_value_categories %]
527
                                                            [% IF f.authorised_value_category == av_cat %]
528
                                                                <option value="[% av_cat | html %]" selected="selected">[% av_cat | html %]</option>
529
                                                            [% ELSE %]
530
                                                                <option value="[% av_cat | html %]">[% av_cat | html %]</option>
531
                                                            [% END %]
532
                                                        [% END %]
533
                                                    </select>
534
                                                </td>
522
                                                <td>
535
                                                <td>
523
                                                    <a class="btn btn-default btn-xs delete-facet" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
536
                                                    <a class="btn btn-default btn-xs delete-facet" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
524
                                                </td>
537
                                                </td>
Lines 536-541 a.add, a.delete { Link Here
536
                                                </select>
549
                                                </select>
537
                                            </td>
550
                                            </td>
538
                                            <td></td>
551
                                            <td></td>
552
                                            <td>
553
                                                <select data-id="facet-av-cat">
554
                                                    [% FOR av_cat IN authorised_value_categories %]
555
                                                        [% IF f.authorised_value_category == av_cat %]
556
                                                            <option value="[% av_cat | html %]" selected="selected">[% av_cat | html %]</option>
557
                                                        [% ELSE %]
558
                                                            <option value="[% av_cat | html %]">[% av_cat | html %]</option>
559
                                                        [% END %]
560
                                                    [% END %]
561
                                                </select>
562
                                            </td>
539
                                            <td><a class="btn btn-default btn-xs add-facet"><i class="fa fa-plus"></i> Add</a></td>
563
                                            <td><a class="btn btn-default btn-xs add-facet"><i class="fa fa-plus"></i> Add</a></td>
540
                                        </tr>
564
                                        </tr>
541
                                    </tfoot>
565
                                    </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()]
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