Skip to content

Commit

Permalink
Fix YAML support and use Template directly
Browse files Browse the repository at this point in the history
  • Loading branch information
kidclamp committed Jun 10, 2021
1 parent c709d3d commit 106584e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
14 changes: 11 additions & 3 deletions Koha/Plugin/Com/ByWaterSolutions/CoverFlow.pm
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ sub configure {
if ( defined $yaml && $yaml =~ /\S/ ) {
$yaml .= "\n\n";
my $mapping;
eval { $mapping = YAML::Load($yaml); };
my $error = $@;
if ( C4::Context->preference('Version') ge '20.120000' ) {
eval { $mapping = YAML::XS::Load($yaml); };
} else {
eval { $mapping = YAML::Load($yaml); };
}
$error = $@;
if ($error) {
my $template =
$self->get_template( { file => 'configure.tt' } );
Expand Down Expand Up @@ -217,7 +221,11 @@ sub upgrade {

my $mapping = $self->retrieve_data('mapping');
my $custom_image = $self->retrieve_data('custom_image');
eval { $mapping = YAML::Load($mapping); };
if ( C4::Context->preference('Version') ge '20.120000' ) {
eval { $mapping = YAML::XS::Load($mapping); };
} else {
eval { $mapping = YAML::Load($mapping); };
}
$self->update_coverflow_js( $mapping, $custom_image );

return 1;
Expand Down
18 changes: 11 additions & 7 deletions Koha/Plugin/Com/ByWaterSolutions/CoverFlow/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ package Koha::Plugin::Com::ByWaterSolutions::CoverFlow::Controller;

use Modern::Perl;

use C4::Context;
use Koha::Plugin::Com::ByWaterSolutions::CoverFlow;

use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON qw(decode_json);
use Encode qw(encode_utf8);
use Template;

use CGI;
use Try::Tiny;

=head1 Koha::Plugin::Com::ByWaterSolutions::CoverFlow::Controller
Expand All @@ -47,10 +48,7 @@ sub get {

return try {
# We need this weird hack until the plugin subsystem is not CGI-oriented
my $cgi = CGI->new;
my $plugin = Koha::Plugin::Com::ByWaterSolutions::CoverFlow->new();
$plugin->{cgi} = $cgi;
my $template = $plugin->get_template({ file => 'report.tt' });

my $data = decode_json( encode_utf8(Koha::Plugin::Com::ByWaterSolutions::CoverFlow::get_report(
{
Expand All @@ -63,19 +61,25 @@ sub get {
my $no_image = $plugin->retrieve_data('custom_image')
|| "https://raw.githubusercontent.com/bywatersolutions/web-assets/master/NoImage.png";

$template->param(
my $template = Template->new({INCLUDE_PATH => join(':',@INC)});
my $content;
my $params = {
data => $data,
coverlinks => $plugin->retrieve_data('coverlinks'),
showtitle => $plugin->retrieve_data('showtitle'),
size_limit => $plugin->retrieve_data('size_limit'),
title_limit => $plugin->retrieve_data('title_limit'),
use_coce => $plugin->retrieve_data('use_coce'),
no_image => $no_image,
);
CoceHost => C4::Context->preference('CoceHost'),
CoceProviders => C4::Context->preference('CoceProviders'),
OPACURLOpenInNewWindow => C4::Context->preference('OPACURLOpenInNewWindow'),
};
$template->process( 'Koha/Plugin/Com/ByWaterSolutions/CoverFlow/report.tt',$params,\$content);

return $c->render(
status => 200,
text => $template->output()
text => $content
);
}
catch {
Expand Down
3 changes: 1 addition & 2 deletions Koha/Plugin/Com/ByWaterSolutions/CoverFlow/report.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[% USE Koha %]
<div class="koha-coverflow" [% IF (use_coce) %]style="min-height: 200px"[% END %]>
<ul>
[% FOREACH d IN data %]
Expand Down Expand Up @@ -53,7 +52,7 @@
[% IF (use_coce) %]
<script type="text/javascript" src="/opac-tmpl/bootstrap/js/coce.js"></script>
<script type="text/javascript">
KOHA.coce.getURL('[% Koha.Preference('CoceHost') %]', '[% Koha.Preference('CoceProviders') %]',[% Koha.Preference('OPACURLOpenInNewWindow') %]);
KOHA.coce.getURL('[% CoceHost %]', '[% CoceProviders %]',[% OPACURLOpenInNewWindow %]);
</script>
[% END %]

Expand Down

0 comments on commit 106584e

Please sign in to comment.