Bugzilla – Attachment 119317 Details for
Bug 20388
Ability to add search fields from UI
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20388 - Elasticsearch - Ability to add search fields from UI
Bug-20388---Elasticsearch---Ability-to-add-search-.patch (text/plain), 12.22 KB, created by
Alex Arnaud
on 2021-04-08 09:21:47 UTC
(
hide
)
Description:
Bug 20388 - Elasticsearch - Ability to add search fields from UI
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2021-04-08 09:21:47 UTC
Size:
12.22 KB
patch
obsolete
>From 96f1c146ee13cdddd239ed159088fcbbcc2512bc Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Wed, 7 Apr 2021 13:20:53 +0000 >Subject: [PATCH] Bug 20388 - Elasticsearch - Ability to add search fields from > UI > >--- > Koha/SearchField.pm | 12 +++++ > admin/searchengine/elasticsearch/mappings.pl | 11 ++-- > .../admin/searchengine/elasticsearch/mappings.tt | 51 ++++++++++++++++++- > .../prog/js/elasticsearch-mappings.js | 59 +++++++++++++++++----- > t/db_dependent/Koha/SearchField.t | 31 +++++++++++- > 5 files changed, 146 insertions(+), 18 deletions(-) > >diff --git a/Koha/SearchField.pm b/Koha/SearchField.pm >index e6c80c7..c303749 100644 >--- a/Koha/SearchField.pm >+++ b/Koha/SearchField.pm >@@ -69,6 +69,18 @@ sub search_marc_maps { > return $marc_map_fields; > } > >+=head3 is_mapped >+ >+my $is_mapped = $search_field->is_mapped >+ >+=cut >+ >+sub is_mapped { >+ my ( $self ) = @_; >+ >+ return $self->search_marc_maps()->count ? 1 : 0; >+} >+ > =head3 is_mapped_biblios > > my $is_mapped_biblios = $search_field->is_mapped_biblios >diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl >index 4f71920..9b0f1d3 100755 >--- a/admin/searchengine/elasticsearch/mappings.pl >+++ b/admin/searchengine/elasticsearch/mappings.pl >@@ -109,6 +109,8 @@ if ( $op eq 'edit' ) { > > eval { > >+ Koha::SearchFields->search()->delete; >+ > for my $i ( 0 .. scalar(@field_name) - 1 ) { > my $field_name = $field_name[$i]; > my $field_label = $field_label[$i]; >@@ -117,9 +119,11 @@ if ( $op eq 'edit' ) { > my $field_staff_client = $field_staff_client[$i]; > my $field_opac = $field_opac[$i]; > >- my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } ); >- $search_field->label($field_label); >- $search_field->type($field_type); >+ my $search_field = Koha::SearchFields->find_or_create({ >+ name => $field_name, >+ label => $field_label, >+ type => $field_type, >+ }); > > if (!length($field_weight)) { > $search_field->weight(undef); >@@ -274,6 +278,7 @@ my @all_search_fields; > while ( my $search_field = $search_fields->next ) { > my $search_field_unblessed = $search_field->unblessed; > $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios; >+ $search_field_unblessed->{is_mapped} = $search_field->is_mapped; > $search_field_unblessed->{aliases} = $search_fields_aliases->{$search_field_unblessed->{name}}; > push @all_search_fields, $search_field_unblessed; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt >index d84131a..a35bcca 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt >@@ -122,7 +122,7 @@ a.add, a.delete { > [% END %] > </ul> > <div id="search_fields" class="ui-tabs-panel"> >- <table class="search_fields" id="search_fields_table"> >+ <table class="search_fields" id="search_fields_table" data-index_name="search_fields"> > <thead> > <tr> > <th>Name</th> >@@ -131,11 +131,13 @@ a.add, a.delete { > <th>Type</th> > <th>Weight</th> > <th colspan="2">Searchable</th> >+ <th> </th> > </tr> > <tr> > <th colspan="5" class="NoSort"> </th> > <th class="NoSort">Staff interface</th> > <th class="NoSort">OPAC</th> >+ <th> </th> > </tr> > </thead> > <tbody> >@@ -237,9 +239,56 @@ a.add, a.delete { > [% END %] > </select> > </td> >+ <td> >+ [% IF search_field.is_mapped %] >+ <a class="btn btn-default btn-xs disabled delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a> >+ [% ELSE %] >+ <a class="btn btn-default btn-xs delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a> >+ [% END %] >+ </td> > </tr> > [% END %] > </tbody> >+ <tfoot> >+ <tr> >+ <td> >+ <input type="text" data-id="search_field_name"/> >+ </td> >+ <td></td> >+ <td> >+ <input type="text" data-id="search_field_label"/> >+ </td> >+ <td> >+ <select data-id="search_field_type"> >+ <option value=""></option> >+ <option value="string">String</option> >+ <option value="date">Date</option> >+ <option value="year">Year</option> >+ <option value="number">Number</option> >+ <option value="boolean">Boolean</option> >+ <option value="sum">Sum</option> >+ <option value="isbn">ISBN</option> >+ <option value="stdno">Std. Number</option> >+ </select> >+ </td> >+ <td> >+ <input type="text" data-id="search_field_weight" value=""> >+ </td> >+ <td> >+ <select data-id="search_field_staff_client"> >+ <option value="1">Yes</option> >+ <option value="0">No</option> >+ </select> >+ </td> >+ <td> >+ <select data-id="search_field_opac"> >+ <option value="1">Yes</option> >+ <option value="0">No</option> >+ </select> >+ </td> >+ <td><a class="btn btn-default btn-xs add-search-field"><i class="fa fa-plus"></i> Add</a></td> >+ </tr> >+ </tfoot> > </table> > </div> > [% FOREACH index IN indexes %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js b/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js >index a6bd0ba..84a00f3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js >@@ -15,6 +15,7 @@ function clone_line(line) { > $(new_line).find("select").each(function () { > var attr = $(this).attr('name'); > var val = $(line).find('[data-id="' + attr + '"]').val(); >+ $(this).find('option').removeAttr('selected'); > $(this).find('option[value="' + val + '"]').attr("selected", "selected"); > }); > return new_line; >@@ -48,17 +49,31 @@ $(document).ready(function () { > }, > }); > >- $('.delete').click(function () { >+ $(document).on('click', '.delete', function() { > if ($(this).hasClass('mandatory') && $(".mandatory[data-field_name=" + $(this).attr('data-field_name') + "]").length < 2) { > alert( __("This field is mandatory and must have at least one mapping") ); > return; > } else { > $(this).parents('tr').remove(); >- } >- }); >+ var line = $(this).closest("tr"); > >- $("table.mappings").tableDnD({ >- onDragClass: "dragClass", >+ var name; >+ // We clicked delete button on search fields tab. >+ if (name = $(line).find('input[name="search_field_name"]').val()) { >+ // Prevent user from using a search field for a mapping >+ // after removing it without saving. >+ $('select[data-id="mapping_search_field_name"]').each(function( index, element) { >+ $(element).find('option[value="' + name + '"]').remove(); >+ }); >+ } >+ >+ var search_field_name = $(line).find('input[name="mapping_search_field_name"]').val(); >+ var mappings = $('input[name="mapping_search_field_name"][type="hidden"][value="' + search_field_name + '"]'); >+ if (mappings.length == 0) { >+ var search_field_line = $('input[name="search_field_name"][value="' + search_field_name + '"]').closest("tr"); >+ $(search_field_line).find('a.btn-default').removeClass('disabled'); >+ } >+ } > }); > > $('.add').click(function () { >@@ -68,18 +83,38 @@ $(document).ready(function () { > var marc_field = $(line).find('input[data-id="mapping_marc_field"]').val(); > if (marc_field.length > 0) { > var new_line = clone_line(line); >+ var search_field_name = $(line).find('select[data-id="mapping_search_field_name"] option:selected').text(); > new_line.appendTo($('table[data-index_name="' + index_name + '"]>tbody')); >- $('.delete').click(function () { >- $(this).parents('tr').remove(); >- }); >- clean_line(line); > >- $(table).tableDnD({ >- onDragClass: "dragClass", >- }); >+ var search_field_line = $('input[name="search_field_name"][value="' + search_field_name + '"]').closest("tr"); >+ $(search_field_line).find('a.btn-default').addClass('disabled'); >+ >+ clean_line(line); > } > }); > $("#facet_biblios > table").tableDnD({ > onDragClass: "dragClass", > }); >+ >+ $('.add-search-field').click(function() { >+ var table = $(this).closest('table'); >+ var line = $(this).closest("tr"); >+ var name = $(line).find('input[data-id="search_field_name"]').val(); >+ let already_exist = 0; >+ >+ if ( $('input[name="search_field_name"][value="' + name + '"]').val() ) { >+ already_exist = 1; >+ } >+ >+ if (already_exist) { >+ alert("SearchField "+ name + " already exist"); >+ } else { >+ var label = $(line).find('input[data-id="search_field_label"]').val(); >+ if ( name.length > 0 && label.length > 0 ) { >+ var new_line = clone_line( line ); >+ new_line.appendTo(table.find('tbody')); >+ clean_line(line); >+ } >+ } >+ }); > }); >diff --git a/t/db_dependent/Koha/SearchField.t b/t/db_dependent/Koha/SearchField.t >index 8212d18..d2394fc 100755 >--- a/t/db_dependent/Koha/SearchField.t >+++ b/t/db_dependent/Koha/SearchField.t >@@ -19,10 +19,11 @@ > > use Modern::Perl; > >-use Test::More tests => 10; >+use Test::More tests => 12; > > use Koha::Database; > use Koha::SearchFields; >+use Koha::SearchMarcMaps; > > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -38,6 +39,32 @@ my $sf = $builder->build({ > source => 'SearchField', > }); > >+my $search_field = Koha::SearchFields->find($sf->{id}); >+ok(!$search_field->is_mapped, 'Search field 1 is not mapped'); >+ >+my $auth_smm = $builder->build({ >+ source => 'SearchMarcMap', >+ value => { >+ index_name => 'authorities', >+ marc_type => 'marc21', >+ marc_field => '200abde' >+ } >+}); >+ >+my $auth_smtf = $builder->build({ >+ source => 'SearchMarcToField', >+ value => { >+ search_marc_map_id => $auth_smm->{id}, >+ search_field_id => $sf->{id} >+ } >+}); >+ >+$search_field = Koha::SearchFields->find($sf->{id}); >+ok($search_field->is_mapped, 'Search field 1 is mapped'); >+ >+Koha::SearchMarcMaps->search({})->delete; >+$schema->resultset('SearchMarcToField')->search({})->delete; >+ > my $smm = $builder->build({ > source => 'SearchMarcMap', > value => { >@@ -72,7 +99,7 @@ my $smtf2 = $builder->build({ > } > }); > >-my $search_field = Koha::SearchFields->find($sf->{id}); >+$search_field = Koha::SearchFields->find($sf->{id}); > my $marc_maps = $search_field->search_marc_maps; > my $marc_map = $marc_maps->next; > is($marc_maps->count, 1, 'search_marc_maps should return 1 marc map'); >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20388
:
73158
|
73165
|
73167
|
73476
|
73626
|
73627
|
73629
|
73681
|
73682
|
73918
|
73919
|
73940
|
73943
|
73944
|
73945
|
73946
|
74261
|
74718
|
74719
|
78658
|
78659
|
80709
|
86912
|
87196
|
87197
|
87198
|
87199
|
87201
|
87202
|
87203
|
87204
|
88075
|
88079
|
88080
|
88081
|
88082
|
88083
|
89117
|
89118
|
89121
|
89733
|
89894
|
90517
|
90518
|
90519
|
90520
|
90521
|
90522
|
90523
|
90524
|
98011
|
98012
|
98013
|
98014
|
98015
|
98016
|
98017
|
98018
|
99960
|
99961
|
99962
|
99963
|
99964
|
99965
|
99966
|
99967
|
119296
|
119317
|
119318
|
120104
|
163449
|
163450
|
163451
|
163452
|
163460
|
163461
|
163462
|
163463
|
164529
|
164530
|
164531
|
164532
|
164533
|
164534
|
164535
|
164789
|
164790
|
164791
|
164792
|
164793