Mailing List Archive

rt branch, 4.4/config-option-search-results-navigation-links, created. rt-4.4.4-2-g3885a01c0a
The branch, 4.4/config-option-search-results-navigation-links has been created
at 3885a01c0a3b7a856fd470064373cc7d589061c8 (commit)

- Log -----------------------------------------------------------------
commit 998c7384076af22d91efcf8cb412c0537baa4fff
Author: craig kaiser <craig@bestpractical.com>
Date: Tue Jun 23 10:17:15 2020 -0400

Add config option to disable search results navigation links

Generating these links requires running the RT::Tickets->_BuildItemMap
method for the current tickets search. which results in the loading of
the ticket display page taking slightly longer.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 54e5949e7a..7e4a14b5cf 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1506,6 +1506,17 @@ ticket display page automatically.

Set($SearchResultsAutoRedirect, 0);

+
+=item C<$SearchResultsNavigationLinks>
+
+Option to build the search navigation options in the RT menu ( First, Last, Prev, Next ).
+This feature requires the re-running of the current search in order to accuratly create
+the menu links, disabling it can speed up ticket load time.
+
+=cut
+
+Set($SearchResultsNavigationLinks, 1);
+
=back


diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index 755c8d219e..fe8d978637 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -865,31 +865,33 @@ my $build_main_nav = sub {
path => "/Articles/Article/ExtractIntoClass.html?Ticket=".$obj->id,
) if $session{CurrentUser}->HasRight( Right => 'ShowArticlesMenu', Object => RT->System );

- if ( defined $session{"tickets"} ) {
- # we have to update session data if we get new ItemMap
- my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
+ if ( RT::Config->Get( 'SearchResultsNavigationLinks' ) ) {
+ if ( defined $session{"tickets"} ) {
+ # we have to update session data if we get new ItemMap
+ my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );

- my $item_map = $session{"tickets"}->ItemMap;
+ my $item_map = $session{"tickets"}->ItemMap;

- if ($updatesession) {
- $session{"tickets"}->PrepForSerialization();
- }
+ if ($updatesession) {
+ $session{"tickets"}->PrepForSerialization();
+ }

- my $search = Menu()->child('search')->child('tickets');
- # Don't display prev links if we're on the first ticket
- if ( $item_map->{$id}->{prev} ) {
- $search->child( first =>
- title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
- $search->child( prev =>
- title => '< ' . loc('Prev'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
- }
- # Don't display next links if we're on the last ticket
- if ( $item_map->{$id}->{next} ) {
- $search->child( next =>
- title => loc('Next') . ' >', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
- if ( $item_map->{last} ) {
- $search->child( last =>
- title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
+ my $search = Menu()->child('search')->child('tickets');
+ # Don't display prev links if we're on the first ticket
+ if ( $item_map->{$id}->{prev} ) {
+ $search->child( first =>
+ title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
+ $search->child( prev =>
+ title => '< ' . loc('Prev'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
+ }
+ # Don't display next links if we're on the last ticket
+ if ( $item_map->{$id}->{next} ) {
+ $search->child( next =>
+ title => loc('Next') . ' >', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
+ if ( $item_map->{last} ) {
+ $search->child( last =>
+ title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
+ }
}
}
}
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 2681a38313..b13fc1fd37 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -240,7 +240,7 @@ my $attachments = $TicketObj->Attachments;
my $attachment_content = $TicketObj->TextAttachments;

my %link_rel;
-if (defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
+if (RT::Config->Get( 'SearchResultsNavigationLinks' ) && defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
my $item_map = $session{'tickets'}->ItemMap;
$link_rel{first} = "/Ticket/Display.html?id=" . $item_map->{first} if $item_map->{$TicketObj->Id}{prev};
$link_rel{prev} = "/Ticket/Display.html?id=" . $item_map->{$TicketObj->Id}{prev} if $item_map->{$TicketObj->Id}{prev};

commit 3885a01c0a3b7a856fd470064373cc7d589061c8
Author: craig kaiser <craig@bestpractical.com>
Date: Tue Jun 23 11:11:36 2020 -0400

Add tests for 'SearchResultsNavigationLinks' config option

diff --git a/t/web/search_linkdisplay.t b/t/web/search_linkdisplay.t
index 8d18f547ad..1c35cadfac 100644
--- a/t/web/search_linkdisplay.t
+++ b/t/web/search_linkdisplay.t
@@ -59,4 +59,25 @@ $ref = $m->find_link( url_regex => qr!/Article/Display.html! );
ok( $ref, "found article link" );
is( $ref->text, $article->URIObj->Resolver->AsString, $article->URIObj->Resolver->AsString . " is displayed" );

+
+# Get a search that returns multiple tickets
+$m->get_ok("/Search/Results.html?Format=id,RefersTo;Query=id>0");
+
+ok $m->goto_ticket( $ticket->Id ), 'opened diplay page of ticket # '.$ticket->Id;
+my $t_link = $m->find_link( id => "search-tickets-next" )->url;
+is ($t_link, "/Ticket/Display.html?id=".$ticket2->Id, 'link to the next ticket in current search found');
+
+diag "Set SearchResultsNavigationLinks to false and confirm we do not load navigation links.";
+{
+ RT::Test->stop_server;
+ RT->Config->Set( 'SearchResultsNavigationLinks' => 0 );
+ ($baseurl, $m) = RT::Test->started_ok;
+
+ # Get a search that returns multiple tickets
+ $m->get_ok("/Search/Results.html?Format=id,RefersTo;Query=id>0");
+
+ ok $m->goto_ticket( $ticket->Id ), 'opened diplay page of ticket # '.$ticket->Id;
+ $t_link = $m->find_link( id => "search-tickets-next" );
+ is($t_link, undef, "Search navigation results are not rendered");
+}
done_testing;

-----------------------------------------------------------------------
_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit