Skip to content
Browse files

add a user picklist to the report limiting options; add some callback…

…s for a new plugin
  • Loading branch information...
1 parent 6146fab commit 3144ae9cddefecc147455cbc76ac2f5370f5e5d9 @tla tla committed Aug 7, 2007
View
6 Changes
@@ -1,3 +1,9 @@
+0.10
+
+ * Added "Limit to user" picklist to the report limiting options
+ * Added some callbacks for plugin functionality
+ * Factored some common code into lib/RT/Extension/ActivityReports.pm
+
0.8
* Removed a stray print statement
View
9 README
@@ -4,8 +4,8 @@ It is freely redistributable under the terms of version 2 of the GNU GPL.
SUMMARY ---
-RT-Extension-ActivityReports provides a number of simple reporting
-tools to analyze the activity of your RT instance.
+RT-Extension-ActivityReports provides a number of reporting tools to
+analyze the activity of your RT instance.
INSTALLATION ---
@@ -19,3 +19,8 @@ automatically detect it.)
$ make
$ make install
+USAGE ---
+
+Once installed, the activity reports can be accessed from the URL
+http://<path_to_your_RT>/Reports/Activity/index.html
+
View
39 html/Reports/Activity/Elements/ActivityDetail
@@ -21,39 +21,28 @@
$query => ''
$start => "2005/01/01"
$end => "2006/01/01"
+$actor => ''
</%args>
<%init>
-my $summary_tickets = RT::Tickets->new($session{'CurrentUser'});
-$summary_tickets->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, "Updated >= '$start' AND Updated <= '$end'"));
+use RT::Extension::ActivityReports qw( RelevantTxns );
my %counts;
-while (my $ticket = $summary_tickets->Next) {
- my $txns = $ticket->Transactions;
- $txns->Limit(FIELD => 'Created', OPERATOR => '>=', VALUE => $start);
- $txns->Limit(FIELD => 'Created', OPERATOR => '<=', VALUE => $end);
- # I think they really don't just want status changes
- $txns->Limit(FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR => 'OR');
- $txns->Limit(FIELD => 'Type', VALUE => 'Create');
+my @items;
+my $tickets = RT::Tickets->new($session{'CurrentUser'});
+$tickets->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, "Updated >= '$start' AND Updated <= '$end'"));
+while (my $ticket = $tickets->Next) {
+ my $txns = RelevantTxns( $ticket, start => $start, end => $end, query => $query );
+ while (my $txn = $txns->Next) {
+ # We have to filter for actor here, not in the query. Alas.
+ if( $actor ) {
+ next unless $txn->CreatorObj->Name eq $actor;
+ }
- while (my $txn = $txns->Next){
+ # For the summary report
my $date = substr($txn->Created, 0, 10);
# we don't have data on the status of a new ticket, default to 'new'
$counts{$date}{$txn->NewValue || 'new'}++;
- }
-}
-
-my $tickets = RT::Tickets->new($session{'CurrentUser'});
-$tickets->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, "Updated >= '$start' AND Updated <= '$end'"));
-my @items;
-while (my $ticket = $tickets->Next) {
- my $txns = $ticket->Transactions;
- $txns->Limit(FIELD => 'Created', OPERATOR => '>=', VALUE => $start);
- $txns->Limit(FIELD => 'Created', OPERATOR => '<=', VALUE => $end);
- # I think they really don't just want status changes
- $txns->Limit(FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR => 'OR');
- $txns->Limit(FIELD => 'Type', VALUE => 'Create');
-
- while (my $txn = $txns->Next) {
+ # For the detail report
push @items, { queue => $txn->TicketObj->QueueObj->Name,
id => $txn->TicketObj->id,
date => (split ' ', $txn->CreatedObj->ISO)[0],
View
14 html/Reports/Activity/Elements/ActivitySummary
@@ -29,6 +29,7 @@
$query => ''
$start => "2005/01/01"
$end => "2006/01/01"
+$actor => ''
</%args>
<%init>
my $tickets = RT::Tickets->new($session{'CurrentUser'});
@@ -39,13 +40,12 @@ my %status;
my %total;
my $total;
while (my $ticket = $tickets->Next) {
- my $txns = $ticket->Transactions;
- $txns->Limit(FIELD => 'Created', OPERATOR => '>=', VALUE => $start);
- $txns->Limit(FIELD => 'Created', OPERATOR => '<=', VALUE => $end);
- $txns->Limit(FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR => 'OR');
- $txns->Limit(FIELD => 'Type', VALUE => 'Create');
-
- while (my $txn = $txns->Next) {
+ my $txns = RelevantTxns( $ticket, start => $start, end => $end, query => $query );
+ while (my $txn = $txns->Next) {
+ # We have to filter for actor here, not in the query. Alas.
+ if( $actor ) {
+ next unless $txn->CreatorObj->Name ne $actor;
+ }
$queues{$txn->TicketObj->QueueObj->Name}{$txn->NewValue || 'new'}++;
$status{$txn->NewValue || 'new'}++;
$total{$txn->TicketObj->QueueObj->Name}++;
View
4 html/Reports/Activity/Elements/LimitReport
@@ -5,20 +5,24 @@ Query:
Report type: <select name="ReportType">
<option value="ActivityDetail" <% $ReportType =~ /ActivityDetail/ ? 'selected' : '' %>>Activity detail</option>
<option value="ActivitySummary" <% $ReportType =~ /ActivitySummary/ ? 'selected' : '' %>>Activity summary</option>
+<& /Elements/Callback, _CallbackName => 'AddReports', ARGSref => \%ARGS &>
<option value="ResolutionComments" <% $ReportType =~ /ResolutionComments/ ? 'selected' : '' %>>Resolution comments</option>
<option value="ResolutionStatistics" <% $ReportType =~ /ResolutionStatistics/ ? 'selected' : '' %>>Resolution statistics</option>
<option value="WorkedStatistics" <% $ReportType =~ /WorkedStatistics/ ? 'selected' : '' %>>Time worked statistics</option>
</select><br />
Start date: <input type="text" name="Start" value="<% $Start %>" /><br />
End date: <input type="text" name="End" value="<% $End %>" /><br />
+Limit to user: <& /Elements/SelectOwner, Name => "Actor", ValueAttribute => 'Name', Default => $Actor &>
+<& /Elements/Callback, _CallbackName => 'AddOptions', ARGSref => \%ARGS &>
<& /Elements/Submit, Label => loc('Report') &>
</form>
<%args>
$ReportType => undef
$Start => undef
$End => undef
$Query => undef
+$Actor => undef
</%args>
<%init>
</%init>
View
5 html/Reports/Activity/Elements/ResolutionComments
@@ -24,14 +24,17 @@
$query => ''
$start => "2005/01/01"
$end => "2006/01/01"
+$actor => ''
</%args>
<%init>
use Time::Duration;
+my $actor_query = '';
+$actor_query = "(Owner = '$actor')" if $actor;
my $summary_tickets = RT::Tickets->new( $session{'CurrentUser'} );
$summary_tickets->FromSQL(
- join " AND ", map {"($_)"} grep {/\S/} ($query, "(Status = 'resolved') AND ( Updated >= '$start' AND Updated <= '$end')"));
+ join " AND ", map {"($_)"} grep {/\S/} ($query, $actor_query, "(Status = 'resolved') AND ( Updated >= '$start' AND Updated <= '$end')"));
my @items;
while ( my $ticket = $summary_tickets->Next ) {
View
5 html/Reports/Activity/Elements/ResolutionStatistics
@@ -37,6 +37,7 @@
$query => ''
$start => "2005/01/01"
$end => "2006/01/01"
+$actor => ''
</%args>
<%init>
@@ -54,12 +55,14 @@ $queries{'Last 60 days'} = "(Resolved >= '".$in_60_days->ISO."')";
$queries{'Last 90 days'} = "(Resolved >= '".$in_90_days->ISO."')";
$queries{'Ever'} = "(Status = 'resolved' OR Status = 'rejected')";
+my $actor_query = '';
+$actor_query = "(Owner = '$actor')" if $actor;
my %closed;
my %queues;
foreach my $period (keys %queries) {
my $tix = RT::Tickets->new($session{'CurrentUser'});
- $tix->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, $queries{$period}));
+ $tix->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, $actor_query, $queries{$period}));
while (my $ticket = $tix->Next) {
push @{ $closed{$period}{$ticket->QueueObj->Name}}, $ticket;
View
6 html/Reports/Activity/Elements/WorkedStatistics
@@ -96,6 +96,7 @@
$query => ""
$start => "2005/01/01"
$end => "2006/01/01"
+$actor => ""
</%args>
<%init>
my $startDate = RT::Date->new($session{'CurrentUser'});
@@ -113,8 +114,11 @@ while (my $queue = $Queues->Next) {
$queue{$queue->Id}{total_open} = $tix->Count();
}
+my $actor_query = '';
+$actor_query = "(Owner = '$actor')" if $actor;
+
my $tix = RT::Tickets->new($session{'CurrentUser'});
-$tix->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, "Updated >= '$start' AND Updated <= '$end'"));
+$tix->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, $actor_query, "Updated >= '$start' AND Updated <= '$end'"));
while (my $ticket = $tix->Next) {
my $created = $ticket->CreatedObj;
my $resolved = $ticket->ResolvedObj;
View
4 html/Reports/Activity/index.html
@@ -35,9 +35,11 @@
$ARGS{show_print_link} = 0 unless $ReportType;
+$m->comp( '/Elements/Callback', _CallbackName => 'FlipInvoiced', ARGSref => \%ARGS );
+
my $saved_search = $m->comp( '/Widgets/SavedSearch:new',
SearchType => 'ActivityReport',
- SearchFields => [qw(Query ReportType Start End)] );
+ SearchFields => [qw(Query ReportType Start End Actor)] );
my @actions = $m->comp( '/Widgets/SavedSearch:process', args => \%ARGS, self => $saved_search );
View
4 html/Search/Elements/ActivityReport
@@ -3,5 +3,7 @@ $ReportType => undef
$Start => undef
$End => undef
$Query => undef
+$Actor => undef
</%args>
-<& '/Reports/Activity/Elements/'.$ReportType, start => $Start, end => $End, query => $Query &>
+<& '/Reports/Activity/Elements/'.$ReportType, start => $Start, end => $End, query => $Query, actor => $Actor &>
+
View
41 lib/RT/Extension/ActivityReports.pm
@@ -1,3 +1,42 @@
package RT::Extension::ActivityReports;
-our $VERSION = '0.9';
+use Exporter qw( import );
+@EXPORT_OK = qw( RelevantTxns );
+
+our $VERSION = '0.10';
+
+=head2 RelevantTxns( $ticket, \%args )
+
+Helper routine for the various activity reports, to get the list of
+relevant transactions on each relevant ticket. Not yet used for
+Resolution* or TimeWorked reports. Args include:
+
+ start
+ end
+ actor
+ timed
+
+=cut
+
+sub RelevantTxns {
+ my( $ticket, %args ) = @_;
+
+ my $txns = $ticket->Transactions;
+ $txns->Limit(FIELD => 'Created', OPERATOR => '>=', VALUE => $args{start});
+ $txns->Limit(FIELD => 'Created', OPERATOR => '<=', VALUE => $args{end});
+ if( $args{timed} ) {
+ # Limit to transactions with positive time taken.
+ $txns->Limit(FIELD => 'TimeTaken', OPERATOR => '>=', VALUE => 1);
+ } else {
+ # Include status changes and ticket creations.
+ $txns->Limit(FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR => 'OR');
+ $txns->Limit(FIELD => 'Type', VALUE => 'Create', ENTRYAGGREGATOR => 'OR');
+ }
+ # Comment/correspond type transactions are always relevant.
+ $txns->Limit(FIELD => 'Type', VALUE => 'Comment', ENTRYAGGREGATOR => 'OR');
+ $txns->Limit(FIELD => 'Type', VALUE => 'Correspond');
+
+ return $txns;
+}
+
+1;

0 comments on commit 3144ae9

Please sign in to comment.
Something went wrong with that request. Please try again.