Bug 40841: Add limits configuration UI
This patch adds branch limits selection to the Z30.50/SRU configuration page. Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
parent
d6aae094b4
commit
3c87468669
|
|
@ -28,10 +28,10 @@ use CGI qw ( -utf8 );
|
|||
use C4::Context;
|
||||
use C4::Auth qw( get_template_and_user );
|
||||
use C4::Output qw( output_html_with_http_headers );
|
||||
use Koha::Database;
|
||||
use Koha::Z3950Servers;
|
||||
use Try::Tiny qw( catch try );
|
||||
|
||||
# Initialize CGI, template, database
|
||||
# Initialize CGI, template
|
||||
|
||||
my $input = CGI->new;
|
||||
my $op = $input->param('op') || 'list';
|
||||
|
|
@ -48,8 +48,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
|
|||
}
|
||||
);
|
||||
|
||||
my $schema = Koha::Database->new()->schema();
|
||||
|
||||
# Main code
|
||||
# First process a confirmed delete, or save a validated record
|
||||
|
||||
|
|
@ -67,18 +65,30 @@ if ( $op eq 'cud-delete_confirmed' && $id ) {
|
|||
recordtype checked servername servertype sru_options sru_fields attributes
|
||||
add_xslt/;
|
||||
my $formdata = _form_data_hashref( $input, \@fields );
|
||||
my @branches = grep { $_ ne q{} } $input->multi_param('branches');
|
||||
|
||||
if ($id) {
|
||||
my $server = Koha::Z3950Servers->find($id);
|
||||
if ($server) {
|
||||
$server->set($formdata)->store;
|
||||
$template->param( msg_updated => 1, msg_add => $formdata->{servername} );
|
||||
try {
|
||||
$server->set($formdata)->store;
|
||||
$server->replace_library_limits( \@branches );
|
||||
$template->param( msg_updated => 1, msg_add => $formdata->{servername} );
|
||||
} catch {
|
||||
$template->param( msg_error => 1, msg_add => $formdata->{servername} );
|
||||
};
|
||||
} else {
|
||||
$template->param( msg_notfound => 1, msg_add => $id );
|
||||
}
|
||||
$id = 0;
|
||||
} else {
|
||||
Koha::Z3950Server->new($formdata)->store;
|
||||
$template->param( msg_added => 1, msg_add => $formdata->{servername} );
|
||||
try {
|
||||
my $server = Koha::Z3950Server->new($formdata)->store;
|
||||
$server->replace_library_limits( \@branches );
|
||||
$template->param( msg_added => 1, msg_add => $formdata->{servername} );
|
||||
} catch {
|
||||
$template->param( msg_error => 1, msg_add => $formdata->{servername} );
|
||||
};
|
||||
}
|
||||
} elsif ( $op eq 'search' ) {
|
||||
|
||||
|
|
@ -88,19 +98,37 @@ if ( $op eq 'cud-delete_confirmed' && $id ) {
|
|||
|
||||
# Now list multiple records, or edit one record
|
||||
|
||||
my $data = [];
|
||||
if ( $op eq 'add_form' || $op eq 'edit_form' ) {
|
||||
$data = ServerSearch( $schema, $id, $searchfield ) if $searchfield || $id;
|
||||
delete $data->[0]->{id} if @$data && $op eq 'add_form'; #cloning record
|
||||
if ( $op eq 'add_form' ) {
|
||||
my $server;
|
||||
|
||||
if ($id) {
|
||||
$server = Koha::Z3950Servers->find($id);
|
||||
if ($server) {
|
||||
|
||||
# Cloning record - remove id
|
||||
$server = $server->unblessed;
|
||||
delete $server->{id};
|
||||
}
|
||||
}
|
||||
|
||||
$template->param(
|
||||
server => @$data ? $data->[0] : undef,
|
||||
server => $server,
|
||||
op => $op,
|
||||
type => ( $op eq 'add_form' ) ? lc $type : ''
|
||||
type => lc $type
|
||||
);
|
||||
} else {
|
||||
$data = ServerSearch( $schema, $id, $searchfield );
|
||||
} elsif ( $op eq 'edit_form' ) {
|
||||
my $server = Koha::Z3950Servers->find($id);
|
||||
$template->param(
|
||||
loop => \@$data, searchfield => $searchfield, id => $id,
|
||||
server => $server,
|
||||
op => $op,
|
||||
type => ''
|
||||
);
|
||||
} else { # search
|
||||
my $data = Koha::Z3950Servers->search(
|
||||
$id ? { id => $id } : { servername => { like => $searchfield . '%' } },
|
||||
);
|
||||
$template->param(
|
||||
loop => $data, searchfield => $searchfield, id => $id,
|
||||
op => 'list'
|
||||
);
|
||||
}
|
||||
|
|
@ -108,14 +136,6 @@ output_html_with_http_headers $input, $cookie, $template->output;
|
|||
|
||||
# End of main code
|
||||
|
||||
sub ServerSearch { #find server(s) by id or name
|
||||
my ( $schema, $id, $searchstring ) = @_;
|
||||
|
||||
return Koha::Z3950Servers->search(
|
||||
$id ? { id => $id } : { servername => { like => $searchstring . '%' } },
|
||||
)->unblessed;
|
||||
}
|
||||
|
||||
sub _form_data_hashref {
|
||||
my ( $input, $fieldref ) = @_;
|
||||
return { map { ( $_ => scalar $input->param($_) // '' ) } @$fieldref };
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
[% USE Koha %]
|
||||
[% USE Asset %]
|
||||
[% USE HtmlTags %]
|
||||
[% USE Branches %]
|
||||
[% PROCESS 'i18n.inc' %]
|
||||
[% SET footerjs = 1 %]
|
||||
[% INCLUDE 'doc-head-open.inc' %]
|
||||
|
|
@ -198,6 +199,13 @@
|
|||
<input type="text" name="add_xslt" id="add_xslt" size="100" value="[% server.add_xslt | html %]" />
|
||||
<div class="hint">Separate multiple filenames by commas.</div>
|
||||
</li>
|
||||
<li>
|
||||
<label for="library_limitation">Library limitation: </label>
|
||||
<select id="library_limitation" name="branches" multiple size="10">
|
||||
[% PROCESS options_for_libraries libraries => Branches.all( selected => server.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
|
||||
</select>
|
||||
<div class="hint">Limits the use of this server to the selected libraries.</div>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
|
||||
|
|
@ -220,7 +228,7 @@
|
|||
<thead
|
||||
><tr
|
||||
><th>Target</th><th>Hostname/Port</th><th>Database</th><th>Userid</th><th>Password</th><th>Preselected</th><th>Rank</th><th>Syntax</th><th>Encoding</th><th>Timeout</th><th>Record type</th><th>Attributes</th
|
||||
><th class="no-export no-sort">Actions</th>
|
||||
><th>Library limitations</th><th class="no-export no-sort">Actions</th>
|
||||
</tr></thead
|
||||
>
|
||||
<tbody>
|
||||
|
|
@ -237,6 +245,28 @@
|
|||
[% END %]
|
||||
</td>
|
||||
<td>[% loo.attributes | html %]</td>
|
||||
<td>
|
||||
[% SET library_limits = loo.library_limits %]
|
||||
[% IF library_limits && library_limits.count > 0 %]
|
||||
[% library_str = "" %]
|
||||
[% FOREACH library IN library_limits %]
|
||||
[%- IF loop.first -%]
|
||||
[% library_str = library.branchname _ " (" _ library.branchcode _ ")" %]
|
||||
[% ELSE %]
|
||||
[% library_str = library_str _ "\n" _ library.branchname _ " (" _ library.branchcode _ ")" %]
|
||||
[% END %]
|
||||
[% END %]
|
||||
<span class="library_limitation" data-bs-toggle="tooltip" title="[% library_str | html %]">
|
||||
[% IF library_limits.count > 1 %]
|
||||
<span>[% library_limits.count | html %] library limitations</span>
|
||||
[% ELSE %]
|
||||
<span>[% library_limits.count | html %] library limitation</span>
|
||||
[% END %]
|
||||
</span>
|
||||
[% ELSE %]
|
||||
<span>No limitation</span>
|
||||
[% END %]
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group dropup">
|
||||
<a class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-bs-toggle="dropdown" href="#"> Actions </a>
|
||||
|
|
|
|||
Loading…
Reference in New Issue