[Rt-commit] r4674 - in rtir/branches/1.9-EXPERIMENTAL:
html/RTIR/Reporting html/RTIR/Reporting/Elements
ruz at bestpractical.com
ruz at bestpractical.com
Fri Mar 3 20:41:58 EST 2006
Author: ruz
Date: Fri Mar 3 20:41:57 2006
New Revision: 4674
Modified:
rtir/branches/1.9-EXPERIMENTAL/ (props changed)
rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Elements/SLASummary
rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Elements/SLASummaryText
rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Report.html
rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/index.html
Log:
r826 at cubic-pc: cubic | 2006-03-03 05:19:20 +0300
* localization
* myend and mystart -> StartDate, EndDate
* new CF handling code use 'Object-RT::Ticket--...' name prefix, fix that
* move duplicated code into anon function
Modified: rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Elements/SLASummary
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Elements/SLASummary (original)
+++ rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Elements/SLASummary Fri Mar 3 20:41:57 2006
@@ -26,34 +26,32 @@
<tr>
<td valign="top" width="45%">
<table width="100%">
- <th colspan="2">At the start of the time period</th>
+ <th colspan="2"><&|/l&>At the start of the time period</&></th>
<tr>
- <td>Outstanding Incident Reports</td>
- <td align="right"> <% scalar %$outstanding %></td>
+ <td><&|/l&>Outstanding Incident Reports</&></td>
+ <td align="right"><% scalar keys %$outstanding %></td>
</tr>
</table>
</td>
<td></td>
<td valign="top" width="45%">
<table width =100%>
- <th colspan="2">During the time period</th>
+ <th colspan="2"><&|/l&>During the time period</&></th>
<tr>
- <td>Total <%$service_level%> Incident Reports created</td>
+ <td><&|/l, $service_level &>Total [_1] Incident Reports created</&></td>
<td align="right"><% $tix_count %></td>
</tr>
<tr>
- <td>
- Incident Reports for which SLA time was met
- </td>
- <td align="right"><% $sla_count %></td>
+ <td><&|/l&>Incident Reports for which SLA time was met</&></td>
+ <td align="right"><% $sla_count %></td>
</tr>
<tr>
- <td>Resolved Incident Reports</td>
- <td align="right"><% $resolved_count%></td>
+ <td><&|/l&>Resolved Incident Reports</&></td>
+ <td align="right"><% $resolved_count %></td>
</tr>
<tr>
- <td>Unresolved Incident Reports </td>
- <td align="right"><% $unresolved_count%></td>
+ <td><&|/l&>Unresolved Incident Reports</&></td>
+ <td align="right"><% $unresolved_count %></td>
</tr>
</table>
</td>
@@ -67,7 +65,7 @@
$sla_count = 0;
$resolved_count = 0;
$unresolved_count = 0;
-
+
# get the number of seconds for the service level
my $sla = RT->Config->Get('SLA')->{$service_level} * 60;
@@ -81,34 +79,33 @@
# correspondence within the time specified by $sla.
#
if ($t->StartsObj->Unix > 0 && $t->StartedObj->Unix > 0) {
- # Get a Business::Hours object for the period in question
- my $bizhours = RT::IR::BusinessHours();
+ # Get a Business::Hours object for the period in question
+ my $bizhours = RT::IR::BusinessHours();
- my $started_time;
- if ($t->StartsObj->Unix < $t->StartedObj->Unix) {
- $bizhours->for_timespan( Start => $t->StartsObj->Unix,
- End => $t->StartedObj->Unix );
-
- $started_time = $bizhours->between( $t->StartsObj->Unix,
- $t->StartedObj->Unix );
- } else {
- $started_time = 0;
- }
-
- if ( $started_time < $sla) {
- $sla_count++;
- }
+ my $started_time;
+ if ($t->StartsObj->Unix < $t->StartedObj->Unix) {
+ $bizhours->for_timespan( Start => $t->StartsObj->Unix,
+ End => $t->StartedObj->Unix );
+
+ $started_time = $bizhours->between( $t->StartsObj->Unix,
+ $t->StartedObj->Unix );
+ } else {
+ $started_time = 0;
+ }
+
+ if ( $started_time < $sla) {
+ $sla_count++;
+ }
}
-
+
if ( $t->ResolvedObj->Unix >= $start->Unix &&
- $t->ResolvedObj->Unix <= $end->Unix) {
- $resolved_count++;
+ $t->ResolvedObj->Unix <= $end->Unix) {
+ $resolved_count++;
}
if ( $t->ResolvedObj->Unix <= 0 ||
- $t->ResolvedObj->Unix > $end->Unix) {
- $unresolved_count++;
+ $t->ResolvedObj->Unix > $end->Unix) {
+ $unresolved_count++;
}
-
}
</%INIT>
Modified: rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Elements/SLASummaryText
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Elements/SLASummaryText (original)
+++ rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Elements/SLASummaryText Fri Mar 3 20:41:57 2006
@@ -22,14 +22,14 @@
%#
%#
%# END LICENSE BLOCK
-At the start of the time period
-Outstanding Incident Reports;<% scalar %$outstanding %>
+<&|/l&>At the start of the time period</&>
+<&|/l&>Outstanding Incident Reports</&>;<% scalar keys %$outstanding %>
-During the time period
-Total <%$service_level%> Incident Reports created;<% $tix_count %>
-Incident Reports for which SLA time was met;<% $sla_count %>
-Resolved Incident Reports;<% $resolved_count%>
-Unresolved Incident Reports;<% $unresolved_count%>
+<&|/l&>During the time period</&>
+<&|/l, $service_level &>Total [_1] Incident Reports created</&>;<% $tix_count %>
+<&|/l&>Incident Reports for which SLA time was met</&>;<% $sla_count %>
+<&|/l&>Resolved Incident Reports</&>;<% $resolved_count%>
+<&|/l&>Unresolved Incident Reports</&>;<% $unresolved_count%>
<%INIT>
my ($tix_count, $sla_count, $resolved_count, $unresolved_count);
@@ -37,7 +37,7 @@
$sla_count = 0;
$resolved_count = 0;
$unresolved_count = 0;
-
+
# get the number of seconds for the service level
my $sla = RT->Config->Get('SLA')->{$service_level} * 60;
Modified: rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Report.html
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Report.html (original)
+++ rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/Report.html Fri Mar 3 20:41:57 2006
@@ -22,145 +22,136 @@
%#
%#
%# END LICENSE BLOCK
-% if ($tabbed) {
-RTIR Periodic Report for <%$Constituency%>
+% if ($TextReport) {
+<&|/l, $Constituency &>RTIR Periodic Report for [_1]</&>
-Start date:;<%$rtstart->AsString%>
-End date:;<%$rtend->AsString%>
+<&|/l&>Start date:</&> <% $rtstart->AsString %>
+<&|/l&>End date:</&> <% $rtend->AsString %>
-Incident Report Summary (including unlinked Incident Reports)
-Outstanding reports at the beginning of this period;<% scalar keys %$outstanding_pruned %>
-Total new reports for this period;<% scalar keys %$tix_created_pruned %>
-Incident Reports resolved during this period;<% scalar keys %$tix_resolved_pruned %>
-Reports unresolved at the end of the period;<% scalar keys %$tix_unresolved_pruned %>
+<&|/l&>Incident Report Summary (including unlinked Incident Reports)</&>
+<&|/l&>Outstanding reports at the beginning of this period;</&><% scalar keys %$outstanding_pruned %>
+<&|/l&>Total new reports for this period</&>;<% scalar keys %$tix_created_pruned %>
+<&|/l&>Incident Reports resolved during this period</&>;<% scalar keys %$tix_resolved_pruned %>
+<&|/l&>Reports unresolved at the end of the period</&>;<% scalar keys %$tix_unresolved_pruned %>
% } else {
-<h1>RTIR Periodic Report for <%$Constituency%></h1>
+<h1><&|/l, $Constituency &>RTIR Periodic Report for [_1]</&></h1>
<table>
<tr>
- <td>Start date:</td>
- <td> <%$rtstart->AsString%></td>
+ <td><&|/l&>Start date:</&></td>
+ <td><% $rtstart->AsString %></td>
</tr>
<tr>
- <td>End date:</td>
- <td><%$rtend->AsString%></td>
+ <td><&|/l&>End date:</&></td>
+ <td><% $rtend->AsString %></td>
</tr>
</table>
+
<table>
-<tr><th align="left" colspan="2">Incident Report Summary (including unlinked Incident Reports)</th></tr>
+<tr><th align="left" colspan="2"><&|/l&>Incident Report Summary (including unlinked Incident Reports)</&></th></tr>
<tr>
- <td>Outstanding reports at the beginning of this period</td>
+ <td><&|/l&>Outstanding reports at the beginning of this period</&></td>
<td class="value"> <% scalar keys %$outstanding_pruned %></td>
</tr>
<tr>
- <td>Total new reports for this period</td>
+ <td><&|/l&>Total new reports for this period</&></td>
<td><% scalar keys %$tix_created_pruned %></td>
</tr>
<tr>
- <td>Incident Reports resolved during this period</td>
+ <td><&|/l&>Incident Reports resolved during this period</&></td>
<td><% scalar keys %$tix_resolved_pruned %></td>
</tr>
<tr>
- <td>Reports unresolved at the end of the period</td>
+ <td><&|/l&>Reports unresolved at the end of the period</&></td>
<td><% scalar keys %$tix_unresolved_pruned %></td>
</tr>
</table>
% }
-<%perl>
-foreach my $key (sort keys %$types) {
- my $incident_type = $types->{$key};
-</%perl>
-% if ($tabbed) {
-<%$incident_type%>
-
+% foreach my $incident_type( @functions ) {
+% if ($TextReport) {
+<% $incident_type %>
% } else {
-<h2><%$incident_type%></h2>
+<h2><% $incident_type %></h2>
% }
-% if ($tabbed) {
-Incident reports received
+% if ($TextReport) {
+<&|/l&>Incident reports received</&>
% } else {
<table>
-<th align="left" colspan="2">Incident reports received</th>
+<th align="left" colspan="2"><&|/l&>Incident reports received</&></th>
% }
-<%perl>
-foreach my $key (sort keys %$classifications) {
- my $class = $classifications->{$key};
+<%PERL>
+
+foreach my $class (@classifications) {
my $class_count = 0;
$tix_created->GotoFirstItem();
- while ( my $t = $tix_created->Next) {
- my $value = get_incident_field( $t, '_RTIR_Constituency');
- next if ($value ne $Constituency);
-
- $value = get_incident_field( $t, '_RTIR_Classification');
- next if ($class ne 'Unclassified' && $value ne $class);
- next if ($class eq 'Unclassified' && $value ne "");
+ while ( my $t = $tix_created->Next ) {
+ my $value = $get_incident_field->( $t, '_RTIR_Constituency');
+ next if ($value ne $Constituency);
+
+ $value = $get_incident_field->( $t, '_RTIR_Classification');
+ next if ($class ne 'Unclassified' && $value ne $class);
+ next if ($class eq 'Unclassified' && $value ne "");
- $value = get_incident_field( $t, '_RTIR_Function');
- next if ($value ne $incident_type);
+ $value = $get_incident_field->( $t, '_RTIR_Function');
+ next if ($value ne $incident_type);
- $class_count++;
+ $class_count++;
}
</%perl>
-% if ($tabbed) {
-<%$class%>;<%$class_count%>
+% if ($TextReport) {
+<% $class %>;<% $class_count %>
% } else {
<tr>
- <td><%$class%></td>
- <td class="value"><%$class_count%></td>
+ <td><% $class %></td>
+ <td class="value"><% $class_count %></td>
</tr>
% }
-<%perl>
-}
-</%perl>
-% if ($tabbed) {
+% }
+% if ($TextReport) {
% } else {
</table>
% }
-<%perl>
- foreach my $service_level (keys %$sla_levels) {
- my $class_tix = RT::Tickets->new( $session{'CurrentUser'} );
- $class_tix->LimitQueue(VALUE => 'Incident Reports');
- $class_tix->LimitCreated(VALUE => $start, OPERATOR => ">");
- $class_tix->LimitCreated(VALUE => $end, OPERATOR => "<");
- $class_tix->LimitCustomField(CUSTOMFIELD => $fid, VALUE => $service_level);
- my $mytix = {};
- while ( my $t = $class_tix->Next) {
- my $value = get_incident_field( $t, '_RTIR_Constituency');
- next if ($value ne $Constituency);
-
- $value = get_incident_field( $t, '_RTIR_Function');
- next unless ($value eq $incident_type);
- $mytix->{$t->Id} = $t;
- }
-
- my $myoutstanding = {};
- while ( my $t = $outstanding->Next) {
- my $value = get_incident_field( $t, '_RTIR_Constituency');
- next if ($value ne $Constituency);
-
- $value = get_incident_field( $t, '_RTIR_Function');
- next unless ($value eq $incident_type);
- $myoutstanding->{$t->Id} = $t;
- }
-
-</%perl>
-% if ($tabbed) {
-<%$service_level%>
+<%PERL>
+ foreach my $service_level( @sla_levels ) {
+ my $class_tix = RT::Tickets->new( $session{'CurrentUser'} );
+ $class_tix->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end' AND CustomField.{_RTIR_SLA} = '$service_level'");
+ my $mytix = $filter_by_incident_field->(
+ $filter_by_incident_field->(
+ $class_tix,
+ '_RTIR_Constituency',
+ $Constituency
+ ),
+ '_RTIR_Function',
+ $incident_type,
+ );
+
+ my $myoutstanding = $filter_by_incident_field->(
+ $filter_by_incident_field->(
+ $outstanding,
+ '_RTIR_Constituency',
+ $Constituency
+ ),
+ '_RTIR_Function',
+ $incident_type,
+ );
+</%PERL>
+% if ($TextReport) {
+<% $service_level %>
% } else {
-<h3><%$service_level%></h3>
+<h3><% $service_level %></h3>
% }
-% if ($tabbed) {
-<& Elements/SLASummaryText,
+% if ($TextReport) {
+<& Elements/SLASummaryText,
class_tix => $mytix, outstanding => $myoutstanding,
service_level => $service_level,
start => $rtstart, end => $rtend &>
% } else {
-<& Elements/SLASummary,
+<& Elements/SLASummary,
class_tix => $mytix, outstanding => $myoutstanding,
service_level => $service_level,
start => $rtstart, end => $rtend &>
@@ -168,78 +159,97 @@
<%perl>
}
}
-if ($tabbed) {
+if ($TextReport) {
$m->abort();
}
-</%perl>
+</%PERL>
-<%init>
-my $tabbed = 0;
-if ($ARGS{TextReport}) {
- $tabbed = 1;
-}
+<%INIT>
+
+my $get_incident_field = sub {
+ my $t = shift;
+ my $field = shift;
+
+ # find the parent incident
+ my $query = "Queue = 'Incidents' AND HasMember = ". $t->Id;
+ my $incidents = new RT::Tickets( $session{'CurrentUser'} );
+ $incidents->FromSQL( $query );
+
+ my $parent = $incidents->First;
+ return undef unless $parent;
+ return RT::IR::Ticket::FirstCustomFieldValue( $parent, $field );
+};
+
+my $filter_by_incident_field = sub {
+ my ($tickets, $field, $condition) = (@_);
+ my $res = {};
+ unless ( ref $tickets eq 'HASH' ) {
+ while ( my $t = $tickets->Next ) { $res->{ $t->Id } = $t }
+ }
+ else {
+ %$res = %$tickets;
+ }
+
+ while( my($id, $t) = each %$res ) {
+ my $value = $get_incident_field->( $t, $field );
+ delete $res->{$id} if !$value || $value ne $condition;
+ }
+ return $res;
+};
-my $start = ParseDateToISO($mystart);
-my $end = ParseDateToISO($myend);
+my $start = ParseDateToISO( $StartDate );
+my $end = ParseDateToISO( $EndDate );
+my $rtstart = new RT::Date($RT::SystemUser);
+$rtstart->Set( Format => 'ISO', Value => $start );
+my $rtend = new RT::Date($RT::SystemUser);
+$rtend->Set( Format => 'ISO', Value => $end );
-$Constituency = $ARGS{$Constituency} if $Constituency;
+$Constituency = $ARGS{ 'Object-RT::Ticket--'. $Constituency } if $Constituency;
# of new reports created during the period broken down by function
-my ($cf, $values, $fid, $types, $classifications, $sla_levels);
-my $i = 0;
-$cf = RT::CustomField->new($session{'CurrentUser'});
-$cf->LoadByNameAndQueue(Queue => 'Incidents', Name => '_RTIR_Function');
-$values = $cf->Values;
-while (my $value = $values->Next) {
- $types->{$i} = $value->Name;
- $i++;
+my @functions;
+{
+ my $cf = RT::CustomField->new( $session{'CurrentUser'} );
+ $cf->LoadByNameAndQueue( Queue => 'Incidents', Name => '_RTIR_Function' );
+ my $values = $cf->Values;
+ while ( my $value = $values->Next ) {
+ push @functions, $value->Name;
+ }
}
# of new reports created during the period broken down by classification
-$i = 0;
-$cf = RT::CustomField->new($session{'CurrentUser'});
-$cf->LoadByNameAndQueue(Queue => 'Incidents', Name => '_RTIR_Classification');
-$values = $cf->Values;
-while (my $value = $values->Next) {
- $classifications->{$i} = $value->Name;
- $i++;
+my @classifications;
+{
+ my $cf = RT::CustomField->new( $session{'CurrentUser'} );
+ $cf->LoadByNameAndQueue( Queue => 'Incidents', Name => '_RTIR_Classification' );
+ my $values = $cf->Values;
+ while ( my $value = $values->Next ) {
+ push @classifications, $value->Name;
+ }
+ push @classifications, 'Unclassified';
}
-$classifications->{$i} = 'Unclassified';
# of new reports created during the period broken down by SLA level
-$cf = RT::CustomField->new($session{'CurrentUser'});
-$cf->LoadByNameAndQueue(Queue => 'Incident Reports', Name => '_RTIR_SLA');
-$fid = $cf->Id;
-$values = $cf->Values;
-while (my $value = $values->Next) {
- $sla_levels->{$value->Name} = $value->Description;
+my @sla_levels;
+{
+ my $cf = RT::CustomField->new( $session{'CurrentUser'} );
+ $cf->LoadByNameAndQueue( Queue => 'Incidents', Name => '_RTIR_SLA' );
+ my $values = $cf->Values;
+ while ( my $value = $values->Next ) {
+ push @sla_levels, $value->Name;
+ }
}
-my $rtstart = new RT::Date($RT::SystemUser);
-$rtstart->Set( Format => 'ISO', Value => $start );
-my $rtend = new RT::Date($RT::SystemUser);
-$rtend->Set( Format => 'ISO', Value => $end );
-
# of new reports outstanding at start of the period
-my $outstanding = RT::Tickets->new($session{'CurrentUser'});
+my $outstanding = RT::Tickets->new( $session{'CurrentUser'} );
$outstanding->FromSQL("Queue = 'Incident Reports' AND Created < '$start' AND (Resolved='1970-01-01 00:00:00' OR Resolved > '$start')");
-my $outstanding_pruned = {};
-while ( my $t = $outstanding->Next) {
- my $value = get_incident_field( $t, '_RTIR_Constituency');
- next unless ($value eq $Constituency || !defined $value);
- $outstanding_pruned->{$t->Id} = $t;
-}
+my $outstanding_pruned = $filter_by_incident_field->($outstanding, '_RTIR_Constituency', $Constituency);
# of new reports created during the period
-my $tix_created = RT::Tickets->new($session{'CurrentUser'});
+my $tix_created = RT::Tickets->new( $session{'CurrentUser'} );
$tix_created->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end'");
-my $tix_created_pruned = {};
-while ( my $t = $tix_created->Next) {
- my $value = get_incident_field( $t, '_RTIR_Constituency');
- next unless ($value eq $Constituency || !defined $value);
- $tix_created_pruned->{$t->Id} = $t;
-}
+my $tix_created_pruned = $filter_by_incident_field->($outstanding, '_RTIR_Constituency', $Constituency);
# of new reports resolved/closed/deleted during the period
# this means "number of reports created during the period that were
@@ -247,47 +257,25 @@
my $tix_resolved = RT::Tickets->new($session{'CurrentUser'});
$tix_resolved->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end' AND (Resolved > '1970-01-01 00:00:00' AND Resolved <'$end')");
-my $tix_resolved_pruned = {};
-while ( my $t = $tix_resolved->Next) {
- my $value = get_incident_field( $t, '_RTIR_Constituency');
- next unless ($value eq $Constituency || !defined $value);
- $tix_resolved_pruned->{$t->Id} = $t;
-}
+my $tix_resolved_pruned = $filter_by_incident_field->($outstanding, '_RTIR_Constituency', $Constituency);
# of new reports oustanding at end of the period
# this is "number of reports created during the period that were also
# closed during the period"
-my $tix_unresolved = RT::Tickets->new($session{'CurrentUser'});
+my $tix_unresolved = RT::Tickets->new( $session{'CurrentUser'} );
$tix_unresolved->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end' AND (Resolved='1970-01-01 00:00:00' OR Resolved>'$end')");
-my $tix_unresolved_pruned = {};
-while ( my $t = $tix_unresolved->Next) {
- my $value = get_incident_field( $t, '_RTIR_Constituency');
- next unless ($value eq $Constituency || !defined $value);
- $tix_unresolved_pruned->{$t->Id} = $t;
-}
-
-sub get_incident_field {
- my $t = shift;
- my $field = shift;
-
- # find the parent incident
- my $query = "Queue = 'Incidents' AND HasMember = ". $t->Id;
- my $incidents = new RT::Tickets( $session{'CurrentUser'} );
- $incidents->FromSQL( $query );
-
- my $parent = $incidents->First;
- return undef unless $parent;
- return RT::IR::Ticket::FirstCustomFieldValue( $parent, $field );
-}
+my $tix_unresolved_pruned = $filter_by_incident_field->($outstanding, '_RTIR_Constituency', $Constituency);
-if ($tabbed) {
+if ($TextReport) {
$r->content_type('text/plain');
}
-</%init>
+</%INIT>
-<%args>
-$mystart => undef
-$myend => undef
+<%ARGS>
+$StartDate => undef
+$EndDate => undef
$Constituency => undef
-</%args>
+$HTMLReport => 1
+$TextReport => !$HTMLReport
+</%ARGS>
Modified: rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/index.html
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/index.html (original)
+++ rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Reporting/index.html Fri Mar 3 20:41:57 2006
@@ -46,13 +46,13 @@
<tr>
<td class="label"><&|/l&>Start Date:</&></td>
<td class="input">
- <input type="text" size="30" name="mystart" value="<% $start->AsString %>" />
+ <input type="text" size="30" name="StartDate" value="<% $start->AsString %>" />
</td>
</tr>
<tr>
<td class="label"><&|/l&>End Date:</&></td>
<td class="input">
- <input type="text" size="30" name="myend" value="<% $end->AsString %>" />
+ <input type="text" size="30" name="EndDate" value="<% $end->AsString %>" />
</td>
</tr>
</table>
More information about the Rt-commit
mailing list