Bug 22639: Add export mappings button to mappings page

This patch adds an 'Export mappings' button to the Elasticsearch
mappings configuration page. It triggers a YAML download of the
current search field mappings using the new API endpoint.

To test:
1. Apply this patch (and the previous API endpoint patch)
2. Navigate to Administration > Search engine configuration
=> SUCCESS: An 'Export mappings' button appears next to 'Reset mappings'
3. Click 'Export mappings'
=> SUCCESS: A 'search_mappings.yaml' file is downloaded
4. Verify the YAML file contains the expected mappings structure
=> SUCCESS: File contains search fields grouped by index
5. Sign off :-D

Signed-off-by: Laurence <laurence.rault@biblibre.com>
Signed-off-by: Thomas Klausner <domm@plix.at>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2026-03-24 10:14:26 +01:00 committed by Lucas Gass
parent caa52ddf91
commit 75eeedd735
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 28 additions and 2 deletions

View File

@ -18,9 +18,9 @@
cursor: pointer;
}
</style>
</head>
<!--</head>-->
<body id="admin_searchengine_mappings" class="admin">
<!--<body id="admin_searchengine_mappings" class="admin">-->
[% WRAPPER 'header.inc' %]
[% INCLUDE 'prefs-admin-search.inc' %]
[% END %]
@ -590,6 +590,7 @@
<form method="get">
<fieldset class="action">
<button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa-solid fa-rotate" aria-hidden="true"></i> Reset mappings</button>
<a id="export_mappings" class="btn btn-default"><i class="fa-solid fa-download" aria-hidden="true"></i> Export mappings</a>
</fieldset>
</form>
[% END %]
@ -597,6 +598,31 @@
[% MACRO jsinclude BLOCK %]
[% INCLUDE 'datatables.inc' %]
[% Asset.js("js/elasticsearch-mappings.js") | $raw %]
<script nonce="[% Koha.CSPNonce | $raw %]">
$("#export_mappings").on("click", function (e) {
e.preventDefault();
fetch("/api/v1/config/search_mappings", {
headers: { Accept: "application/yaml" },
})
.then(function (response) {
if (!response.ok) throw new Error("Export failed");
return response.blob();
})
.then(function (blob) {
var url = URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = url;
a.download = "search_mappings.yaml";
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
})
.catch(function () {
alert(_("Failed to export mappings."));
});
});
</script>
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]