Skip to content

Commit

Permalink
Add maintenance announcement tag helper
Browse files Browse the repository at this point in the history
Change-Id: Ie4a18bf28e38613f9f2faded9c84be023f517b34
  • Loading branch information
Akron committed Dec 15, 2023
1 parent efa2f76 commit 459bf58
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Update Piwik dependency to point to matomo.js. (diewald)
- Add addon to title and description. (diewald)
- Improve Dockerfile to enable docker-slim. (diewald)
- Introduce maintenance tag helper. (diewald)

0.51 2023-09-27
- Support defined log file in configuration. (diewald)
Expand Down
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ WriteMakefile(
'Mojolicious::Plugin::AutoSecrets' => 0.006,
'Mojolicious::Plugin::TagHelpers::ContentBlock' => 0.11,
'Cache::FastMmap' => 1.57,
'DateTime' => 1.63,

# Required for Mojolicious::Plugin::CHI
'Data::Serializer' => 0.65,
Expand Down
31 changes: 30 additions & 1 deletion kalamar.dict
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ my $THOUSAND_SEP_RE = qr/(
$num =~ s/$THOUSAND_SEP_RE/$1\./g;
return $num;
},
numo => sub {
shift;
my %val = @_;
my $day = $val{day} or return '';
return $day . '.';
},
about => 'Über KorAP',
login => 'Anmelden',
logout => 'Abmelden',
Expand Down Expand Up @@ -63,6 +69,11 @@ my $THOUSAND_SEP_RE = qr/(
privacy => 'Datenschutz',
imprint => 'Impressum',
settings => 'Einstellungen',
'oclock' => 'Uhr',
maintenanceWork => {
time => 'Wartungsfenster',
desc => 'Aufgrund von Wartungsarbeiten wird es zu Unterbrechungen des Dienstes kommen.',
},
Template => {
intro => 'de/intro',
doc => {
Expand Down Expand Up @@ -105,7 +116,7 @@ my $THOUSAND_SEP_RE = qr/(
'annotation' => 'Annotationen',
'#default-foundries' => 'Standard Foundries',
'development' => 'Entwicklung',
'faq' => 'FAQ'
'faq' => 'FAQ',
},
QL => {
cqp => 'CQP (neu)'
Expand All @@ -120,6 +131,19 @@ my $THOUSAND_SEP_RE = qr/(
$num =~ s/$THOUSAND_SEP_RE/$1\,/g;
return $num;
},
numo => sub {
shift;
my %val = @_;
my $day = $val{day} or return '';
if ($day > 3) {
return $day . 'th';
} elsif ($day == 3) {
return '3rd';
} elsif ($day == 2) {
return '2nd';
};
return '1st';
},
about => 'About KorAP',
login => 'Login',
logout => 'Logout',
Expand Down Expand Up @@ -152,6 +176,7 @@ my $THOUSAND_SEP_RE = qr/(
},
activateJS => 'To make use of all features, please activate JavaScript!',
faq => 'FAQ',
'oclock' => 'o\'clock',
underConstruction => 'Under Construction!',
tutorial => 'Help and Documentation',
korap => {
Expand All @@ -174,6 +199,10 @@ my $THOUSAND_SEP_RE = qr/(
privacy => 'Privacy',
imprint => 'Imprint',
settings => 'Settings',
maintenanceWork => {
time => 'Maintenance',
desc => 'Due to maintenance work the service will be interrupted.',
},
Template => {
intro => 'intro',
doc => {
Expand Down
37 changes: 36 additions & 1 deletion lib/Kalamar/Plugin/KalamarHelpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package Kalamar::Plugin::KalamarHelpers;
use Mojo::ByteStream 'b';
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::Util qw/deprecated/;

use DateTime;

sub register {
my ($plugin, $mojo) = @_;
Expand Down Expand Up @@ -169,6 +169,41 @@ sub register {
);
}
);


# Maintenance announcement tag helper
# Use as '<%= korap_maintenance '2023-11-03', '13:00', '14:00' $>'
$mojo->helper(
korap_maintenance => sub {
my $c = shift;
my ($date, $start_time, $end_time) = @_;

if (!$date || !$start_time || !$end_time) {
return '';
};

my ($year, $month, $day) = split('-', $date);

if (!$year || !$month || !$day) {
return '';
};

my $dt = DateTime->new(
year => $year,
month => $month,
day => $day
);

$dt->set_locale($c->localize->locale->[0] // 'en');

return $c->include(
'partial/maintenance',
dt => $dt,
start_time => $start_time,
end_time => $end_time
)
}
);
};


Expand Down
16 changes: 16 additions & 0 deletions t/page.t
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ $t->get_ok('/')
->text_is('div.logoaddon', 'Test')
;

like($app->korap_maintenance('2023-10-03','13:00','15:00'), qr!<time datetime="2023-10-03">!);
like($app->korap_maintenance('2023-10-03','13:00','15:00'), qr!Tuesday, 3rd October 2023!);
like($app->korap_maintenance('2023-10-03','13:00','15:00'), qr!Maintenance 13:00 - 15:00 o&#39;clock!);
like($app->korap_maintenance('2023-10-03','13:00','15:00'), qr!Due to maintenance work the service will be interrupted\.!);


$c = $app->build_controller;
$c->req->headers->accept_language('de-DE, en-US, en');
$c->app($app);

like($c->korap_maintenance('2023-10-03','13:00','15:00'), qr!<time datetime="2023-10-03">!);
like($c->korap_maintenance('2023-10-03','13:00','15:00'), qr!Dienstag, 3\. Oktober 2023!);
like($c->korap_maintenance('2023-10-03','13:00','15:00'), qr!Wartungsfenster 13:00 - 15:00 Uhr!);
like($c->korap_maintenance('2023-10-03','13:00','15:00'), qr!Aufgrund von Wartungsarbeiten wird es zu Unterbrechungen des Dienstes kommen\.!);


done_testing;

1;
5 changes: 5 additions & 0 deletions templates/partial/maintenance.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<dt class="maintenance"><time datetime="<%= $dt->ymd %>"><%= $dt->day_name %>, <%= loc('numo', day => $dt->day) %> <%= $dt->month_name %> <%= $dt->year %></time></dt>
<dd class="maintenance">
<h4><%= loc 'maintenanceWork_time' %> <%= $start_time %> - <%= $end_time %> <%= loc('oclock') %></h4>
<p><%= loc 'maintenanceWork_desc' %></p>
</dd>

0 comments on commit 459bf58

Please sign in to comment.