[Rt-commit] rt branch, 4.4-on-4.2/queue-like-search, created. rt-4.2.13-77-g1a87cb0

Jim Brandt jbrandt at bestpractical.com
Fri Dec 23 13:54:02 EST 2016


The branch, 4.4-on-4.2/queue-like-search has been created
        at  1a87cb0855796df01d35624529f6c09de921f7b3 (commit)

- Log -----------------------------------------------------------------
commit 822dc3a411f9b24b95e8b5e12f5a385c972c5131
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 23 11:37:45 2016 -0500

    Support LIKE and NOT LIKE searches on queue

diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index a86f947..f8d0c01 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -104,7 +104,7 @@ __PACKAGE__->RegisterCustomFieldJoin(@$_) for
 
 our %FIELD_METADATA = (
     Status          => [ 'STRING', ], #loc_left_pair
-    Queue           => [ 'ENUM' => 'Queue', ], #loc_left_pair
+    Queue           => [ 'QUEUE' ], #loc_left_pair
     Type            => [ 'ENUM', ], #loc_left_pair
     Creator         => [ 'ENUM' => 'User', ], #loc_left_pair
     LastUpdatedBy   => [ 'ENUM' => 'User', ], #loc_left_pair
@@ -184,6 +184,7 @@ our %dispatch = (
     LINK            => \&_LinkLimit,
     DATE            => \&_DateLimit,
     STRING          => \&_StringLimit,
+    QUEUE           => \&_QueueLimit,
     TRANSFIELD      => \&_TransLimit,
     TRANSCONTENT    => \&_TransContentLimit,
     TRANSDATE       => \&_TransDateLimit,
@@ -218,6 +219,12 @@ my %DefaultEA = (
         'LIKE'     => 'AND',
         'NOT LIKE' => 'AND'
     },
+    QUEUE => {
+         '='        => 'OR',
+         '!='       => 'AND',
+         'LIKE'     => 'OR',
+         'NOT LIKE' => 'AND'
+    },
     TRANSFIELD   => 'AND',
     TRANSDATE    => 'AND',
     LINK         => 'OR',
@@ -706,6 +713,49 @@ sub _StringLimit {
     );
 }
 
+=head2 _QueueLimit
+
+Handle Queue field supporting both is and match.
+
+Input should be a queue name or a paritial string.
+
+=cut
+
+sub _QueueLimit {
+    my ($sb, $field, $op, $value, @rest ) = @_;
+    my $alias;
+
+    if ($op eq 'LIKE' || $op eq 'NOT LIKE') {
+        $alias = $sb->{_sql_aliases}{queues} ||= $sb->Join(
+            ALIAS1 => 'main',
+            FIELD1 => 'Queue',
+            TABLE2 => 'Queues',
+            FIELD2 => 'id',
+        );
+
+        return $sb->Limit(
+           ALIAS         => $alias,
+           FIELD         => 'Name',
+           OPERATOR      => $op,
+           VALUE         => $value,
+           CASESENSITIVE => 0,
+           @rest,
+       );
+
+    }
+
+    my $o = RT::Queue->new( $sb->CurrentUser );
+    $o->Load($value);
+    $value = $o->Id || 0;
+    $sb->Limit(
+        FIELD         => $field,
+        OPERATOR      => $op,
+        VALUE         => $value,
+        CASESENSITIVE => 0,
+        @rest,
+    );
+}
+
 =head2 _TransDateLimit
 
 Handle fields limiting based on Transaction Date.
@@ -1289,7 +1339,7 @@ sub OrderByCols {
                 next;
             }
 
-            if ( $meta->[0] eq 'ENUM' && ($meta->[1]||'') eq 'Queue' ) {
+            if ( $meta->[0] eq 'QUEUE' ) {
                 my $alias = $self->Join(
                     TYPE   => 'LEFT',
                     ALIAS1 => 'main',

commit f0cf2d158d195741027b3ea9a12e0d30bcf3e1a3
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 23 11:46:30 2016 -0500

    Add matches and doesn't match options to query builder for queue
    
    The additional javascript also toggles between a dropdown with
    available queues for is/isn't and a text box for matches
    and doesn't match.

diff --git a/share/html/Search/Elements/PickBasics b/share/html/Search/Elements/PickBasics
index 4a794b1..6fcd8a4 100644
--- a/share/html/Search/Elements/PickBasics
+++ b/share/html/Search/Elements/PickBasics
@@ -83,8 +83,8 @@ my @lines = (
         Field => loc('Queue'),
         Op => {
             Type => 'component',
-            Path => '/Elements/SelectBoolean',
-            Arguments => { TrueVal=> '=', FalseVal => '!=' },
+            Path => '/Elements/SelectMatch',
+            Arguments => { Default => '=' },
         },
         Value => {
             Type => 'component',
@@ -226,6 +226,47 @@ my @lines = (
 $m->callback( Conditions => \@lines );
 
 </%INIT>
+
+<script type="text/javascript">
+    jQuery(function() {
+
+    // move the actual value to a hidden value, and shadow the others
+    var hidden = jQuery('<input>').attr('type','hidden').attr('name','ValueOfQueue')
+
+    // change the selector's name, but preserve the values, we'll set value via js
+    var selector = jQuery("[name='ValueOfQueue']");
+
+    // rename the selector so we don't get an extra term in the query
+    selector[0].name = "";
+    selector.bind('change',function() {
+        hidden[0].value = selector[0].value;
+    });
+
+    // create a text input box and hide it for use with matches / doesn't match
+    // NB: if you give text a name it will add an additional term to the query!
+    var text = jQuery('<input>').attr('type','text');
+    text.hide();
+    text.bind('change',function() {
+        hidden[0].value = text[0].value;
+    });
+
+    // hook the op field so that we can swap between the two input types
+    var op = jQuery("[name='QueueOp']");
+    op.bind('change',function() {
+        if (op[0].value == "=" || op[0].value == "!=" ) {
+            text.hide()
+            selector.show()
+        } else {
+            text.show()
+            selector.hide()
+        }
+    })
+
+    // add the fields to the DOM
+    selector.before(hidden);
+    selector.after(text);
+    });
+</script>
 <%ARGS>
 %queues => ()
 </%ARGS>

commit 46c6c6d6d090d61a356df630ca1ec0eb8e7518c4
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 23 11:55:59 2016 -0500

    Add QueueOp in tests to handle LIKE/NOT LIKE changes

diff --git a/t/web/cf_access.t b/t/web/cf_access.t
index 48ab5a2..059493e 100644
--- a/t/web/cf_access.t
+++ b/t/web/cf_access.t
@@ -223,6 +223,7 @@ $m->submit_form(
         idOp => '=',
         ValueOfid => $tid,
         ValueOfQueue => 'General',
+        QueueOp => '=',
     },
     button => 'AddClause',
 );
diff --git a/t/web/query_builder_queue_limits.t b/t/web/query_builder_queue_limits.t
index 6bbf333..c1f0a72 100644
--- a/t/web/query_builder_queue_limits.t
+++ b/t/web/query_builder_queue_limits.t
@@ -89,7 +89,7 @@ is_deeply(
 
 diag "limit queue to foo";
 $m->submit_form(
-    fields => { ValueOfQueue => 'foo' },
+    fields => { ValueOfQueue => 'foo', QueueOp => '=' },
     button => 'AddClause',
 );
 
@@ -114,7 +114,7 @@ is_deeply(
 diag "limit queue to general too";
 
 $m->submit_form(
-    fields => { ValueOfQueue => 'General' },
+    fields => { ValueOfQueue => 'General', QueueOp => '=' },
     button => 'AddClause',
 );
 

commit 1a87cb0855796df01d35624529f6c09de921f7b3
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 23 13:53:36 2016 -0500

    Add new queue LIKE and NOT LIKE tests

diff --git a/t/ticket/search.t b/t/ticket/search.t
index a43433f..dad94a1 100644
--- a/t/ticket/search.t
+++ b/t/ticket/search.t
@@ -150,11 +150,21 @@ is($tix->Count, 1, "matched identical subject")
     or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
 
 $tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL("Queue LIKE '$queue' AND CF.SearchTest = 'foo1'");
+is($tix->Count, 1, "matched identical subject and LIKE Queue")
+    or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
+
+$tix = RT::Tickets->new(RT->SystemUser);
 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo1'");
 is($tix->Count, 1, "matched LIKE subject")
     or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
 
 $tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL("Queue LIKE '$queue' AND CF.SearchTest LIKE 'foo1'");
+is($tix->Count, 1, "matched LIKE queue and LIKE subject")
+    or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
+
+$tix = RT::Tickets->new(RT->SystemUser);
 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest = 'foo'");
 is($tix->Count, 0, "IS a regexp match")
     or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
@@ -272,6 +282,10 @@ $tix->FromSQL("(CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3') AND (CF.Search
 is($tix->Count, 1, "(is cf1 or is cf1) and (is cf2 or is cf2)");
 
 $tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL("(Queue LIKE '$queue') AND (CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3') AND (CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2')");
+is($tix->Count, 1, "(queue LIKE) and (is cf1 or is cf1) and (is cf2 or is cf2)");
+
+$tix = RT::Tickets->new(RT->SystemUser);
 $tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3' OR CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2'");
 is($tix->Count, 3, "is cf1 or is cf1 or is cf2 or is cf2");
 
diff --git a/t/ticket/search_by_queue.t b/t/ticket/search_by_queue.t
index 0327152..cdfa23b 100644
--- a/t/ticket/search_by_queue.t
+++ b/t/ticket/search_by_queue.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use RT::Test nodata => 1, tests => 34;
+use RT::Test nodata => 1, no_plan => 1;
 use RT::Ticket;
 
 my $qa = RT::Test->load_or_create_queue( Name => 'Queue A' );
@@ -31,6 +31,16 @@ run_tests( \@tickets,
 
     'Queue = "Bad Queue"' => { a1 => 0, a2 => 0, b1 => 0, b2 => 0 },
     'Queue != "Bad Queue"' => { a1 => 1, a2 => 1, b1 => 1, b2 => 1 },
+
+    'Queue LIKE "Queue A"' => { a1 => 1, a2 => 1, b1 => 0, b2 => 0 },
+    'Queue LIKE "Queue B"' => { a1 => 0, a2 => 0, b1 => 1, b2 => 1 },
+    'Queue LIKE "Bad Queue"' => { a1 => 0, a2 => 0, b1 => 0, b2 => 0 },
+    'Queue LIKE "Queue"' => { a1 => 1, a2 => 1, b1 => 1, b2 => 1 },
+
+    'Queue NOT LIKE "Queue B"' => { a1 => 1, a2 => 1, b1 => 0, b2 => 0 },
+    'Queue NOT LIKE "Queue A"' => { a1 => 0, a2 => 0, b1 => 1, b2 => 1 },
+    'Queue NOT LIKE "Bad Queue"' => { a1 => 1, a2 => 1, b1 => 1, b2 => 1 },
+    'Queue NOT LIKE "Queue"' => { a1 => 0, a2 => 0, b1 => 0, b2 => 0 },
 );
 
 sub run_tests {

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


More information about the rt-commit mailing list