From 2ce07a807ab533107a2b1b8b05c062aec0afae66 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 11 Mar 2015 12:55:03 +0100 Subject: toplist: handle empty list result (fix division by zero) --- index.pl | 17 ++++++++++------- public/css/default.css | 6 ++++++ templates/toplist.html.ep | 7 +++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/index.pl b/index.pl index 6a7805f..9ae057d 100644 --- a/index.pl +++ b/index.pl @@ -512,13 +512,16 @@ get '/top' => sub { } my @argsort = reverse sort { $rates[$a] <=> $rates[$b] } ( 1 .. 99 ); - my @toplist = map { - [ - $translation{$_} // $_, - sprintf( '%.2f%%', $rates[$_] * 100 / $total ), - $rates[$_] - ] - } @argsort; + my @toplist; + if ( $total > 0 ) { + @toplist = map { + [ + $translation{$_} // $_, + sprintf( '%.2f%%', $rates[$_] * 100 / $total ), + $rates[$_] + ] + } @argsort; + } $self->render( 'toplist', diff --git a/public/css/default.css b/public/css/default.css index 77964cd..cdbcf82 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -9,6 +9,12 @@ div.globalstats { margin-bottom: 1em; } +div.error { + color: orangered; + font-weight: bold; + margin: 2em; +} + div.about { position: absolute; top: 0.5em; diff --git a/templates/toplist.html.ep b/templates/toplist.html.ep index daead42..f639e36 100644 --- a/templates/toplist.html.ep +++ b/templates/toplist.html.ep @@ -1,5 +1,11 @@ %= include 'topform'; +% if (@{$toplist} == 0) { +
+Keine Daten mit diesen Parametern gefunden. +
+% } +% else {
@@ -13,3 +19,4 @@ % }
MeldungAnteilAnzahl
+% } -- cgit v1.2.3