From a85f89276ad376424d8641d035d29ec5f7b59c31 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 26 Mar 2019 22:04:14 +0000 Subject: [PATCH] Bug 18645: (follow-up) Making feature release tool work with all syspref types This patch is a work in progress. I've separated the template code into an include for the preferences page and feature release page. Am now working on making the feature release perl code work with this template. Struggling to avoid duplicating code. If anyone has a suggestion on a good way to use essentially all the methods in admin/preferences.pl again in installer/featurereleasetool.pl without repeating them, I'd appreciate hearing them. Sponsored-by: Catalyst IT --- admin/preferences.pl | 78 ++++++++++----------- installer/featurereleasetool.pl | 80 ++++++++++++++++------ .../intranet-tmpl/prog/en/includes/prefs-rows.inc | 74 ++++++++++++++++++++ .../prog/en/modules/admin/preferences.tt | 69 +------------------ .../en/modules/installer/featurereleasetool.tt | 65 ++---------------- 5 files changed, 180 insertions(+), 186 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/prefs-rows.inc diff --git a/admin/preferences.pl b/admin/preferences.pl index 8a00260..a30d797 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -18,6 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; +use Data::Dumper; use CGI qw ( -utf8 ); use C4::Auth; @@ -57,21 +58,21 @@ sub GetTab { } sub _get_chunk { - my ( $value, %options ) = @_; + my ( $value, %options ) = @_; - my $name = $options{'pref'}; - my $chunk = { name => $name, value => $value, type => $options{'type'} || 'input', class => $options{'class'} }; + my $name = $options{'pref'}; + my $chunk = { name => $name, value => $value, type => $options{'type'} || 'input', class => $options{'class'} }; - if ( $options{'class'} && $options{'class'} eq 'password' ) { - $chunk->{'input_type'} = 'password'; - } elsif ( $options{'class'} && $options{'class'} eq 'date' ) { - $chunk->{'dateinput'} = 1; - } elsif ( $options{'type'} && ( $options{'type'} eq 'opac-languages' || $options{'type'} eq 'staff-languages' ) ) { - my $current_languages = { map { +$_, 1 } split( /\s*,\s*/, $value ) }; + if ( $options{'class'} && $options{'class'} eq 'password' ) { + $chunk->{'input_type'} = 'password'; + } elsif ( $options{'class'} && $options{'class'} eq 'date' ) { + $chunk->{'dateinput'} = 1; + } elsif ( $options{'type'} && ( $options{'type'} eq 'opac-languages' || $options{'type'} eq 'staff-languages' ) ) { + my $current_languages = { map { +$_, 1 } split( /\s*,\s*/, $value ) }; - my $theme; - my $interface; - if ( $options{'type'} eq 'opac-languages' ) { + my $theme; + my $interface; + if ( $options{'type'} eq 'opac-languages' ) { # this is the OPAC $interface = 'opac'; $theme = C4::Context->preference('opacthemes'); @@ -80,7 +81,7 @@ sub _get_chunk { $interface = 'intranet'; $theme = C4::Context->preference('template'); } - $chunk->{'languages'} = getTranslatedLanguages( $interface, $theme, $lang, $current_languages ); + $chunk->{'languages'} = getTranslatedLanguages( $interface, $theme, undef, $current_languages ); $chunk->{'type'} = 'languages'; } elsif ( $options{ 'choices' } ) { if ( $options{'choices'} && ref( $options{ 'choices' } ) eq '' ) { @@ -99,32 +100,32 @@ sub _get_chunk { $value ||= 0; $chunk->{'type'} = 'select'; - $chunk->{'CHOICES'} = [ - sort { $a->{'text'} cmp $b->{'text'} } - map { { text => $options{'choices'}->{$_}, value => $_, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } } - keys %{ $options{'choices'} } - ]; - } elsif ( $options{'multiple'} ) { - my @values; - @values = split /,/, $value if defined($value); - $chunk->{type} = 'multiple'; - $chunk->{CHOICES} = [ - sort { $a->{'text'} cmp $b->{'text'} } - map { - my $option_value = $_; - { - text => $options{multiple}->{$option_value}, - value => $option_value, - selected => (grep /^$option_value$/, @values) ? 1 : 0, - } - } - keys %{ $options{multiple} } - ]; - } + $chunk->{'CHOICES'} = [ + sort { $a->{'text'} cmp $b->{'text'} } + map { { text => $options{'choices'}->{$_}, value => $_, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } } + keys %{ $options{'choices'} } + ]; + } elsif ( $options{'multiple'} ) { + my @values; + @values = split /,/, $value if defined($value); + $chunk->{type} = 'multiple'; + $chunk->{CHOICES} = [ + sort { $a->{'text'} cmp $b->{'text'} } + map { + my $option_value = $_; + { + text => $options{multiple}->{$option_value}, + value => $option_value, + selected => (grep /^$option_value$/, @values) ? 1 : 0, + } + } + keys %{ $options{multiple} } + ]; + } $chunk->{ 'type_' . $chunk->{'type'} } = 1; - return $chunk; + return $chunk; } sub TransformPrefsToHTML { @@ -149,6 +150,7 @@ sub TransformPrefsToHTML { } foreach my $line ( @{ $tab->{ $group } } ) { + warn Dumper($line); my @chunks; my @names; @@ -164,8 +166,7 @@ sub TransformPrefsToHTML { } else { $value = $row->{'value'}; } - my $source = "preferences"; - my $chunk = _get_chunk( $value, $source, %$piece ); + my $chunk = _get_chunk( $value, %$piece ); # No highlighting of inputs yet, but would be useful $chunk->{'highlighted'} = 1 if ( $searchfield && $name =~ /^$searchfield$/i ); @@ -225,7 +226,6 @@ sub SearchPrefs { my ( $input, $searchfield ) = @_; my @tabs; - warn $input, $searchfield; my %tab_files = _get_pref_files( $input ); our @terms = split( /\s+/, $searchfield ); diff --git a/installer/featurereleasetool.pl b/installer/featurereleasetool.pl index f5e4ccb..19c129f 100755 --- a/installer/featurereleasetool.pl +++ b/installer/featurereleasetool.pl @@ -106,30 +106,70 @@ my @prefsloop; my @lines = split /\n/, $file; foreach my $line (@lines) { my $query = qq| - SELECT variable, value, options, display_choices, explanation, type from systempreferences WHERE version= ? |; + SELECT variable, value, options, explanation, type from systempreferences WHERE version= ? |; my $sth = $dbh->prepare($query); $sth->execute($line); - while (my ($variable, $value, $options, $display_choices, $explanation, $type) = $sth->fetchrow) { - if ($options) { - push @prefsloop, { - variable => $variable, - value => $value, - options => $options, - explanation => $explanation, - type => $type, - display_choices => $display_choices, - }; - } else { - push @prefsloop, { - variable => $variable, - value => $value, - explanation => $explanation, - type => $type, - display_choices => $display_choices, - }; + + while (my ($variable, $value, $options, $explanation, $type) = $sth->fetchrow) { + my $chunk = { name => $variable, value => $value, options => $options, explanation => $explanation, type => $type || 'input' }; + if ( $chunk->{'name'} eq 'opaclanguages' || $chunk->{'name'} eq 'language' ) ) { + my $current_languages = { map { +$_, 1 } split( /\s*,\s*/, $value ) }; + + my $theme; + my $interface; + if ( $chunk{'name'} eq 'opaclanguages' ) { + # this is the OPAC + $interface = 'opac'; + $theme = C4::Context->preference('opacthemes'); + } else { + # this is the staff client + $interface = 'intranet'; + $theme = C4::Context->preference('template'); + } + $chunk->{'languages'} = getTranslatedLanguages( $interface, $theme, undef, $current_languages ); + $chunk->{'type'} = 'languages'; + } elsif ( $chunk->{'type'} eq 'Choice' ) { + if ( $chunk->{'name'} eq 'DefaultClassificationSource' ) { + my $sources = GetClassSources(); + $chunk->{'options'} = { map { $_ => $sources->{$_}->{'description'} } keys %$sources }; + } elsif ( $chunk->{'name'} eq 'opacthemes' ) { + $chunk->{'options'} = { map { $_ => $_ } getallthemes( 'opac' ) } + } elsif ( $chunk->{'name'} eq 'template' ) { + $chunk->{'choices'} = { map { $_ => $_ } getallthemes( 'intranet' ) } + } else { + die 'Unrecognized source of preference values: ' . $options{'choices'}; + } + + $value ||= 0; + + $chunk->{'type'} = 'select'; + $chunk->{'CHOICES'} = [ + sort { $a->{'text'} cmp $b->{'text'} } + map { { text => $chunk->{'options'}->{$_}, value => $_, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } } + keys %{ $chunk{'options'} } + ]; + } elsif ( $chunk->{'type'} eq 'multiple' ) { + my @values; + @values = split /,/, $value if defined($value); + $chunk->{CHOICES} = [ + sort { $a->{'text'} cmp $b->{'text'} } + map { + my $option_value = $_; + { + #FIXME: text => $options{multiple}->{$option_value}, + value => $option_value, + selected => (grep /^$option_value$/, @values) ? 1 : 0, + } + } + #FIXME: keys %{ $options{multiple} } + ]; } + + $chunk->{ 'type_' . $chunk->{'type'} } = 1; + + push @prefsloop, $chunk; } -}; +} $template->param( prefs => \@prefsloop, submitted_form => $op ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-rows.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-rows.inc new file mode 100644 index 0000000..8256041 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-rows.inc @@ -0,0 +1,74 @@ +[% IF ( pref.type_text ) %] + [% pref.contents | $raw %] +[% ELSIF ( pref.type_input ) %] + [% IF ( pref.input_type ) %] + [% IF ( pref.dateinput ) %][% INCLUDE 'date-format.inc' %][% END %] + [% ELSE %] + [% IF ( pref.dateinput ) %][% INCLUDE 'date-format.inc' %][% END %] + [% END %] +[% ELSIF ( pref.type_select ) %] + +[% ELSIF ( pref.type_multiple ) %] + +[% ELSIF ( pref.type_textarea ) || ( pref.type_htmlarea )%] + [% IF ( pref.type_htmlarea ) && ( Koha.Preference('UseWYSIWYGinSystemPreferences') ) %] + + [% ELSE %] + + [% END %] +[% ELSIF ( pref.type_languages ) %] + +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index 43e892f..869b933 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -74,73 +74,8 @@
- [% FOREACH CHUNK IN LINE.CHUNKS %] - [% IF ( CHUNK.type_text ) %] - [% CHUNK.contents | $raw %] - [% ELSIF ( CHUNK.type_input ) %] - [% IF ( CHUNK.dateinput ) %][% INCLUDE 'date-format.inc' %][% END %] - [% ELSIF ( CHUNK.type_select ) %] - - [% ELSIF ( CHUNK.type_multiple ) %] - - [% ELSIF ( CHUNK.type_textarea ) || ( CHUNK.type_htmlarea )%] - [% IF ( CHUNK.type_htmlarea ) && ( Koha.Preference('UseWYSIWYGinSystemPreferences') ) %] - - [% ELSE %] - - - - [% END %] - [% ELSIF ( CHUNK.type_languages ) %] -
    - [% FOREACH language IN CHUNK.languages %] - [% IF ( language.plural ) %] -
  • - [% IF ( language.native_description ) %] - [% language.native_description | html %] - [% ELSE %] - [% language.rfc4646_subtag | html %] - [% END %] - [% IF language.sublanguages_loop.size > 0 %] -
      - [% FOREACH sublanguages_loo IN language.sublanguages_loop %] -
    • - - [% IF ( sublanguages_loo.enabled ) %] - - [% ELSE %] - - [% END %] -
    • - [% END # FOREACH sublanguages %] -
    - [% END %] -
  • - [% ELSE %] -
  • - - [% IF ( language.group_enabled ) %] - - [% ELSE %] - - [% END %] -
  • - [% END # IF language.plural %] - [% END # FOREACH language %] -
- [% END %] + [% FOREACH pref IN LINE.CHUNKS %] + [% INCLUDE 'prefs-rows.inc' %] [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/featurereleasetool.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/featurereleasetool.tt index e51bace..4984865 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/featurereleasetool.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/featurereleasetool.tt @@ -87,78 +87,23 @@ td, th {

Koha

- - + +
-

New sysprefs added to Koha since Koha [% dbversion %]

+

New system preferences added to Koha since Koha [% dbversion %]

The system preferences listed below were all installed in the update from Koha [% dbversion %] to Koha [% kohaversion %]. The default values of each of the system preferences are displayed for you to review and modify and submit by selecting the 'Save all preferences' button

-
+ - [% FOREACH pref IN prefs %] - - - - - + [% INCLUDE 'prefs-rows.inc' %] [% END %]
Preference Description Value
- - [% pref.variable %] - - [% pref.explanation %] - - [% IF (pref.value != '') %] - [% IF (pref.type == "Integer") || (pref.type == "integer" ) || (pref.type == "Free") %] - - [% ELSIF (pref.type == "Choice") %] - - [% ELSIF (pref.type == "YesNo") %] - - [% END %] - [% ELSE %] - No default value - [% END %] -
[% IF !(submitted_form) %] -- 2.1.4