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

(-)a/Koha/SearchField.pm (+16 lines)
Lines 67-72 sub search_marc_maps { Link Here
67
67
68
}
68
}
69
69
70
=head3 is_mapped
71
72
my $is_mapped = $search_field->is_mapped
73
74
=cut
75
76
sub is_mapped {
77
    my ( $self ) = @_;
78
79
    if ( scalar $self->search_marc_maps ) {
80
        return 1;
81
    }
82
83
    return 0;
84
}
85
70
=head3 is_mapped_biblios
86
=head3 is_mapped_biblios
71
87
72
my $is_mapped_biblios = $search_field->is_mapped_biblios
88
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 50-55 Link Here
50
                } );
50
                } );
51
            }
51
            }
52
        });
52
        });
53
        $('.add-search-field').click(function() {
54
            var table = $(this).closest('table');
55
            var line = $(this).closest("tr");
56
            var name = $(line).find('input[data-id="search_field_name"]').val();
57
            var label = $(line).find('input[data-id="search_field_name"]').val();
58
            if ( name.length > 0 && label.length > 0 ) {
59
                var new_line = clone_line( line );
60
                new_line.appendTo($('table[data-index_name=search_fields]>tbody'));
61
                $('.delete').click(function() {
62
                    $(this).parents('tr').remove();
63
                });
64
                clean_line(line);
65
66
                $(table).tableDnD( {
67
                    onDragClass: "dragClass",
68
                } );
69
            }
70
        });
53
    });
71
    });
54
</script>
72
</script>
55
<style type="text/css">
73
<style type="text/css">
Lines 127-139 a.add, a.delete { Link Here
127
                [% END %]
145
                [% END %]
128
            </ul>
146
            </ul>
129
            <div id="search_fields">
147
            <div id="search_fields">
130
              <table class="search_fields">
148
              <table class="search_fields" data-index_name="search_fields">
131
                <thead>
149
                <thead>
132
                  <tr>
150
                  <tr>
133
                    <th>Name</th>
151
                    <th>Name</th>
134
                    <th>Label</th>
152
                    <th>Label</th>
135
                    <th>Type</th>
153
                    <th>Type</th>
136
                    <th>Weight</th>
154
                    <th>Weight</th>
155
                    <th></th>
137
                  </tr>
156
                  </tr>
138
                </thead>
157
                </thead>
139
                <tbody>
158
                <tbody>
Lines 184-192 a.add, a.delete { Link Here
184
                      [% ELSE %]
203
                      [% ELSE %]
185
                        <td><input type="hidden" name="search_field_weight" value=""></td>
204
                        <td><input type="hidden" name="search_field_weight" value=""></td>
186
                      [% END %]
205
                      [% END %]
206
                      <td>
207
                        [% IF search_field.is_mapped %]
208
                          <a class="btn btn-default btn-xs disabled delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
209
                        [% ELSE %]
210
                          <a class="btn btn-default btn-xs delete" style="cursor: pointer;"><i class="fa fa-trash"></i> Delete</a>
211
                        [% END %]
212
                      </td>
187
                    </tr>
213
                    </tr>
188
                  [% END %]
214
                  [% END %]
189
                </tbody>
215
                </tbody>
216
                <tfoot>
217
                  <tr>
218
                    <td>
219
                      <input type="text" data-id="search_field_name"/>
220
                    </td>
221
                    <td>
222
                      <input type="text" data-id="search_field_label"/>
223
                    </td>
224
                    <td>
225
                      <select data-id="search_field_type">
226
                        <option value=""></option>
227
                        <option value="string">String</option>
228
                        <option value="date">Date</option>
229
                        <option value="number">Number</option>
230
                        <option value="boolean">Boolean</option>
231
                        <option value="sum">Sum</option>
232
                      </select>
233
                    </td>
234
                    <td><input type="hidden" name="search_field_weight" value=""></td>
235
                    <td><a class="btn btn-default btn-xs add-search-field"><i class="fa fa-plus"></i> Add</a></td>
236
                  </tr>
237
                </tfoot>
190
              </table>
238
              </table>
191
            </div>
239
            </div>
192
            [% FOREACH index IN indexes %]
240
            [% 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 => 16;
22
use Test::More tests => 18;
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_map = $search_field->search_marc_maps;
102
my @marc_map = $search_field->search_marc_maps;
77
is(scalar(@marc_map), 1, 'search_marc_maps should return 1 marc map');
103
is(scalar(@marc_map), 1, 'search_marc_maps should return 1 marc map');
78
is($marc_map[0]->index_name, 'biblios', 'Marc map index name is biblios');
104
is($marc_map[0]->index_name, 'biblios', 'Marc map index name is biblios');
79
- 

Return to bug 20388