[Bps-public-commit] rt-extension-jsgantt branch, master, updated. bd433cdf5d3e201c30bca664ad5724cec307ba86
? sunnavy
sunnavy at bestpractical.com
Tue Feb 1 02:04:47 EST 2011
The branch, master has been updated
via bd433cdf5d3e201c30bca664ad5724cec307ba86 (commit)
via 0e7c5246072517e48ee89594899538574bab1ff3 (commit)
from d1cacc161161f5aa964b90df4486a0d6c9f89029 (commit)
Summary of changes:
lib/RT/Extension/JSGantt.pm | 133 +++++++++++++++++++++++++-----------------
1 files changed, 79 insertions(+), 54 deletions(-)
- Log -----------------------------------------------------------------
commit 0e7c5246072517e48ee89594899538574bab1ff3
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Feb 1 14:09:28 2011 +0800
abstract start/end dates into a sub
diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index 5c89f01..75475ba 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -66,60 +66,8 @@ sub TicketsInfo {
$parent = $Ticket->MemberOf->First->TargetObj->id;
}
- # find start/end, this is, uhh, long long way to go
- my ( $start_obj, $start ) = _GetDate( $Ticket, 'Starts', 'Started' );
- my ( $end_obj, $end ) = _GetDate( $Ticket, 'Due' );
-
- # if $start or $end is empty still
- unless ( $start && $end ) {
- my $hours_per_day = RT->Config->Get('JSGanttWorkingHoursPerDay')
- || 8;
- my $total_time =
- defined $Ticket->TimeLeft && $Ticket->TimeLeft =~ /\d/
- ? ( $Ticket->TimeWorked + $Ticket->TimeLeft )
- : $Ticket->TimeEstimated;
- $total_time ||= 0;
- my $days = int( $total_time / ( 60 * $hours_per_day ) );
- $days ||= RT->Config->Get('JSGanttDefaultDays') || 7;
-
- # since we only use date without time, let's make days inclusive
- # ( i.e. 5/12/2010 minus 3 days is 5/10/2010. 10,11,12, 3 days! )
- $days = $days =~ /\./ ? int $days : $days - 1;
- $days = 0 if $days < 0;
-
- if ( $start && !$end ) {
- $end_obj = RT::Date->new( $args{CurrentUser} );
- $end_obj->Set( Value => $start_obj->Unix );
- $end_obj->AddDays($days);
- my ( $day, $month, $year ) =
- ( $end_obj->Localtime('user') )[ 3, 4, 5 ];
- $end = join '/', $month + 1, $day, $year;
- }
-
- if ( $end && !$start ) {
- $start_obj = RT::Date->new( $args{CurrentUser} );
- $start_obj->Set( Value => $end_obj->Unix );
- $start_obj->AddDays( -1 * $days );
- my ( $day, $month, $year ) =
- ( $start_obj->Localtime('user') )[ 3, 4, 5 ];
- $start = join '/', $month + 1, $day, $year;
- }
- }
-
- if ( !$start ) {
- $RT::Logger->warning( "Ticket "
- . $Ticket->id
- . " doesn't have Starts/Started defined, and we can't figure it out either"
- );
- $start = $end;
- }
- if ( !$end ) {
- $RT::Logger->warning( "Ticket "
- . $Ticket->id
- . " doesn't have Due defined, and we can't figure it out either"
- );
- $end = $start;
- }
+ # find start/end
+ my ( $start_obj, $start, $end_obj, $end ) = _GetTimeRange( $Ticket, %args );
if ( $start_obj
&& ( !$min_start_obj || $min_start_obj->Unix > $start_obj->Unix ) )
@@ -193,6 +141,67 @@ sub TicketsInfo {
return \@ids, \%info;
}
+sub _GetTimeRange {
+ my ( $Ticket, %args ) = @_;
+
+ # the, uh, long way
+ my ( $start_obj, $start ) = _GetDate( $Ticket, 'Starts', 'Started' );
+ my ( $end_obj, $end ) = _GetDate( $Ticket, 'Due' );
+
+ # if $start or $end is empty still
+ unless ( $start && $end ) {
+ my $hours_per_day = RT->Config->Get('JSGanttWorkingHoursPerDay')
+ || 8;
+ my $total_time =
+ defined $Ticket->TimeLeft && $Ticket->TimeLeft =~ /\d/
+ ? ( $Ticket->TimeWorked + $Ticket->TimeLeft )
+ : $Ticket->TimeEstimated;
+ $total_time ||= 0;
+ my $days = int( $total_time / ( 60 * $hours_per_day ) );
+ $days ||= RT->Config->Get('JSGanttDefaultDays') || 7;
+
+ # since we only use date without time, let's make days inclusive
+ # ( i.e. 5/12/2010 minus 3 days is 5/10/2010. 10,11,12, 3 days! )
+ $days = $days =~ /\./ ? int $days : $days - 1;
+ $days = 0 if $days < 0;
+
+ if ( $start && !$end ) {
+ $end_obj = RT::Date->new( $args{CurrentUser} );
+ $end_obj->Set( Value => $start_obj->Unix );
+ $end_obj->AddDays($days);
+ my ( $day, $month, $year ) =
+ ( $end_obj->Localtime('user') )[ 3, 4, 5 ];
+ $end = join '/', $month + 1, $day, $year;
+ }
+
+ if ( $end && !$start ) {
+ $start_obj = RT::Date->new( $args{CurrentUser} );
+ $start_obj->Set( Value => $end_obj->Unix );
+ $start_obj->AddDays( -1 * $days );
+ my ( $day, $month, $year ) =
+ ( $start_obj->Localtime('user') )[ 3, 4, 5 ];
+ $start = join '/', $month + 1, $day, $year;
+ }
+ }
+
+ if ( !$start ) {
+ $RT::Logger->warning( "Ticket "
+ . $Ticket->id
+ . " doesn't have Starts/Started defined, and we can't figure it out either"
+ );
+ $start = $end if $end;
+ }
+ if ( !$end ) {
+ $RT::Logger->warning( "Ticket "
+ . $Ticket->id
+ . " doesn't have Due defined, and we can't figure it out either"
+ );
+ $end = $start if $start;
+ }
+
+ return ( $start_obj, $start, $end_obj, $end );
+}
+
sub _RelatedTickets {
my $ticket = shift;
my @types = @_;
commit bd433cdf5d3e201c30bca664ad5724cec307ba86
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Feb 1 14:54:45 2011 +0800
try to find the start from txn
diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index 75475ba..43557ed 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -185,6 +185,22 @@ sub _GetTimeRange {
}
if ( !$start ) {
+ my $Transactions = $Ticket->Transactions;
+ while ( my $Transaction = $Transactions->Next ) {
+ next
+ unless $Transaction->TimeTaken
+ || ( $Transaction->Type eq 'Set'
+ && $Transaction->Field eq 'TimeWorked'
+ && $Transaction->NewValue > $Transaction->OldValue );
+ $start_obj = $Transaction->CreatedObj;
+ my ( $day, $month, $year ) =
+ ( $start_obj->Localtime('user') )[ 3, 4, 5 ];
+ $start = join '/', $month + 1, $day, $year;
+ last;
+ }
+ }
+
+ if ( !$start ) {
$RT::Logger->warning( "Ticket "
. $Ticket->id
. " doesn't have Starts/Started defined, and we can't figure it out either"
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list