View | Details | Raw Unified | Return to bug 22639
Collapse All | Expand All

(-)a/admin/searchengine/elasticsearch/mappings.pl (+146 lines)
Lines 21-32 use Scalar::Util qw(looks_like_number); Link Here
21
use List::Util qw( first );
21
use List::Util qw( first );
22
use C4::Koha;
22
use C4::Koha;
23
use C4::Output;
23
use C4::Output;
24
use C4::Context;
24
use C4::Auth;
25
use C4::Auth;
26
use Text::CSV::Encoded;
27
use C4::Reports::Guided;
25
28
26
use Koha::SearchEngine::Elasticsearch;
29
use Koha::SearchEngine::Elasticsearch;
27
use Koha::SearchEngine::Elasticsearch::Indexer;
30
use Koha::SearchEngine::Elasticsearch::Indexer;
28
use Koha::SearchMarcMaps;
31
use Koha::SearchMarcMaps;
29
use Koha::SearchFields;
32
use Koha::SearchFields;
33
use Koha::Util::OpenDocument;
30
34
31
use Try::Tiny;
35
use Try::Tiny;
32
36
Lines 151-156 elsif( $op eq 'reset_confirmed' ) { Link Here
151
elsif( $op eq 'reset_confirm' ) {
155
elsif( $op eq 'reset_confirm' ) {
152
    $template->param( reset_confirm => 1 );
156
    $template->param( reset_confirm => 1 );
153
}
157
}
158
elsif ($op eq 'download'){
159
    my $format = $input->param("format");
160
    my $table  = $input->param("table");
161
    my ($type,$reportfilename, $csv, $ods_fh, $ods_filepath);
162
163
    if ($format eq "tab"){
164
        $type = 'application/octet-stream';
165
166
    } elsif ($format eq "csv"){
167
        $type = 'application/csv';
168
        my $delimiter = C4::Context->preference('delimiter') || ',';
169
        $delimiter = "\t" if ($delimiter eq 'tabulation');
170
        $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter});
171
        $csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag();
172
173
    } elsif ($format eq "ods"){
174
        $type = 'application/vnd.oasis.opendocument.spreadsheet';
175
        $ods_fh = File::Temp->new( UNLINK => 0 );
176
        $ods_filepath = $ods_fh->filename;
177
    }
178
179
    #search_fields var
180
    my (@search_field_names, @search_fileds_labels, @search_fileds_types, @search_field_weights);
181
    #facet_var
182
    my (@display_facet, @label_facet);
183
    #biblios and authorities var
184
    my (@sort, @facet, @suggestible, @marc_field);
185
186
    my @header_row;
187
    if ($table eq "search_fields"){
188
        $reportfilename = "search_fields_table";
189
        @search_field_names   = $input->multi_param("search_field_name");
190
        @search_fileds_labels = $input->multi_param("search_field_label");
191
        @search_fileds_types  = $input->multi_param("search_field_type");
192
        @search_field_weights = $input->multi_param("search_field_weight");
193
        @header_row = ("Name\t\t\t","Label\t\t\t","Type","Weight");
194
195
    } elsif ($table eq "facet"){
196
        $reportfilename = "facet_order_table";
197
        @search_field_names = $input->multi_param("search_fields_facet");
198
        @label_facet        = $input->multi_param("label_facet");
199
        @display_facet      = $input->multi_param("display");
200
        @header_row = ("Search field","Label\t\t","Display");
201
202
    } else {
203
        $reportfilename = $table . "_table";
204
        @search_field_names = $input->multi_param("search_field_names_". $table);
205
        @sort               = $input->multi_param("sort_". $table);
206
        @facet              = $input->multi_param("facet_". $table);
207
        @suggestible        = $input->multi_param("suggestible_". $table);
208
        @marc_field         = $input->multi_param("marc_field_". $table);
209
        @header_row = ("Search field\t","Sortable","Facetable","Suggestible","Mapping");
210
    }
211
212
    my $i = 0;
213
    my ($content, $ods_content);
214
215
    if ($format eq 'tab') {
216
        $reportfilename .= ".tab";
217
        $content .= join("\t\t", @header_row) . "\n";
218
        $content = Encode::decode('UTF-8', $content);
219
220
        foreach my $search_field_name (@search_field_names){
221
            my @row;
222
            if ($table eq "search_fields"){
223
                $search_field_name .= ' ' while (length($search_field_name)< 25);
224
                $search_fileds_labels[$i] .= ' ' while (length($search_fileds_labels[$i])< 25);
225
                @row = ($search_field_name, $search_fileds_labels[$i], $search_fileds_types[$i], $search_field_weights[$i]);
226
            } elsif ($table eq "facet"){
227
                $search_field_name .= ' ' while (length($search_field_name)< 15);
228
                $label_facet[$i] .= ' ' while (length($label_facet[$i])< 20);
229
                @row = ($search_field_name, $label_facet[$i], $display_facet[$i]);
230
            } else {
231
                $search_field_name .= ' ' while (length($search_field_name)< 20);
232
                $sort[$i] .= ' ' while (length($sort[$i])< 15);
233
                $facet[$i] .= ' ' while (length($facet[$i])< 15);
234
                $suggestible[$i] .= ' ' while (length($suggestible[$i])< 15);
235
                @row = ($search_field_name,$sort[$i],$facet[$i],$suggestible[$i],$marc_field[$i]);
236
            }
237
            $content .= join("\t\t", @row) . "\n";
238
            $i++;
239
        }
240
    } elsif( $format eq 'csv' ) {
241
        $reportfilename .= ".csv";
242
        if ($csv->combine(@header_row)) {
243
            $content .= Encode::decode('UTF-8', $csv->string()) . "\n";
244
                foreach my $search_field_name (@search_field_names){
245
                    my @row;
246
				    if ($table eq "search_fields"){
247
                        @row = ($search_field_name,$search_fileds_labels[$i],$search_fileds_types[$i],$search_field_weights[$i]);
248
                    } elsif ($table eq "facet"){
249
                        @row = ($search_field_name, $label_facet[$i], $display_facet[$i]);
250
                    } else {
251
                        @row = ($search_field_name,$sort[$i],$facet[$i],$suggestible[$i],$marc_field[$i]);
252
                    }
253
                    if ($csv->combine(@row)) {
254
                        $content .= $csv->string() . "\n";
255
                    }
256
                    $i++;
257
                }
258
            }
259
    } elsif ( $format eq 'ods' ) {
260
        $reportfilename .= ".ods";
261
        my @headers = @header_row;
262
        push @$ods_content, \@headers;
263
264
        foreach my $search_field_name (@search_field_names){
265
            my @content_row;
266
            if ($table eq "search_fields"){
267
                push @content_row, Encode::encode( 'UTF8', $search_field_name ), Encode::encode( 'UTF8', $search_fileds_labels[$i] ) , $search_fileds_types[$i],$search_field_weights[$i];
268
            } elsif ($table eq "facet"){
269
                push @content_row, Encode::encode( 'UTF8', $search_field_name ), Encode::encode( 'UTF8', $label_facet[$i] ) , $display_facet[$i];
270
            } else {
271
                push @content_row, Encode::encode( 'UTF8', $search_field_name ), $sort[$i] , $facet[$i], $suggestible[$i], Encode::encode( 'UTF8', $marc_field[$i] );
272
            }
273
            push @$ods_content, \@content_row;
274
                $i++;
275
            }
276
        generate_ods($ods_filepath, $ods_content);
277
        binmode(STDOUT);
278
        open $ods_fh, '<', $ods_filepath;
279
        $content .= $_ while <$ods_fh>;
280
        unlink $ods_filepath;
281
    }
282
283
    print $input->header(
284
        -type => $type,
285
        -attachment=> $reportfilename
286
    );
287
    print $content;
288
    exit;
289
}
154
290
155
291
156
my @indexes;
292
my @indexes;
Lines 215-225 while ( my $search_field = $search_fields->next ) { Link Here
215
    push @all_search_fields, $search_field_unblessed;
351
    push @all_search_fields, $search_field_unblessed;
216
}
352
}
217
353
354
my @extensions = ("csv","tab","ods");
355
my @formats_and_extensions =("Semicolon separated test (.csv)","Tab separated text (.tab)","Open Document Spreadsheet (.ods)");
356
my @formats;
357
my $j = 0;
358
foreach my $extension (@extensions){
359
    push (@formats , { extension => $extension, format_and_extension =>$formats_and_extensions[$j] });
360
    $j++;
361
}
362
218
$template->param(
363
$template->param(
219
    indexes           => \@indexes,
364
    indexes           => \@indexes,
220
    all_search_fields => \@all_search_fields,
365
    all_search_fields => \@all_search_fields,
221
    facetable_fields  => \@facetable_fields,
366
    facetable_fields  => \@facetable_fields,
222
    messages          => \@messages,
367
    messages          => \@messages,
368
    formats           => \@formats,
223
);
369
);
224
370
225
output_html_with_http_headers $input, $cookie, $template->output;
371
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-6 / +121 lines)
Lines 26-31 Link Here
26
        return new_line;
26
        return new_line;
27
    }
27
    }
28
28
29
    function create_input(value, name){
30
        $("#save_or_reset").append('<input class="remove" type="hidden" value="' + value + '" name="' + name + '"/>' );
31
    }
32
33
    function create_submit(format, table_name){
34
        $(".remove").remove();
35
        create_input("download","op");
36
        create_input(format,"format");
37
        create_input(table_name,"table");
38
        $("#save_or_reset").submit();
39
    }
40
29
    $(document).ready(function() {
41
    $(document).ready(function() {
30
        $("#tabs").tabs();
42
        $("#tabs").tabs();
31
        $('.delete').click(function() {
43
        $('.delete').click(function() {
Lines 56-67 Link Here
56
        $("#facet_biblios > table").tableDnD( {
68
        $("#facet_biblios > table").tableDnD( {
57
            onDragClass: "dragClass",
69
            onDragClass: "dragClass",
58
        } );
70
        } );
71
72
        $("#edit").click(function () {
73
            $(".remove").remove();
74
            create_input("edit","op");
75
            $("#save_or_reset").submit();
76
        });
77
        $("#reset_confirm").click(function () {
78
            $(".remove").remove();
79
            create_input("reset_confirm","op");
80
            $("#save_or_reset").submit();
81
        });
82
83
        [% FOREACH format IN formats %]
84
            $("#link_[% format.extension | html %]").click( function () {
85
                create_submit("[% format.extension | html %]","search_fields");
86
            });
87
            $("#link_[% format.extension | html %]_facet").click( function () {
88
                create_submit("[% format.extension | html %]","facet");
89
            });
90
91
            [% FOREACH index IN indexes %]
92
            $("#link_[% index.index_name | html %]_[% format.extension | html %]").click( function () {
93
                create_submit("[% format.extension | html %]","[% index.index_name | html %]");
94
            });
95
          [% END %]
96
        [% END %]
59
    });
97
    });
60
</script>
98
</script>
61
<style>
99
<style>
62
a.add, a.delete {
100
a.add, a.delete {
63
    cursor: pointer;
101
    cursor: pointer;
64
}
102
}
103
104
#inline {
105
    display : inline;
106
}
107
65
</style>
108
</style>
66
</head>
109
</head>
67
<body id="admin_searchengine_mappings" class="admin">
110
<body id="admin_searchengine_mappings" class="admin">
Lines 142-148 a.add, a.delete { Link Here
142
            </form>
185
            </form>
143
        </div>
186
        </div>
144
    [% END %]
187
    [% END %]
145
    <form method="post">
188
    <form method="post" id="save_or_reset" >
146
        <div id="tabs" class="toptabs" style="clear:both">
189
        <div id="tabs" class="toptabs" style="clear:both">
147
            <ul>
190
            <ul>
148
                <li><a href="#search_fields">Search fields</a></li>
191
                <li><a href="#search_fields">Search fields</a></li>
Lines 154-159 a.add, a.delete { Link Here
154
                [% END %]
197
                [% END %]
155
            </ul>
198
            </ul>
156
            <div id="search_fields">
199
            <div id="search_fields">
200
                <div id="inline">
201
                    <button class="btn btn-default" type="submit" name="op" value="edit"><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
202
                    <button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
203
204
                    <div class="btn-group">
205
                        <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" class="format"><i class="fa fa-upload"></i> Download Search fields table <span class="caret"></span></button>
206
                        <ul class="dropdown-menu">
207
                          [% FOREACH format IN formats%]
208
                            <li><a href="#" id="link_[% format.extension | html %]">[% format.format_and_extension | html%]</a></li>
209
                          [% END %]
210
                        </ul>
211
                    </div><br/>
212
                </div><br/>
213
157
              <table class="search_fields">
214
              <table class="search_fields">
158
                <thead>
215
                <thead>
159
                  <tr>
216
                  <tr>
Lines 222-229 a.add, a.delete { Link Here
222
                </tbody>
279
                </tbody>
223
              </table>
280
              </table>
224
            </div>
281
            </div>
282
225
            [% FOREACH index IN indexes %]
283
            [% FOREACH index IN indexes %]
226
                <div id="mapping_[% index.index_name | html %]">
284
                <div id="mapping_[% index.index_name | html %]">
285
                    <div id="inline">
286
                      <button class="btn btn-default" type="submit" name="op" value="edit"><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
287
                      <button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
288
289
                      <div class="btn-group">
290
                        <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" class="format"><i class="fa fa-upload"></i> Download [% index.index_name | html %] table <span class="caret"></span></button>
291
                        <ul class="dropdown-menu">
292
                          [% FOREACH format IN formats%]
293
                            <li><a href="#" id="link_[% index.index_name | html %]_[% format.extension | html %]">[% format.format_and_extension | html%]</a></li>
294
                          [% END %]
295
                        </ul>
296
                      </div>
297
298
                      [% IF index.index_name == "biblios" %]
299
                        <div class="btn-group">
300
                          <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" class="format"><i class="fa fa-upload"></i> Download facet order table <span class="caret"></span></button>
301
                          <ul class="dropdown-menu">
302
                            [% FOREACH format IN formats%]
303
                              <li><a href="#" id="link_[% format.extension | html %]_facet">[% format.format_and_extension | html%]</a></li>
304
                            [% END %]
305
                          </ul>
306
                        </div>
307
                      [% END %]
308
                      <br/>
309
                    </div><br/>
310
311
                    [% FOREACH mappings IN index.mappings %]
312
                      <input type="hidden" value="[% mappings.search_field_name | html %]" name="search_field_names_[% index.index_name | html %]" />
313
                      <input type="hidden" value="[% mappings.sort | html %]" name="sort_[% index.index_name | html %]" />
314
                      <input type="hidden" value="[% mappings.facet | html %]" name="facet_[% index.index_name | html %]" />
315
                      <input type="hidden" value="[% mappings.suggestible | html %]" name="suggestible_[% index.index_name | html %]" />
316
                      <input  type="hidden" value="[% mappings.marc_field | html %]" name="marc_field_[% index.index_name | html %]" />
317
                    [% END %]
318
227
                    <table class="mappings" data-index_name="[% index.index_name | html %]">
319
                    <table class="mappings" data-index_name="[% index.index_name | html %]">
228
                      <thead>
320
                      <thead>
229
                        <tr class="nodrag nodrop">
321
                        <tr class="nodrag nodrop">
Lines 357-383 a.add, a.delete { Link Here
357
                                        <tr>
449
                                        <tr>
358
                                            <td>
450
                                            <td>
359
                                                [% f.name | html %]
451
                                                [% f.name | html %]
452
                                                <input type="hidden" value="[% f.name | html %]" name="search_fields_facet" />
360
                                            </td>
453
                                            </td>
361
                                            <td>
454
                                            <td>
362
                                                [% SWITCH f.name %]
455
                                                [% SWITCH f.name %]
363
                                                [% CASE 'author' %]Authors
456
                                                [% CASE 'author' %]Authors
457
                                                <input type="hidden" value="Authors" name="label_facet" />
458
364
                                                [% CASE 'itype' %]Item Types
459
                                                [% CASE 'itype' %]Item Types
460
                                                <input type="hidden" value="Item Types" name="label_facet" />
461
365
                                                [% CASE 'location' %]Locations
462
                                                [% CASE 'location' %]Locations
463
                                                <input type="hidden" value="Locations" name="label_facet" />
464
366
                                                [% CASE 'su-geo' %]Places
465
                                                [% CASE 'su-geo' %]Places
466
                                                <input type="hidden" value="Places" name="label_facet" />
467
367
                                                [% CASE 'title-series' %]Series
468
                                                [% CASE 'title-series' %]Series
469
                                                <input type="hidden" value="Series" name="label_facet" />
470
368
                                                [% CASE 'subject' %]Topics
471
                                                [% CASE 'subject' %]Topics
472
                                                <input type="hidden" value="Topics" name="label_facet" />
473
369
                                                [% CASE 'ccode' %]Collections
474
                                                [% CASE 'ccode' %]Collections
475
                                                <input type="hidden" value="Collections" name="label_facet" />
476
370
                                                [% CASE 'holdingbranch' %]Holding libraries
477
                                                [% CASE 'holdingbranch' %]Holding libraries
478
                                                <input type="hidden" value="Holding libraries" name="label_facet" />
479
371
                                                [% CASE 'homebranch' %]Home libraries
480
                                                [% CASE 'homebranch' %]Home libraries
481
                                                <input type="hidden" value="Home libraries" name="label_facet" />
482
372
                                                [% CASE 'ln' %]Language
483
                                                [% CASE 'ln' %]Language
484
                                                <input type="hidden" value="Language" name="label_facet" />
373
                                                [% CASE %][% f | html %]
485
                                                [% CASE %][% f | html %]
374
                                                [% END %]
486
                                                [% END %]
487
375
                                            </td>
488
                                            </td>
376
                                            <td>
489
                                            <td>
377
                                                [% IF f.facet_order %]
490
                                                [% IF f.facet_order %]
378
                                                    <input type="checkbox" name="display_facet" value="[% f.name | html %]" checked="checked" />
491
                                                    <input type="checkbox" name="display_facet" value="[% f.name | html %]" checked="checked" />
492
                                                    <input type="hidden" value="1" name="display" />
379
                                                [% ELSE %]
493
                                                [% ELSE %]
380
                                                    <input type="checkbox" name="display_facet" value="[% f.name | html %]" />
494
                                                    <input type="checkbox" name="display_facet" value="[% f.name | html %]" />
495
                                                    <input type="hidden" value="0" name="display" />
381
                                                [% END %]
496
                                                [% END %]
382
                                            </td>
497
                                            </td>
383
                                        </tr>
498
                                        </tr>
Lines 389-400 a.add, a.delete { Link Here
389
                </div>
504
                </div>
390
            [% END %]
505
            [% END %]
391
        </div>
506
        </div>
392
        <p>
507
393
            <button class="btn btn-default" type="submit" name="op" value="edit"><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
394
            <button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
395
        </p>
396
    </form>
508
    </form>
397
509
510
    <p>
511
      <button id ="edit" class="btn btn-default" type="submit" ><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
512
      <button id="reset_confirm" class="btn btn-default" type="submit"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
513
    </p>
398
            </main>
514
            </main>
399
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
515
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
400
516
401
- 

Return to bug 22639