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

(-)a/Koha/SearchField.pm (+12 lines)
Lines 70-75 sub search_marc_maps { Link Here
70
    return $marc_map_fields;
70
    return $marc_map_fields;
71
}
71
}
72
72
73
=head3 is_mapped
74
75
my $is_mapped = $search_field->is_mapped
76
77
=cut
78
79
sub is_mapped {
80
    my ( $self ) = @_;
81
82
    return $self->search_marc_maps()->count ? 1 : 0;
83
}
84
73
=head3 is_mapped_biblios
85
=head3 is_mapped_biblios
74
86
75
my $is_mapped_biblios = $search_field->is_mapped_biblios
87
my $is_mapped_biblios = $search_field->is_mapped_biblios
(-)a/admin/searchengine/elasticsearch/mappings.pl (-3 / +11 lines)
Lines 87-101 if ( $op eq 'edit' ) { Link Here
87
87
88
    eval {
88
    eval {
89
89
90
        Koha::SearchFields->search()->delete;
91
90
        for my $i ( 0 .. scalar(@field_name) - 1 ) {
92
        for my $i ( 0 .. scalar(@field_name) - 1 ) {
91
            my $field_name = $field_name[$i];
93
            my $field_name = $field_name[$i];
92
            my $field_label = $field_label[$i];
94
            my $field_label = $field_label[$i];
93
            my $field_type = $field_type[$i];
95
            my $field_type = $field_type[$i];
94
            my $field_weight = $field_weight[$i];
96
            my $field_weight = $field_weight[$i];
95
97
96
            my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } );
98
            my $search_field = Koha::SearchFields->find_or_create({
97
            $search_field->label($field_label);
99
                name => $field_name,
98
            $search_field->type($field_type);
100
                label => $field_label,
101
                type => $field_type,
102
            });
99
103
100
            if (!length($field_weight)) {
104
            if (!length($field_weight)) {
101
                $search_field->weight(undef);
105
                $search_field->weight(undef);
Lines 212-217 my @all_search_fields; Link Here
212
while ( my $search_field = $search_fields->next ) {
216
while ( my $search_field = $search_fields->next ) {
213
    my $search_field_unblessed = $search_field->unblessed;
217
    my $search_field_unblessed = $search_field->unblessed;
214
    $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios;
218
    $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios;
219
220
    $search_field_unblessed->{is_mapped} = $schema->resultset('SearchMarcToField')->search(
221
        { search_field_id => $search_field->id })->count;
222
215
    push @all_search_fields, $search_field_unblessed;
223
    push @all_search_fields, $search_field_unblessed;
216
}
224
}
217
225
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-1 / +52 lines)
Lines 53-61 Link Here
53
                } );
53
                } );
54
            }
54
            }
55
        });
55
        });
56
56
        $("#facet_biblios > table").tableDnD( {
57
        $("#facet_biblios > table").tableDnD( {
57
            onDragClass: "dragClass",
58
            onDragClass: "dragClass",
58
        } );
59
        } );
60
61
        $('.add-search-field').click(function() {
62
            var table = $(this).closest('table');
63
            var line = $(this).closest("tr");
64
            var name = $(line).find('input[data-id="search_field_name"]').val();
65
            var label = $(line).find('input[data-id="search_field_name"]').val();
66
            if ( name.length > 0 && label.length > 0 ) {
67
                var new_line = clone_line( line );
68
                new_line.appendTo($('table[data-index_name=search_fields]>tbody'));
69
                $('.delete').click(function() {
70
                    $(this).parents('tr').remove();
71
                });
72
                clean_line(line);
73
74
                $(table).tableDnD( {
75
                    onDragClass: "dragClass",
76
                } );
77
            }
78
        });
59
    });
79
    });
60
</script>
80
</script>
61
<style>
81
<style>
Lines 154-166 a.add, a.delete { Link Here
154
                [% END %]
174
                [% END %]
155
            </ul>
175
            </ul>
156
            <div id="search_fields">
176
            <div id="search_fields">
157
              <table class="search_fields">
177
              <table class="search_fields" data-index_name="search_fields">
158
                <thead>
178
                <thead>
159
                  <tr>
179
                  <tr>
160
                    <th>Name</th>
180
                    <th>Name</th>
161
                    <th>Label</th>
181
                    <th>Label</th>
162
                    <th>Type</th>
182
                    <th>Type</th>
163
                    <th>Weight</th>
183
                    <th>Weight</th>
184
                    <th></th>
164
                  </tr>
185
                  </tr>
165
                </thead>
186
                </thead>
166
                <tbody>
187
                <tbody>
Lines 217-225 a.add, a.delete { Link Here
217
                        <input type="hidden" name="search_field_weight" value="">
238
                        <input type="hidden" name="search_field_weight" value="">
218
                      [% END %]
239
                      [% END %]
219
                      </td>
240
                      </td>
241
                      <td>
242
                        [% IF search_field.is_mapped %]
243
                          <a class="btn btn-default btn-xs disabled delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
244
                        [% ELSE %]
245
                          <a class="btn btn-default btn-xs delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
246
                        [% END %]
247
                      </td>
248
                      </td>
220
                    </tr>
249
                    </tr>
221
                  [% END %]
250
                  [% END %]
222
                </tbody>
251
                </tbody>
252
                <tfoot>
253
                  <tr>
254
                    <td>
255
                      <input type="text" data-id="search_field_name"/>
256
                    </td>
257
                    <td>
258
                      <input type="text" data-id="search_field_label"/>
259
                    </td>
260
                    <td>
261
                      <select data-id="search_field_type">
262
                        <option value=""></option>
263
                        <option value="string">String</option>
264
                        <option value="date">Date</option>
265
                        <option value="number">Number</option>
266
                        <option value="boolean">Boolean</option>
267
                        <option value="sum">Sum</option>
268
                      </select>
269
                    </td>
270
                    <td><input type="hidden" name="search_field_weight" value=""></td>
271
                    <td><a class="btn btn-default btn-xs add-search-field"><i class="fa fa-plus"></i> Add</a></td>
272
                  </tr>
273
                </tfoot>
223
              </table>
274
              </table>
224
            </div>
275
            </div>
225
            [% FOREACH index IN indexes %]
276
            [% FOREACH index IN indexes %]
(-)a/t/db_dependent/Koha/SearchField.t (-3 / +28 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 15;
22
use Test::More tests => 17;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::SearchFields;
25
use Koha::SearchFields;
Lines 38-43 my $sf = $builder->build({ Link Here
38
    source => 'SearchField',
38
    source => 'SearchField',
39
});
39
});
40
40
41
my $search_field = Koha::SearchFields->find($sf->{id});
42
ok(!$search_field->is_mapped, 'Search field 1 is not mapped');
43
44
my $auth_smm = $builder->build({
45
    source => 'SearchMarcMap',
46
    value => {
47
        index_name  => 'authorities',
48
        marc_type   => 'marc21',
49
        marc_field  => '200abde'
50
    }
51
});
52
53
my $auth_smtf = $builder->build({
54
    source => 'SearchMarcToField',
55
    value => {
56
        search_marc_map_id  => $auth_smm->{id},
57
        search_field_id     => $sf->{id}
58
    }
59
});
60
61
$search_field = Koha::SearchFields->find($sf->{id});
62
ok($search_field->is_mapped, 'Search field 1 is mapped');
63
64
Koha::SearchMarcMaps->search({})->delete;
65
$schema->resultset('SearchMarcToField')->search({})->delete;
66
41
my $smm = $builder->build({
67
my $smm = $builder->build({
42
    source => 'SearchMarcMap',
68
    source => 'SearchMarcMap',
43
    value => {
69
    value => {
Lines 72-78 my $smtf2 = $builder->build({ Link Here
72
    }
98
    }
73
});
99
});
74
100
75
my $search_field = Koha::SearchFields->find($sf->{id});
101
$search_field = Koha::SearchFields->find($sf->{id});
76
my $marc_maps = $search_field->search_marc_maps;
102
my $marc_maps = $search_field->search_marc_maps;
77
my $marc_map = $marc_maps->next;
103
my $marc_map = $marc_maps->next;
78
is($marc_maps->count, 1, 'search_marc_maps should return 1 marc map');
104
is($marc_maps->count, 1, 'search_marc_maps should return 1 marc map');
79
- 

Return to bug 20388