Bug 19482: (follow-up) Fix select and adjust export of new field
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / searchengine / elasticsearch / mappings.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% PROCESS 'i18n.inc' %]
4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Koha &rsaquo; Administration &rsaquo; Search engine configuration (Elasticsearch)</title>
6 [% INCLUDE 'doc-head-close.inc' %]
7 [% Asset.js("lib/jquery/plugins/jquery.tablednd.js") | $raw %]
8 <script>
9     function clean_line( line ) {
10         $(line).find('input[type="text"]').val("");
11         $(line).find('select').find('option:first').attr("selected", "selected");
12     }
13
14     function clone_line( line ) {
15         var new_line = $(line).clone();
16         $(new_line).removeClass("nodrag nodrop");
17         $(new_line).find('td:last-child>a').removeClass("add").addClass("delete").html(_("Delete"));
18         $(new_line).find('[data-id]').each( function() {
19             $(this).attr({ name: $(this).attr('data-id') }).removeAttr('data-id');
20         } );
21         $(new_line).find("select").each( function() {
22             var attr = $(this).attr('name');
23             var val = $(line).find('[data-id="' + attr + '"]').val();
24             $(this).find('option[value="' + val + '"]').attr("selected", "selected");
25         } );
26         return new_line;
27     }
28
29     $(document).ready(function() {
30         $("#tabs").tabs();
31         $('.delete').click(function() {
32             if( $(this).hasClass('mandatory') && $(".mandatory[data-field_name="+$(this).attr('data-field_name')+"]").length < 2 ){
33                 alert("This field is mandatory and must have at least one mapping");
34                 return;
35             } else {
36                 $(this).parents('tr').remove();
37             }
38         });
39
40         $("table.mappings").tableDnD( {
41             onDragClass: "dragClass",
42         } );
43         $('.add').click(function() {
44             var table = $(this).closest('table');
45             var index_name   = $(table).attr('data-index_name');
46             var line = $(this).closest("tr");
47             var marc_field = $(line).find('input[data-id="mapping_marc_field"]').val();
48             if ( marc_field.length > 0 ) {
49                 var new_line = clone_line( line );
50                 new_line.appendTo($('table[data-index_name="'+index_name+'"]>tbody'));
51                 $('.delete').click(function() {
52                     $(this).parents('tr').remove();
53                 });
54                 clean_line(line);
55
56                 $(table).tableDnD( {
57                     onDragClass: "dragClass",
58                 } );
59             }
60         });
61         $("#facet_biblios > table").tableDnD( {
62             onDragClass: "dragClass",
63         } );
64     });
65 </script>
66 <style>
67 a.add, a.delete {
68     cursor: pointer;
69 }
70 </style>
71 </head>
72 <body id="admin_searchengine_mappings" class="admin">
73 [% INCLUDE 'header.inc' %]
74 [% INCLUDE 'prefs-admin-search.inc' %]
75
76 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Search engine configuration (Elasticsearch)</div>
77
78 [% INCLUDE 'blocking_errors.inc' %]
79
80 <div class="main container-fluid">
81     <div class="row">
82         <div class="col-sm-10 col-sm-push-2">
83             <main>
84
85     [% FOR m IN messages %]
86       <div class="dialog [% m.type | html %]">
87         [% SWITCH m.code %]
88         [% CASE 'error_on_update' %]
89           [% tx("An error occurred when updating mappings: {message}.", { message = m.message }) | html %]
90         [% CASE 'error_on_delete' %]
91           [% t("An error occurred when deleting the existing mappings. Nothing has been changed!") | $raw %]
92           [% tx("(search field {field_name} with mapping {marc_field}.)", { field_name = m.values.field_name, marc_field = m.values.marc_field }) | html %]
93         [% CASE 'invalid_field_weight' %]
94           [% tx("Invalid field weight '{weight}', must be a positive decimal number.", { weight = m.weight }) | html %]
95         [% CASE 'missing_mandatory_fields' %]
96           [% t("You attempted to delete all mappings for a required index, you must leave at least one mapping") | $raw %]
97         [% CASE 'error_on_update_es_mappings' %]
98           [% tx("An error occurred when updating Elasticsearch index mappings: {message}.", { message = m.message }) | html %]
99         [% CASE 'reindex_required' %]
100           [% tx("Index '{index}' needs to be reindexed.", { index = m.index }) | html %]
101         [% CASE 'recreate_required' %]
102           [% tx("Index '{index}' needs to be recreated.", { index = m.index }) | html %]
103         [% CASE 'success_on_update' %]
104           [% t("Mappings updated successfully.") | $raw %]
105         [% CASE 'success_on_reset' %]
106           [% t("Mappings have been reset successfully.") | $raw %]
107         [% CASE 'elasticsearch_disabled' %]
108           [% t("Elasticsearch is currently disabled.") | $raw %]
109         [% CASE %]
110           [% m.code | html %]
111         [% END %]
112       </div>
113     [% END %]
114
115     <h1>Search engine configuration (Elasticsearch)</h1>
116     <div class="dialog message">
117         Warning: Any changes to the configuration will only take effect after a full reindex. Until then searching may not work correctly.
118
119         <p>Weight: define weight as a positive number. Higher numbers indicate increased relevancy.
120         <strong>Note that fields weighting works only for simple search.</strong></p>
121         <ol>
122           <li>only search fields mapped with biblios can be weighted</li>
123           <li>search will boost/increase weighted field(s) relevancy</li>
124         </ol>
125     </div>
126     [% IF errors %]
127         <div class="dialog alert">
128         Changes have not been applied. Please check the following values:
129           <ul>
130             [% FOREACH e IN errors %]
131                 <li>
132                     [% IF ( e.type == "malformed_mapping" ) %]
133                         <span>The value "[% e.value | html %]" is not supported for mappings</span>
134                     [% ELSIF ( e.type == "no_mapping" ) %]
135                         <span>There is no mapping for the index [% e.value | html %]</span>
136                     [% END %]
137                 </li>
138             [% END %]
139           </ul>
140         </div>
141     [% END %]
142
143     [% IF reset_confirm %]
144         <div class="dialog alert">
145             <h3>The current mappings you see on the screen will be erased and replaced by the mappings in the mappings.yaml file.</h3>
146             <form method="post">
147                 <input type="hidden" name="op" value="reset_confirmed" />
148                 <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, reset mappings</button>
149             </form>
150             <br>
151             <form method="post">
152                 <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not reset mappings</button>
153             </form>
154         </div>
155     [% END %]
156     <form method="post">
157         <div id="tabs" class="toptabs" style="clear:both">
158             <ul>
159                 <li><a href="#search_fields">Search fields</a></li>
160                 [% FOREACH index IN indexes %]
161                     [% SWITCH index.index_name %]
162                         [% CASE 'biblios' %]<li><a href="#mapping_biblios">Bibliographic records</a></li>
163                         [% CASE 'authorities' %]<li><a href="#mapping_authorities">Authorities</a></li>
164                     [% END %]
165                 [% END %]
166             </ul>
167             <div id="search_fields">
168               <table class="search_fields">
169                 <thead>
170                   <tr>
171                     <th>Name</th>
172                     <th>Label</th>
173                     <th>Type</th>
174                     <th colspan="2">Searchable</th>
175                     <th>Weight</th>
176                   </tr>
177                   <tr>
178                     <th colspan=3>&nbsp;</th>
179                     <th>Staff interface</th>
180                     <th>OPAC</th>
181                     <th>&nbsp;</th>
182                   </tr>
183                 </thead>
184                 <tbody>
185                   [% FOREACH search_field IN all_search_fields %]
186                       [% IF search_field.mandatory %]
187                           [% SET is_readonly = "readonly" %]
188                       [% ELSE %]
189                           [% SET is_readonly = "" %]
190                       [% END %]
191                     <tr>
192                       <td>
193                         <input type="text" name="search_field_name" value="[% search_field.name | html %]" [% is_readonly %]/>
194                       </td>
195                       <td>
196                         <input type="text" name="search_field_label" value="[% search_field.label | html %]" [% is_readonly %]/>
197                       <td>
198                         [% IF is_readonly %]
199                             <input type="hidden" name="search_field_type" value="[% search_field.type | html %]" />
200                             <select name="search_field_type" disabled>
201                         [% ELSE %]
202                             <select name="search_field_type">
203                         [% END %]
204                               <option value=""></option>
205                               [% IF search_field.type == "string" %]
206                                 <option value="string" selected="selected">String</option>
207                               [% ELSE %]
208                                 <option value="string">String</option>
209                               [% END %]
210                               [% IF search_field.type == "date" %]
211                                 <option value="date" selected="selected">Date</option>
212                               [% ELSE %]
213                                 <option value="date">Date</option>
214                               [% END %]
215                               [% IF search_field.type == "year" %]
216                                 <option value="year" selected="selected">Year</option>
217                               [% ELSE %]
218                                 <option value="year">Year</option>
219                               [% END %]
220                               [% IF search_field.type == "number" %]
221                                 <option value="number" selected="selected">Number</option>
222                               [% ELSE %]
223                                 <option value="number">Number</option>
224                               [% END %]
225                               [% IF search_field.type == "boolean" %]
226                                 <option value="boolean" selected="selected">Boolean</option>
227                               [% ELSE %]
228                                 <option value="boolean">Boolean</option>
229                               [% END %]
230                               [% IF search_field.type == "sum" %]
231                                 <option value="sum" selected="selected">Sum</option>
232                               [% ELSE %]
233                                 <option value="sum">Sum</option>
234                               [% END %]
235                               [% IF search_field.type == "isbn" %]
236                                 <option value="isbn" selected="selected">ISBN</option>
237                               [% ELSE %]
238                                 <option value="isbn">ISBN</option>
239                               [% END %]
240                               [% IF search_field.type == "stdno" %]
241                                 <option value="stdno" selected="selected">Std. Number</option>
242                               [% ELSE %]
243                                 <option value="stdno">Std. Number</option>
244                               [% END %]
245                             </select>
246                       </td>
247                       <td>
248                         <select name="search_field_staff_client">
249                           [% IF search_field.staff_client %]
250                             <option value="1" selected="selected">Yes</option>
251                             <option value="0">No</option>
252                           [% ELSE %]
253                             <option value="1">Yes</option>
254                             <option value="0" selected="selected">No</option>
255                           [% END %]
256                         </select>
257                       </td>
258                       <td>
259                         <select name="search_field_opac">
260                           [% IF search_field.opac %]
261                             <option value="1" selected="selected">Yes</option>
262                             <option value="0">No</option>
263                           [% ELSE %]
264                             <option value="1">Yes</option>
265                             <option value="0" selected="selected">No</option>
266                           [% END %]
267                         </select>
268                       </td>
269                       <td>
270                         [% IF search_field.mapped_biblios %]
271                             <input type="number" step="0.01" min="0.01" max="999.99" name="search_field_weight" value="[% search_field.weight | html %]" />
272                         [% ELSE %]
273                             <input type="hidden" name="search_field_weight" value="">
274                         [% END %]
275                       </td>
276                     </tr>
277                   [% END %]
278                 </tbody>
279               </table>
280             </div>
281             [% FOREACH index IN indexes %]
282                 <div id="mapping_[% index.index_name | html %]">
283                     <table class="mappings" data-index_name="[% index.index_name | html %]">
284                       <thead>
285                         <tr class="nodrag nodrop">
286                           <th>Search field</th>
287                           <th>Sortable</th>
288                           <th>Facetable</th>
289                           <th>Suggestible</th>
290                           <th>Searchable</th>
291                           <th>Mapping</th>
292                           <th></th>
293                         </tr>
294                       </thead>
295                       <tbody>
296                         [% FOREACH mapping IN index.mappings %]
297                             [% IF mapping.search_field_mandatory && mapping.search_field_label != loop.next.search_field_label && mapping.search_field_label != loop.prev.search_field_label %]
298                               <tr>
299                                 <td>
300                                   <input type="hidden" name="mapping_index_name" value="[% index.index_name | html %]" />
301                                   <input type="hidden" name="mapping_search_field_name" value="[% mapping.search_field_name | html %]">
302                                   [% mapping.search_field_label | html %]
303                                 </td>
304                                 <td>
305                                   <input type="hidden" name="mapping_sort" value="[% mapping.sort | html %]" readonly />[% IF mapping.sort == 'undef' %]Undef[% ELSE %][% mapping.sort | html %][% END %]
306                                 </td>
307                                 <td>
308                                   <input type="hidden" name="mapping_facet" value="[% mapping.facet | html %]" readonly />[% IF mapping.facet == 1 %]Yes[% ELSE %]No[% END %]
309                                 </td>
310                                 <td>
311                                   <input type="hidden" name="mapping_suggestible" value="[% mapping.suggestible | html %]" readonly />[% IF mapping.suggestible == 1 %]Yes[% ELSE %]No[% END %]
312                                 </td>
313                                 <td>
314                                   <input type="hidden" name="mapping_search" value="[% mapping.search | html %]" readonly />[% IF mapping.search == 1 %]Yes[% ELSE %]No[% END %]
315                                 </td>
316                                 <td>
317                                     <input name="mapping_marc_field" type="text" value="[% mapping.marc_field | html %]" />
318                                 </td>
319                               </tr>
320                             [% ELSE %]
321                               <tr>
322                                 <td>
323                                   <input type="hidden" name="mapping_index_name" value="[% index.index_name | html %]" />
324                                   <input type="hidden" name="mapping_search_field_name" value="[% mapping.search_field_name | html %]">
325                                   [% mapping.search_field_label | html %]
326                                 </td>
327                                 <td>
328                                   <select name="mapping_sort">
329                                     [% IF mapping.sort == 'undef' %]
330                                       <option value="undef" selected="selected">Undef</option>
331                                     [% ELSE %]
332                                       <option value="undef">Undef</option>
333                                     [% END %]
334                                     [% IF mapping.sort == 0 %]
335                                       <option value="0" selected="selected">0</option>
336                                     [% ELSE %]
337                                       <option value="0">0</option>
338                                     [% END %]
339                                     [% IF  mapping.sort == 1 %]
340                                       <option value="1" selected="selected">1</option>
341                                     [% ELSE %]
342                                       <option value="1">1</option>
343                                     [% END %]
344                                   </select>
345                                 </td>
346                                 <td>
347                                   [% IF mapping.is_facetable %]
348                                     <select name="mapping_facet">
349                                       [% IF mapping.facet %]
350                                         <option value="0">No</option>
351                                         <option value="1" selected="selected">Yes</option>
352                                       [% ELSE %]
353                                         <option value="0" selected="selected">No</option>
354                                         <option value="1">Yes</option>
355                                       [% END %]
356                                     </select>
357                                   [% ELSE %]
358                                     <input type="hidden" name="mapping_facet" value="0" />
359                                     No
360                                   [% END %]
361                                 </td>
362                                 <td>
363                                   <select name="mapping_suggestible">
364                                     [% IF mapping.suggestible %]
365                                       <option value="0">No</option>
366                                       <option value="1" selected="selected">Yes</option>
367                                     [% ELSE %]
368                                       <option value="0" selected="selected">No</option>
369                                       <option value="1">Yes</option>
370                                     [% END %]
371                                   </select>
372                                 </td>
373                                 <td>
374                                   <select name="mapping_search">
375                                     [% IF mapping.search %]
376                                       <option value="0">No</option>
377                                       <option value="1" selected="selected">Yes</option>
378                                     [% ELSE %]
379                                       <option value="0" selected="selected">No</option>
380                                       <option value="1">Yes</option>
381                                     [% END %]
382                                   </select>
383                                 </td>
384                                 <td>
385                                     <input name="mapping_marc_field" type="text" value="[% mapping.marc_field | html %]" />
386                                 </td>
387                                 [% IF mapping.search_field_mandatory %]
388                                     <td><a class="btn btn-default btn-xs delete mandatory" data-field_name="[% mapping.search_field_name %]" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a></td>
389                                 [% ELSE %]
390                                     <td><a class="btn btn-default btn-xs delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a></td>
391                                 [% END %]
392                               </tr>
393                             [% END %]
394                         [% END %]
395                       </tbody>
396                       <tfoot>
397                         <tr class="nodrag nodrop">
398                           <td>
399                             <input data-id="mapping_index_name" type="hidden" value="[% index.index_name | html %]" />
400                             <select data-id="mapping_search_field_name">
401                              [% FOREACH f IN all_search_fields %]
402                                <option value="[% f.name | html %]">[% f.name | html %]</option>
403                              [% END %]
404                             </select>
405                           </td>
406                           <td>
407                             <select data-id="mapping_sort">
408                               <option value="undef">Undef</option>
409                               <option value="0">0</option>
410                               <option value="1">1</option>
411                             </select>
412                           </td>
413                           <td>
414                             <select data-id="mapping_facet">
415                               [% IF mapping.facet %]
416                                 <option value="0">No</option>
417                                 <option value="1" selected="selected">Yes</option>
418                               [% ELSE %]
419                                 <option value="0" selected="selected">No</option>
420                                 <option value="1">Yes</option>
421                               [% END %]
422                             </select>
423                           </td>
424                           <td>
425                             <select data-id="mapping_suggestible">
426                               [% IF mapping.suggestible %]
427                                 <option value="0">No</option>
428                                 <option value="1" selected="selected">Yes</option>
429                               [% ELSE %]
430                                 <option value="0" selected="selected">No</option>
431                                 <option value="1">Yes</option>
432                               [% END %]
433                             </select>
434                           </td>
435                           <td>
436                             <select data-id="mapping_search">
437                               [% IF mapping.search %]
438                                 <option value="0">No</option>
439                                 <option value="1" selected="selected">Yes</option>
440                               [% ELSE %]
441                                 <option value="0" selected="selected">No</option>
442                                 <option value="1">Yes</option>
443                               [% END %]
444                             </select>
445                           </td>
446                           <td><input data-id="mapping_marc_field" type="text" /></td>
447                           <td><a class="btn btn-default btn-xs add"><i class="fa fa-plus"></i> Add</a></td>
448                         </tr>
449                       </tfoot>
450                     </table>
451
452                     [% IF index.index_name == 'biblios' %]
453                         <h3>Facet order</h3>
454                         <div id="facet_[% index.index_name | html %]">
455                             <table>
456                                 <thead>
457                                     <tr>
458                                         <th>Search field</th>
459                                         <th>Label</th>
460                                         <th>Display</th>
461                                     </tr>
462                                 </thead>
463                                 <tbody>
464                                     [% FOREACH f IN facetable_fields %]
465                                         <tr>
466                                             <td>
467                                                 [% f.name | html %]
468                                             </td>
469                                             <td>
470                                                 [% SWITCH f.name %]
471                                                 [% CASE 'author' %]Authors
472                                                 [% CASE 'itype' %]Item Types
473                                                 [% CASE 'location' %]Locations
474                                                 [% CASE 'su-geo' %]Places
475                                                 [% CASE 'title-series' %]Series
476                                                 [% CASE 'subject' %]Topics
477                                                 [% CASE 'ccode' %]Collections
478                                                 [% CASE 'holdingbranch' %]Holding libraries
479                                                 [% CASE 'homebranch' %]Home libraries
480                                                 [% CASE 'ln' %]Language
481                                                 [% CASE %][% f | html %]
482                                                 [% END %]
483                                             </td>
484                                             <td>
485                                                 [% IF f.facet_order %]
486                                                     <input type="checkbox" name="display_facet" value="[% f.name | html %]" checked="checked" />
487                                                 [% ELSE %]
488                                                     <input type="checkbox" name="display_facet" value="[% f.name | html %]" />
489                                                 [% END %]
490                                             </td>
491                                         </tr>
492                                     [% END %]
493                                 </tbody>
494                             </table>
495                         </div>
496                     [% END %]
497                 </div>
498             [% END %]
499         </div>
500         <p>
501             <button class="btn btn-default" type="submit" name="op" value="edit"><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
502             <button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
503         </p>
504     </form>
505
506             </main>
507         </div> <!-- /.col-sm-10.col-sm-push-2 -->
508
509         <div class="col-sm-2 col-sm-pull-10">
510             <aside>
511                 [% INCLUDE 'admin-menu.inc' %]
512             </aside>
513         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
514      </div> <!-- /.row -->
515
516 [% INCLUDE 'intranet-bottom.inc' %]