Browse Source

Bug 8976: Sort subfields for authority records

Same patch for the authority frameworks/records

Sponsored-by: Orex Digital

Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
master
Jonathan Druart 4 months ago
parent
commit
ebe11f70e2
6 changed files with 65 additions and 24 deletions
  1. +7
    -5
      C4/AuthoritiesMarc.pm
  2. +10
    -5
      admin/auth_subfields_structure.pl
  3. +8
    -5
      authorities/authorities.pl
  4. +8
    -1
      installer/data/mysql/atomicupdate/bug_8976.perl
  5. +1
    -0
      installer/data/mysql/kohastructure.sql
  6. +31
    -8
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt

+ 7
- 5
C4/AuthoritiesMarc.pm View File

@@ -471,10 +471,10 @@ sub GetTagsLabels {
$res->{$tag}->{repeatable} = $repeatable;
}
$sth= $dbh->prepare(
"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue
"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue, display_order
FROM auth_subfield_structure
WHERE authtypecode=?
ORDER BY tagfield,tagsubfield"
ORDER BY tagfield, display_order, tagsubfield"
);
$sth->execute($authtypecode);

@@ -485,17 +485,18 @@ ORDER BY tagfield,tagsubfield"
my $seealso;
my $hidden;
my $isurl;
my $link;
my $defaultvalue;
my $display_order;

while (
( $tag, $subfield, $liblibrarian, , $libopac, $tab,
$mandatory, $repeatable, $authorised_value, $authtypecode,
$value_builder, $kohafield, $seealso, $hidden,
$isurl, $defaultvalue, $link )
$isurl, $defaultvalue, $display_order )
= $sth->fetchrow
)
{
$res->{$tag}->{$subfield}->{subfield} = $subfield;
$res->{$tag}->{$subfield}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
$res->{$tag}->{$subfield}->{tab} = $tab;
$res->{$tag}->{$subfield}->{mandatory} = $mandatory;
@@ -507,9 +508,10 @@ ORDER BY tagfield,tagsubfield"
$res->{$tag}->{$subfield}->{seealso} = $seealso;
$res->{$tag}->{$subfield}->{hidden} = $hidden;
$res->{$tag}->{$subfield}->{isurl} = $isurl;
$res->{$tag}->{$subfield}->{link} = $link;
$res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue;
$res->{$tag}->{$subfield}->{display_order} = $display_order;
}

return $res;
}



+ 10
- 5
admin/auth_subfields_structure.pl View File

@@ -34,7 +34,7 @@ sub string_search {
my $dbh = C4::Context->dbh;
$searchstring=~ s/\'/\\\'/g;
my @data=split(' ',$searchstring);
my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield, display_order");
$sth->execute("$searchstring%",$authtypecode);
my $results = $sth->fetchall_arrayref({});
return (scalar(@$results), $results);
@@ -124,7 +124,7 @@ if ($op eq 'add_form') {
closedir DIR;

# build values list
my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=? order by display_order"); # and tagsubfield='$tagsubfield'");
$sth->execute($tagfield,$authtypecode);
my @loop_data = ();
my $i=0;
@@ -189,9 +189,9 @@ if ($op eq 'add_form') {
$template->param(tagfield => "$input->param('tagfield')");
# my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
# values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue)
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=?
my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue, display_order)
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=?, display_order=?
where authtypecode=? and tagfield=? and tagsubfield=?");
my @tagsubfield = $input->multi_param('tagsubfield');
my @liblibrarian = $input->multi_param('liblibrarian');
@@ -205,6 +205,8 @@ if ($op eq 'add_form') {
my @frameworkcodes = $input->multi_param('frameworkcode');
my @value_builder =$input->multi_param('value_builder');
my @defaultvalue = $input->multi_param('defaultvalue');

my $display_order;
for (my $i=0; $i<= $#tagsubfield ; $i++) {
my $tagfield =$input->param('tagfield');
my $tagsubfield =$tagsubfield[$i];
@@ -241,6 +243,7 @@ if ($op eq 'add_form') {
$hidden,
$isurl,
$defaultvalue,
$display_order->{$tagfield} || 0,
(
$authtypecode,
$tagfield,
@@ -265,8 +268,10 @@ if ($op eq 'add_form') {
$hidden,
$isurl,
$defaultvalue,
display_order => $display_order->{$tagfield} || 0,
);
}
$display_order->{$tagfield}++;
}
}
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&amp;authtypecode=$authtypecode");


+ 8
- 5
authorities/authorities.pl View File

@@ -477,14 +477,17 @@ sub build_tabs {
}
else {
my @subfields_data;
foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
next if ( length $subfield != 1 );
next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9';
next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
foreach my $subfield (
sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} }
grep { ref($_) && %$_ } # Not a subfield (values for "important", "lib", "mandatory", etc.) or empty
values %{ $tagslib->{$tag} } )
{
next if $subfield->{hidden} && $subfield->{subfield} ne '9';
next if ( $subfield->{tab} ne $tabloop );
push(
@subfields_data,
&create_input(
$tag, $subfield, '', $index_tag, $tabloop, $record,
$tag, $subfield->{subfield}, '', $index_tag, $tabloop, $record,
$authorised_values_sth,$input
)
);


+ 8
- 1
installer/data/mysql/atomicupdate/bug_8976.perl View File

@@ -8,6 +8,13 @@ if( CheckVersion( $DBversion ) ) {
});
}

unless ( column_exists( 'auth_subfield_structure', 'display_order' ) ) {
$dbh->do(q{
ALTER TABLE auth_subfield_structure
ADD COLUMN display_order INT(2) NOT NULL DEFAULT 0 AFTER defaultvalue
});
}

# Always end with this (adjust the bug info)
NewVersion( $DBversion, XXXXX, "Description");
NewVersion( $DBversion, 8976, "Description");
}

+ 1
- 0
installer/data/mysql/kohastructure.sql View File

@@ -844,6 +844,7 @@ CREATE TABLE `auth_subfield_structure` (
`kohafield` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT '',
`frameworkcode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`defaultvalue` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`display_order` INT(2) NOT NULL DEFAULT 0,
PRIMARY KEY (`authtypecode`,`tagfield`,`tagsubfield`),
KEY `tab` (`authtypecode`,`tab`),
CONSTRAINT `auth_subfield_structure_ibfk_1` FOREIGN KEY (`authtypecode`) REFERENCES `auth_types` (`authtypecode`) ON DELETE CASCADE ON UPDATE CASCADE


+ 31
- 8
koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt View File

@@ -44,13 +44,13 @@
<div id="subfieldtabs" class="toptabs numbered">
<ul>
[% FOREACH loo IN loop %]
[% IF ( loo.new_subfield ) %]
<li><a href="#sub[% loo.tagsubfield | html_entity %]field" title="[% loo.liblibrarian | html_entity %]">New</a></li>
[% ELSE %]
<li><a href="#sub[% loo.tagsubfield | html_entity %]field" title="[% loo.liblibrarian | html_entity %]">
[% loo.tagsubfield | html %]
</a></li>
[% END %]
<li id="tab_subfield_[% loo.tagsubfield | html %]">
[% IF ( loo.new_subfield ) %]
<a href="#sub[% loo.tagsubfield | html_entity %]field" title="[% loo.liblibrarian | html_entity %]">New</a>
[% ELSE %]
<a href="#sub[% loo.tagsubfield | html_entity %]field" title="[% loo.liblibrarian | html_entity %]">[% loo.tagsubfield | html %]</a>
[% END %]
</li>
[% END %]
</ul>

@@ -350,13 +350,36 @@
[% Asset.js("js/admin-menu.js") | $raw %]
<script>
$(document).ready(function() {
$('#subfieldtabs').tabs();
$("#table_authsubfieldstructure").dataTable($.extend(true, {}, dataTablesDefaults, {
"columnDefs": [
{ 'sortable': false, 'targets': [ 'NoSort' ] }
],
aaSorting: [],
paginate: false
}));

var tabs = $('#subfieldtabs').tabs();
var current_index;
tabs.find( ".ui-tabs-nav" ).sortable({
axis: "x",
start: function (e, ui) {
current_index = $(ui.item[0]).index();
},
stop: function (e, ui) {
var new_index = $(ui.item[0]).index();
if (current_index < new_index) new_index++;
var subfield_code = $(ui.item[0]).attr('id').replace( /^tab_subfield_/, '');
var content = $('#sub' + subfield_code + 'field');
var panels = $("#subfieldtabs > div");
if ( new_index < $(panels).size() ){
$(content).insertBefore($("#subfieldtabs > div")[new_index]);
} else {
$(content).insertAfter($("#subfieldtabs > div")[new_index-1]);
}
tabs.tabs("refresh");
}
});

});
</script>
[% END %]


Loading…
Cancel
Save