[Rt-commit] rt branch, 4.2/queue-like-search, created. rt-4.2.13-74-g64bdfad

Dave Goehrig dave at bestpractical.com
Wed Dec 21 14:51:44 EST 2016


The branch, 4.2/queue-like-search has been created
        at  64bdfad1c7f2a8b5399f85874d7a92a200007ed9 (commit)

- Log -----------------------------------------------------------------
commit 64bdfad1c7f2a8b5399f85874d7a92a200007ed9
Author: Dave Goehrig <dave at bestpractical.com>
Date:   Wed Dec 21 14:49:39 2016 -0500

    Add queue like/not like search query

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',
diff --git a/share/html/Search/Elements/PickBasics b/share/html/Search/Elements/PickBasics
index 4a794b1..b4c3045 100644
--- a/share/html/Search/Elements/PickBasics
+++ b/share/html/Search/Elements/PickBasics
@@ -83,8 +83,7 @@ my @lines = (
         Field => loc('Queue'),
         Op => {
             Type => 'component',
-            Path => '/Elements/SelectBoolean',
-            Arguments => { TrueVal=> '=', FalseVal => '!=' },
+            Path => '/Elements/SelectMatch'
         },
         Value => {
             Type => 'component',
@@ -226,6 +225,48 @@ 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()
+        }
+    })
+    op[0].value = "=";        // select "is" by default rather than "match"
+
+    // add the fields to the DOM
+    selector.before(hidden);
+    selector.after(text);
+    });
+</script>
 <%ARGS>
 %queues => ()
 </%ARGS>
diff --git a/t/ticket/sort-by-queue.t b/t/ticket/sort-by-queue.t
index f54ccf7..e87a78c 100644
--- a/t/ticket/sort-by-queue.t
+++ b/t/ticket/sort-by-queue.t
@@ -84,3 +84,4 @@ sub run_tests {
 run_tests();
 
 @tickets = ();
+
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',
 );
 

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


More information about the rt-commit mailing list