From 09aa4ca78df448f73e440a25a024e44eaf00c827 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 8 Apr 2011 00:27:00 +0000 Subject: [PATCH] display customer agent, class, tag in ticket search, #8784 --- rt/etc/RT_Config.pm.in | 6 +- rt/lib/RT/Tickets_Overlay.pm | 6 ++ rt/lib/RT/URI/freeside.pm | 25 +++++++ rt/lib/RT/URI/freeside/Internal.pm | 25 +++++++ rt/share/html/Elements/RT__Ticket/ColumnMap | 86 +++++++++++++++++++++---- rt/share/html/Search/Elements/BuildFormatString | 2 +- 6 files changed, 133 insertions(+), 17 deletions(-) diff --git a/rt/etc/RT_Config.pm.in b/rt/etc/RT_Config.pm.in index 2fd22ef7f..201802373 100644 --- a/rt/etc/RT_Config.pm.in +++ b/rt/etc/RT_Config.pm.in @@ -1400,13 +1400,13 @@ Set ($DefaultSearchResultFormat, qq{ '__Subject__/TITLE:Subject', Customer, Status, - QueueName, + QueueName, OwnerName, Priority, '__NEWLINE__', - '', - '__Requestors__', '', + '__Requestors__', + '__CustomerTags__', '__CreatedRelative__', '__ToldRelative__', '__LastUpdatedRelative__', diff --git a/rt/lib/RT/Tickets_Overlay.pm b/rt/lib/RT/Tickets_Overlay.pm index 687be738e..5a7e02056 100644 --- a/rt/lib/RT/Tickets_Overlay.pm +++ b/rt/lib/RT/Tickets_Overlay.pm @@ -1791,6 +1791,12 @@ sub OrderByCols { $custalias.last || ', ' || $custalias.first )"; } + elsif ( $subkey eq 'Class' ) { + $field = "$custalias.classnum"; + } + elsif ( $subkey eq 'Agent' ) { + $field = "$custalias.agentnum"; + } else { # no other cases exist yet, but for obviousness: $field = $subkey; diff --git a/rt/lib/RT/URI/freeside.pm b/rt/lib/RT/URI/freeside.pm index 00a9ebb1c..33845dda6 100644 --- a/rt/lib/RT/URI/freeside.pm +++ b/rt/lib/RT/URI/freeside.pm @@ -299,6 +299,31 @@ if ($@ && die $@; }; +=item AgentName + +Return the name of the customer's agent. + +=cut + +sub AgentName { undef } + +=item CustomerClass + +Return the name of the customer's class. + +=cut + +sub CustomerClass { undef } + +=item CustomerTags + +Return the list of tags attached to the customer. Each tag is returned +as a hashref with keys "name", "desc", and "color". + +=cut + +sub CustomerTags { ( ) } + =back =cut diff --git a/rt/lib/RT/URI/freeside/Internal.pm b/rt/lib/RT/URI/freeside/Internal.pm index b5af134ac..6d3adc2ef 100644 --- a/rt/lib/RT/URI/freeside/Internal.pm +++ b/rt/lib/RT/URI/freeside/Internal.pm @@ -142,4 +142,29 @@ sub _FreesideURILabelLong { } +sub AgentName { + my $self = shift; + my $rec = $self->_FreesideGetRecord() or return; + my $agent = $rec->{'_object'}->agent or return; + return $agent->agentnum . ': ' . $agent->agent; +} + +sub CustomerClass { + my $self = shift; + my $rec = $self->_FreesideGetRecord() or return; + my $cust_class = $rec->{'_object'}->cust_class or return; + return $cust_class->classname; +} + +sub CustomerTags { + my $self = shift; + my $rec = $self->_FreesideGetRecord() or return; + my @part_tag = $rec->{'_object'}->part_tag; + return map { + { 'name' => $_->tagname, + 'desc' => $_->tagdesc, + 'color' => $_->tagcolor } + } @part_tag; +} + 1; diff --git a/rt/share/html/Elements/RT__Ticket/ColumnMap b/rt/share/html/Elements/RT__Ticket/ColumnMap index 7efc4b43e..411b3e56b 100644 --- a/rt/share/html/Elements/RT__Ticket/ColumnMap +++ b/rt/share/html/Elements/RT__Ticket/ColumnMap @@ -316,24 +316,84 @@ $COLUMN_MAP = { Customer => { title => 'Customer', #loc - attribute => 'Customer', #title/attribute/name... what does it all mean? + attribute => 'Customer.Number', #title/attribute/name... what does it all mean? value => sub { - my $Ticket = shift; - my @Customers = @{ $Ticket->Customers->ItemsArrayRef }; - my @CustResolvers = map $_->TargetURI->Resolver, @Customers; - my @return = (); - for ( 0 .. $#CustResolvers ) { - my $c = @CustResolvers[$_]; - push @return, \'', $c->AsString, \''; - push @return, \'
' if scalar(@CustResolvers) > 1 - && $_ != $#CustResolvers; - } - @return; + my $Ticket = shift; + my @return = (); + foreach my $c (ticket_cust_resolvers($Ticket)) { + push @return, \'', + $c->AsString, + \'', + \'
'; + } + pop @return; + @return; + }, + }, + # For future reference: + # hash key = name of the column in the format string + # (see /Search/Elements/BuildFormatString) + # title = displayed name in the table header + # attribute = the field to ORDER BY when sorting on this column + Agent => { + title => 'Agent', + attribute => 'Customer.Agent', + value => sub { + my $Ticket = shift; + my @return = (); + foreach my $c (ticket_cust_resolvers($Ticket)) { + push @return, $c->AgentName, \'
'; + } + pop @return; + @return; + }, + }, + CustomerClass => { + title => 'Class', + attribute => 'Customer.Class', + value => sub { + my $Ticket = shift; + my @return = (); + foreach my $c (ticket_cust_resolvers($Ticket)) { + push @return, $c->CustomerClass, \'
'; + } + pop @return; + @return; + }, + }, + CustomerTags => { + title => '', + attribute => '', + value => sub { + my $Ticket = shift; + my @return = (); + foreach my $c (ticket_cust_resolvers($Ticket)) { + my @tags = sort { $a->{'name'} cmp $b->{'name'} } + $c->CustomerTags; + foreach my $t (@tags) { + push @return, \' ', + $t->{'name'}, + \' ', + \' ' + ; + } + pop @return; + push @return, \'
'; + } + pop @return; + @return; }, }, - }; +sub ticket_cust_resolvers { + my $Ticket = shift; + my @Customers = @{ $Ticket->Customers->ItemsArrayRef }; + return map $_->TargetURI->Resolver, @Customers; +} + # if no GPG support, then KeyOwnerName and KeyRequestors fall back to the regular # versions if (RT->Config->Get('GnuPG')->{'Enable'}) { diff --git a/rt/share/html/Search/Elements/BuildFormatString b/rt/share/html/Search/Elements/BuildFormatString index 654f1db3c..dc07c683b 100644 --- a/rt/share/html/Search/Elements/BuildFormatString +++ b/rt/share/html/Search/Elements/BuildFormatString @@ -72,7 +72,7 @@ $CurrentDisplayColumns => undef my @fields = qw( id QueueName Subject - Customer + Customer Agent CustomerClass CustomerTags Status ExtendedStatus UpdateStatus Type -- 2.11.0