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

? sunnavy sunnavy at bestpractical.com
Wed Oct 26 02:36:34 EDT 2011


The branch, master has been updated
       via  cc03b29d6d85fe0f10de6a69b2c42576e7311f66 (commit)
       via  6edf43281c030e5656c30a40cff385d7868705d4 (commit)
       via  52c5b462907c68e1f02d5113019dd45f9254a243 (commit)
       via  f6c2a3c5464c11c002fed2acaa05ee9e0acae36a (commit)
       via  5463f3b55990ed1e564fdda2dcbf3a37755878b5 (commit)
      from  edbc5a80e2476f4bf004fafd801dc8ea8a25d806 (commit)

Summary of changes:
 META.yml                    |    1 +
 Makefile.PL                 |    1 +
 lib/RT/Extension/JSGantt.pm |  114 ++++++++++++++++++++++++++++++------------
 3 files changed, 83 insertions(+), 33 deletions(-)

- Log -----------------------------------------------------------------
commit 5463f3b55990ed1e564fdda2dcbf3a37755878b5
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Oct 26 12:25:47 2011 +0800

    extract all the members first so they can be showed just after their parents
    
    in previous versions, members may be shown far away from parents
    this only works for queries like /Search/JSGantt.html?Ticket=12

diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index 7e26bbb..264e65b 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -53,7 +53,7 @@ RT::Extension::JSGantt - Gantt charts for your tickets
 =head1 SYNOPSIS
 
     use RT::Extension::JSGantt;
-  
+
 =cut
 
 package RT::Extension::JSGantt;
@@ -99,7 +99,9 @@ sub AllRelatedTickets {
             }
         }
 
-        _GetOrderedTickets( \@tickets, \@to_be_checked, \%checked );
+        _GetOrderedTickets( \@tickets, \@to_be_checked, \%checked,
+            'Members' );
+        _GetOrderedTickets( \@tickets, [@tickets], {}, );
     }
     return @tickets;
 }
@@ -159,7 +161,7 @@ sub TicketsInfo {
         if ( $depends->Count ) {
             while ( my $d = $depends->Next ) {
                 # skip the remote links
-                next unless $d->TargetObj; 
+                next unless $d->TargetObj;
                 push @depends, $d->TargetObj->id;
             }
         }
@@ -333,7 +335,7 @@ sub _GetDate {
     my $depth;
     if ( $_[0] =~ /^\d+$/ ) {
         $depth = shift;
-    } 
+    }
     else {
         $depth = 0;
     }
@@ -366,32 +368,42 @@ sub _GetOrderedTickets {
     my $tickets       = shift;
     my $to_be_checked = shift;
     my $checked       = shift;
-    while ( my $ticket = shift @$to_be_checked ) {
-        push @$tickets, $ticket
-          unless grep { $ticket->id eq $_->id } @$tickets;
-        next if $checked->{$ticket->id}++;
+    my $type          = shift;
 
-        for my $member ( grep { !$checked->{ $_->id } }
-            _RelatedTickets( $ticket, 'Members' ) )
-        {
-            unshift @$to_be_checked, $member;
-            _GetOrderedTickets( $tickets,$to_be_checked, $checked );
-        }
 
-        for my $parent ( grep { !$checked->{ $_->id } }
-            _RelatedTickets( $ticket, 'MemberOf' ) )
-        {
-            unshift @$to_be_checked, $parent;
-            _GetOrderedTickets( $tickets, $to_be_checked, $checked );
+    if ( $type && $type eq 'Members' ) {
+        while ( my $ticket = shift @$to_be_checked ) {
+            push @$tickets, $ticket
+              unless grep { $ticket->id eq $_->id } @$tickets;
+            next if $checked->{ $ticket->id }++;
+
+            for my $member ( grep { !$checked->{ $_->id } }
+                _RelatedTickets( $ticket, 'Members' ) )
+            {
+                push @$to_be_checked, $member;
+                _GetOrderedTickets( $tickets, $to_be_checked, $checked,
+                    'Members' );
+            }
         }
+    }
+    else {
+        while ( my $ticket = shift @$to_be_checked ) {
+            push @$tickets, $ticket
+              unless grep { $ticket->id eq $_->id } @$tickets;
+            next if $checked->{ $ticket->id }++;
 
-        for my $related ( grep { !$checked->{ $_->id } }
-            _RelatedTickets( $ticket, 'DependsOn', 'DependedOnBy', 'RefersTo',
-            'ReferredToBy' ))
-        {
-            push @$to_be_checked, $related;
-            _GetOrderedTickets( $tickets, $to_be_checked, $checked );
+            for my $related (
+                grep { !$checked->{ $_->id } } _RelatedTickets(
+                    $ticket,    'MemberOf', 'DependsOn', 'DependedOnBy',
+                    'RefersTo', 'ReferredToBy'
+                )
+              )
+            {
+                push @$to_be_checked, $related;
+                _GetOrderedTickets( $tickets, $to_be_checked, $checked );
+            }
         }
+
     }
 }
 

commit f6c2a3c5464c11c002fed2acaa05ee9e0acae36a
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Oct 26 12:47:45 2011 +0800

    in jsgantt, only the first parent matters as it only supports single parent.
    
    so if it's not the first parent, folder doesn't work.
    here we make a more strict "has_members" testing to avoid invalid "folder" chars

diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index 264e65b..7461278 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -155,6 +155,21 @@ sub TicketsInfo {
         }
 
         my $has_members = $Ticket->Members->Count ? 1 : 0;
+        if ($has_members) {
+
+           # need to examine more as it may not the first parent of it's members
+            my $members = $Ticket->Members;
+            my $indeed_has_members;
+            while ( my $member = $members->Next ) {
+                if ( $member->BaseObj->MemberOf->First->TargetObj->id == $Ticket->id )
+                {
+                    $indeed_has_members = 1;
+                    last;
+                }
+            }
+
+            $has_members = $indeed_has_members || 0;
+        }
 
         my $depends = $Ticket->DependsOn;
         my @depends;

commit 52c5b462907c68e1f02d5113019dd45f9254a243
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Oct 26 13:05:37 2011 +0800

    we don't acutally need named %checked

diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index 7461278..e1295ee 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -74,7 +74,6 @@ sub AllRelatedTickets {
     my %args = ( Ticket => undef, CurrentUser => undef, @_ );
 
     my @tickets;
-    my %checked;
     my @to_be_checked;
     my $ticket = RT::Ticket->new( $args{CurrentUser} );
     $ticket->Load( $args{Ticket} );
@@ -99,8 +98,7 @@ sub AllRelatedTickets {
             }
         }
 
-        _GetOrderedTickets( \@tickets, \@to_be_checked, \%checked,
-            'Members' );
+        _GetOrderedTickets( \@tickets, \@to_be_checked, {}, 'Members' );
         _GetOrderedTickets( \@tickets, [@tickets], {}, );
     }
     return @tickets;

commit 6edf43281c030e5656c30a40cff385d7868705d4
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Oct 26 13:37:31 2011 +0800

    refactor _GetOrderedTickets a bit
    
    so we can just call @tickets = _GetOrderedTickets(...);

diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index e1295ee..b19dc2c 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -98,8 +98,7 @@ sub AllRelatedTickets {
             }
         }
 
-        _GetOrderedTickets( \@tickets, \@to_be_checked, {}, 'Members' );
-        _GetOrderedTickets( \@tickets, [@tickets], {}, );
+        @tickets = _GetOrderedTickets( @to_be_checked );
     }
     return @tickets;
 }
@@ -376,8 +375,17 @@ sub _GetDate {
     }
 }
 
-
 sub _GetOrderedTickets {
+    my @tickets;
+    my @to_be_checked = @_;
+
+    my %map;
+    __GetOrderedTickets( \@tickets, \@to_be_checked, {}, 'Members' );
+    __GetOrderedTickets( \@tickets, \@to_be_checked, {}, );
+    return @tickets;
+}
+
+sub __GetOrderedTickets {
     my $tickets       = shift;
     my $to_be_checked = shift;
     my $checked       = shift;
@@ -394,7 +402,7 @@ sub _GetOrderedTickets {
                 _RelatedTickets( $ticket, 'Members' ) )
             {
                 push @$to_be_checked, $member;
-                _GetOrderedTickets( $tickets, $to_be_checked, $checked,
+                __GetOrderedTickets( $tickets, $to_be_checked, $checked,
                     'Members' );
             }
         }
@@ -413,7 +421,7 @@ sub _GetOrderedTickets {
               )
             {
                 push @$to_be_checked, $related;
-                _GetOrderedTickets( $tickets, $to_be_checked, $checked );
+                __GetOrderedTickets( $tickets, $to_be_checked, $checked );
             }
         }
 

commit cc03b29d6d85fe0f10de6a69b2c42576e7311f66
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Oct 26 14:06:47 2011 +0800

    we should insert ticket right after its parent if exists
    
    linear "push @tickets, $ticket" is wrong, here is an example:
    12 has 1 children: 13
    12 has 2 parents: 10 and 3
    3 has 2 children: 5 and 12
    
    to get all related tickets of 12, let's see how @tickets change in old way:
    
    (10,3) # initial
    (10,3,12) # after searching ticket 10
    (10,3,12,5) # after searching ticket 3
    (10,3,12,5,13) # after searching ticket 12
    
    aparently, 5(child of 3) should appear right after 3 insetad of 12,
    while 13(children of 12) should appear right after 12

diff --git a/META.yml b/META.yml
index 63467de..8438e74 100644
--- a/META.yml
+++ b/META.yml
@@ -20,6 +20,7 @@ no_index:
     - inc
 requires:
   JSON: 0
+  List::MoreUtils: 0
 resources:
   repository: git://github.com/bestpractical/rt-extension-jsgantt.git
 version: 0.14
diff --git a/Makefile.PL b/Makefile.PL
index 9e9fcdb..681901f 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -8,5 +8,6 @@ license('GPLv2');
 repository 'git://github.com/bestpractical/rt-extension-jsgantt.git';
 
 requires( 'JSON' );
+requires( 'List::MoreUtils' );
 
 &WriteAll;
diff --git a/lib/RT/Extension/JSGantt.pm b/lib/RT/Extension/JSGantt.pm
index b19dc2c..a27aacc 100644
--- a/lib/RT/Extension/JSGantt.pm
+++ b/lib/RT/Extension/JSGantt.pm
@@ -62,6 +62,7 @@ our $VERSION = '0.14';
 
 use warnings;
 use strict;
+use List::MoreUtils 'insert_after';
 
 =head2 AllRelatedTickets
 
@@ -134,12 +135,8 @@ sub TicketsInfo {
         my $progress = 0;
         my $subject = $Ticket->Subject;
 
-        my $parent = 0;
-        if ( $Ticket->MemberOf->Count ) {
-            # skip the remote links
-            next unless $Ticket->MemberOf->First->TargetObj;
-            $parent = $Ticket->MemberOf->First->TargetObj->id;
-        }
+        my $parent = _ParentTicket( $Ticket );
+        $parent = $parent ? $parent->id : 0;
 
         # find start/end
         my ( $start_obj, $start, $end_obj, $end ) = _GetTimeRange( $Ticket, %args );
@@ -381,7 +378,7 @@ sub _GetOrderedTickets {
 
     my %map;
     __GetOrderedTickets( \@tickets, \@to_be_checked, {}, 'Members' );
-    __GetOrderedTickets( \@tickets, \@to_be_checked, {}, );
+    __GetOrderedTickets( \@tickets, [@tickets], {}, );
     return @tickets;
 }
 
@@ -394,12 +391,20 @@ sub __GetOrderedTickets {
 
     if ( $type && $type eq 'Members' ) {
         while ( my $ticket = shift @$to_be_checked ) {
-            push @$tickets, $ticket
-              unless grep { $ticket->id eq $_->id } @$tickets;
+            unless ( grep { $ticket->id eq $_->id } @$tickets ) {
+                my $parent = _ParentTicket($ticket);
+
+                if ( !$parent || !insert_after { $_->id == $parent->id } $ticket,
+                    @$tickets )
+                {
+                    push @$tickets, $ticket;
+                }
+            }
+
             next if $checked->{ $ticket->id }++;
 
             for my $member ( grep { !$checked->{ $_->id } }
-                _RelatedTickets( $ticket, 'Members' ) )
+                sort { $b->id <=> $a->id } _RelatedTickets( $ticket, 'Members' ) )
             {
                 push @$to_be_checked, $member;
                 __GetOrderedTickets( $tickets, $to_be_checked, $checked,
@@ -428,4 +433,14 @@ sub __GetOrderedTickets {
     }
 }
 
+sub _ParentTicket {
+    my $ticket = shift;
+    if ( $ticket->MemberOf->Count ) {
+        # skip the remote links
+        next unless $ticket->MemberOf->First->TargetObj;
+        return $ticket->MemberOf->First->TargetObj;
+    }
+    return;
+}
+
 1;

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



More information about the Bps-public-commit mailing list