[PATCH] Allow search output format to be customised per queue and/or lifecycle

Sometimes we want to customise the default view that users see either
for a particular queue, or all queues in a given lifecycle (for example
the ‘change’ lifecycle). This patch adds that functionality to the
Results.html output. It makes use of a group of RT_SiteConfig.pm
parameters to extend the default l format and order/order by options:

$DefaultSearchResultFormat_<queuename>
$DefaultSearchResultFormatLifecycle_<lifecycle>
$DefaultSearchResultOrder_<queuename>
$DefaultSearchResultOrderLifecycle_<lifecycle>
$DefaultSearchResultOrderBy_<queuename>
$DefaultSearchResultOrderByLifecycle_<lifecycle>

where <queuename> is the name of the queue and <lifecycle> is the name
of the life cycle. If either of these have spaces in them, they are
replaced by underscores in the variable.

So for example to adjust the format for any queues in the ‘change’
lifecycle pop this into the RT_SiteConfig.pm, clear the Mason cache and
restart the web server:

Set($DefaultSearchResultFormatLifecycle_change, qq{
   '<B><A HREF="__WebPath__/Ticket/Display.html?id=__id__">__id__</a></B>/TITLE:#',
   '<B><A HREF="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a></B>/TITLE:Subject',
   'Status',
   'Owner',
   'CustomField.{Change Type}',
   'Starts',
   'Due'
   '__NEWLINE__',
   '__NBSP__',
   '<small>__Requestors__</small>',
   '<small>__CreatedRelative__</small>',
   '__NBSP__',
   '__NBSP__',
   '__NBSP__',
   '__NBSP__',
});

 share/html/Search/Results.html | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/share/html/Search/Results.html b/share/html/Search/Results.html
index abee929..f763884 100644
--- a/share/html/Search/Results.html
+++ b/share/html/Search/Results.html
@@ -102,11 +102,23 @@ $m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' );
 # Read from user preferences
 my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
 
+# See if we're looking at a particular queue.
+my $queueName = '';
+my $lifecycle = '';
+    if($Query =~ /Queue = '([a-zA-Z0-0_ ]+)'/) {
+    $queueName = $1;
+    my $Queue = RT::Queue->new( $session{'CurrentUser'} );
+    $Queue->Load($queueName);
+    $lifecycle = $Queue->Lifecycle();
+    $queueName =~ s/ /_/g;
+    $lifecycle =~ s/ /_/g;
+}
+
 # These variables are what define a search_hash; this is also
 # where we give sane defaults.
-$Format      ||= $prefs->{'Format'} || RT->Config->Get('DefaultSearchResultFormat');
-$Order       ||= $prefs->{'Order'} || RT->Config->Get('DefaultSearchResultOrder');
-$OrderBy     ||= $prefs->{'OrderBy'} || RT->Config->Get('DefaultSearchResultOrderBy');
+$Format      ||= $prefs->{'Format'} || RT->Config->Get('DefaultSearchResultFormat_'.$queueName) || RT->Config->Get('DefaultSearchResultFormatLifecycle_'.$lifecycle) || RT->Config->Get('DefaultSearchResultFormat');
+$Order       ||= $prefs->{'Order'} || RT->Config->Get('DefaultSearchResultOrder_'.$queueName) || RT->Config->Get('DefaultSearchResultOrderLifecycle_'.$lifecycle) || RT->Config->Get('DefaultSearchResultOrder');
+$OrderBy     ||= $prefs->{'OrderBy'} || RT->Config->Get('DefaultSearchResultOrderBy_'.$queueName) || RT->Config->Get('DefaultSearchResultOrderByLifeCycle_'.$lifecycle) || RT->Config->Get('DefaultSearchResultOrderBy');
 
 # Some forms pass in "RowsPerPage" rather than "Rows"
 # We call it RowsPerPage everywhere else.
-- 
2.1.4
1 Like