[Rt-commit] r9628 - in rt/branches/3.6-RELEASE: .

sartak at bestpractical.com sartak at bestpractical.com
Fri Nov 9 15:49:02 EST 2007


Author: sartak
Date: Fri Nov  9 15:49:01 2007
New Revision: 9628

Modified:
   rt/branches/3.6-RELEASE/   (props changed)
   rt/branches/3.6-RELEASE/html/Search/Chart

Log:
 r44879 at onn:  sartak | 2007-11-09 15:48:26 -0500
 If there are no tickets found in a search, give an error-message image instead of silently failing to load.


Modified: rt/branches/3.6-RELEASE/html/Search/Chart
==============================================================================
--- rt/branches/3.6-RELEASE/html/Search/Chart	(original)
+++ rt/branches/3.6-RELEASE/html/Search/Chart	Fri Nov  9 15:49:01 2007
@@ -86,6 +86,26 @@
 $chart->set_values_font( $font, 9 ) if $chart->can('set_values_font');
 $chart->set_value_font( $font, 9 ) if $chart->can('set_value_font');
 
+# Pie charts don't like having no input, so we show a special image
+# that indicates an error message. Because this is used in an <img>
+# context, it can't be a simple error message. Without this check,
+# the chart will just be a non-loading image.
+if ($tix->Count == 0) {
+    my $plot = GD::Image->new(600 => 400);
+    $plot->colorAllocate(255, 255, 255); # background
+    my $black = $plot->colorAllocate(0, 0, 0);
+
+    require GD::Text::Wrap;
+    my $error = GD::Text::Wrap->new($plot,
+        color => $black,
+        text  => loc("No tickets found."),
+    );
+    $error->set_font( $font, 12 );
+    $error->draw(0, 0);
+
+    $m->comp( 'SELF:Plot', plot => $plot, %ARGS );
+}
+
 if ($chart_class eq "GD::Graph::bars") {
     $chart->set(
         x_label => $tix->Label( $PrimaryGroupBy ),
@@ -143,17 +163,26 @@
 
 
 my $plot = $chart->plot( [ [@sorted_keys], [@sorted_values] ] ) or die $chart->error;
+$m->comp( 'SELF:Plot', plot => $plot, %ARGS );
+</%init>
 
-if ( $plot->can('png') ) {
-    $r->content_type('image/png');
-    $m->out( $plot->png );
-}
-elsif ( $plot->can('gif') ) {
-    $r->content_type('image/gif');
-    $m->out( $plot->gif );
+<%METHOD Plot>
+<%ARGS>
+$plot => undef
+</%ARGS>
+<%INIT>
+my @types = ('png', 'gif');
+
+for my $type (@types) {
+    $plot->can($type)
+        or next;
+
+    $r->content_type("image/$type");
+    $m->out( $plot->$type );
+    $m->abort();
 }
-else { 
-    die "Your GD library appears to support neither PNG nor GIF";
-}
-$m->abort();
-</%init>
+
+die "Your GD library appears to support none of the following image types: " . join(', ', @types);
+</%INIT>
+
+</%METHOD>


More information about the Rt-commit mailing list