From e53c9745765728eba14e35ce1edcee758a847431 Mon Sep 17 00:00:00 2001
From: Axel Amghar <axel.amghar@biblibre.com>
Date: Fri, 14 Jun 2019 15:45:20 +0200
Subject: [PATCH] Bug 22639: Elasticsearch ability to export mappings and
 facets settings

With this patch you can download search fields , facets order, biblios and authorities table in search engine configuration

Test plan:
- apply the patch
- make sure you have "elasticsearch" as value for the syspref "SearchEngine"
- go to search engine configuration in the admin page
- in the search fields part, you have a button "Export"
- verify all formats are correct
- verify that you have the same table in your file than in the search fields table
- make the same test for
	: biblios table
	: authorities table
- Add some mappings, modify some fields, change the facets order
- Save your modifications
- Then dowload again
- Your new files must be modified

ps:with this patch you can't download the facet order table
---
 admin/columns_settings.yml                         | 34 ++++++++++++++++++++++
 .../admin/searchengine/elasticsearch/mappings.tt   | 17 +++++++----
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml
index f484ed9..3ca6173 100644
--- a/admin/columns_settings.yml
+++ b/admin/columns_settings.yml
@@ -176,6 +176,40 @@ modules:
           cannot_be_toggled: 1
           cannot_be_modified: 1
 
+    mappings:
+      search-field-table:
+        -
+          columnname: names
+        -
+          columnname: label
+        -
+          columnname: type
+        -
+          columnname: weight
+
+      bilios-table:
+        -
+          columnname: search_field
+        -
+          columnname: sortable
+        -
+          columnname: facetable
+        -
+          columnname: suggestible
+        -
+          columnname: mapping
+
+      auth-table:
+        -
+          columnname: search_field
+        -
+          columnname: sortable
+        -
+          columnname: facetable
+        -
+          columnname: suggestible
+        -
+          columnname: mapping
 
   catalogue:
     detail:
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 d5b6f76..001c0c8 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
@@ -1,10 +1,12 @@
 [% USE raw %]
 [% USE Asset %]
+[% USE ColumnsSettings %]
 [% PROCESS 'i18n.inc' %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Search engine configuration</title>
 [% INCLUDE 'doc-head-close.inc' %]
 [% INCLUDE 'datatables.inc' %]
+[% INCLUDE 'columns_settings.inc' %]
 [% Asset.js("lib/jquery/plugins/jquery.tablednd.js") | $raw %]
 [% Asset.css("css/datatables.css") | $raw %]
 <script>
@@ -66,27 +68,30 @@
     }
 
     $(document).ready(function() {
+        let columns_settings_search_fields = [% ColumnsSettings.GetColumns('admin', 'mappings', 'search-field-table', 'json') | $raw %];
+        let columns_settings_biblios = [% ColumnsSettings.GetColumns('admin', 'mappings', 'bilios-table', 'json') | $raw %];
+        let columns_settings_authorities = [% ColumnsSettings.GetColumns('admin', 'mappings', 'auth-table', 'json') | $raw %];
         $("#tabs").tabs();
-            searchfieldst = $('#search-fieldst').dataTable($.extend(true, {}, dataTablesDefaults, {
+            searchfieldst = KohaTable("search-fieldst", {
                 "aoColumnDefs": [
                     { "sType": "string", "aTargets": [ "string-sort" ] }
                 ],
                 "sPaginationType": "full_numbers",
-            }));
+            }, columns_settings_search_fields);
 
-            bibliost = $('#bibliost').dataTable($.extend(true, {}, dataTablesDefaults, {
+            bibliost = KohaTable("bibliost", {
                 "aoColumnDefs": [
                     { "sType": "string", "aTargets": [ "string-sort" ] }
                 ],
                 "sPaginationType": "full_numbers",
-            }));
+            }, columns_settings_biblios);
 
-            authoritiest = $('#authoritiest').dataTable($.extend(true, {}, dataTablesDefaults, {
+            authoritiest = KohaTable("authoritiest" ,{
                 "aoColumnDefs": [
                     { "sType": "string", "aTargets": [ "string-sort" ] }
                 ],
                 "sPaginationType": "full_numbers",
-            }));
+            }, columns_settings_authorities);
 
             $('#save').click(function() {
                 show_all_rows();
-- 
2.7.4