[Rt-commit] r2209 - in RT-View-Tree: . html/Search lib/RT/View
jesse at bestpractical.com
jesse at bestpractical.com
Thu Feb 10 13:56:18 EST 2005
Author: jesse
Date: Thu Feb 10 13:56:17 2005
New Revision: 2209
Modified:
RT-View-Tree/ (props changed)
RT-View-Tree/META.yml
RT-View-Tree/html/Search/Tree.html
RT-View-Tree/lib/RT/View/Tree.pm
RT-View-Tree/testdata
Log:
r2299 at hualien (orig r297): jesse | 2004-09-10T05:05:54.780944Z
r10227 at tinbook: jesse | 2004-09-10T05:04:15.978977Z
Much better duplicate suppression
Modified: RT-View-Tree/META.yml
==============================================================================
--- RT-View-Tree/META.yml (original)
+++ RT-View-Tree/META.yml Thu Feb 10 13:56:17 2005
@@ -1,5 +1,5 @@
name: RT-View-Tree
-version: 0.6
+version: 0.7
abstract: RT View-Tree Extension
license: unknown
distribution_type: module
Modified: RT-View-Tree/html/Search/Tree.html
==============================================================================
--- RT-View-Tree/html/Search/Tree.html (original)
+++ RT-View-Tree/html/Search/Tree.html Thu Feb 10 13:56:17 2005
@@ -1,53 +1,3 @@
-<& /Elements/Header, Title => $title, Refresh => $session{'tickets_refresh_interval'} &>
-<& /Ticket/Elements/Tabs,
- current_tab => "Search/Tree.html".$QueryString,
- Ticket => $Ticket,
- Title => $title,
- Format => $Format,
- Query => $Query,
- Rows => $Rows,
- OrderBy => $OrderBy,
- Order => $Order &>
-<hr>
-
-
-<TABLE BORDER=0 cellspacing=0 cellpadding=1 WIDTH=100%>
-<& /Elements/CollectionAsTable/Header,
- Format => \@Format,
- AllowSorting => 0,
- Query => $Query,
-
-&>
-
-<%perl>
-
-
-
-foreach my ($ticket, $kids) (@tree) {
- $m->comp( '.entry', Ticket => $ticket, Depth => 0, Format => \@Format, Children => $kids);
-
-}
-
-</%perl>
-</table>
-<hr>
-<form method="get" action="/Search/Tree.html">
-<input type="hidden" name="Query" value="<%$Query%>">
-<input type="hidden" name="Format" value="<%$Format%>">
-<& /Elements/TitleBoxStart, title => loc('Display options') &>
-<ul>
-<li><&|/l&>Show this many levels:</&> <input type=text size=3 name="MaxDepth"
-value=<%$MaxDepth%>>
-(<i><&|/l&>Leave this field blank to show everything</&></i>)
-</li>
-<li><input type="checkbox" name="HideChildren" <%$HideChildren&& 'CHECKED'%>><&|/l&>Hide subtasks</&></li>
-<li><input type="checkbox" name="HideDependencies" <%$HideDependencies && 'CHECKED'%>><&|/l&>Hide dependencies</&></li>
-</ul>
-<& /Elements/Submit &>
-<& /Elements/TitleBoxEnd &>
-</form>
-
-
<%ARGS>
$id => undef
$Query => undef
@@ -56,77 +6,85 @@
$OrderBy => undef
$Order => undef
$Page => undef
-$MaxDepth => undef
+$MaxDepth => 7
$HideChildren => undef
$HideDependencies => undef
</%ARGS>
<%init>
+
+# {{{ Generic setup
+
my $title = loc('Tree view');
my $QueryString = "?"
. $m->comp(
'/Elements/QueryString',
- Query => $Query,
- Format => $Format,
- Rows => $Rows,
- OrderBy => $OrderBy,
- Order => $Order,
- Page => $Page,
- MaxDepth => $MaxDepth,
- HideChildren => $HideChildren,
+ Query => $Query,
+ Format => $Format,
+ Rows => $Rows,
+ OrderBy => $OrderBy,
+ Order => $Order,
+ Page => $Page,
+ MaxDepth => $MaxDepth,
+ HideChildren => $HideChildren,
HideDependencies => $HideDependencies
);
-# If we load a ticket, this search is on a given ticket and we'll get the
+# }}}
+
+# {{{ If we load a ticket, this search is on a given ticket and we'll get the
# ticket menus instead of the tree ones
my $Ticket;
if ($id) {
$Ticket = RT::Ticket->new( $session{'CurrentUser'} );
$Ticket->Load($id) if ($id);
}
-$Format ||= $RT::DefaultSearchResultFormat;
+# }}}
-# Scrub the html of the format string to remove any potential nasties.a
-$Format = $m->comp( '/Elements/ScrubHTML', Content => $Format );
-my (@Format) = $m->comp( '/Elements/CollectionAsTable/ParseFormat', Format => $Format );
+# {{{ Scrub the html of the format string to remove any potential nasties.a
+$Format = $m->comp( '/Elements/ScrubHTML', Content => ($Format||
+$RT::DefaultSearchResultFormat));
+my (@Format) =
+ $m->comp( '/Elements/CollectionAsTable/ParseFormat', Format => $Format );
-# Update the format string to do treeview style indents
-my @TreeFormat;
+# Alter the format to do treeview indents.
foreach my $entry (@Format) {
-
my @output;
foreach my $item ( @{ $entry->{'output'} } ) {
- if ( $item eq '__Subject__' ) {
+ if ( $item eq '__Subject__' ) {
push @output, '___RT_TreeView_Indent__', $item;
- }
+ }
else {
push @output, $item;
}
}
- $entry->{'output'}=\@output;
+ $entry->{'output'} = \@output;
}
+# }}}
-
-my ($ticketcount);
my $tickets = RT::Tickets->new( $session{'CurrentUser'} );
$tickets->FromSQL($Query);
-$tickets->OrderBy( FIELD => $OrderBy , ORDER => $Order);
-my $top_tickets = ();
-my @tickets;
- at tickets = @{ $tickets->ItemsArrayRef || [] };
+$tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
+
+my $TopTickets = ();
+my @tickets = @{ $tickets->ItemsArrayRef || [] };
+
+
foreach my $ticket (@tickets) {
- $top_tickets->{ $ticket->id } = $ticket;
+ $TopTickets->{ $ticket->id } = $ticket;
}
-
my @tree;
foreach my $ticket (@tickets) {
- next unless exists $top_tickets->{ $ticket->id };
+
+ # If the parent ticket hasn't been invalidated by being displayed deeper...
+ # recurse now and add it in
+ next unless exists $TopTickets->{ $ticket->id };
my $kids = build_subtree(
Ticket => $ticket,
- TopTickets => $top_tickets,
- Depth => 0,
+ TopTickets => $TopTickets,
+ Depth => 1,
MaxDepth => $MaxDepth,
HideChildren => $HideChildren,
HideDependencies => $HideDependencies
@@ -138,115 +96,141 @@
# Ok. Let's build up our tree of tickets, recursing down.
sub build_subtree {
- my %args = ( Ticket => undef,
- TopTickets => undef,
- HideChildren => undef,
- HideDependencies => undef,
- Depth => undef,
- MaxDepth => undef,
- @_);
-
+ my %args = (
+ Ticket => undef,
+ TopTickets => undef,
+ HideChildren => undef,
+ HideDependencies => undef,
+ Depth => undef,
+ MaxDepth => undef,
+ @_
+ );
- my $ticket = $args{'Ticket'};
- my $top_tickets = $args{'TopTickets'};
+ return if ( $args{'Depth'} >= $args{'MaxDepth'} );
+ my $ticket = $args{'Ticket'};
+ my $TopTickets = $args{'TopTickets'};
my $deps = RT::Tickets->new( $session{'CurrentUser'} );
my @query;
my @tickets;
- unless ($args{'HideDependencies'}) {
- push @query, 'DependentOn = '.$ticket->id;
- }
- unless ($args{'HideChildren'}) {
- push @query, 'MemberOf = '.$ticket->id;
+ push @query, 'DependentOn = ' . $ticket->id
+ unless ( $args{'HideDependencies'} );
+ push @query, 'MemberOf = ' . $ticket->id unless ( $args{'HideChildren'} );
+
+ $deps->FromSQL( join( ' OR ', @query ) );
+ $deps->OrderBy( FIELD => $args{'OrderBy'}, ORDER => $args{'Order'} );
- }
- $deps->FromSQL( join(' OR ', @query));
- $kids->OrderBy( FIELD => $args{'OrderBy'} , ORDER => $args{'Order'});
while ( my $dep = $deps->Next ) {
- # Discard
- delete $top_tickets->{ $dep->id };
+ delete $TopTickets->{ $dep->id };
my $kids = undef;
- $kids = build_subtree(
- Ticket => $dep,
- TopTickets => $top_tickets,
- Depth => $Depth+1,
- MaxDepth => $MaxDepth,
- HideChildren => $HideChildren,
- HideDependencies => $HideDependencies
- );
- unless ($args{'Depth'} >$args{'MaxDepth'});
- push @tickets, [$dep,$kids];
+ $kids = build_subtree(
+ Ticket => $dep,
+ TopTickets => $TopTickets,
+ Depth => ( $args{'Depth'} + 1 ),
+ MaxDepth => $args{'MaxDepth'},
+ HideChildren => $args{'HideChildren'},
+ HideDependencies => $args{'HideDependencies'}
+ );
+ push @tickets, [ $dep, $kids ];
}
- return (\@tickets);
+
+ return ( \@tickets );
}
-# for each ticket found by our search, check to see if it depends on any
-# others. if so, discard it
</%init>
+<& /Elements/Header, Title => $title, Refresh => $session{'tickets_refresh_interval'} &>
+<& /Ticket/Elements/Tabs,
+ current_tab => "Search/Tree.html".$QueryString,
+ Ticket => $Ticket,
+ Title => $title,
+ Format => $Format,
+ Query => $Query,
+ Rows => $Rows,
+ OrderBy => $OrderBy,
+ Order => $Order &>
+<hr>
+<TABLE BORDER=0 cellspacing=0 cellpadding=1 WIDTH=100%>
+<& /Elements/CollectionAsTable/Header,
+ Format => \@Format,
+ AllowSorting => 0,
+ Query => $Query,
+
+&>
+<%perl>
+ foreach my $row (@tree) {
+ $m->comp( '.entry',
+ Ticket => $row->[0],
+ Depth => 0,
+ Format => \@Format,
+ Children => $row->[1],
+ Parents => { $row->[0]->id => 1 }
+ );
+
+ }
+</%perl>
+</table>
+<hr>
+<form method="get" action="/Search/Tree.html">
+<input type="hidden" name="Query" value="<%$Query%>">
+<input type="hidden" name="Format" value="<%$Format%>">
+<& /Elements/TitleBoxStart, title => loc('Display options') &>
+<ul>
+<li><&|/l&>Show this many levels:</&> <input type=text size=3 name="MaxDepth"
+value=<%$MaxDepth%>>
+(<i><&|/l&>Leave this field blank to show everything</&></i>)
+</li>
+<li><input type="checkbox" name="HideChildren" <%$HideChildren&& 'CHECKED'%>><&|/l&>Hide subtasks</&></li>
+<li><input type="checkbox" name="HideDependencies" <%$HideDependencies && 'CHECKED'%>><&|/l&>Hide dependencies</&></li>
+</ul>
+<& /Elements/Submit &>
+<& /Elements/TitleBoxEnd &>
+</form>
+
+
<%DEF .entry>
<%args>
$Ticket
$Depth => 0
-$Parents => undef
+$Children => undef
@Format => undef
$MaxDepth => undef
-$HideChildren => undef
-$HideDependencies => undef
-$Order => undef
-$OrderBy => undef
+$Parents => undef
</%args>
-<& /Elements/CollectionAsTable/Row, Format => \@Format, i => $Depth, record =>
-$Ticket&>
+<& /Elements/CollectionAsTable/Row, Format => \@Format, i => $Depth, record => $Ticket&>
<%perl>
-if ( !$MaxDepth || $Depth <= $MaxDepth ) {
-
- # if we have not found a loop, print the kid.
- unless ( $Parents->{ $Ticket->id } ) {
- $Parents->{ $Ticket->id } = 1;
- my $kids = RT::Tickets->new( $session{'CurrentUser'} );
- my @query;
- unless ($HideDependencies) {
- push @query, 'DependentOn = ' . $Ticket->id;
- }
- unless ($HideChildren) {
- push @query, 'MemberOf = ' . $Ticket->id;
- }
- $kids->FromSQL( join( ' OR ', @query ) );
- $kids->OrderBy( FIELD => $OrderBy , ORDER => $Order);
-
- while ( my $kid = $kids->Next ) {
-
+ foreach my $row (@$Children) {
+ if (!exists $Parents->{$row->[0]->id}) {
+ $Parents->{$row->[0]->id} = 1;
# look to see if the child is a parent up the tree
$m->comp(
'.entry',
- Ticket => $kid,
+ Ticket => $row->[0],
+ Children => $row->[1],
Depth => ( $Depth + 1 ),
- Parents => $Parents,
MaxDepth => $MaxDepth,
- HideChildren => $HideChildren,
- HideDependencies => $HideDependencies,
- OrderBy => $OrderBy,
- Order => $Order,
- Format => \@Format
+ Format => \@Format,
+ Parents => $Parents
);
}
- }
else { # found a loop
my @Blank;
foreach my $entry (@Format) {
my @output = [' '];
+ my $title = '';
foreach my $item ( @{ $entry->{'output'} } ) {
if ( $item =~ /Subject/i ) {
@output = [ '___RT_TreeView_Indent__', '...' ];
- }
+ } elsif ($item =~ /__NEWLINE__/i ) {
+ $title = 'NEWLINE';
+ }
}
- push @Blank, { output => @output };
+ push @Blank, { output => @output, title => $title };
}
$m->comp(
'/Elements/CollectionAsTable/Row',
@@ -256,7 +240,7 @@
);
}
-}
+ }
</%perl>
</%DEF>
Modified: RT-View-Tree/lib/RT/View/Tree.pm
==============================================================================
--- RT-View-Tree/lib/RT/View/Tree.pm (original)
+++ RT-View-Tree/lib/RT/View/Tree.pm Thu Feb 10 13:56:17 2005
@@ -1,6 +1,6 @@
package RT::View::Tree;
-our $VERSION = '0.7';
+our $VERSION = '0.8';
1;
Modified: RT-View-Tree/testdata
==============================================================================
--- RT-View-Tree/testdata (original)
+++ RT-View-Tree/testdata Thu Feb 10 13:56:17 2005
@@ -12,9 +12,13 @@
$top->Create(Queue => 'general', Subject => 'Top TreeView Ticket');
my $child_1 = new_child($top->id, 'second level #1');
my $child_2 = new_child($top->id, 'second level #2');
+my $sub_1 = new_child($child_2->id, 'third level #1');
+my $sub_2 = new_child($child_2->id, 'third level #2');
+
my $kid2 = RT::Ticket->new( $RT::SystemUser);
$kid2->Create(Queue => 'general', Subject => 'another Second level TreeView Ticket', MemberOf => $top->id);
+$kid2->AddLink(Type => 'MemberOf', Target => $sub_2->id);
@@ -23,5 +27,5 @@
my $subject = shift;
my $kid1 = RT::Ticket->new( $RT::SystemUser);
$kid1->Create(Queue => 'general', Subject => $subject.'-TreeView', MemberOf => $parent_id);
- return($kid1->id);
+ return($kid1);
}
More information about the Rt-commit
mailing list