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

? sunnavy sunnavy at bestpractical.com
Thu Jul 1 13:01:32 EDT 2010


The branch, master has been updated
       via  e860637c4dc90e599695688e27f94cd4b1cdd9c6 (commit)
       via  15b9f2e14e1fa080b52893f750f0ad46afe3e666 (commit)
      from  7b175e65edff8bbb3eae63dd70c7f9c1c5e67510 (commit)

Summary of changes:
 html/Search/JSGantt.html |  293 +++++++++++++++++++++++++++-------------------
 1 files changed, 172 insertions(+), 121 deletions(-)

- Log -----------------------------------------------------------------
commit 15b9f2e14e1fa080b52893f750f0ad46afe3e666
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 2 00:23:06 2010 +0800

    move major logic into <%init>

diff --git a/html/Search/JSGantt.html b/html/Search/JSGantt.html
index 8d524fd..dc7fc59 100644
--- a/html/Search/JSGantt.html
+++ b/html/Search/JSGantt.html
@@ -15,8 +15,6 @@
     g.setShowRes(<% RT->Config->Get('JSGanttShowOwner')? 1 : 0 %>);
     g.setShowDur(<% RT->Config->Get('JSGanttShowDuration')? 1 : 0 %> );
 
-% my $progress = 0;
-% my $show_progress = RT->Config->Get('JSGanttShowProgress' );
 % if ( $show_progress ) {
         g.setShowComp(1);
 % } else {
@@ -33,129 +31,13 @@
     // Parameters             (pID, pName,                  pStart,      pEnd,        pColor,   pLink,          pMile, pRes,  pComp, pGroup, pParent, pOpen, pDepend, pCaption)
     
     // You can also use the XML file parser JSGantt.parseXML('project.xml',g)
-%   my @colors = grep { defined } RT->Config->Get('JSGanttColorScheme');
-%   @colors = ( 'ff0000', 'ffff00', 'ff00ff', '00ff00', '00ffff', '0000ff' )  unless @colors;
-%   my $i;
-%   my @info;
-%   my ( $min_start, $min_start_obj );
-%   for my $Ticket ( @Tickets ) {
-%   my $subject = $Ticket->Subject;
-%   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;
-%   }
-%   # 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->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( $session{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( $session{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;
-%   }
-
-%   my $has_members = $Ticket->Members->Count ? 1 : 0;
-
-%   # parent ticket's start date is not used
-%   if ( !$has_members && $start_obj && ( !$min_start_obj || $min_start_obj->Unix > $start_obj->Unix ) ) {
-%       $min_start_obj = $start_obj;
-%       $min_start = $start;
-%   }
-
-%   my $parent = 0;
-%   if ( $Ticket->MemberOf->Count ) {
-%       $parent = $Ticket->MemberOf->First->TargetObj->id;
-%   }
-
-%   my $depends = $Ticket->DependsOn;
-%   my @depends;
-%   if ( $depends->Count ) {
-%       while ( my $d = $depends->Next ) {
-%           push @depends, $d->TargetObj->id;
-%       }
-%   }
-%   if ( $show_progress ) {
-%       my $total_time = defined $Ticket->TimeLeft ? ( $Ticket->TimeWorked +
-%           $Ticket->TimeLeft ) : $Ticket->TimeEstimated;
-%       if ( $Ticket->TimeWorked ) {
-%           $progress = int( 100 * $Ticket->TimeWorked / $total_time );
-%       }
-%   }
-
-%   push @info, [ $Ticket->id, ( $Ticket->id . ': ' . substr $subject, 0, 30 ),
-%       $start, $end, $colors[$i++%@colors],
-%       ( RT->Config->Get('WebPath') . '/Ticket/Display.html?id=' .  $Ticket->id ),
-%       0, ( $Ticket->OwnerObj->Name || $Ticket->OwnerObj->EmailAddress ),
-%       $progress, $has_members, $parent, 1, ( @depends ? join ',', @depends : 0 )];
-
-%   }
-
-
-%# here let's tweak our results
-%# set to now if all tickets don't have start/end dates
-%   if ( ! $min_start ) {
-%       $min_start_obj = RT::Date->new($session{CurrentUser});
-%       $min_start_obj->SetToNow;
-%       my ($day,$month,$year) = ($min_start_obj->Localtime('user'))[3,4,5];
-%       $min_start = join '/', $month+1, $day, $year;
-%   }
-
-%   my $no_dates_color = RT->Config->Get('JSGanttNullDatesColor') || '333';
-%   for my $item ( @info ) {
-%       $item->[4] = $no_dates_color unless $item->[2];
-%       $item->[2] ||= $min_start;
-%       $item->[3] ||= $min_start;
-%   }
-
 %   use JSON;
 %   for my $item ( @info ) {
 %       my $json = to_json( $item ); $json =~ s/^\[//; $json =~ s/\]$//;
         g.AddTaskItem(new JSGantt.TaskItem( <% $json |n%> ));
 %   }
 
+
     g.Draw();    
     g.DrawDependencies();
 
@@ -253,6 +135,159 @@ else {
     $m->abort;
 }
 
+my $progress = 0;
+my $show_progress = RT->Config->Get('JSGanttShowProgress' );
+
+my @colors = grep { defined } RT->Config->Get('JSGanttColorScheme');
+ at colors = ( 'ff0000', 'ffff00', 'ff00ff', '00ff00', '00ffff', '0000ff' )  unless @colors;
+my $i;
+my @info;
+my ( $min_start, $min_start_obj );
+for my $Ticket (@Tickets) {
+    my $subject = $Ticket->Subject;
+    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;
+    }
+
+    # 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->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( $session{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( $session{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;
+    }
+
+    my $has_members = $Ticket->Members->Count ? 1 : 0;
+
+    # parent ticket's start date is not used
+    if (  !$has_members
+        && $start_obj
+        && ( !$min_start_obj || $min_start_obj->Unix > $start_obj->Unix ) )
+    {
+        $min_start_obj = $start_obj;
+        $min_start     = $start;
+    }
+
+    my $parent = 0;
+    if ( $Ticket->MemberOf->Count ) {
+        $parent = $Ticket->MemberOf->First->TargetObj->id;
+    }
+
+    my $depends = $Ticket->DependsOn;
+    my @depends;
+    if ( $depends->Count ) {
+        while ( my $d = $depends->Next ) {
+            push @depends, $d->TargetObj->id;
+        }
+    }
+    if ($show_progress) {
+        my $total_time =
+          defined $Ticket->TimeLeft
+          ? ( $Ticket->TimeWorked + $Ticket->TimeLeft )
+          : $Ticket->TimeEstimated;
+        if ( $Ticket->TimeWorked ) {
+            $progress = int( 100 * $Ticket->TimeWorked / $total_time );
+        }
+    }
+
+    push @info,
+      [
+        $Ticket->id,
+        ( $Ticket->id . ': ' . substr $subject, 0, 30 ),
+        $start, $end,
+        $colors[ $i++ % @colors ],
+        (
+                RT->Config->Get('WebPath')
+              . '/Ticket/Display.html?id='
+              . $Ticket->id
+        ),
+        0,
+        ( $Ticket->OwnerObj->Name || $Ticket->OwnerObj->EmailAddress ),
+        $progress,
+        $has_members,
+        $parent, 1,
+        ( @depends ? join ',', @depends : 0 )
+      ];
+
+}
+
+
+#let's tweak our results
+#set to now if all tickets don't have start/end dates
+if ( ! $min_start ) {
+    $min_start_obj = RT::Date->new($session{CurrentUser});
+    $min_start_obj->SetToNow;
+    my ($day,$month,$year) = ($min_start_obj->Localtime('user'))[3,4,5];
+    $min_start = join '/', $month+1, $day, $year;
+}
+
+my $no_dates_color = RT->Config->Get('JSGanttNullDatesColor') || '333';
+for my $item ( @info ) {
+    $item->[4] = $no_dates_color unless $item->[2];
+    $item->[2] ||= $min_start;
+    $item->[3] ||= $min_start;
+}
+
 </%init>
 
 <%args>

commit e860637c4dc90e599695688e27f94cd4b1cdd9c6
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 2 01:02:49 2010 +0800

    use parent's start/end dates if not defined

diff --git a/html/Search/JSGantt.html b/html/Search/JSGantt.html
index dc7fc59..d38d724 100644
--- a/html/Search/JSGantt.html
+++ b/html/Search/JSGantt.html
@@ -32,8 +32,11 @@
     
     // You can also use the XML file parser JSGantt.parseXML('project.xml',g)
 %   use JSON;
-%   for my $item ( @info ) {
-%       my $json = to_json( $item ); $json =~ s/^\[//; $json =~ s/\]$//;
+%   for my $id ( @ids ) {
+%       my $json = to_json( [ $id, map { $info{$id}{$_} } qw/name start end
+%           color link milestone owner progress has_members parent open
+%           depends/ ] );
+%       $json =~ s/^\[//; $json =~ s/\]$//;
         g.AddTaskItem(new JSGantt.TaskItem( <% $json |n%> ));
 %   }
 
@@ -141,10 +144,18 @@ my $show_progress = RT->Config->Get('JSGanttShowProgress' );
 my @colors = grep { defined } RT->Config->Get('JSGanttColorScheme');
 @colors = ( 'ff0000', 'ffff00', 'ff00ff', '00ff00', '00ffff', '0000ff' )  unless @colors;
 my $i;
-my @info;
+my ( @ids, %info );
 my ( $min_start, $min_start_obj );
+
 for my $Ticket (@Tickets) {
     my $subject = $Ticket->Subject;
+
+    my $parent = 0;
+    if ( $Ticket->MemberOf->Count ) {
+        $parent = $Ticket->MemberOf->First->TargetObj->id;
+    }
+
+    # find start/end, this is, uhh, long long way to go
     my ( $start, $end ) = ( '', '' );
     my ( $start_obj, $end_obj );
     if ( $Ticket->StartsObj->Unix ) {
@@ -169,36 +180,44 @@ for my $Ticket (@Tickets) {
 
     # 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->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( $session{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 ( $parent ) {
+            # yep, it's sure that $parent lives in %info already
+            $start ||= $info{$parent}{start};
+            $end ||= $info{$parent}{end};
         }
+        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( $session{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( $session{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( $session{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;
+            }
         }
     }
 
@@ -219,7 +238,7 @@ for my $Ticket (@Tickets) {
 
     my $has_members = $Ticket->Members->Count ? 1 : 0;
 
-    # parent ticket's start date is not used
+    # parent ticket's start date is not used when drawing
     if (  !$has_members
         && $start_obj
         && ( !$min_start_obj || $min_start_obj->Unix > $start_obj->Unix ) )
@@ -228,11 +247,6 @@ for my $Ticket (@Tickets) {
         $min_start     = $start;
     }
 
-    my $parent = 0;
-    if ( $Ticket->MemberOf->Count ) {
-        $parent = $Ticket->MemberOf->First->TargetObj->id;
-    }
-
     my $depends = $Ticket->DependsOn;
     my @depends;
     if ( $depends->Count ) {
@@ -240,6 +254,7 @@ for my $Ticket (@Tickets) {
             push @depends, $d->TargetObj->id;
         }
     }
+
     if ($show_progress) {
         my $total_time =
           defined $Ticket->TimeLeft
@@ -250,25 +265,26 @@ for my $Ticket (@Tickets) {
         }
     }
 
-    push @info,
-      [
-        $Ticket->id,
-        ( $Ticket->id . ': ' . substr $subject, 0, 30 ),
-        $start, $end,
-        $colors[ $i++ % @colors ],
-        (
+    push @ids, $Ticket->id;
+    $info{$Ticket->id} = 
+      {
+        name => ( $Ticket->id . ': ' . substr $subject, 0, 30 ),
+        start => $start,
+        end => $end,
+        color => $colors[ $i++ % @colors ],
+        link => (
                 RT->Config->Get('WebPath')
               . '/Ticket/Display.html?id='
               . $Ticket->id
         ),
-        0,
-        ( $Ticket->OwnerObj->Name || $Ticket->OwnerObj->EmailAddress ),
-        $progress,
-        $has_members,
-        $parent, 1,
-        ( @depends ? join ',', @depends : 0 )
-      ];
-
+        milestone => 0,
+        owner => ( $Ticket->OwnerObj->Name || $Ticket->OwnerObj->EmailAddress ),
+        progress => $progress,
+        has_members => $has_members,
+        parent => $parent,
+        open => 1,
+        depends => ( @depends ? join ',', @depends : 0 )
+      };
 }
 
 
@@ -282,10 +298,10 @@ if ( ! $min_start ) {
 }
 
 my $no_dates_color = RT->Config->Get('JSGanttNullDatesColor') || '333';
-for my $item ( @info ) {
-    $item->[4] = $no_dates_color unless $item->[2];
-    $item->[2] ||= $min_start;
-    $item->[3] ||= $min_start;
+for my $id ( @ids ) {
+    $info{$id}{color} = $no_dates_color unless $info{$id}{start};
+    $info{$id}{start} ||= $min_start;
+    $info{$id}{end} ||= $min_start;
 }
 
 </%init>

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



More information about the Bps-public-commit mailing list