From 08ace3203b2aae3d87e478525ddb7350fde6fb0c Mon Sep 17 00:00:00 2001 From: Axel Amghar Date: Wed, 29 May 2019 09:20:44 +0200 Subject: [PATCH] Bug 19598: ES configuration - Make the columns searchable Test plan: - apply the patch - at the top of each table you have a search line - In search fields: verify that the search is correct with all the fields(name, label, type and weight) - Go to bilios table: verify that the search is correct with all the new fields - make a search and verify that the button reset search is valid - add some mappings (without save) and test the search again - save and test the search once again - then, make the same with authorities table --- .../admin/searchengine/elasticsearch/mappings.tt | 282 +++++++++++++++++++-- 1 file changed, 264 insertions(+), 18 deletions(-) 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..c2debb5 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 @@ -13,8 +13,17 @@ function clone_line( line ) { var new_line = $(line).clone(); + let my_index_name = $(new_line).find('td:first-child > input:first-child').val(); $(new_line).removeClass("nodrag nodrop"); - $(new_line).find('td:last-child>a').removeClass("add").addClass("delete").html(_("Delete")); + + //add class for the research + $(new_line).find('td:first-child > select').addClass("field_name_research_" + my_index_name); + $(new_line).find('td:nth-child(2)> select').addClass("sort_research_" + my_index_name); + $(new_line).find('td:nth-child(3)> select').addClass("facet_research_select_" + my_index_name); + $(new_line).find('td:nth-child(4)> select').addClass("suggestible_research_" + my_index_name); + $(new_line).find('td:nth-child(5)> input').addClass("mapping_research_" + my_index_name); + + $(new_line).find('td:last-child>a').removeClass("add").addClass("delete").html(' Delete'); $(new_line).find('[data-id]').each( function() { $(this).attr({ name: $(this).attr('data-id') }).removeAttr('data-id'); } ); @@ -26,6 +35,28 @@ return new_line; } + function search_input(imput_search_val, input_class) { + if (imput_search_val != ""){ + $('input.' + input_class ).each ( function () { + //if the search correspond with the begining of a input value + if (($(this).val().toLowerCase().indexOf(imput_search_val.toLowerCase()) == -1) + && ($(this).val().toLowerCase().indexOf(imput_search_val.replace(',','.').toLowerCase()) == -1)){ + $(this).parents('tr').hide(); + } + }); + } + } + + function search_select(select_search_val, select_class){ + if (select_search_val != "All"){ + $('select.' + select_class +' option:selected').each( function () { + if ($(this).val() != select_search_val){ + $(this).parents('tr').hide(); + } + }); + } + } + $(document).ready(function() { $("#tabs").tabs(); $('.delete').click(function() { @@ -38,11 +69,14 @@ $('.add').click(function() { var table = $(this).closest('table'); var index_name = $(table).attr('data-index_name'); + + //remove the no matches tr from if the search give no results search + $(".delete_tr_" + index_name).remove(); var line = $(this).closest("tr"); var marc_field = $(line).find('input[data-id="mapping_marc_field"]').val(); if ( marc_field.length > 0 ) { var new_line = clone_line( line ); - new_line.appendTo($('table[data-index_name="'+index_name+'"]>tbody')); + new_line.appendTo($('table[data-index_name="'+ index_name+ '"]>.' + index_name + '_table')); $('.delete').click(function() { $(this).parents('tr').remove(); }); @@ -56,9 +90,156 @@ $("#facet_biblios > table").tableDnD( { onDragClass: "dragClass", } ); + + + //SEARCH FOR SEARCH FIELDS TABLE + + let search_field_table = $(".search_field_table"); + search_field_table.each( function () { + $(this).children().attr("style","display: table-row"); + }); + + let searching_fields_name = $("#searching_fields_name"); + let searching_fields_label = $("#searching_fields_label"); + let searching_fields_type = $("#searching_fields_type"); + let searching_fields_weight = $("#searching_fields_weight"); + + function search_fields (){ + + $(".delete_tr").remove(); + search_field_table.each( function () { + $(this).children().show(); + }); + + search_input(searching_fields_name.val(),"field_name_research"); + search_input(searching_fields_label.val(),"field_label_research"); + search_select(searching_fields_type.val(),"field_type_research"); + search_input(searching_fields_weight.val(),"field_weight_research"); + + let find = false; + let tr_search_field_table = $(".search_field_table > tr"); + tr_search_field_table.each(function(){ + if ($(this).css("display") == "table-row"){ + find = true; + } + }); + if (find == false){ + search_field_table.append('

no matches

'); + } + } + + searching_fields_name.on("click paste keyup", search_fields); + searching_fields_label.on("click paste keyup", search_fields); + searching_fields_type.change(search_fields); + searching_fields_weight.on("click paste keyup", search_fields); + + //SEARCH FOR BIBLIOS AND AUTHORITIES TABLE + + [% FOREACH index IN indexes %] + + let [% index.index_name | html %]_table = $(".[% index.index_name | html %]_table"); + [% index.index_name | html %]_table.each( function () { + $(this).children().attr("style","display: table-row"); + }); + + let searching_fields_[% index.index_name | html %] = $("#searching_fields_[% index.index_name | html %]"); + let searching_sortable_[% index.index_name | html %] = $("#searching_sortable_[% index.index_name | html %]"); + let searching_facetable_[% index.index_name | html %] = $("#searching_facetable_[% index.index_name | html %]"); + let searching_suggestible_[% index.index_name | html %] = $("#searching_suggestible_[% index.index_name | html %]"); + let searching_mappings_[% index.index_name | html %] = $("#searching_mappings_[% index.index_name | html %]"); + + function search_[% index.index_name | html %] (){ + + //remove the no matches tr from the previous search + $(".delete_tr_[% index.index_name | html %]").remove(); + + [% index.index_name | html %]_table.each( function () { + $(this).children().show(); + }); + + search_input(searching_fields_[% index.index_name | html %].val(),"field_name_research_[% index.index_name | html %]"); + search_select(searching_sortable_[% index.index_name | html %].val(),"sort_research_[% index.index_name | html %]"); + search_select(searching_suggestible_[% index.index_name | html %].val(),"suggestible_research_[% index.index_name | html %]"); + search_input(searching_mappings_[% index.index_name | html %].val(),"mapping_research_[% index.index_name | html %]"); + + if (searching_fields_[% index.index_name | html %].val() != ""){ + $('select.field_name_research_[% index.index_name | html %] option:selected').each( function () { + if ($(this).val().toLowerCase().indexOf(searching_fields_[% index.index_name | html %].val().toLowerCase()) == -1 ){ + $(this).parents('tr').hide(); + } + }); + } + + if (searching_facetable_[% index.index_name | html %].val() != "All"){ + $('select.facet_research_select_[% index.index_name | html %] option:selected').each( function () { + if ($(this).val() != searching_facetable_[% index.index_name | html %].val()){ + $(this).parents('tr').hide(); + } + }); + $('input.facet_research_input_[% index.index_name | html %]').each( function () { + if ($(this).val() != searching_facetable_[% index.index_name | html %].val()){ + $(this).parents('tr').hide(); + } + }); + } + + let find = false; + let tr_[% index.index_name | html %]_table = $(".[% index.index_name | html %]_table > tr"); + tr_[% index.index_name | html %]_table.each(function(){ + if ($(this).css("display") == "table-row"){ + find = true; + } + }); + if (find == false){ + [% index.index_name | html %]_table.append('

no matches

'); + } + } + + searching_fields_[% index.index_name | html %].on("paste keyup", search_[% index.index_name | html %]); + searching_sortable_[% index.index_name | html %].change(search_[% index.index_name | html %]); + searching_facetable_[% index.index_name | html %].change(search_[% index.index_name | html %]); + searching_suggestible_[% index.index_name | html %].change(search_[% index.index_name | html %]); + searching_mappings_[% index.index_name | html %].on("click paste keyup", search_[% index.index_name | html %]); + + $('.reset_search_[% index.index_name | html %]').click(function() { + searching_fields_[% index.index_name | html %].val(""); + searching_sortable_[% index.index_name | html %].val("All"); + searching_facetable_[% index.index_name | html %].val("All"); + searching_suggestible_[% index.index_name | html %].val("All"); + searching_mappings_[% index.index_name | html %].val(""); + search_[% index.index_name | html %](); + }); + [% END %] });