[Rt-commit] r5049 - in rt/branches/3.7-EXPERIMENTAL: . html/Search
ruz at bestpractical.com
ruz at bestpractical.com
Wed Apr 19 10:47:52 EDT 2006
Author: ruz
Date: Wed Apr 19 10:47:50 2006
New Revision: 5049
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/html/Search/Chart
rt/branches/3.7-EXPERIMENTAL/html/Search/Chart.html
rt/branches/3.7-EXPERIMENTAL/html/Search/Elements/Chart
Log:
r2407 at cubic-pc: cubic | 2006-04-19 18:31:58 +0400
* FromSQL drops previouse joins and conditions so do it first
* Column returns name of the column, use it
* add lable 'no value'
* refactor it a little
Modified: rt/branches/3.7-EXPERIMENTAL/html/Search/Chart
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Search/Chart (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Search/Chart Wed Apr 19 10:47:50 2006
@@ -7,18 +7,17 @@
<%init>
my @keys;
my @values;
-my $chart_class;
+my $chart_class;
use GD;
use GD::Text;
if ($ChartStyle eq 'pie') {
require GD::Graph::pie;
- $chart_class= "GD::Graph::pie";
+ $chart_class = "GD::Graph::pie";
} else {
require GD::Graph::bars;
- $chart_class= "GD::Graph::bars";
+ $chart_class = "GD::Graph::bars";
}
-use RT::Report::Tickets;
my $chart = $chart_class->new( 600 => 400 );
if ($chart_class eq "GD::Graph::bars") {
@@ -27,56 +26,47 @@
x_labels_vertical => 1,
y_label => 'Tickets',
show_values => 1
- );
+ );
$chart->set_legend_font( ['verdana', 'arial', gdMediumBoldFont], 12);
-
}
-my $tix = RT::Report::Tickets->new( $session{'CurrentUser'} );
-$tix->GroupBy($PrimaryGroupBy);
-$tix->Column( FUNCTION => 'COUNT', FIELD => 'id' );
-$tix->Column( FIELD => $PrimaryGroupBy );
+use RT::Report::Tickets;
+my $tix = RT::Report::Tickets->new( $session{'CurrentUser'} );
+$tix->FromSQL( $Query );
+my $count_name = $tix->Column( FUNCTION => 'COUNT', FIELD => 'id' );
+$tix->GroupBy( $PrimaryGroupBy );
+my $value_name = $tix->Column( FIELD => $PrimaryGroupBy );
+
+my %class = (
+ Queue => 'RT::Queue',
+ Owner => 'RT::User',
+);
+my $class = $class{ $PrimaryGroupBy };
-$tix->FromSQL($Query);
-$tix->_DoSearch();
while ( my $entry = $tix->Next ) {
- my $class;
- if ( $PrimaryGroupBy eq 'Queue' ) {
- $class = "RT::Queue";
- }
- elsif ( $PrimaryGroupBy eq 'Owner' ) {
- $class = "RT::User";
- }
- if ($class) {
- my $q = $class->new( $session{'CurrentUser'} );
- $q->Load( $entry->__Value($PrimaryGroupBy) );
- if ($chart_class eq 'GD::Graph::pie') {
- push @keys, $q->Name() . " - ".$entry->id;
- }
- else {
- push @keys, $q->Name();
- }
- }
- else {
- if ($chart_class eq 'GD::Graph::pie') {
- push @keys, $entry->__Value($PrimaryGroupBy). "- ".$entry->id;
- }
- else {
- push @keys, $entry->__Value($PrimaryGroupBy);
- }
- }
- push @values, $entry->id;
+ if ( $class ) {
+ my $q = $class->new( $session{'CurrentUser'} );
+ $q->Load( $entry->__Value( $value_name ) );
+ push @keys, $q->Name;
+ }
+ else {
+ push @keys, $entry->__Value($value_name);
}
- #$chart->set( title => loc("[_1] grouped by [_2]",$Query, $PrimaryGroupBy) ) or die $chart->error;
-
- unless (@keys && @values) {
- @keys = ('');
- @values = (0);
+ $keys[-1] ||= loc('(no value)');
+ if ($chart_class eq 'GD::Graph::pie') {
+ $keys[-1] .= " - ". $entry->__Value( $count_name );
}
+ push @values, $entry->__Value($count_name);
+}
+
+unless (@keys && @values) {
+ @keys = ('');
+ @values = (0);
+}
- my $plot = $chart->plot( [ [@keys], [@values] ] ) or die $chart->error;
- $r->content_type('image/png');
- $m->out( $plot->png );
- $m->abort();
+my $plot = $chart->plot( [ [@keys], [@values] ] ) or die $chart->error;
+$r->content_type('image/png');
+$m->out( $plot->png );
+$m->abort;
</%init>
Modified: rt/branches/3.7-EXPERIMENTAL/html/Search/Chart.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Search/Chart.html (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Search/Chart.html Wed Apr 19 10:47:50 2006
@@ -4,7 +4,7 @@
</%args>
<%init>
-my $title = loc("Search results grouped by [_1]", $PrimaryGroupBy);
+my $title = loc("Search results grouped by [_1]", $PrimaryGroupBy);
</%init>
<& /Elements/Header, Title => $title &>
Modified: rt/branches/3.7-EXPERIMENTAL/html/Search/Elements/Chart
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Search/Elements/Chart (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Search/Elements/Chart Wed Apr 19 10:47:50 2006
@@ -5,36 +5,32 @@
$ChartStyle => 'bars'
</%args>
<%init>
-my @keys;
-my @values;
-
use RT::Report::Tickets;
+my $tix = RT::Report::Tickets->new( $session{'CurrentUser'} );
+$tix->FromSQL( $Query );
+my $count_name = $tix->Column( FUNCTION => 'COUNT', FIELD => 'id' );
+$tix->GroupBy( $PrimaryGroupBy );
+my $value_name = $tix->Column( FIELD => $PrimaryGroupBy );
+
+my %class = (
+ Queue => 'RT::Queue',
+ Owner => 'RT::User',
+);
+my $class = $class{ $PrimaryGroupBy };
-my $tix = RT::Report::Tickets->new( $session{'CurrentUser'} );
-
-$tix->GroupBy($PrimaryGroupBy);
-$tix->Column( FUNCTION => 'COUNT', FIELD => 'id' );
-$tix->Column( FIELD => $PrimaryGroupBy );
-$tix->FromSQL($Query);
-$tix->_DoSearch();
+my (@keys, @values);
while ( my $entry = $tix->Next ) {
- my $class;
- if ( $PrimaryGroupBy eq 'Queue' ) {
- $class = "RT::Queue";
- }
- elsif ( $PrimaryGroupBy eq 'Owner' ) {
- $class = "RT::User";
- }
- if ($class) {
- my $q = $class->new( $session{'CurrentUser'} );
- $q->Load( $entry->__Value($PrimaryGroupBy) );
- push @keys, $q->Name();
- }
- else {
- push @keys, $entry->__Value($PrimaryGroupBy);
- }
- push @values, $entry->id;
+ if ($class) {
+ my $q = $class->new( $session{'CurrentUser'} );
+ $q->Load( $entry->__Value( $value_name ) );
+ push @keys, $q->Name;
}
+ else {
+ push @keys, $entry->__Value( $value_name );
+ }
+ $keys[-1] ||= loc('(no value)');
+ push @values, $entry->__Value( $count_name );
+}
my $query_string = $m->comp('/Elements/QueryString', %ARGS);
@@ -77,4 +73,3 @@
</tr>
</table>
-
More information about the Rt-commit
mailing list