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 63-77 if ( $op eq 'edit' ) { Link Here
63
63
64
    eval {
64
    eval {
65
65
66
        Koha::SearchFields->search()->delete;
67
66
        for my $i ( 0 .. scalar(@field_name) - 1 ) {
68
        for my $i ( 0 .. scalar(@field_name) - 1 ) {
67
            my $field_name = $field_name[$i];
69
            my $field_name = $field_name[$i];
68
            my $field_label = $field_label[$i];
70
            my $field_label = $field_label[$i];
69
            my $field_type = $field_type[$i];
71
            my $field_type = $field_type[$i];
70
            my $field_weight = $field_weight[$i];
72
            my $field_weight = $field_weight[$i];
71
73
72
            my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } );
74
            my $search_field = Koha::SearchFields->find_or_create({
73
            $search_field->label($field_label);
75
                name => $field_name,
74
            $search_field->type($field_type);
76
                label => $field_label,
77
                type => $field_type,
78
            });
75
79
76
            if (!length($field_weight)) {
80
            if (!length($field_weight)) {
77
                $search_field->weight(undef);
81
                $search_field->weight(undef);
Lines 156-161 my @all_search_fields; Link Here
156
while ( my $search_field = $search_fields->next ) {
160
while ( my $search_field = $search_fields->next ) {
157
    my $search_field_unblessed = $search_field->unblessed;
161
    my $search_field_unblessed = $search_field->unblessed;
158
    $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios;
162
    $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios;
163
164
    $search_field_unblessed->{is_mapped} = $schema->resultset('SearchMarcToField')->search(
165
        { search_field_id => $search_field->id })->count;
166
159
    push @all_search_fields, $search_field_unblessed;
167
    push @all_search_fields, $search_field_unblessed;
160
}
168
}
161
169
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-1 / +50 lines)
Lines 52-57 Link Here
52
                } );
52
                } );
53
            }
53
            }
54
        });
54
        });
55
        $('.add-search-field').click(function() {
56
            var table = $(this).closest('table');
57
            var line = $(this).closest("tr");
58
            var name = $(line).find('input[data-id="search_field_name"]').val();
59
            var label = $(line).find('input[data-id="search_field_name"]').val();
60
            if ( name.length > 0 && label.length > 0 ) {
61
                var new_line = clone_line( line );
62
                new_line.appendTo($('table[data-index_name=search_fields]>tbody'));
63
                $('.delete').click(function() {
64
                    $(this).parents('tr').remove();
65
                });
66
                clean_line(line);
67
68
                $(table).tableDnD( {
69
                    onDragClass: "dragClass",
70
                } );
71
            }
72
        });
55
    });
73
    });
56
</script>
74
</script>
57
<style>
75
<style>
Lines 144-156 a.add, a.delete { Link Here
144
                [% END %]
162
                [% END %]
145
            </ul>
163
            </ul>
146
            <div id="search_fields">
164
            <div id="search_fields">
147
              <table class="search_fields">
165
              <table class="search_fields" data-index_name="search_fields">
148
                <thead>
166
                <thead>
149
                  <tr>
167
                  <tr>
150
                    <th>Name</th>
168
                    <th>Name</th>
151
                    <th>Label</th>
169
                    <th>Label</th>
152
                    <th>Type</th>
170
                    <th>Type</th>
153
                    <th>Weight</th>
171
                    <th>Weight</th>
172
                    <th></th>
154
                  </tr>
173
                  </tr>
155
                </thead>
174
                </thead>
156
                <tbody>
175
                <tbody>
Lines 207-215 a.add, a.delete { Link Here
207
                        <input type="hidden" name="search_field_weight" value="">
226
                        <input type="hidden" name="search_field_weight" value="">
208
                      [% END %]
227
                      [% END %]
209
                      </td>
228
                      </td>
229
                      <td>
230
                        [% IF search_field.is_mapped %]
231
                          <a class="btn btn-default btn-xs disabled delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
232
                        [% ELSE %]
233
                          <a class="btn btn-default btn-xs delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
234
                        [% END %]
235
                      </td>
236
                      </td>
210
                    </tr>
237
                    </tr>
211
                  [% END %]
238
                  [% END %]
212
                </tbody>
239
                </tbody>
240
                <tfoot>
241
                  <tr>
242
                    <td>
243
                      <input type="text" data-id="search_field_name"/>
244
                    </td>
245
                    <td>
246
                      <input type="text" data-id="search_field_label"/>
247
                    </td>
248
                    <td>
249
                      <select data-id="search_field_type">
250
                        <option value=""></option>
251
                        <option value="string">String</option>
252
                        <option value="date">Date</option>
253
                        <option value="number">Number</option>
254
                        <option value="boolean">Boolean</option>
255
                        <option value="sum">Sum</option>
256
                      </select>
257
                    </td>
258
                    <td><input type="hidden" name="search_field_weight" value=""></td>
259
                    <td><a class="btn btn-default btn-xs add-search-field"><i class="fa fa-plus"></i> Add</a></td>
260
                  </tr>
261
                </tfoot>
213
              </table>
262
              </table>
214
            </div>
263
            </div>
215
            [% FOREACH index IN indexes %]
264
            [% 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