[Bps-public-commit] rt-extension-jsgantt branch, master, updated. d176e130b9094b55e539b774ecdb11d59c892b0e

? sunnavy sunnavy at bestpractical.com
Tue Jul 6 04:25:54 EDT 2010


The branch, master has been updated
       via  d176e130b9094b55e539b774ecdb11d59c892b0e (commit)
       via  097aa9786a0b1c304a4e7eaaafd7b0116551570d (commit)
       via  35b497d7760ab8f6b28d2ddeef5d89e1f92979b5 (commit)
      from  1ee905688e3d8c0e3ec0c5b1abbbb36743ead043 (commit)

Summary of changes:
 lib/RT/Extension/JSGantt.pm |  130 +++++++++++++++++++++----------------------
 1 files changed, 64 insertions(+), 66 deletions(-)

- Log -----------------------------------------------------------------
commit 35b497d7760ab8f6b28d2ddeef5d89e1f92979b5
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 6 15:56:51 2010 +0800

    limit parent depth, or it may cause endless recursion

diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index 2bc567a..25ee72e 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -19,13 +19,14 @@ sub AllRelatedTickets {
         # find the highest ancestors to make chart pretty
         my @parents = _RelatedTickets( $ticket, 'MemberOf' );
         @parents = $ticket unless @parents;
-        while (@parents) {
+        my $depth = 0;
+        while (@parents ) {
             my @ancestors;
             for my $parent (@parents) {
                 unshift @ancestors, _RelatedTickets( $parent, 'MemberOf' );
             }
 
-            if (@ancestors) {
+            if (@ancestors && $depth++ < 10 ) {
                 @parents = @ancestors;
             }
             else {
@@ -111,8 +112,6 @@ sub TicketsInfo {
         # if $start or $end is empty still
         unless ( $start && $end ) {
             if ($parent) {
-
-                # yep, it's sure that $parent lives in %info already
                 $start ||= $info{$parent}{start};
                 $end   ||= $info{$parent}{end};
             }
@@ -170,7 +169,7 @@ sub TicketsInfo {
         my $has_members = $Ticket->Members->Count ? 1 : 0;
 
         # parent ticket's start date is not used when drawing
-        if (  !$has_members
+        if ( !has_members
             && $start_obj
             && ( !$min_start_obj || $min_start_obj->Unix > $start_obj->Unix ) )
         {

commit 097aa9786a0b1c304a4e7eaaafd7b0116551570d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 6 16:00:07 2010 +0800

    parent's dates are used for children's dates, so min_date can't skip parents anymore

diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index 25ee72e..5ddefc1 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -166,17 +166,15 @@ sub TicketsInfo {
             $end = $start;
         }
 
-        my $has_members = $Ticket->Members->Count ? 1 : 0;
-
-        # parent ticket's start date is not used when drawing
-        if ( !has_members
-            && $start_obj
+        if ( $start_obj
             && ( !$min_start_obj || $min_start_obj->Unix > $start_obj->Unix ) )
         {
             $min_start_obj = $start_obj;
             $min_start     = $start;
         }
 
+        my $has_members = $Ticket->Members->Count ? 1 : 0;
+
         my $depends = $Ticket->DependsOn;
         my @depends;
         if ( $depends->Count ) {

commit d176e130b9094b55e539b774ecdb11d59c892b0e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 6 16:24:24 2010 +0800

    support dates inheritance for ?Query=...

diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index 5ddefc1..3645021 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -87,67 +87,42 @@ sub TicketsInfo {
         }
 
         # find start/end, this is, uhh, long long way to go
-        my ( $start, $end ) = ( '', '' );
-        my ( $start_obj, $end_obj );
-        if ( $Ticket->StartsObj->Unix ) {
-            my ( $day, $month, $year ) =
-              ( $Ticket->StartsObj->Localtime('user') )[ 3, 4, 5 ];
-            $start = join '/', $month + 1, $day, $year;
-            $start_obj = $Ticket->StartsObj;
-        }
-        elsif ( $Ticket->StartedObj->Unix ) {
-            my ( $day, $month, $year ) =
-              ( $Ticket->StartedObj->Localtime('user') )[ 3, 4, 5 ];
-            $start = join '/', $month + 1, $day, $year;
-            $start_obj = $Ticket->StartedObj;
-        }
-
-        if ( $Ticket->DueObj->Unix ) {
-            my ( $day, $month, $year ) =
-              ( $Ticket->DueObj->Localtime('user') )[ 3, 4, 5 ];
-            $end = join '/', $month + 1, $day, $year;
-            $end_obj = $Ticket->DueObj;
-        }
+        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 ) {
-            if ($parent) {
-                $start ||= $info{$parent}{start};
-                $end   ||= $info{$parent}{end};
+            my $hours_per_day = RT->Config->Get('JSGanttWorkingHoursPerDay')
+              || 8;
+            my $total_time =
+              defined $Ticket->TimeLeft
+              ? ( $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;
             }
-            else {
-                my $hours_per_day = RT->Config->Get('JSGanttWorkingHoursPerDay')
-                  || 8;
-                my $total_time =
-                  defined $Ticket->TimeLeft
-                  ? ( $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 ( $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;
             }
         }
 
@@ -254,6 +229,32 @@ sub _RelatedTickets {
 }
 
 
+sub _GetDate {
+    my $ticket = shift;
+    my @fields = @_;
+    my ( $date_obj, $date );
+    for my $field (@fields) {
+        my $obj = $field . 'Obj';
+        if ( $ticket->$obj->Unix ) {
+            $date_obj = $ticket->$obj;
+            my ( $day, $month, $year ) =
+              ( $date_obj->Localtime('user') )[ 3, 4, 5 ];
+            $date = join '/', $month + 1, $day, $year;
+        }
+    }
+
+    if ($date) {
+        return ( $date_obj, $date );
+    }
+
+    # inherit from parents
+    for my $member_of ( @{ $ticket->MemberOf->ItemsArrayRef } ) {
+        my $parent = $member_of->TargetObj;
+        return _GetDate( $parent, @fields );
+    }
+}
+
+
 =head1 NAME
 
 RT::Extension::JSGantt - 

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



More information about the Bps-public-commit mailing list