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

(-)a/admin/searchengine/elasticsearch/mappings.pl (+166 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, $content, $reportfilename, $csv, $ods_fh, $ods_filepath, $ods_content);
162
    my $i = 0;
163
164
    if ($format eq "tab"){
165
        $type = 'application/octet-stream';
166
167
    } elsif ($format eq "csv"){
168
        $type = 'application/csv';
169
        my $delimiter = C4::Context->preference('delimiter') || ',';
170
        $delimiter = "\t" if ($delimiter eq 'tabulation');
171
        $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter});
172
        $csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag();
173
174
    } elsif ($format eq "ods"){
175
        $type = 'application/vnd.oasis.opendocument.spreadsheet';
176
        $ods_fh = File::Temp->new( UNLINK => 0 );
177
        $ods_filepath = $ods_fh->filename;
178
    }
179
180
    if ($table eq "search_fields"){
181
        $reportfilename = "search_fields_table";
182
        my @search_field_names   = $input->multi_param("search_field_name");
183
        my @search_fileds_labels = $input->multi_param("search_field_label");
184
        my @search_fileds_types  = $input->multi_param("search_field_type");
185
        my @search_field_weights = $input->multi_param("search_field_weight");
186
187
        if ($format eq 'tab') {
188
            my @header_row = ("Name\t\t\t","Label\t\t\t","Type","Weight");
189
            $content .= join("\t\t", @header_row) . "\n";
190
            $content = Encode::decode('UTF-8', $content);
191
192
            foreach my $search_field_name (@search_field_names){
193
                my @row;
194
                $search_field_name .= ' ' while (length($search_field_name)< 25);
195
                $search_fileds_labels[$i] .= ' ' while (length($search_fileds_labels[$i])< 25);
196
                @row = ($search_field_name, $search_fileds_labels[$i], $search_fileds_types[$i], $search_field_weights[$i]);
197
                $content .= join("\t\t", @row) . "\n";
198
                $i++;
199
            }
200
        } else {
201
            my @header_row = ("Name","Label","Type","Weight");
202
203
            if ( $format eq 'csv' ) {
204
                if ($csv->combine(@header_row)) {
205
                    $content .= Encode::decode('UTF-8', $csv->string()) . "\n";
206
                    foreach my $search_field_name (@search_field_names){
207
                        my @row;
208
                        @row = ($search_field_name,$search_fileds_labels[$i],$search_fileds_types[$i],$search_field_weights[$i]);
209
                        if ($csv->combine(@row)) {
210
                            $content .= $csv->string() . "\n";
211
                        }
212
                        $i++;
213
                    }
214
                }
215
            } elsif ( $format eq 'ods' ) {
216
                my @headers = @header_row;
217
                push @$ods_content, \@headers;
218
219
                foreach my $search_field_name (@search_field_names){
220
                    my @content_row;
221
                    push @content_row, Encode::encode( 'UTF8', $search_field_name ), Encode::encode( 'UTF8', $search_fileds_labels[$i] ) , $search_fileds_types[$i],$search_field_weights[$i];
222
                    push @$ods_content, \@content_row;
223
                    $i++;
224
                }
225
                generate_ods($ods_filepath, $ods_content);
226
                binmode(STDOUT);
227
                open $ods_fh, '<', $ods_filepath;
228
                $content .= $_ while <$ods_fh>;
229
                unlink $ods_filepath;
230
            }
231
        }
232
    } else {
233
        my (@search_field_names, @sort, @facet, @suggestible, @marc_field);
234
        if ($table eq "biblios"){
235
            $reportfilename = "biblios_table";
236
            @search_field_names = $input->multi_param("search_field_names_biblios");
237
            @sort               = $input->multi_param("sort_biblios");
238
            @facet              = $input->multi_param("facet_biblios");
239
            @suggestible        = $input->multi_param("suggestible_biblios");
240
            @marc_field         = $input->multi_param("marc_field_biblios");
241
242
        } elsif ($table eq "authorities"){
243
            $reportfilename = "authorities_table";
244
            @search_field_names = $input->multi_param("search_field_names_authorities");
245
            @sort               = $input->multi_param("sort_authorities");
246
            @facet              = $input->multi_param("facet_authorities");
247
            @suggestible        = $input->multi_param("suggestible_authorities");
248
            @marc_field         = $input->multi_param("marc_field_authorities");
249
        }
250
        if ($format eq "tab"){
251
            my @header_row = ("Search field\t\t","Sortable","Facetable","Suggestible","Mapping");
252
            $content .= join("\t", @header_row) . "\n";
253
            $content = Encode::decode('UTF-8', $content);
254
255
            foreach my $search_field_name (@search_field_names){
256
                my @row;
257
                $search_field_name .= ' ' while (length($search_field_name)< 20);
258
                @row = ($search_field_name,$sort[$i],$facet[$i],$suggestible[$i],$marc_field[$i]);
259
                $content .= join("\t\t", @row) . "\n";
260
                $i++;
261
            }
262
        } else {
263
            my @header_row = ("Search field","Sortable","Facetable","Suggestible","Mapping ");
264
            if ( $format eq 'csv' ) {
265
                if ($csv->combine(@header_row)) {
266
                    $content .= Encode::decode('UTF-8', $csv->string()) . "\n";
267
                    foreach my $search_field_name (@search_field_names){
268
                        my @row;
269
                        @row = ($search_field_name,$sort[$i],$facet[$i],$suggestible[$i],$marc_field[$i]);
270
                        if ($csv->combine(@row)) {
271
                            $content .= $csv->string() . "\n";
272
                        }
273
                        $i++;
274
                    }
275
                }
276
            } elsif ( $format eq 'ods' ) {
277
                my @headers = @header_row;
278
                push @$ods_content, \@headers;
279
280
                foreach my $search_field_name (@search_field_names){
281
                    my @content_row;
282
                    push @content_row, Encode::encode( 'UTF8', $search_field_name ), $sort[$i] , $facet[$i], $suggestible[$i], Encode::encode( 'UTF8', $marc_field[$i] );
283
                    push @$ods_content, \@content_row;
284
                    $i++;
285
                }
286
                generate_ods($ods_filepath, $ods_content);
287
                binmode(STDOUT);
288
                open $ods_fh, '<', $ods_filepath;
289
                $content .= $_ while <$ods_fh>;
290
                unlink $ods_filepath;
291
            }
292
        }
293
    }
294
295
    if ($format eq "tab"){
296
        $reportfilename .= ".tab";
297
    } elsif ($format eq "csv"){
298
        $reportfilename .= ".csv";
299
    } elsif ($format eq "ods"){
300
        $reportfilename .= ".ods";
301
    }
302
303
    print $input->header(
304
        -type => $type,
305
        -attachment=> $reportfilename
306
    );
307
    print $content;
308
    exit;
309
}
154
310
155
311
156
my @indexes;
312
my @indexes;
Lines 215-225 while ( my $search_field = $search_fields->next ) { Link Here
215
    push @all_search_fields, $search_field_unblessed;
371
    push @all_search_fields, $search_field_unblessed;
216
}
372
}
217
373
374
my @extensions = ("csv","tab","ods");
375
my @formats_and_extensions =("Semicolon separated test (.csv)","Tab separated text (.tab)","Open Document Spreadsheet (.ods)");
376
my @formats;
377
my $j = 0;
378
foreach my $extension (@extensions){
379
    push (@formats , { extension => $extension, format_and_extension =>$formats_and_extensions[$j] });
380
    $j++;
381
}
382
218
$template->param(
383
$template->param(
219
    indexes           => \@indexes,
384
    indexes           => \@indexes,
220
    all_search_fields => \@all_search_fields,
385
    all_search_fields => \@all_search_fields,
221
    facetable_fields  => \@facetable_fields,
386
    facetable_fields  => \@facetable_fields,
222
    messages          => \@messages,
387
    messages          => \@messages,
388
    formats           => \@formats,
223
);
389
);
224
390
225
output_html_with_http_headers $input, $cookie, $template->output;
391
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-6 / +83 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
88
            [% FOREACH index IN indexes %]
89
            $("#link_[% index.index_name | html %]_[% format.extension | html %]").click( function () {
90
                create_submit("[% format.extension | html %]","[% index.index_name | html %]");
91
            });
92
          [% END %]
93
        [% END %]
59
    });
94
    });
60
</script>
95
</script>
61
<style>
96
<style>
62
a.add, a.delete {
97
a.add, a.delete {
63
    cursor: pointer;
98
    cursor: pointer;
64
}
99
}
100
101
#inline {
102
    display : inline;
103
}
104
65
</style>
105
</style>
66
</head>
106
</head>
67
<body id="admin_searchengine_mappings" class="admin">
107
<body id="admin_searchengine_mappings" class="admin">
Lines 142-148 a.add, a.delete { Link Here
142
            </form>
182
            </form>
143
        </div>
183
        </div>
144
    [% END %]
184
    [% END %]
145
    <form method="post">
185
    <form method="post" id="save_or_reset" >
146
        <div id="tabs" class="toptabs" style="clear:both">
186
        <div id="tabs" class="toptabs" style="clear:both">
147
            <ul>
187
            <ul>
148
                <li><a href="#search_fields">Search fields</a></li>
188
                <li><a href="#search_fields">Search fields</a></li>
Lines 154-159 a.add, a.delete { Link Here
154
                [% END %]
194
                [% END %]
155
            </ul>
195
            </ul>
156
            <div id="search_fields">
196
            <div id="search_fields">
197
                <div id="inline">
198
                    <button class="btn btn-default" type="submit" name="op" value="edit"><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
199
                    <button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
200
201
                    <div class="btn-group">
202
                        <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>
203
                        <ul class="dropdown-menu">
204
                          [% FOREACH format IN formats%]
205
                            <li><a href="#" id="link_[% format.extension | html %]">[% format.format_and_extension | html%]</a></li>
206
                          [% END %]
207
                        </ul>
208
                    </div><br/>
209
                </div><br/>
210
157
              <table class="search_fields">
211
              <table class="search_fields">
158
                <thead>
212
                <thead>
159
                  <tr>
213
                  <tr>
Lines 222-229 a.add, a.delete { Link Here
222
                </tbody>
276
                </tbody>
223
              </table>
277
              </table>
224
            </div>
278
            </div>
279
225
            [% FOREACH index IN indexes %]
280
            [% FOREACH index IN indexes %]
226
                <div id="mapping_[% index.index_name | html %]">
281
                <div id="mapping_[% index.index_name | html %]">
282
                    <div id="inline">
283
                      <button class="btn btn-default" type="submit" name="op" value="edit"><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
284
                      <button class="btn btn-default" type="submit" name="op" value="reset_confirm"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
285
286
                      <div class="btn-group">
287
                        <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>
288
                        <ul class="dropdown-menu">
289
                          [% FOREACH format IN formats%]
290
                            <li><a href="#" id="link_[% index.index_name | html %]_[% format.extension | html %]">[% format.format_and_extension | html%]</a></li>
291
                          [% END %]
292
                        </ul>
293
                      </div><br/>
294
                    </div><br/>
295
296
                    [% FOREACH mappings IN index.mappings %]
297
                      <input type="hidden" value="[% mappings.search_field_name | html %]" name="search_field_names_[% index.index_name | html %]" />
298
                      <input type="hidden" value="[% mappings.sort | html %]" name="sort_[% index.index_name | html %]" />
299
                      <input type="hidden" value="[% mappings.facet | html %]" name="facet_[% index.index_name | html %]" />
300
                      <input type="hidden" value="[% mappings.suggestible | html %]" name="suggestible_[% index.index_name | html %]" />
301
                      <input  type="hidden" value="[% mappings.marc_field | html %]" name="marc_field_[% index.index_name | html %]" />
302
                    [% END %]
303
227
                    <table class="mappings" data-index_name="[% index.index_name | html %]">
304
                    <table class="mappings" data-index_name="[% index.index_name | html %]">
228
                      <thead>
305
                      <thead>
229
                        <tr class="nodrag nodrop">
306
                        <tr class="nodrag nodrop">
Lines 389-400 a.add, a.delete { Link Here
389
                </div>
466
                </div>
390
            [% END %]
467
            [% END %]
391
        </div>
468
        </div>
392
        <p>
469
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>
470
    </form>
397
471
472
    <p>
473
      <button id ="edit" class="btn btn-default" type="submit" ><i class="fa fa-hdd-o" aria-hidden="true"></i> Save</button>
474
      <button id="reset_confirm" class="btn btn-default" type="submit"><i class="fa fa-refresh" aria-hidden="true"></i> Reset Mappings</button>
475
    </p>
398
            </main>
476
            </main>
399
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
477
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
400
478
401
- 

Return to bug 22639