[Rt-commit] rt branch, 4.2/date-time-improvements-in-charts, updated. rt-3.8.10-91-gf2ee0fe

Ruslan Zakirov ruz at bestpractical.com
Wed Jun 22 15:25:09 EDT 2011


The branch, 4.2/date-time-improvements-in-charts has been updated
       via  f2ee0fe0a7150b4d53608dd70e33f1a1db4af936 (commit)
       via  68cac83015685c7ab5476a8810c336333e32a1e2 (commit)
       via  46af784173ad607677299c78784480a501a505fa (commit)
       via  673f14cb3df3b6bb3a8ff112df0ed539d8fe0126 (commit)
       via  ffdc102d01463d40a393112a1c798bea484396c9 (commit)
       via  7095724af6633a5f56e98206ca1b8e819481907c (commit)
      from  5966a7f04caa3da9c0a790656347ce7a6fb6e0d8 (commit)

Summary of changes:
 lib/RT/Report/Tickets.pm         |   18 ++++++++++++++++++
 lib/RT/Report/Tickets/Entry.pm   |   17 ++++++++---------
 share/html/Search/Chart          |   27 ++++++++++++++++++++-------
 share/html/Search/Elements/Chart |    9 ++++++++-
 t/web/charting.t                 |   22 +++++++++++-----------
 t/web/saved_search_chart.t       |    8 ++++----
 6 files changed, 69 insertions(+), 32 deletions(-)

- Log -----------------------------------------------------------------
commit 7095724af6633a5f56e98206ca1b8e819481907c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 22 17:13:08 2011 +0400

    LabelValueCode - fector out it for re-use
    
    we need direct references to code that turns raw
    value of a statistic into a user friendly thing

diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 62b93ca..1ed19a5 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -667,6 +667,17 @@ sub GenerateWatcherFunction {
     return %args;
 }
 
+
+sub LabelValueCode {
+    my $self = shift;
+    my $name = shift;
+
+    my $display = $self->ColumnInfo( $name )->{'META'}{'Display'};
+    return undef unless $display;
+    return $self->FindImplementationCode( $display );
+}
+
+
 sub FindImplementationCode {
     my $self = shift;
     my $value = shift;
diff --git a/lib/RT/Report/Tickets/Entry.pm b/lib/RT/Report/Tickets/Entry.pm
index 7cd5e1a..e0cc854 100644
--- a/lib/RT/Report/Tickets/Entry.pm
+++ b/lib/RT/Report/Tickets/Entry.pm
@@ -81,18 +81,13 @@ sub LabelValue {
     my $name = shift;
 
     my $raw = $self->RawValue( $name, @_ );
-    my $info = $self->ColumnInfo( $name );
-    my $meta = $info->{'META'};
-
-    if (
-        $meta and $meta->{'Display'}
-        and my $code = $self->FindImplementationCode( $meta->{'Display'} )
-    ) {
-        return $code->( $self, %$info, VALUE => $raw );
+
+    if ( my $code = $self->LabelCode( $name ) ) {
+        return $code->( $self, %{ $self->ColumnInfo( $name ) }, VALUE => $raw );
     }
 
     return $self->loc('(no value)') unless defined $raw && length $raw;
-    return $self->loc($raw) if $info->{'META'}{'Localize'};
+    return $self->loc($raw) if $self->ColumnInfo( $name )->{'META'}{'Localize'};
     return $raw;
 }
 
@@ -131,6 +126,10 @@ sub Query {
     return join ' AND ', grep defined && length, @parts;
 }
 
+sub LabelCode {
+    return RT::Report::Tickets->can('LabelValueCode')->(@_);
+}
+
 sub FindImplementationCode {
     return RT::Report::Tickets->can('FindImplementationCode')->(@_);
 }

commit ffdc102d01463d40a393112a1c798bea484396c9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 22 17:16:26 2011 +0400

    convert intervals from seconds

diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 1ed19a5..ad811f4 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -266,6 +266,13 @@ our %STATISTICS_META = (
 
             return (FUNCTION => "$function($interval)");
         },
+        Display => sub {
+            my $self = shift;
+            my %args = @_;
+            my $v = $args{'VALUE'};
+            return $self->loc("(no value)") unless defined $v && length $v;
+            return RT::Date->new( $self->CurrentUser )->DurationAsString( $v );
+        },
     },
 );
 

commit 673f14cb3df3b6bb3a8ff112df0ed539d8fe0126
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 22 17:19:28 2011 +0400

    apply conversion on stats in tables and pictures

diff --git a/share/html/Search/Chart b/share/html/Search/Chart
index b315251..0f9a430 100644
--- a/share/html/Search/Chart
+++ b/share/html/Search/Chart
@@ -101,7 +101,7 @@ while ( my $entry = $report->Next ) {
 
     my @values = map $entry->RawValue($_), @{ $columns{'Functions'} };
     if ($chart_class eq 'GD::Graph::pie') {
-        $key .= ' - '. $values[0];
+        $key .= ' - '. $entry->LabelValue( $columns{'Functions'}[0] );
     }
 
     push @{ $data[0] }, $key;
@@ -152,19 +152,29 @@ $chart->set_values_font( $font, 12 ) if $chart->can('set_values_font');
 $chart->set_value_font( $font, 12 ) if $chart->can('set_value_font');
 
 if ($chart_class eq "GD::Graph::bars") {
+    my %args;
     my $count = @{ $data[0] };
-    my $bar_spacing =
+    $args{'bar_spacing'} =
         $count > 30 ? 1
         : $count > 20 ? 2
         : $count > 10 ? 3
         : 5
     ;
+    if ( my $code = $report->First->LabelCode( $columns{'Functions'}[0] ) ) {
+        my %info = %{ $report->ColumnInfo( $columns{'Functions'}[0] ) };
+        $args{'values_format'} = $args{'y_number_format'} = sub {
+            return $code->($report, %info, VALUE => shift );
+        };
+    }
+    $report->GotoFirstItem;
+
     $chart->set(
+        %args,
         x_label => join( ' - ', map $report->Label( $_ ), @{ $columns{'Groups'} } ),
-        y_label => $report->Label( $columns{'Functions'}[0] ),
-        show_values => 1,
         x_label_position => 0.6,
+        y_label => $report->Label( $columns{'Functions'}[0] ),
         y_label_position => 0.6,
+        show_values => 1,
         values_space => -1,
 # use a top margin enough to display values over the top line if needed
         t_margin => 18,
@@ -172,8 +182,7 @@ if ($chart_class eq "GD::Graph::bars") {
         y_max_value => 5*(int($max_value/5) + 2),
 # if there're too many bars or at least one key is too long, use vertical
         x_labels_vertical => ( $count * $max_key_length > 60 ) ? 1 : 0,
-        bar_spacing => $bar_spacing,
-        bargroup_spacing => $bar_spacing*5,
+        bargroup_spacing => $args{'bar_spacing'}*5,
     );
 }
 
diff --git a/share/html/Search/Elements/Chart b/share/html/Search/Elements/Chart
index 7e3f82c..0d10d7c 100644
--- a/share/html/Search/Elements/Chart
+++ b/share/html/Search/Elements/Chart
@@ -112,7 +112,8 @@ my $query_string = $m->comp('/Elements/QueryString', %ARGS, GroupBy => \@GroupBy
 
 % foreach my $column ( @{ $columns{'Functions'} } ) {
 <td class="value collection-as-table">
-% $total{ $column } += my $value = $entry->RawValue( $column );
+% $total{ $column } += $entry->RawValue( $column );
+% my $value = $entry->LabelValue( $column );
 % if ( $entry_query ) {
 <a href="<% RT->Config->Get('WebPath') %>/Search/Results.html?Query=<% "$Query AND $entry_query" |un %>&<% $base_query %>"><% $value %></a>
 % } else {
@@ -128,8 +129,13 @@ my $query_string = $m->comp('/Elements/QueryString', %ARGS, GroupBy => \@GroupBy
 <tr class="<% $i%2 ? 'evenline' : 'oddline' %>">
 <td class="label collection-as-table" colspan="<% scalar @{ $columns{'Groups'} } %>"><% loc('Total') %></td>
 % foreach my $column ( @{ $columns{'Functions'} } ) {
+% if ( my $code = $report->LabelValueCode( $column ) ) {
+% my $info = $report->ColumnInfo( $column );
+<td class="value collection-as-table"><% $code->( $report, %$info, VALUE => $total{ $column } ) %></td>
+% } else {
 <td class="value collection-as-table"><% $total{ $column } %></td>
 % }
+% }
 </tr>
 
 </table>

commit 46af784173ad607677299c78784480a501a505fa
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 22 18:34:53 2011 +0400

    put back grouping by Queue if all are invalid

diff --git a/share/html/Search/Chart b/share/html/Search/Chart
index 0f9a430..8f34a3d 100644
--- a/share/html/Search/Chart
+++ b/share/html/Search/Chart
@@ -83,6 +83,7 @@ if ( $Cache and my $data = delete $session{'charts_cache'}{ $Cache } ) {
         next unless $report->IsValidGrouping( Query => $Query, GroupBy => $e );
         push @GroupBy, $e;
     }
+    @GroupBy = ('Queue') unless @GroupBy;
 
     %columns = $report->SetupGroupings(
         Query => $Query,
diff --git a/share/html/Search/Elements/Chart b/share/html/Search/Elements/Chart
index 0d10d7c..e68d0b6 100644
--- a/share/html/Search/Elements/Chart
+++ b/share/html/Search/Elements/Chart
@@ -61,6 +61,7 @@ foreach my $e ( splice @GroupBy ) {
     next unless $report->IsValidGrouping( Query => $Query, GroupBy => $e );
     push @GroupBy, $e;
 }
+ at GroupBy = ('Queue') unless @GroupBy;
 
 my %columns = $report->SetupGroupings(
     Query => $Query,

commit 68cac83015685c7ab5476a8810c336333e32a1e2
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 22 18:36:08 2011 +0400

    update tests with the latest changes in code

diff --git a/t/web/charting.t b/t/web/charting.t
index 7c11f9c..9105a3c 100644
--- a/t/web/charting.t
+++ b/t/web/charting.t
@@ -27,7 +27,7 @@ ok( $m->login, "Logged in" );
 # Test that defaults work
 $m->get_ok( "/Search/Chart.html?Query=id>0" );
 $m->content_like(qr{<th[^>]*>\s*Queue\s*</th>\s*<th[^>]*>\s*Tickets\s*</th>}, "Grouped by queue");
-$m->content_like(qr{General</a>\s*</td>\s*<td[^>]*>\s*7}, "Found results in table");
+$m->content_like(qr{General\s*</td>\s*<td[^>]*>\s*<a[^>]*>7}, "Found results in table");
 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
 
 $m->get_ok( "/Search/Chart?Query=id>0" );
@@ -36,34 +36,34 @@ ok( length($m->content), "Has content" );
 
 
 # Group by Queue
-$m->get_ok( "/Search/Chart.html?Query=id>0&PrimaryGroupBy=Queue" );
+$m->get_ok( "/Search/Chart.html?Query=id>0&GroupBy=Queue" );
 $m->content_like(qr{<th[^>]*>\s*Queue\s*</th>\s*<th[^>]*>\s*Tickets\s*</th>}, "Grouped by queue");
-$m->content_like(qr{General</a>\s*</td>\s*<td[^>]*>\s*7}, "Found results in table");
+$m->content_like(qr{General\s*</td>\s*<td[^>]*>\s*<a[^>]*>7}, "Found results in table");
 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
 
-$m->get_ok( "/Search/Chart?Query=id>0&PrimaryGroupBy=Queue" );
+$m->get_ok( "/Search/Chart?Query=id>0&GroupBy=Queue" );
 is( $m->content_type, "image/png" );
 ok( length($m->content), "Has content" );
 
 
 # Group by Requestor email
-$m->get_ok( "/Search/Chart.html?Query=id>0&PrimaryGroupBy=Requestor.EmailAddress" );
-$m->content_like(qr{<th[^>]*>\s*Requestor\.EmailAddress\s*</th>\s*<th[^>]*>\s*Tickets\s*</th>},
+$m->get_ok( "/Search/Chart.html?Query=id>0&GroupBy=Requestor.EmailAddress" );
+$m->content_like(qr{<th[^>]*>\s*Requestor\s+EmailAddress\s*</th>\s*<th[^>]*>\s*Tickets\s*</th>},
                  "Grouped by requestor");
-$m->content_like(qr{root0\@localhost</a>\s*</td>\s*<td[^>]*>\s*3}, "Found results in table");
+$m->content_like(qr{root0\@localhost\s*</td>\s*<td[^>]*>\s*<a[^>]*>3}, "Found results in table");
 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
 
-$m->get_ok( "/Search/Chart?Query=id>0&PrimaryGroupBy=Requestor.Email" );
+$m->get_ok( "/Search/Chart?Query=id>0&GroupBy=Requestor.Email" );
 is( $m->content_type, "image/png" );
 ok( length($m->content), "Has content" );
 
 
 # Group by Requestor phone -- which is bogus, and falls back to queue
-$m->get_ok( "/Search/Chart.html?Query=id>0&PrimaryGroupBy=Requestor.Phone" );
-$m->content_like(qr{General</a>\s*</td>\s*<td[^>]*>\s*7},
+$m->get_ok( "/Search/Chart.html?Query=id>0&GroupBy=Requestor.Phone" );
+$m->content_like(qr{General\s*</td>\s*<td[^>]*>\s*<a[^>]*>7},
                  "Found queue results in table, as a default");
 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
 
-$m->get_ok( "/Search/Chart?Query=id>0&PrimaryGroupBy=Requestor.Phone" );
+$m->get_ok( "/Search/Chart?Query=id>0&GroupBy=Requestor.Phone" );
 is( $m->content_type, "image/png" );
 ok( length($m->content), "Has content" );
diff --git a/t/web/saved_search_chart.t b/t/web/saved_search_chart.t
index 1051662..b509e4e 100644
--- a/t/web/saved_search_chart.t
+++ b/t/web/saved_search_chart.t
@@ -58,7 +58,7 @@ $m->submit_form(
     form_name => 'SaveSearch',
     fields    => {
         Query          => 'id=2',
-        PrimaryGroupBy => 'Status',
+        GroupBy        => 'Status',
         ChartStyle     => 'pie',
     },
     button => 'SavedSearchSave',
@@ -67,13 +67,13 @@ $m->submit_form(
 $m->content_like( qr/Chart first chart updated/, 'found updated message' );
 $m->content_like( qr/id=2/,                      'Query is updated' );
 $m->content_like( qr/value="Status"\s+selected="selected"/,
-    'PrimaryGroupBy is updated' );
+    'GroupBy is updated' );
 $m->content_like( qr/value="pie"\s+selected="selected"/,
     'ChartType is updated' );
 ok( $search->Load($id) );
 is( $search->SubValue('Query'), 'id=2', 'Query is indeed updated' );
-is( $search->SubValue('PrimaryGroupBy'),
-    'Status', 'PrimaryGroupBy is indeed updated' );
+is( $search->SubValue('GroupBy'),
+    'Status', 'GroupBy is indeed updated' );
 is( $search->SubValue('ChartStyle'), 'pie', 'ChartStyle is indeed updated' );
 
 # finally, let's test delete

commit f2ee0fe0a7150b4d53608dd70e33f1a1db4af936
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jun 22 18:44:15 2011 +0400

    y_min_value, 10% lower than minimum value

diff --git a/share/html/Search/Chart b/share/html/Search/Chart
index 8f34a3d..71dd41f 100644
--- a/share/html/Search/Chart
+++ b/share/html/Search/Chart
@@ -96,6 +96,7 @@ if ( $Cache and my $data = delete $session{'charts_cache'}{ $Cache } ) {
 
 my @data = ([],[]);
 my $max_value = 0;
+my $min_value;
 my $max_key_length = 0;
 while ( my $entry = $report->Next ) {
     my $key = join ' - ', map $entry->LabelValue( $_ ), @{ $columns{'Groups'} };
@@ -112,6 +113,7 @@ while ( my $entry = $report->Next ) {
 
     foreach my $v ( @values ) {
         $max_value = $v if $max_value < $v;
+        $min_value = $v if !defined $min_value || $min_value > $v;
     }
     $max_key_length = length $key if $max_key_length < length $key;
 }
@@ -180,7 +182,8 @@ if ($chart_class eq "GD::Graph::bars") {
 # use a top margin enough to display values over the top line if needed
         t_margin => 18,
 # the following line to make sure there's enough space for values to show
-        y_max_value => 5*(int($max_value/5) + 2),
+        y_max_value => $max_value * 1.10,
+        y_min_value => $min_value * 0.9,
 # if there're too many bars or at least one key is too long, use vertical
         x_labels_vertical => ( $count * $max_key_length > 60 ) ? 1 : 0,
         bargroup_spacing => $args{'bar_spacing'}*5,

-----------------------------------------------------------------------


More information about the Rt-commit mailing list