Browse Source

Bug 17515: Order Z3950 server by rank and preserve ordering

Previously we put all the servers into an object with keys of the server id

This patch converts it to an array of objects to preserve order, and adjusts code to use the array index
where necessary and store the server id within the array

To test:
1 - Add some new Z3950 servers, they don't need to be valid
    FIRST
    SECOND
    THIRD
    FOURTH
2 - Adjust the ranking so FOURTH:1 THIRD:2 SECOND:3 FIRST:4
3 - Enable and launch the advanced editor
4 - Click 'Advanced' under search on the left
5 - Note the list displays in the order you entered the servers
6 - Apply patch
7 - Reload
8 - Order is correct
9 - With valid servers, confirm that searching still works and servers can be checked or unchecked to include/remove from results

https://bugs.koha-community.org/show_bug.cgi?id=17515

Signed-off-by: B Johnson <barbara.johnson@bedfordtx.gov>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Nick Clemens 11 months ago
committed by Jonathan Druart
parent
commit
7bbf4f7b5f
  1. 2
      Koha/MetaSearcher.pm
  2. 2
      cataloguing/editor.pl
  3. 4
      koha-tmpl/intranet-tmpl/lib/koha/cateditor/search.js
  4. 33
      koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc
  5. 1
      svc/cataloguing/metasearch

2
Koha/MetaSearcher.pm

@ -127,7 +127,7 @@ sub search {
extra => $2,
id => $server_id,
host => $server_id,
name => $server_id,
servername => $server_id,
};
}
}

2
cataloguing/editor.pl

@ -81,7 +81,7 @@ my $dbh = C4::Context->dbh;
$template->{VARS}->{z3950_servers} = $dbh->selectall_arrayref( q{
SELECT * FROM z3950servers
WHERE recordtype != 'authority' AND servertype = 'zed'
ORDER BY servername
ORDER BY rank,servername
}, { Slice => {} } );
output_html_with_http_headers $input, $cookie, $template->output;

4
koha-tmpl/intranet-tmpl/lib/koha/cateditor/search.js

@ -73,8 +73,8 @@ define( [ 'koha-backend', 'marc-record' ], function( KohaBackend, MARC ) {
var itemTag = KohaBackend.GetSubfieldForKohaField('items.itemnumber')[0];
$.each( servers, function ( id, info ) {
if ( info.checked ) Search.includedServers.push( id );
$.each( servers, function ( index, info ) {
if ( info.checked ) Search.includedServers.push( info.server_id );
} );
if ( Search.includedServers.length == 0 ) return false;

33
koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc

@ -41,20 +41,22 @@ require.config( {
<script>
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'preferences', 'resources', 'text-marc', 'widget' ], function( KohaBackend, Search, Macros, MARCEditor, MARC, Preferences, Resources, TextMARC, Widget ) {
var z3950Servers = {
'koha:biblioserver': {
var z3950Servers = [
{
server_id: 'koha:biblioserver',
name: _("Local catalog"),
recordtype: 'biblio',
checked: false,
},
[%- FOREACH server = z3950_servers -%]
[% server.id | html %]: {
{
server_id: [% server.id | html %],
name: '[% server.servername | html %]',
recordtype: '[% server.recordtype | html %]',
checked: [% server.checked ? 'true' : 'false' | html %],
},
[%- END -%]
};
];
// The columns that should show up in a search, in order, and keyed by the corresponding <metadata> tag in the XSL and Pazpar2 config
var z3950Labels = [
@ -405,8 +407,8 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
// Search functions
function showAdvancedSearch() {
$('#advanced-search-servers').empty();
$.each( z3950Servers, function( server_id, server ) {
$('#advanced-search-servers').append( '<li data-server-id="' + server_id + '"><label><input class="search-toggle-server" type="checkbox"' + ( server.checked ? ' checked="checked">' : '>' ) + server.name + '</label></li>' );
$.each( z3950Servers, function( index, server ) {
$('#advanced-search-servers').append( '<li data-server-id="' + index + '"><label><input class="search-toggle-server" type="checkbox"' + ( server.checked ? ' checked="checked">' : '>' ) + server.name + '</label></li>' );
} );
$('#advanced-search-ui').modal('show');
}
@ -457,18 +459,18 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
$('#searchresults tbody').empty();
$('#search-serversinfo').empty();
$.each( z3950Servers, function( server_id, server ) {
var num_fetched = data.num_fetched[server_id];
$.each( z3950Servers, function( index, server ) {
var num_fetched = data.num_fetched[server.server_id];
if ( data.errors[server_id] ) {
num_fetched = data.errors[server_id];
if ( data.errors[server.server_id] ) {
num_fetched = data.errors[server.server_id];
} else if ( num_fetched == null ) {
num_fetched = '-';
} else if ( num_fetched < data.num_hits[server_id] ) {
} else if ( num_fetched < data.num_hits[server.server_id] ) {
num_fetched += '+';
}
$('#search-serversinfo').append( '<li data-server-id="' + server_id + '"><label><input class="search-toggle-server" type="checkbox"' + ( server.checked ? ' checked="checked">' : '>' ) + server.name + ' (' + num_fetched + ')' + '</label></li>' );
$('#search-serversinfo').append( '<li data-server-id="' + index + '"><label><input class="search-toggle-server" type="checkbox"' + ( server.checked ? ' checked="checked">' : '>' ) + server.name + ' (' + num_fetched + ')' + '</label></li>' );
} );
var seenColumns = {};
@ -511,7 +513,8 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
}
var result = '<tr>';
result += '<td class="sourcecol">' + z3950Servers[ hit.server ].name + '</td>';
var server_name = hit.servername == 'koha:biblioserver' ? _("Local catalog") : hit.servername;
result += '<td class="sourcecol">' + server_name + '</td>';
$.each( z3950Labels, function( undef, label ) {
if ( !seenColumns[ label[0] ] ) return;
@ -641,8 +644,8 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
// Macros loaded on first show of modal
break;
case 'selected_search_targets':
$.each( z3950Servers, function( server_id, server ) {
var saved_val = Preferences.user.selected_search_targets[server_id];
$.each( z3950Servers, function( index, server ) {
var saved_val = Preferences.user.selected_search_targets[server.server_id];
if ( saved_val != null ) server.checked = saved_val;
} );

1
svc/cataloguing/metasearch

@ -56,6 +56,7 @@ my @hits;
foreach my $hit ( $searcher->results( $offset, $page_size ) ) {
push @hits, {
server => $hit->{server}->{id},
servername => $hit->{server}->{servername},
index => $hit->{index},
record => $hit->{record}->as_xml_record(),
metadata => $hit->{metadata}

Loading…
Cancel
Save