Bugzilla – Attachment 87196 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 - Add/delete search fields from search engine configuration page
Bug-20388---Adddelete-search-fields-from-search-en.patch (text/plain), 8.53 KB, created by
Alex Arnaud
on 2019-03-29 12:57:53 UTC
(
hide
)
Description:
Bug 20388 - Add/delete search fields from search engine configuration page
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2019-03-29 12:57:53 UTC
Size:
8.53 KB
patch
obsolete
>From c2c3bb5c96d7224a8b657c50e8da4b69eba78dd1 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Thu, 22 Mar 2018 15:36:03 +0000 >Subject: [PATCH] Bug 20388 - Add/delete search fields from search engine > configuration page >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Test plan: > > - apply this patch, > - check that SearchEngine system preference is set to Elasticsearch, > - go to Admin > Search engine configuration, > - on the search fields tab, fill a new line at the bottom of the table > (name, label, type) > - click on the "Add" button and save, > - check that the new search field has been saved, > - also test field deletions, > - check that you can't delete already mapped fields. > >Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr> >Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/SearchField.pm | 12 +++++ > admin/searchengine/elasticsearch/mappings.pl | 14 ++++-- > .../admin/searchengine/elasticsearch/mappings.tt | 53 +++++++++++++++++++++- > t/db_dependent/Koha/SearchField.t | 30 +++++++++++- > 4 files changed, 103 insertions(+), 6 deletions(-) > >diff --git a/Koha/SearchField.pm b/Koha/SearchField.pm >index efabb8d..1bf782a 100644 >--- a/Koha/SearchField.pm >+++ b/Koha/SearchField.pm >@@ -70,6 +70,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 f91399a..298e5f7 100755 >--- a/admin/searchengine/elasticsearch/mappings.pl >+++ b/admin/searchengine/elasticsearch/mappings.pl >@@ -87,15 +87,19 @@ 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]; > my $field_type = $field_type[$i]; > my $field_weight = $field_weight[$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); >@@ -212,6 +216,10 @@ 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} = $schema->resultset('SearchMarcToField')->search( >+ { search_field_id => $search_field->id })->count; >+ > 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 33df1fb..6e90e7b 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 >@@ -53,9 +53,29 @@ > } ); > } > }); >+ > $("#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(); >+ var label = $(line).find('input[data-id="search_field_name"]').val(); >+ if ( name.length > 0 && label.length > 0 ) { >+ var new_line = clone_line( line ); >+ new_line.appendTo($('table[data-index_name=search_fields]>tbody')); >+ $('.delete').click(function() { >+ $(this).parents('tr').remove(); >+ }); >+ clean_line(line); >+ >+ $(table).tableDnD( { >+ onDragClass: "dragClass", >+ } ); >+ } >+ }); > }); > </script> > <style> >@@ -154,13 +174,14 @@ a.add, a.delete { > [% END %] > </ul> > <div id="search_fields"> >- <table class="search_fields"> >+ <table class="search_fields" data-index_name="search_fields"> > <thead> > <tr> > <th>Name</th> > <th>Label</th> > <th>Type</th> > <th>Weight</th> >+ <th></th> > </tr> > </thead> > <tbody> >@@ -217,9 +238,39 @@ a.add, a.delete { > <input type="hidden" name="search_field_weight" value=""> > [% END %] > </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> >+ </td> > </tr> > [% END %] > </tbody> >+ <tfoot> >+ <tr> >+ <td> >+ <input type="text" data-id="search_field_name"/> >+ </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="number">Number</option> >+ <option value="boolean">Boolean</option> >+ <option value="sum">Sum</option> >+ </select> >+ </td> >+ <td><input type="hidden" name="search_field_weight" value=""></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/t/db_dependent/Koha/SearchField.t b/t/db_dependent/Koha/SearchField.t >index af8f35d..f778713 100644 >--- a/t/db_dependent/Koha/SearchField.t >+++ b/t/db_dependent/Koha/SearchField.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 15; >+use Test::More tests => 17; > > use Koha::Database; > use Koha::SearchFields; >@@ -38,6 +38,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 +98,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