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 (-5 / +12 lines)
Lines 62-78 if ( $op eq 'edit' ) { Link Here
62
62
63
    eval {
63
    eval {
64
64
65
        Koha::SearchFields->search()->delete;
66
65
        for my $i ( 0 .. scalar(@field_name) - 1 ) {
67
        for my $i ( 0 .. scalar(@field_name) - 1 ) {
66
            my $field_name = $field_name[$i];
68
            my $field_name = $field_name[$i];
67
            my $field_label = $field_label[$i];
69
            my $field_label = $field_label[$i];
68
            my $field_type = $field_type[$i];
70
            my $field_type = $field_type[$i];
69
            my $field_weight = $field_weight[$i];
71
            my $field_weight = $field_weight[$i];
70
72
71
            my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } );
73
            my $search_field = Koha::SearchFields->find_or_create({
72
            $search_field->label($field_label);
74
                name => $field_name,
73
            $search_field->type($field_type);
75
                label => $field_label,
74
            $search_field->weight($field_weight || '');
76
                type => $field_type,
75
            $search_field->store;
77
                weight =>$field_weight
78
            });
76
        }
79
        }
77
80
78
        Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete;
81
        Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete;
Lines 142-147 my @all_search_fields; Link Here
142
while ( my $search_field = $search_fields->next ) {
145
while ( my $search_field = $search_fields->next ) {
143
    my $search_field_unblessed = $search_field->unblessed;
146
    my $search_field_unblessed = $search_field->unblessed;
144
    $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios;
147
    $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios;
148
149
    $search_field_unblessed->{is_mapped} = $schema->resultset('SearchMarcToField')->search(
150
        { search_field_id => $search_field->id })->count;
151
145
    push @all_search_fields, $search_field_unblessed;
152
    push @all_search_fields, $search_field_unblessed;
146
}
153
}
147
154
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-1 / +49 lines)
Lines 51-56 Link Here
51
                } );
51
                } );
52
            }
52
            }
53
        });
53
        });
54
        $('.add-search-field').click(function() {
55
            var table = $(this).closest('table');
56
            var line = $(this).closest("tr");
57
            var name = $(line).find('input[data-id="search_field_name"]').val();
58
            var label = $(line).find('input[data-id="search_field_name"]').val();
59
            if ( name.length > 0 && label.length > 0 ) {
60
                var new_line = clone_line( line );
61
                new_line.appendTo($('table[data-index_name=search_fields]>tbody'));
62
                $('.delete').click(function() {
63
                    $(this).parents('tr').remove();
64
                });
65
                clean_line(line);
66
67
                $(table).tableDnD( {
68
                    onDragClass: "dragClass",
69
                } );
70
            }
71
        });
54
    });
72
    });
55
</script>
73
</script>
56
<style type="text/css">
74
<style type="text/css">
Lines 128-140 a.add, a.delete { Link Here
128
                [% END %]
146
                [% END %]
129
            </ul>
147
            </ul>
130
            <div id="search_fields">
148
            <div id="search_fields">
131
              <table class="search_fields">
149
              <table class="search_fields" data-index_name="search_fields">
132
                <thead>
150
                <thead>
133
                  <tr>
151
                  <tr>
134
                    <th>Name</th>
152
                    <th>Name</th>
135
                    <th>Label</th>
153
                    <th>Label</th>
136
                    <th>Type</th>
154
                    <th>Type</th>
137
                    <th>Weight</th>
155
                    <th>Weight</th>
156
                    <th></th>
138
                  </tr>
157
                  </tr>
139
                </thead>
158
                </thead>
140
                <tbody>
159
                <tbody>
Lines 185-193 a.add, a.delete { Link Here
185
                      [% ELSE %]
204
                      [% ELSE %]
186
                        <td><input type="hidden" name="search_field_weight" value=""></td>
205
                        <td><input type="hidden" name="search_field_weight" value=""></td>
187
                      [% END %]
206
                      [% END %]
207
                      <td>
208
                        [% IF search_field.is_mapped %]
209
                          <a class="btn btn-default btn-xs disabled delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
210
                        [% ELSE %]
211
                          <a class="btn btn-default btn-xs delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
212
                        [% END %]
213
                      </td>
188
                    </tr>
214
                    </tr>
189
                  [% END %]
215
                  [% END %]
190
                </tbody>
216
                </tbody>
217
                <tfoot>
218
                  <tr>
219
                    <td>
220
                      <input type="text" data-id="search_field_name"/>
221
                    </td>
222
                    <td>
223
                      <input type="text" data-id="search_field_label"/>
224
                    </td>
225
                    <td>
226
                      <select data-id="search_field_type">
227
                        <option value=""></option>
228
                        <option value="string">String</option>
229
                        <option value="date">Date</option>
230
                        <option value="number">Number</option>
231
                        <option value="boolean">Boolean</option>
232
                        <option value="sum">Sum</option>
233
                      </select>
234
                    </td>
235
                    <td><input type="hidden" name="search_field_weight" value=""></td>
236
                    <td><a class="btn btn-default btn-xs add-search-field"><i class="fa fa-plus"></i> Add</a></td>
237
                  </tr>
238
                </tfoot>
191
              </table>
239
              </table>
192
            </div>
240
            </div>
193
            [% FOREACH index IN indexes %]
241
            [% 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