Bugzilla – Attachment 73918 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.52 KB, created by
Alex Arnaud
on 2018-04-10 09:51:29 UTC
(
hide
)
Description:
Bug 20388 - Add/delete search fields from search engine configuration page
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2018-04-10 09:51:29 UTC
Size:
8.52 KB
patch
obsolete
>From c6135f765e1a0f20118817ef175f6cd784779c95 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 | 16 +++++++ > admin/searchengine/elasticsearch/mappings.pl | 17 +++++--- > .../admin/searchengine/elasticsearch/mappings.tt | 49 +++++++++++++++++++++- > t/db_dependent/Koha/SearchField.t | 30 ++++++++++++- > 4 files changed, 104 insertions(+), 8 deletions(-) > >diff --git a/Koha/SearchField.pm b/Koha/SearchField.pm >index a734204..8ee405d 100644 >--- a/Koha/SearchField.pm >+++ b/Koha/SearchField.pm >@@ -67,6 +67,22 @@ sub search_marc_maps { > > } > >+=head3 is_mapped >+ >+my $is_mapped = $search_field->is_mapped >+ >+=cut >+ >+sub is_mapped { >+ my ( $self ) = @_; >+ >+ if ( scalar $self->search_marc_maps ) { >+ return 1; >+ } >+ >+ return 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 0c5def7..3c681c6 100755 >--- a/admin/searchengine/elasticsearch/mappings.pl >+++ b/admin/searchengine/elasticsearch/mappings.pl >@@ -62,17 +62,20 @@ 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); >- $search_field->weight($field_weight || ''); >- $search_field->store; >+ my $search_field = Koha::SearchFields->find_or_create({ >+ name => $field_name, >+ label => $field_label, >+ type => $field_type, >+ weight =>$field_weight >+ }); > } > > Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete; >@@ -142,6 +145,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 7a4774c..ed097e1 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 >@@ -50,6 +50,24 @@ > } ); > } > }); >+ $('.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 type="text/css"> >@@ -127,13 +145,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> >@@ -184,9 +203,37 @@ a.add, a.delete { > [% ELSE %] > <td><input type="hidden" name="search_field_weight" value=""></td> > [% END %] >+ <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> >+ <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><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 3338b59..99e4675 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 => 16; >+use Test::More tests => 18; > > 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_map = $search_field->search_marc_maps; > is(scalar(@marc_map), 1, 'search_marc_maps should return 1 marc map'); > is($marc_map[0]->index_name, 'biblios', 'Marc map index name is biblios'); >-- >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