[Rt-commit] rt branch, 4.0/search-tabs, updated. rt-4.0.0rc6-31-g48ba346

Shawn Moore sartak at bestpractical.com
Mon Mar 14 14:52:38 EDT 2011


The branch, 4.0/search-tabs has been updated
       via  48ba3468a1e6b349943c68ea3826db7cc5940423 (commit)
      from  d1d03343e95a872434e60004b0d1e74157e8f128 (commit)

Summary of changes:
 share/html/Search/Build.html            |  215 ++-----------------------------
 share/html/Search/Elements/EditSearches |  214 ++++++++++++++++++++++++++++++
 2 files changed, 226 insertions(+), 203 deletions(-)

- Log -----------------------------------------------------------------
commit 48ba3468a1e6b349943c68ea3826db7cc5940423
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Mon Mar 14 14:28:40 2011 -0400

    Move the Search/Build regenerate logic into EditSearches

diff --git a/share/html/Search/Build.html b/share/html/Search/Build.html
index 494bdcf..6cce850 100644
--- a/share/html/Search/Build.html
+++ b/share/html/Search/Build.html
@@ -70,7 +70,7 @@
 
 <form method="post" action="Build.html" name="BuildQuery" id="BuildQuery">
 <input type="hidden" class="hidden" name="SavedSearchId" value="<% $saved_search{'Id'} %>" />
-<input type="hidden" class="hidden" name="SavedChartSearchId" value="<% $ARGS{'SavedChartSearchId'} %>" />
+<input type="hidden" class="hidden" name="SavedChartSearchId" value="<% $SavedChartSearchId %>" />
 <input type="hidden" class="hidden" name="Query" value="<% $query{'Query'} %>" />
 <input type="hidden" class="hidden" name="Format" value="<% $query{'Format'} %>" />
 
@@ -78,7 +78,7 @@
 
 
 <div id="pick-criteria">
-    <& Elements/PickCriteria, query => $query{'Query'}, cfqueues => $queues &>
+    <& Elements/PickCriteria, query => $query{'Query'}, cfqueues => \%cfqueues &>
 </div>
 <& /Elements/Submit,  Label => loc('Add these terms'), Name => 'AddClause'&>
 <& /Elements/Submit, Label => loc('Add these terms and Search'), Name => 'DoSearch'&>
@@ -107,212 +107,21 @@
 </form>
 
 <%INIT>
-use RT::Interface::Web::QueryBuilder;
-use RT::Interface::Web::QueryBuilder::Tree;
-
-$ARGS{SavedChartSearchId} ||= 'new';
-
 my $title = loc("Query Builder");
 
-my %query;
-for( qw(Query Format OrderBy Order RowsPerPage) ) {
-    $query{$_} = $ARGS{$_};
-}
-
-my %saved_search;
-my @actions = $m->comp( 'Elements/EditSearches:Init', %ARGS, Query => \%query, SavedSearch => \%saved_search);
-
-if ( $NewQuery ) {
-
-    # Wipe all data-carrying variables clear if we want a new
-    # search, or we're deleting an old one..
-    %query = ();
-    %saved_search = ( Id => 'new' );
-
-    # ..then wipe the session out..
-    delete $session{'CurrentSearchHash'};
-
-    # ..and the search results.
-    $session{'tickets'}->CleanSlate if defined $session{'tickets'};
-}
-
-{ # Attempt to load what we can from the session and preferences, set defaults
-
-    my $current = $session{'CurrentSearchHash'};
-    my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
-    my $default = { Query => '', Format => '', OrderBy => 'id', Order => 'ASC', RowsPerPage => 50 };
-
-    for( qw(Query Format OrderBy Order RowsPerPage) ) {
-        $query{$_} = $current->{$_} unless defined $query{$_};
-        $query{$_} = $prefs->{$_} unless defined $query{$_};
-        $query{$_} = $default->{$_} unless defined $query{$_};
-    }
-
-    for( qw(Order OrderBy) ) {
-        if (ref $query{$_} eq "ARRAY") {
-            $query{$_} = join( '|', @{ $query{$_} } );
-        }
-    }
-    if ( $query{'Format'} ) {
-        # Clean unwanted junk from the format
-        $query{'Format'} = $m->comp( '/Elements/ScrubHTML', Content => $query{'Format'} );
-    }
-}
-
-my $ParseQuery = sub {
-    my ($string, $results) = @_;
-
-    my $tree = RT::Interface::Web::QueryBuilder::Tree->new('AND');
-    @$results = $tree->ParseSQL( Query => $string, CurrentUser => $session{'CurrentUser'} );
-
-    return $tree;
-};
-
-my @parse_results;
-my $tree = $ParseQuery->( $query{'Query'}, \@parse_results );
-
-# if parsing went poorly, send them to the edit page to fix it
-if ( @parse_results ) {
-    push @actions, @parse_results;
-    return $m->comp(
-        "Edit.html",
-        Query => $query{'Query'},
-        Format => $query{'Format'},
-        SavedSearchId => $saved_search{'Id'},
-        actions => \@actions,
-    );
-}
-
-my @options = $tree->GetDisplayedNodes;
-my @current_values = grep defined, @options[@clauses];
-my @new_values = ();
-
-# Try to find if we're adding a clause
-foreach my $arg ( keys %ARGS ) {
-    next unless $arg =~ m/^ValueOf(\w+|'CF.{.*?}')$/
-                && ( ref $ARGS{$arg} eq "ARRAY"
-                     ? grep $_ ne '', @{ $ARGS{$arg} }
-                     : $ARGS{$arg} ne '' );
-
-    # We're adding a $1 clause
-    my $field = $1;
-
-    my ($op, $value);
-
-    #figure out if it's a grouping
-    my $keyword = $ARGS{ $field . "Field" } || $field;
-
-    my ( @ops, @values );
-    if ( ref $ARGS{ 'ValueOf' . $field } eq "ARRAY" ) {
-        # we have many keys/values to iterate over, because there is
-        # more than one CF with the same name.
-        @ops    = @{ $ARGS{ $field . 'Op' } };
-        @values = @{ $ARGS{ 'ValueOf' . $field } };
-    }
-    else {
-        @ops    = ( $ARGS{ $field . 'Op' } );
-        @values = ( $ARGS{ 'ValueOf' . $field } );
-    }
-    $RT::Logger->error("Bad Parameters passed into Query Builder")
-        unless @ops == @values;
-
-    for ( my $i = 0; $i < @ops; $i++ ) {
-        my ( $op, $value ) = ( $ops[$i], $values[$i] );
-        next if !defined $value || $value eq '';
-
-        if ( $value eq 'NULL' && $op =~ /=/ ) {
-            if ( $op eq '=' ) {
-                $op = "IS";
-            }
-            elsif ( $op eq '!=' ) {
-                $op = "IS NOT";
-            }
-
-            # This isn't "right", but...
-            # It has to be this way until #5182 is fixed
-            $value = "'NULL'";
-        }
-        else {
-            $value =~ s/'/\\'/g;
-            $value = "'$value'" unless $value =~ /^\d+$/;
-        }
-
-        my $clause = {
-            Key   => $keyword,
-            Op    => $op,
-            Value => $value
-        };
-
-        push @new_values, RT::Interface::Web::QueryBuilder::Tree->new($clause);
-    }
-}
-
-
-push @actions, $m->comp('Elements/EditQuery:Process',
+my (%saved_search, %query, $optionlist, %cfqueues, $AvailableColumns, $CurrentFormat);
+my @actions = $m->comp('Elements/EditSearches:Regenerate',
     %ARGS,
-    Tree     => $tree,
-    Selected => \@current_values,
-    New      => \@new_values,
+    saved_search       => \%saved_search,
+    query              => \%query,
+    optionlist         => \$optionlist,
+    cfqueues           => \%cfqueues,
+    AvailableColumns   => \$AvailableColumns,
+    CurrentFormat      => \$CurrentFormat,
+    SavedChartSearchId => \$SavedChartSearchId,
 );
 
-# Rebuild $Query based on the additions / movements
-
-my $optionlist_arrayref;
-($query{'Query'}, $optionlist_arrayref) = $tree->GetQueryAndOptionList(\@current_values);
-
-my $optionlist = join "\n", map { qq(<option value="$_->{INDEX}" $_->{SELECTED}>) 
-                                  . ("&nbsp;" x (5 * $_->{DEPTH}))
-                                  . $m->interp->apply_escapes($_->{TEXT}, 'h') . qq(</option>) } @$optionlist_arrayref;
-
-
-my $queues = $tree->GetReferencedQueues;
-
-# Deal with format changes
-my ( $AvailableColumns, $CurrentFormat );
-( $query{'Format'}, $AvailableColumns, $CurrentFormat ) = $m->comp(
-    'Elements/BuildFormatString',
-    %ARGS,
-    cfqueues => $queues,
-    Format => $query{'Format'},
-);
-
-
-# if we're asked to save the current search, save it
-push @actions, $m->comp( 'Elements/EditSearches:Save', %ARGS, Query => \%query, SavedSearch => \%saved_search);
-
-# Push the updates into the session so we don't lose 'em
-
-$session{'CurrentSearchHash'} = {
-    %query,
-    SearchId    => $saved_search{'Id'},
-    Object      => $saved_search{'Object'},
-    Description => $saved_search{'Description'},
-};
-
-
-# Show the results, if we were asked.
-
-if ( $ARGS{'DoSearch'} ) {
-    $m->comp( 'Results.html', %query, SavedChartSearchId => $ARGS{'SavedChartSearchId'}, );
-    $m->comp( '/Elements/Footer' );
-    $m->abort;
-}
-
-
-# Build a querystring for the tabs
-
-my $QueryString = '';
-if ($NewQuery) {
-    $QueryString = 'NewQuery=1';
-}
-elsif ( $query{'Query'} ) {
-    $QueryString = $m->comp('/Elements/QueryString', %query );
-}
-
-
 </%INIT>
-
 <%ARGS>
-$NewQuery => 0
- at clauses => ()
+$SavedChartSearchId => 'new'
 </%ARGS>
diff --git a/share/html/Search/Elements/EditSearches b/share/html/Search/Elements/EditSearches
index 7f2f9f6..c87a1b4 100644
--- a/share/html/Search/Elements/EditSearches
+++ b/share/html/Search/Elements/EditSearches
@@ -321,3 +321,217 @@ return @results;
 
 </%INIT>
 </%METHOD>
+<%METHOD Regenerate>
+<%ARGS>
+$NewQuery => 0
+ at clauses => ()
+
+$saved_search
+$query
+$optionlist
+$cfqueues
+$AvailableColumns
+$CurrentFormat
+$SavedChartSearchId
+</%ARGS>
+<%INIT>
+use RT::Interface::Web::QueryBuilder;
+use RT::Interface::Web::QueryBuilder::Tree;
+
+$$SavedChartSearchId ||= 'new';
+
+for( qw(Query Format OrderBy Order RowsPerPage) ) {
+    $query->{$_} = $ARGS{$_};
+}
+
+my @actions = $m->comp( 'EditSearches:Init', %ARGS, Query => $query, SavedSearch => $saved_search);
+
+if ( $NewQuery ) {
+
+    # Wipe all data-carrying variables clear if we want a new
+    # search, or we're deleting an old one..
+    %$query = ();
+    %$saved_search = ( Id => 'new' );
+
+    # ..then wipe the session out..
+    delete $session{'CurrentSearchHash'};
+
+    # ..and the search results.
+    $session{'tickets'}->CleanSlate if defined $session{'tickets'};
+}
+
+{ # Attempt to load what we can from the session and preferences, set defaults
+
+    my $current = $session{'CurrentSearchHash'};
+    my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
+    my $default = { Query => '', Format => '', OrderBy => 'id', Order => 'ASC', RowsPerPage => 50 };
+
+    for( qw(Query Format OrderBy Order RowsPerPage) ) {
+        $query->{$_} = $current->{$_} unless defined $query->{$_};
+        $query->{$_} = $prefs->{$_} unless defined $query->{$_};
+        $query->{$_} = $default->{$_} unless defined $query->{$_};
+    }
+
+    for( qw(Order OrderBy) ) {
+        if (ref $query->{$_} eq "ARRAY") {
+            $query->{$_} = join( '|', @{ $query->{$_} } );
+        }
+    }
+    if ( $query->{'Format'} ) {
+        # Clean unwanted junk from the format
+        $query->{'Format'} = $m->comp( '/Elements/ScrubHTML', Content => $query->{'Format'} );
+    }
+}
+
+my $ParseQuery = sub {
+    my ($string, $results) = @_;
+
+    my $tree = RT::Interface::Web::QueryBuilder::Tree->new('AND');
+    @$results = $tree->ParseSQL( Query => $string, CurrentUser => $session{'CurrentUser'} );
+
+    return $tree;
+};
+
+my @parse_results;
+my $tree = $ParseQuery->( $query->{'Query'}, \@parse_results );
+
+# if parsing went poorly, send them to the edit page to fix it
+if ( @parse_results ) {
+    push @actions, @parse_results;
+    return $m->comp(
+        "Edit.html",
+        Query => $query->{'Query'},
+        Format => $query->{'Format'},
+        SavedSearchId => $saved_search->{'Id'},
+        actions => \@actions,
+    );
+}
+
+my @options = $tree->GetDisplayedNodes;
+my @current_values = grep defined, @options[@clauses];
+my @new_values = ();
+
+# Try to find if we're adding a clause
+foreach my $arg ( keys %ARGS ) {
+    next unless $arg =~ m/^ValueOf(\w+|'CF.{.*?}')$/
+                && ( ref $ARGS{$arg} eq "ARRAY"
+                     ? grep $_ ne '', @{ $ARGS{$arg} }
+                     : $ARGS{$arg} ne '' );
+
+    # We're adding a $1 clause
+    my $field = $1;
+
+    my ($op, $value);
+
+    #figure out if it's a grouping
+    my $keyword = $ARGS{ $field . "Field" } || $field;
+
+    my ( @ops, @values );
+    if ( ref $ARGS{ 'ValueOf' . $field } eq "ARRAY" ) {
+        # we have many keys/values to iterate over, because there is
+        # more than one CF with the same name.
+        @ops    = @{ $ARGS{ $field . 'Op' } };
+        @values = @{ $ARGS{ 'ValueOf' . $field } };
+    }
+    else {
+        @ops    = ( $ARGS{ $field . 'Op' } );
+        @values = ( $ARGS{ 'ValueOf' . $field } );
+    }
+    $RT::Logger->error("Bad Parameters passed into Query Builder")
+        unless @ops == @values;
+
+    for ( my $i = 0; $i < @ops; $i++ ) {
+        my ( $op, $value ) = ( $ops[$i], $values[$i] );
+        next if !defined $value || $value eq '';
+
+        if ( $value eq 'NULL' && $op =~ /=/ ) {
+            if ( $op eq '=' ) {
+                $op = "IS";
+            }
+            elsif ( $op eq '!=' ) {
+                $op = "IS NOT";
+            }
+
+            # This isn't "right", but...
+            # It has to be this way until #5182 is fixed
+            $value = "'NULL'";
+        }
+        else {
+            $value =~ s/'/\\'/g;
+            $value = "'$value'" unless $value =~ /^\d+$/;
+        }
+
+        my $clause = {
+            Key   => $keyword,
+            Op    => $op,
+            Value => $value
+        };
+
+        push @new_values, RT::Interface::Web::QueryBuilder::Tree->new($clause);
+    }
+}
+
+
+push @actions, $m->comp('EditQuery:Process',
+    %ARGS,
+    Tree     => $tree,
+    Selected => \@current_values,
+    New      => \@new_values,
+);
+
+# Rebuild $Query based on the additions / movements
+
+my $optionlist_arrayref;
+($query->{'Query'}, $optionlist_arrayref) = $tree->GetQueryAndOptionList(\@current_values);
+
+$$optionlist = join "\n", map { qq(<option value="$_->{INDEX}" $_->{SELECTED}>) 
+                                  . ("&nbsp;" x (5 * $_->{DEPTH}))
+                                  . $m->interp->apply_escapes($_->{TEXT}, 'h') . qq(</option>) } @$optionlist_arrayref;
+
+
+%$cfqueues = %{ $tree->GetReferencedQueues };
+
+# Deal with format changes
+( $query->{'Format'}, $$AvailableColumns, $$CurrentFormat ) = $m->comp(
+    'BuildFormatString',
+    %ARGS,
+    cfqueues => $cfqueues,
+    Format => $query->{'Format'},
+);
+
+
+# if we're asked to save the current search, save it
+push @actions, $m->comp( 'EditSearches:Save', %ARGS, Query => $query, SavedSearch => $saved_search);
+
+# Push the updates into the session so we don't lose 'em
+
+$session{'CurrentSearchHash'} = {
+    %$query,
+    SearchId    => $saved_search->{'Id'},
+    Object      => $saved_search->{'Object'},
+    Description => $saved_search->{'Description'},
+};
+
+
+# Show the results, if we were asked.
+
+if ( $ARGS{'DoSearch'} ) {
+    $m->comp( '/Search/Results.html', %$query, SavedChartSearchId => $$SavedChartSearchId );
+    $m->comp( '/Elements/Footer' );
+    $m->abort;
+}
+
+
+# Build a querystring for the tabs
+
+my $QueryString = '';
+if ($NewQuery) {
+    $QueryString = 'NewQuery=1';
+}
+elsif ( $query->{'Query'} ) {
+    $QueryString = $m->comp('/Elements/QueryString', %$query );
+}
+
+return @actions;
+</%INIT>
+</%METHOD>

-----------------------------------------------------------------------


More information about the Rt-commit mailing list