[Rt-commit] r11837 - in rt/branches/3.8-TESTING: html/Ticket/Graphs html/Ticket/Graphs/Elements
ruz at bestpractical.com
ruz at bestpractical.com
Tue Apr 22 22:41:31 EDT 2008
Author: ruz
Date: Tue Apr 22 22:41:30 2008
New Revision: 11837
Modified:
rt/branches/3.8-TESTING/html/Ticket/Graphs/Elements/EditGraphProperties
rt/branches/3.8-TESTING/html/Ticket/Graphs/index.html
rt/branches/3.8-TESTING/lib/RT/Graph/Tickets.pm
Log:
* rewrite graphs extension partly
** merge two types of graphs
** add LeadingLink option
** MaxDepth is accounted using only leading links
** add ShowLinks option
** allow to select additional properties for all graphs
Modified: rt/branches/3.8-TESTING/html/Ticket/Graphs/Elements/EditGraphProperties
==============================================================================
--- rt/branches/3.8-TESTING/html/Ticket/Graphs/Elements/EditGraphProperties (original)
+++ rt/branches/3.8-TESTING/html/Ticket/Graphs/Elements/EditGraphProperties Tue Apr 22 22:41:30 2008
@@ -46,13 +46,28 @@
%#
%# END BPS TAGGED BLOCK }}}
<&| /Widgets/TitleBox, title => loc('Graph Properties') &>
-Depth <select name="Depth">
+
+<% loc('Main type of links') %> <select name="LeadingLink">
+% foreach ( @link_types ) {
+<option value="<% $_ %>" <% ($LeadingLink||'Members') eq $_? 'selected="selected"': '' |n %>><% loc($_) %></option>
+% }
+</select>
+
+<% loc('maximum depth') %> <select name="MaxDepth">
<option value="0"><% loc('Unlimit') %></option>
% foreach ( 1..6 ) {
-<option value="<% $_ %>" <% ($Depth||0) == $_? 'selected': '' %>><% $_ %></option>
+<option value="<% $_ %>" <% ($MaxDepth||0) == $_? 'selected': '' %>><% $_ %></option>
% }
</select><br />
+<% loc('Show as well') %>:
+% foreach my $type ( @link_types ) {
+% my $checked = '';
+% $checked = 'checked="checked"' if grep $type eq $_, @ShowLinks;
+<input type="checkbox" name="ShowLinks" value="<% $type %>" <% $checked |n %> /><% loc($type) %>
+% }
+<br />
+
% my @properties = RT::Graph::Tickets->TicketProperties( $session{'CurrentUser'} );
Fill boxes with color using:
@@ -81,19 +96,17 @@
% }
<%PERL>
-if ( $AllowAdditionalProperties ) {
- for my $i ( 1..($Depth||6) ) {
- my @default;
- if ( my $tmp = $ARGS{ 'Level-'. $i .'-Properties' } ) {
- @default = ref $tmp? @$tmp : ($tmp);
- }
-
- $m->comp('SELF:Properties',
- Level => $i,
- Available => \@properties,
- Default => \@default,
- );
+for my $i ( 1..($MaxDepth||6) ) {
+ my @default;
+ if ( my $tmp = $ARGS{ 'Level-'. $i .'-Properties' } ) {
+ @default = ref $tmp? @$tmp : ($tmp);
}
+
+ $m->comp('SELF:Properties',
+ Level => $i,
+ Available => \@properties,
+ Default => \@default,
+ );
}
</%PERL>
@@ -103,14 +116,18 @@
<%ARGS>
$id => undef
-$Depth => 3
+$LeadingLink => 'Members'
+ at ShowLinks => ('MemberOf', 'DependsOn', 'RefersTo')
+$MaxDepth => 3
$FillUsing => ''
$ShowLinkDescriptions => 0
-$AllowAdditionalProperties => 1
</%ARGS>
<%INIT>
require RT::Graph::Tickets;
require RT::Link;
+
+my @link_types = qw(Members MemberOf RefersTo ReferredToBy DependsOn DependedOnBy);
+ at ShowLinks = grep $_ ne $LeadingLink, @ShowLinks;
</%INIT>
<%METHOD Properties>
Modified: rt/branches/3.8-TESTING/html/Ticket/Graphs/index.html
==============================================================================
--- rt/branches/3.8-TESTING/html/Ticket/Graphs/index.html (original)
+++ rt/branches/3.8-TESTING/html/Ticket/Graphs/index.html Tue Apr 22 22:41:30 2008
@@ -58,14 +58,8 @@
<form action="<% $RT::WebPath %><% $m->request_comp->path %>">
<input type="hidden" class="hidden" name="id" value="<% $id %>" />
-<input type="hidden" class="hidden" name="Type" value="<% $ARGS{'Type'} %>" />
-<& Elements/EditGraphProperties,
- %ARGS,
- Ticket => $ticket,
- Type => $Type,
- AllowAdditionalProperties => $Type eq 'Links'? 0 : 1,
-&>
+<& Elements/EditGraphProperties, %ARGS, Ticket => $ticket &>
<input type="hidden" class="hidden" name="SavedSearchId" value="<% $saved_search->{Id} %>" />
<& /Search/Elements/EditSearches,
@@ -84,7 +78,7 @@
use RT::Graph::Tickets;
my @results;
-my @save_arguments = qw(Type id Depth FillUsing ShowLinkDescriptions);
+my @save_arguments = qw(id LeadingLink ShowLinks MaxDepth FillUsing ShowLinkDescriptions);
foreach my $level ( 0 .. 6 ) {
push @save_arguments, "Level-". $level ."-Properties";
}
@@ -100,13 +94,14 @@
my $ticket = LoadTicket( $id );
$ARGS{'id'} = $id = $ticket->id;
-my $Type = $ARGS{'Type'} || 'Links';
-$Type = ucfirst lc $Type;
-unless ( $Type eq 'Links' || $Type eq 'Members' ) {
- $RT::Logger->error("'$Type' is incorrect type of ticket graph");
- $ARGS{'Type'} = $Type = 'Links';
+$ARGS{'LeadingLink'} ||= 'Members';
+if ( $ARGS{'ShowLinks'} && !ref $ARGS{'ShowLinks'} ) {
+ $ARGS{'ShowLinks'} = [$ARGS{'ShowLinks'}];
+} elsif ( !$ARGS{'ShowLinks'} ) {
+ $ARGS{'ShowLinks'} = [ qw(MemberOf DependsOn RefersTo) ];
}
-$ARGS{'Depth'} = 3 unless defined $ARGS{'Depth'} && length $ARGS{'Depth'};
+$ARGS{'ShowLinks'} = [ grep $_ ne $ARGS{'LeadingLink'}, @{ $ARGS{'ShowLinks'} } ];
+$ARGS{'MaxDepth'} = 3 unless defined $ARGS{'MaxDepth'} && length $ARGS{'MaxDepth'};
push @results, $m->comp( '/Search/Elements/EditSearches:Save',
%ARGS,
@@ -115,10 +110,5 @@
SearchFields => \@save_arguments,
);
-my $title;
-if ( $Type eq 'Links' ) {
- $title = loc( "Ticket #[_1] full relationships graph", $id );
-} else {
- $title = loc( "Ticket #[_1] relationships graph", $id );
-}
+my $title = loc( "Ticket #[_1] relationships graph", $id );
</%INIT>
Modified: rt/branches/3.8-TESTING/lib/RT/Graph/Tickets.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Graph/Tickets.pm (original)
+++ rt/branches/3.8-TESTING/lib/RT/Graph/Tickets.pm Tue Apr 22 22:41:30 2008
@@ -71,8 +71,8 @@
my %link_style = (
MemberOf => { style => 'solid' },
- DependsOn => { style => 'dashed', constraint => 'false' },
- RefersTo => { style => 'dotted', constraint => 'false' },
+ DependsOn => { style => 'dashed' },
+ RefersTo => { style => 'dotted' },
);
# We don't use qw() because perl complains about "possible attempt to put comments in qw() list"
@@ -104,58 +104,6 @@
our (%fill_cache, @available_colors) = ();
-sub TicketMembers {
- my $self = shift;
- my %args = (
- Ticket => undef,
- Graph => undef,
- Seen => undef,
- Depth => 0,
- CurrentDepth => 1,
- @_
- );
- unless ( $args{'Graph'} ) {
- $args{'Graph'} = GraphViz->new(
- name => "ticket_members_". $args{'Ticket'}->id,
- bgcolor => "transparent",
- node => { shape => 'box', style => 'rounded,filled', fillcolor => 'white' },
- );
- %fill_cache = ();
- @available_colors = @fill_colors;
- }
-
- $self->AddTicket( %args );
-
- $args{'Seen'} ||= {};
- return $args{'Graph'} if $args{'Seen'}{ $args{'Ticket'}->id }++;
-
- return $args{'Graph'} if $args{'Depth'} && $args{'CurrentDepth'} >= $args{'Depth'};
-
- my $show_link_descriptions = $args{'ShowLinkDescriptions'}
- && RT::Link->can('Description');
-
- my $to_links = $args{'Ticket'}->Links('Target', 'MemberOf');
- $to_links->GotoFirstItem;
- while ( my $link = $to_links->Next ) {
- my $base = $link->BaseObj;
- next unless $base->isa('RT::Ticket');
-
- $self->TicketMembers(
- %args,
- Ticket => $base,
- CurrentDepth => $args{'CurrentDepth'} + 1,
- );
-
- my $desc;
- $desc = $link->Description if $show_link_descriptions;
- $args{'Graph'}->add_edge(
- $args{'Ticket'}->id => $base->id,
- $desc? (label => gv_escape $desc): (),
- );
- }
- return $args{'Graph'};
-};
-
my %property_cb = (
Queue => sub { return $_[0]->QueueObj->Name || $_[0]->Queue },
CF => sub {
@@ -304,11 +252,19 @@
sub TicketLinks {
my $self = shift;
my %args = (
- Ticket => undef,
- Graph => undef,
- Seen => undef,
- SeenEdge => undef,
- Depth => 0,
+ Ticket => undef,
+
+ Graph => undef,
+ Seen => undef,
+ SeenEdge => undef,
+
+ LeadingLink => 'Members',
+ ShowLinks => [],
+
+ MaxDepth => 0,
+ CurrentDepth => 1,
+
+ ShowLinkDescriptions => 0,
@_
);
unless ( $args{'Graph'} ) {
@@ -320,65 +276,54 @@
%fill_cache = ();
@available_colors = @fill_colors;
}
- $self->AddTicket( %args );
$args{'Seen'} ||= {};
return $args{'Graph'} if $args{'Seen'}{ $args{'Ticket'}->id }++;
- return $args{'Graph'} if $args{'Depth'} && $args{'Depth'} == 1;
+ $self->AddTicket( %args );
+
+ return $args{'Graph'} if $args{'MaxDepth'} && $args{'CurrentDepth'} >= $args{'MaxDepth'};
$args{'SeenEdge'} ||= {};
my $show_link_descriptions = $args{'ShowLinkDescriptions'}
&& RT::Link->can('Description');
- my $from_links = $args{'Ticket'}->Links('Base');
- $from_links->GotoFirstItem;
- while ( my $link = $from_links->Next ) {
- my $target = $link->TargetObj;
- next unless $target->isa('RT::Ticket');
-
- $self->TicketLinks(
- %args,
- Ticket => $target,
- Depth => $args{'Depth'}? $args{'Depth'} - 1 : 0,
- );
- next if $args{'SeenEdge'}{ $link->id }++;
-
- my $desc;
- $desc = $link->Description if $show_link_descriptions;
- $args{'Graph'}->add_edge(
- $link->Type eq 'MemberOf'
- ? ($target->id => $args{'Ticket'}->id)
- : ($args{'Ticket'}->id => $target->id),
- %{ $link_style{ $link->Type } || {} },
- $desc? (label => gv_escape $desc): (),
- );
+ foreach my $type ( $args{'LeadingLink'}, @{ $args{'ShowLinks'} } ) {
+ my $links = $args{'Ticket'}->$type();
+ $links->GotoFirstItem;
+ while ( my $link = $links->Next ) {
+ next if $args{'SeenEdge'}{ $link->id }++;
+
+ my $target = $link->TargetObj;
+ next unless $target->isa('RT::Ticket');
+
+ my $base = $link->BaseObj;
+ next unless $target->isa('RT::Ticket');
+
+ my $next = $target->id == $args{'Ticket'}->id? $base : $target;
+
+ $self->TicketLinks(
+ %args,
+ Ticket => $next,
+ $type eq $args{'LeadingLink'}
+ ? ( CurrentDepth => $args{'CurrentDepth'} + 1 )
+ : ( MaxDepth => 1, CurrentDepth => 1 ),
+ );
+
+ my $desc;
+ $desc = $link->Description if $show_link_descriptions;
+ $args{'Graph'}->add_edge(
+ # we revers order of member links to get better layout
+ $link->Type eq 'MemberOf'
+ ? ($target->id => $base->id, dir => 'back')
+ : ($base->id => $target->id),
+ %{ $link_style{ $link->Type } || {} },
+ $desc? (label => gv_escape $desc): (),
+ );
+ }
}
- my $to_links = $args{'Ticket'}->Links('Target');
- $to_links->GotoFirstItem;
- while ( my $link = $to_links->Next ) {
- my $base = $link->BaseObj;
- next unless $base->isa('RT::Ticket');
-
- $self->TicketLinks(
- %args,
- Ticket => $base,
- Depth => $args{'Depth'}? $args{'Depth'} - 1 : 0,
- );
- next if $args{'SeenEdge'}{ $link->id }++;
-
- my $desc;
- $desc = $link->Description if $show_link_descriptions;
- $args{'Graph'}->add_edge(
- $link->Type eq 'MemberOf'
- ? ($args{'Ticket'}->id => $base->id)
- : ($base->id => $args{'Ticket'}->id),
- %{ $link_style{ $link->Type } || {} },
- $desc? (label => gv_escape $desc): (),
- );
- }
return $args{'Graph'};
}
More information about the Rt-commit
mailing list