[Rt-commit] r2830 - in rt/branches/QUEBEC-EXPERIMENTAL: .
html/Search html/Search/Elements
jesse at bestpractical.com
jesse at bestpractical.com
Wed May 4 00:19:34 EDT 2005
Author: jesse
Date: Wed May 4 00:19:34 2005
New Revision: 2830
Added:
rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Chart.html
rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/SelectChartType
rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/SelectGroupBy
Modified:
rt/branches/QUEBEC-EXPERIMENTAL/ (props changed)
rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Chart.png
rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/DisplayOptions
rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Results.html
Log:
r15713 at hualien: jesse | 2005-05-04 00:17:54 -0400
* Graphing and charting
Added: rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Chart.html
==============================================================================
--- (empty file)
+++ rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Chart.html Wed May 4 00:19:34 2005
@@ -0,0 +1,76 @@
+<%args>
+$Query => "id > 0"
+$PrimaryGroupBy => 'Queue'
+$SecondaryGroupBy => undef
+$ChartStyle => 'bars'
+</%args>
+<%init>
+my @keys;
+my @values;
+
+use RT::Report::Tickets;
+
+my $tix = RT::Report::Tickets->new( $session{'CurrentUser'} );
+
+my @groupby = (
+ { FIELD => $PrimaryGroupBy },
+
+ #{ FIELD => $SecondaryGroupBy}
+);
+$tix->GroupByCols(@groupby);
+$tix->Column( FUNCTION => 'COUNT', FIELD => 'id' );
+$tix->Column( FIELD => $PrimaryGroupBy );
+
+#$tix->Column( FIELD => $SecondaryGroupBy);
+$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) );
+ push @keys, $q->Name();
+ }
+ else {
+ push @keys, $entry->__Value($PrimaryGroupBy);
+ }
+ push @values, $entry->id;
+ }
+
+my $title = loc("[_1] grouped by [_2]",$Query, $PrimaryGroupBy);
+
+my $query_string = $m->comp('/Elements/QueryString', %ARGS);
+</%init>
+<& /Elements/Header, Title => $title &>
+<& /Ticket/Elements/Tabs &>
+
+<img src="<%$RT::WebPath%>/Search/Chart.png?<%$query_string|n%>">
+<br>
+
+<table class="collection-as-table">
+<tr>
+<th class="collection-as-table"><%loc($PrimaryGroupBy)%>
+</th>
+<th class="collection-as-table"><&|/l&>Tickets</&>
+</th>
+</tr>
+% my $i;
+% while (my $key = shift @keys) {
+% $i++;
+<tr class="<%$i%2 ? 'evenline' : 'oddline' %>">
+<td class="label collection-as-table">
+<%$key%>
+</td>
+<td class="value collection-as-table">
+<%shift @values%>
+</td>
+</tr>
+% }
+</table>
+
Modified: rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Chart.png
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Chart.png (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Chart.png Wed May 4 00:19:34 2005
@@ -2,14 +2,35 @@
$Query => "id > 0"
$PrimaryGroupBy => 'Queue'
$SecondaryGroupBy => undef
+$ChartStyle => 'bars'
</%args>
<%init>
my @keys;
my @values;
-use GD::Graph::bars;
+my $chart_class;
+use GD;
+use GD::Text;
+
+if ($ChartStyle eq 'pie') {
+ require GD::Graph::pie;
+ $chart_class= "GD::Graph::pie";
+} else {
+ require GD::Graph::bars;
+ $chart_class= "GD::Graph::bars";
+}
use RT::Report::Tickets;
-my $chart = GD::Graph::bars->new( 600 => 400 );
+my $chart = $chart_class->new( 600 => 400 );
+if ($chart_class eq "GD::Graph::bars") {
+ $chart->set(
+ x_label => $PrimaryGroupBy,
+ 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'} );
my @groupby = (
@@ -34,26 +55,29 @@
$class = "RT::User";
}
if ($class) {
- warn "Trying to load class $class";
- warn $entry->__Value($PrimaryGroupBy);
my $q = $class->new( $session{'CurrentUser'} );
$q->Load( $entry->__Value($PrimaryGroupBy) );
- push @keys, $q->Name();
+ if ($chart_class eq 'GD::Graph::pie') {
+ push @keys, $q->Name() . " - ".$entry->id;
+ }
+ else {
+ push @keys, $q->Name();
+ }
}
else {
- push @keys, $entry->__Value($PrimaryGroupBy);
+ if ($chart_class eq 'GD::Graph::pie') {
+ push @keys, $entry->__Value($PrimaryGroupBy). "- ".$entry->id;
+ }
+ else {
+ push @keys, $entry->__Value($PrimaryGroupBy);
+ }
}
push @values, $entry->id;
}
- use YAML;
- warn YAML::Dump \@keys;
- $chart->set(
- x_label => $PrimaryGroupBy,
- y_label => 'Tickets',
- title => "$Query\n split by $PrimaryGroupBy",
- )
- or die $chart->error;
+ $chart->set( title => loc("[_1] grouped by [_2]",$Query, $PrimaryGroupBy)
+ ) or die $chart->error;
+
my $plot = $chart->plot( [ [@keys], [@values] ] ) or die $chart->error;
$r->content_type('image/png');
Modified: rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/DisplayOptions
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/DisplayOptions (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/DisplayOptions Wed May 4 00:19:34 2005
@@ -79,6 +79,7 @@
</select>
</td>
</tr>
+<tr>
<td class=label>
<&|/l&>Rows per page</&>:
</td><td class="value">
@@ -108,4 +109,5 @@
$OrderBy => undef
$RowsPerPage => undef
$Format => undef
+$GroupBy => 'id'
</%ARGS>
Added: rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/SelectChartType
==============================================================================
--- (empty file)
+++ rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/SelectChartType Wed May 4 00:19:34 2005
@@ -0,0 +1,9 @@
+<%args>
+$Name => 'ChartType'
+$Default => 'bar'
+</%args>
+<select name="<%$Name%>">
+% foreach my $option qw(bar pie) {
+<option value="<%$option%>" <% $option eq $Default ? 'SELECTED' : '' %>><%loc($option)%></option>
+% }
+</select>
Added: rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/SelectGroupBy
==============================================================================
--- (empty file)
+++ rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Elements/SelectGroupBy Wed May 4 00:19:34 2005
@@ -0,0 +1,9 @@
+<%args>
+$Name => 'GroupBy'
+$Default => 'Status'
+</%args>
+<select name="<%$Name%>">
+% foreach my $option qw(Owner Queue Status) {
+<option value="<%$option%>" <% $option eq $Default ? 'SELECTED' : '' %>><%loc($option)%></option>
+% }
+</select>
Modified: rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Results.html
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Results.html (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/html/Search/Results.html Wed May 4 00:19:34 2005
@@ -82,6 +82,17 @@
<a href="<%$RT::WebPath%>/Search/Results.tsv<%$QueryString%>"><&|/l&>spreadsheet</&></a> |
<a href="<%$RT::WebPath%>/Search/Results.rdf<%$QueryString%>"><&|/l&>RSS</&></a> |
<a href="<%$RT::WebPath%>/Tools/Offline.html<%$QueryString%>"><&|/l&>Work offline</&></a><br>
+<form method="get" action="<%$RT::WebPath%>/Search/Chart.html"><&|/l&>chart</&>
+% my @vars = (Query => $Query, Format => $Format, Rows => $Rows, OrderBy => $OrderBy, Order => $Order);
+%while (my $var = shift (@vars)) {
+<input type="hidden" name="<%$var%>" value="<%shift(@vars)%>"/>
+%}
+</%perl>
+<&|/l, $m->scomp('Elements/SelectGroupBy', Name => 'PrimaryGroupBy') &>grouped by [_1]</&>
+<&|/l, $m->scomp('Elements/SelectChartType', Name => 'ChartStyle') &>style: [_1]</&>
+
+<input type="submit" value="<%loc('Go')%>"/>
+</form>
<& /Elements/Callback, _CallbackName => 'SearchActions', QueryString => $QueryString&>
</div>
<%INIT>
More information about the Rt-commit
mailing list