From befca21d24a1ede94cf3a972a50141cb15e4a02f Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Mon, 20 May 2024 23:16:06 +0200 Subject: [PATCH] Bug 15536: Refactor to remove duplicated code. --- admin/matching-rules.pl | 46 ++-- .../prog/en/modules/admin/matching-rules.tt | 222 +++++------------- 2 files changed, 75 insertions(+), 193 deletions(-) diff --git a/admin/matching-rules.pl b/admin/matching-rules.pl index 3021bdb990..6c3d3d3ffb 100755 --- a/admin/matching-rules.pl +++ b/admin/matching-rules.pl @@ -128,43 +128,27 @@ sub add_update_matching_rule { # match checks my @mc_nums = sort map { /^mc_(\d+)_id/ ? int($1): () } $input->multi_param; foreach my $mc_num (@mc_nums) { - # source components my $src_components = []; - my @src_comp_nums = sort map { /^mc_${mc_num}_src_c_(\d+)_tag/ ? int($1): () } $input->multi_param; - foreach my $comp_num (@src_comp_nums) { - my $component = {}; - $component->{'tag'} = $input->param("mc_${mc_num}_src_c_${comp_num}_tag"); - $component->{'subfields'} = $input->param("mc_${mc_num}_src_c_${comp_num}_subfields"); - $component->{'offset'} = $input->param("mc_${mc_num}_src_c_${comp_num}_offset"); - $component->{'length'} = $input->param("mc_${mc_num}_src_c_${comp_num}_length"); - # norms - $component->{'norms'} = []; - my @norm_nums = sort map { /^mc_${mc_num}_src_c_${comp_num}_n_(\d+)_norm/ ? int($1): () } $input->multi_param; - foreach my $norm_num (@norm_nums) { - push @{ $component->{'norms'} }, $input->multi_param("mc_${mc_num}_src_c_${comp_num}_n_${norm_num}_norm"); - } - push @$src_components, $component; - } - # target components my $tgt_components = []; - my @tgt_comp_nums = sort map { /^mc_${mc_num}_tgt_c_(\d+)_tag/ ? int($1): () } $input->multi_param; - foreach my $comp_num (@tgt_comp_nums) { - my $component = {}; - $component->{'tag'} = $input->param("mc_${mc_num}_tgt_c_${comp_num}_tag"); - $component->{'subfields'} = $input->param("mc_${mc_num}_tgt_c_${comp_num}_subfields"); - $component->{'offset'} = $input->param("mc_${mc_num}_tgt_c_${comp_num}_offset"); - $component->{'length'} = $input->param("mc_${mc_num}_tgt_c_${comp_num}_length"); - # norms - $component->{'norms'} = []; - my @norm_nums = sort map { /^mc_${mc_num}_tgt_c_${comp_num}_n_(\d+)_norm/ ? int($1): () } $input->multi_param; - foreach my $norm_num (@norm_nums) { - push @{ $component->{'norms'} }, $input->multi_param("mc_${mc_num}_tgt_c_${comp_num}_n_${norm_num}_norm"); + foreach my $w (['src', $src_components], ['tgt', $tgt_components]) { + my ($which, $components) = @$w; + my @comp_nums = sort map { /^mc_${mc_num}_${which}_c_(\d+)_tag/ ? int($1): () } $input->multi_param; + foreach my $comp_num (@comp_nums) { + my $component = {}; + my $p = "mc_${mc_num}_${which}_c_${comp_num}_"; + map { $component->{$_} = $input->param("${p}$_") } qw(tag subfields offset length); + # norms + $component->{'norms'} = []; + my @norm_nums = sort map { /^${p}n_(\d+)_norm/ ? int($1): () } $input->multi_param; + foreach my $norm_num (@norm_nums) { + push @{ $component->{'norms'} }, $input->multi_param("${p}n_${norm_num}_norm"); + } + push @$components, $component; } - push @$tgt_components, $component; } $matcher->add_required_check($src_components, $tgt_components); } - + if (defined $matcher_id and $matcher_id =~ /^\d+/) { $matcher->_id($matcher_id); $template->param(edited_matching_rule => $matcher->code()); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt index 7349551b57..7abd5784e2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt @@ -54,6 +54,60 @@ [% END %] +[% BLOCK match_check_component %] + [%# PARAMS mc_num, which, components %] + [% IF (!components) %] + [% SET components = [ + { + comp_num => 1, norms => [ + { + norm_num => 1, + norm = "none" + } + ], + tag => '', + subfields => '', + offset => '', + length => '' + } + ] %] + [% END %] + [% FOREACH component IN components %] + [% SET pc = "mc_${mc_num}_${which}_c_${component.comp_num}" %] +
+ [% IF (which == 'src') %] + Source (incoming) record check field + [% ELSE %] + Target (database) record check field + [% END %] +
    +
  1. + + +
  2. +
  3. + + +
  4. +
  5. + + +
  6. +
  7. + + +
  8. + [% FOREACH norm IN component.norms %] +
  9. + + [% PROCESS norms_select selected_norm=norm.norm id="${pc}_n_${norm.norm_num}_norm" name="${pc}_n_${norm.norm_num}_norm" %] +
  10. + [% END %] +
+
+ [% END #/FOREACH component %] +[% END %] +