[Rt-commit] '' 01/04: Display Edit and Show search options only when a search is available

Jim Brandt jbrandt at bestpractical.com
Fri Apr 26 15:27:59 EDT 2013


This is an automated email from the git hooks/post-receive script.

jbrandt pushed a commit to branch 2.9/search-menu-fixes
in repository rtir.

commit 6076487ea0c14a7761b606e2f06ccdaa400f4b9b
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Apr 24 14:44:56 2013 -0400

    Display Edit and Show search options only when a search is available
    
    Also rename Build Search to Edit Search to be consistent with the Edit
    Search submenu.
---
 html/Callbacks/RTIR/Elements/Tabs/Privileged | 115 +++++++++++++++------------
 t/walk-web.t                                 |   4 +-
 2 files changed, 67 insertions(+), 52 deletions(-)

diff --git a/html/Callbacks/RTIR/Elements/Tabs/Privileged b/html/Callbacks/RTIR/Elements/Tabs/Privileged
index ff8b936..9ffd165 100644
--- a/html/Callbacks/RTIR/Elements/Tabs/Privileged
+++ b/html/Callbacks/RTIR/Elements/Tabs/Privileged
@@ -24,16 +24,31 @@ my $query_string = sub {
     return $u->query || '';
 };
 
+my $current_search = $session{"CurrentSearchHash"} || {};
+my $has_query = 1 if ( $DECODED_ARGS->{'Query'} or $current_search->{'Query'} );
+my $args = $m->request_args;
+my $search_arguments = sub {
+    my %res = ();
+    my @query_fields = qw(Query Format RowsPerPage Page OrderBy Order);
+    if ( my $refined = $m->notes('RefinedSearch') ) {
+        @res{ @query_fields } = @{ $refined->{'query'} }{ @query_fields };
+    } else {
+        @res{ @query_fields } = @{ $args }{ @query_fields };
+    }
+    delete $res{$_} foreach grep !defined $res{$_}, keys %res;
+    return %res;
+};
+
 my $root = Menu->child( rtir => title => loc('RTIR'), path => '/RTIR/' );
 
 my $search = $root->child( search => title => loc('Search'), path => '/RTIR/Search/' );
-$search->child( new => title => loc('New Query'), path => '/RTIR/Search/?NewQuery=1' );
-# XXX: query string
-$search->child( build => title => loc('Build Search'), path => '/RTIR/Search/' );
-if ( $session{'CurrentSearchHash'} ) {
-    $search->child( results => title => loc('Show Results'), path => '/RTIR/Search/Results.html' );
-} else {
-
+$search->child( new => title => loc('New Search'), path => '/RTIR/Search/?NewQuery=1' );
+if ( $has_query ) {
+    $search->child( edit => title => loc('Edit Search'), path => '/RTIR/Search/' );
+    # If we got a query, use it. Otherwise, use the last saved query.
+    my %search_args = $DECODED_ARGS->{'Query'} ? $search_arguments->() : %{$current_search};
+    $search->child( results => title => loc('Show Results'),
+                    path => "/RTIR/Search/Results.html?" . $query_string->( %search_args ) );
 }
 
 $root->child(
@@ -77,21 +92,8 @@ $scripted_actions->child( ip => title => loc('By IP address'), path => '/RTIR/To
 my $request_path = $HTML::Mason::Commands::r->path_info;
 return unless $request_path =~ m{^/RTIR/};
 
-my $args = $m->request_args;
 my $re_rtir_types = '(?:'. join( '|', map "\Q$_\E", RT::IR->Types ) .')';
 
-my $search_arguments = sub {
-    my %res = ();
-    my @query_fields = qw(Query Format RowsPerPage Page OrderBy Order);
-    if ( my $refined = $m->notes('RefinedSearch') ) {
-        @res{ @query_fields } = @{ $refined->{'query'} }{ @query_fields };
-    } else {
-        @res{ @query_fields } = @{ $args }{ @query_fields };
-    }
-    delete $res{$_} foreach grep !defined $res{$_}, keys %res;
-    return %res;
-};
-
 if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update|Forward|Advanced)\.html$} ) {
     my $id = $args->{'id'};
 
@@ -381,6 +383,10 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update|Forward|
 } elsif ( $request_path =~ m{^/RTIR/(Search/|Incident/BulkAbandon\.html$|Report/BulkReject\.html$)} ) {
     my %args = $search_arguments->();
 
+    # Use 'Refine' only for Bulk operations
+    my $bulk_path = 1 if $request_path =~ m{^/RTIR/(Incident/BulkAbandon\.html$|Report/BulkReject\.html$)};
+    my $search_page = $bulk_path ? "Refine.html" : "";
+
     my $queue = $args->{'Queue'} || '';
     unless ( $queue ) {
         if ( $request_path =~ /Incident/ ) {
@@ -398,17 +404,23 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update|Forward|
 
     $args{'Queue'} = $queue if $queue;
 
-    PageMenu()->child(
-        link => title => loc('Show Results'),
-        path => "/RTIR/Search/Results.html?". $query_string->( %args ),
-    );
+    if ( not $args{'Query'} and not $args{'Queue'} ){
+        %args = %{$current_search};
+    }
+
+    if ( $has_query ){
+        PageMenu()->child(
+            link => title => loc('Show Results'),
+            path => "/RTIR/Search/Results.html?". $query_string->( %args ),
+        );
+    }
     PageMenu()->child(
         edit_search => title => loc('Edit Search'),
-        path => "/RTIR/Search/Refine.html?". $query_string->( %args ),
+        path => "/RTIR/Search/$search_page?". $query_string->( %args ),
     );
     PageMenu()->child(
         new_search => title => loc('New Search'),
-        path => "/RTIR/Search/Refine.html?". $query_string->(
+        path => "/RTIR/Search/$search_page?". $query_string->(
             NewQuery => 1,
             Queue => $queue,
         ),
@@ -431,22 +443,24 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update|Forward|
             path => "/RTIR/Report/BulkReject.html?". $query_string->( %args ),
         );
     }
-    PageMenu()->child(
-        chart => title => loc('Chart'),
-        path => "/RTIR/Search/Reporting.html?". $query_string->( %args ),
-    );
-
-    my $more = PageMenu->child( more => title => loc('Feeds') );
-    $more->child(
-        spreadsheet => title => loc('Spreadsheet'),
-        path => "/Search/Results.tsv?". $query_string->( %args ),
-    );
 
     # other paths need query defined
     $args{'Query'} = RT::IR->Query( Queue => $args{'Queue'} )
         if !$args{'Query'} && $args{'Queue'};
 
-    if ( $args{'Query'} ) {
+    if ( $args{'Query'} or $has_query ) {
+
+        PageMenu()->child(
+            chart => title => loc('Chart'),
+            path => "/RTIR/Search/Reporting.html?". $query_string->( %args ),
+        );
+
+        my $more = PageMenu->child( more => title => loc('Feeds') );
+        $more->child(
+            spreadsheet => title => loc('Spreadsheet'),
+            path => "/Search/Results.tsv?". $query_string->( %args ),
+        );
+
         my $RSSPath = join '/', map $m->interp->apply_escapes( $_, 'u' ),
             $session{'CurrentUser'}->UserObj->Name,
             $session{'CurrentUser'}->UserObj->GenerateAuthString(
@@ -466,21 +480,20 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update|Forward|
             $args{Query}
         ;
         $more->child( ical => title => loc('iCal') => path => '/NoAuth/iCal/'.$ical_path);
-    }
 
-    if ( $args{'Query'} && $session{'CurrentUser'}->HasRight(
-        Right => 'SuperUser', Object => RT->System
-    ) ) {
-        my $shred_args = $query_string->(
-            search          => 1,
-            plugin          => 'Tickets',
-            'Tickets:query' => $args{'Query'},
-            'Tickets:limit' => $args{'RowsPerPage'},
-        );
-        $more->child(
-            shredder => title => loc('Shredder'),
-            path => '/Admin/Tools/Shredder/?' . $shred_args
-        );
+        if ( $session{'CurrentUser'}->HasRight(
+                 Right => 'SuperUser', Object => RT->System) ) {
+            my $shred_args = $query_string->(
+                search          => 1,
+                plugin          => 'Tickets',
+                'Tickets:query' => $args{'Query'},
+                'Tickets:limit' => $args{'RowsPerPage'},
+            );
+            $more->child(
+                shredder => title => loc('Shredder'),
+                path => '/Admin/Tools/Shredder/?' . $shred_args
+            );
+        }
     }
 } elsif ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?Split\.html$} ) {
     my $id = $args->{'Split'};
diff --git a/t/walk-web.t b/t/walk-web.t
index 4730303..d14ca3f 100644
--- a/t/walk-web.t
+++ b/t/walk-web.t
@@ -5,7 +5,7 @@ use warnings;
 
 use HTML::TreeBuilder;
 
-use RT::IR::Test tests => 609;
+use RT::IR::Test tests => undef;
 
 RT::Test->started_ok;
 my $m = default_agent();
@@ -51,3 +51,5 @@ sub test_page {
     }
 }
 
+undef $m;
+done_testing;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Rt-commit mailing list