Commit cc03b29d authored by sunnavy's avatar sunnavy
Browse files

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
parent 6edf4328
......@@ -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
......@@ -8,5 +8,6 @@ license('GPLv2');
repository 'git://github.com/bestpractical/rt-extension-jsgantt.git';
requires( 'JSON' );
requires( 'List::MoreUtils' );
&WriteAll;
......@@ -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;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment