[Rt-commit] rt branch 5.0/tweak-query-builder-criteria created. rt-5.0.1-610-g385718d876

BPS Git Server git at git.bestpractical.com
Tue Aug 17 14:28:25 UTC 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/tweak-query-builder-criteria has been created
        at  385718d876731bdbf05f9a82e53e768ae4d4d159 (commit)

- Log -----------------------------------------------------------------
commit 385718d876731bdbf05f9a82e53e768ae4d4d159
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jun 19 02:01:02 2021 +0800

    Merge custom field criteria in search builder
    
    This makes UI more compact especially when there are many custom fields.

diff --git a/share/html/Search/Elements/ConditionRow b/share/html/Search/Elements/ConditionRow
index f200fda63d..df26d50bab 100644
--- a/share/html/Search/Elements/ConditionRow
+++ b/share/html/Search/Elements/ConditionRow
@@ -45,7 +45,7 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<div class="form-row">
+<div class="form-row <% $Condition->{Class} || '' %>">
   <div class="label col-3">
     <% $handle_block->( $Condition->{'Field'}, $Condition->{'Name'} .'Field' ) |n %>
   </div>
@@ -89,7 +89,8 @@ $handle_block = sub {
     }
     if ( $box->{'Type'} eq 'select' ) {
         my $res = '';
-        $res .= qq{<select id="$name" name="$name" class="form-control selectpicker">};
+        my $id = $box->{Id} // $name;
+        $res .= qq{<select id="$id" name="$name" class="form-control selectpicker">};
         my @options = @{ $box->{'Options'} };
         while( defined( my $k = shift @options ) ) {
             my $v = shift @options;
diff --git a/share/html/Search/Elements/PickCFs b/share/html/Search/Elements/PickCFs
index cd136bd902..bb46a6ca41 100644
--- a/share/html/Search/Elements/PickCFs
+++ b/share/html/Search/Elements/PickCFs
@@ -57,7 +57,7 @@ $m->callback(
 
 my @lines;
 while ( my $CustomField = $CustomFields->Next ) {
-    my %line;
+    my %line = ( Class => 'hidden' );
     $line{'Name'} = "$TicketSQLField.{" . $CustomField->Name . "}";
     $line{'Field'} = $CustomField->Name;
 
@@ -99,6 +99,28 @@ while ( my $CustomField = $CustomFields->Next ) {
 
 $m->callback( Conditions => \@lines, Queues => \%queues );
 
+if (@lines) {
+    my %lines = (
+        Name  => 'SelectCustomField',
+        Field => {
+            Type    => 'select',
+            Options => [ '' => loc('Select Custom Field'), map { $_->{Name}, $_->{Field} } @lines ],
+        },
+        Op => {
+            Type      => 'component',
+            Path      => '/Elements/SelectCustomFieldOperator',
+            Arguments => {
+                True     => loc("is"),
+                False    => loc("isn't"),
+                TrueVal  => '=',
+                FalseVal => '!=',
+            },
+        },
+        Value => { Type => 'text', Size => 20, Id => '' },
+    );
+    push @lines, \%lines for 1 .. ( $TicketSQLField eq 'CF' ? 3 : 1 );
+}
+
 </%INIT>
 
 <%ARGS>
diff --git a/share/static/js/util.js b/share/static/js/util.js
index 5c0c7fc18f..609d72e2b5 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -862,6 +862,36 @@ jQuery(function() {
             file_input.prop('checked', false);
         });
     });
+
+    jQuery('form[name=BuildQuery] select[name^=SelectCustomField]').change(function() {
+        var form = jQuery(this).closest('form');
+        var row = jQuery(this).closest('div.form-row');
+        var val = jQuery(this).val();
+
+        var new_operator = form.find(':input[name="' + val + 'Op"]:first').clone();
+        row.children('div.operator').children().remove();
+        row.children('div.operator').append(new_operator);
+        row.children('div.operator').find('select.selectpicker').selectpicker();
+
+        var new_value = form.find(':input[name="ValueOf' + val + '"]:first');
+        if ( new_value.hasClass('ui-autocomplete-input') ) {
+            var source = new_value.autocomplete( "option" ).source;
+            new_value = new_value.clone();
+            new_value.autocomplete({ source: source });
+        }
+        else {
+            new_value = new_value.clone();
+        }
+
+        new_value.attr('id', null);
+        row.children('div.value').children().remove();
+        row.children('div.value').append(new_value);
+        row.children('div.value').find('select.selectpicker').selectpicker();
+        if ( new_value.hasClass('datepicker') ) {
+            new_value.removeClass('hasDatepicker');
+            initDatePicker(row);
+        }
+    });
 });
 
 /* inline edit */

commit b5a2dc0f143e3f6c87266e77fdb062768e36691e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jun 18 23:12:16 2021 +0800

    Merge custom roles criteria in search builder
    
    This makes UI more compact especially when there are many custom roles.

diff --git a/share/html/Search/Elements/PickCustomRoles b/share/html/Search/Elements/PickCustomRoles
index b57ae5bd68..cd55a95bed 100644
--- a/share/html/Search/Elements/PickCustomRoles
+++ b/share/html/Search/Elements/PickCustomRoles
@@ -63,19 +63,20 @@ $m->callback(
 );
 
 my @lines;
-while ( my $Role = $CustomRoles->Next ) {
-    my $name = "CustomRole.{" . $Role->Name . "}";
+
+if (my @roles = @{$CustomRoles->ItemsArrayRef}) {
+    my $name = 'CustomRole';
     my %line = (
-        Name => $name,
+        Name  => $name,
         Field => {
-            Type => 'component',
-            Path => 'SelectPersonType',
-            Arguments => { Role => $Role, Default => $name },
+            Type      => 'component',
+            Path      => 'SelectPersonType',
+            Arguments => { Roles => \@roles, Default => "CustomRole.{" . $roles[0]->Name . "}" },
         },
         Op => {
-            Type => 'component',
-            Path => '/Elements/SelectMatch',
-            Arguments => { IncludeShallow => $Role->SingleValue ? 0 : 1 },
+            Type      => 'component',
+            Path      => '/Elements/SelectMatch',
+            Arguments => { IncludeShallow => grep( { !$_->MaxValues } @roles ) ? 1 : 0 },
         },
         Value => { Type => 'text', Size => 20 },
     );
diff --git a/share/html/Search/Elements/SelectPersonType b/share/html/Search/Elements/SelectPersonType
index ffb07e3641..c4ee5c3723 100644
--- a/share/html/Search/Elements/SelectPersonType
+++ b/share/html/Search/Elements/SelectPersonType
@@ -94,6 +94,9 @@ else {
           [ "CustomRole.{" . $Role->Name . "}", $Role->Name ],
        );
    }
+   elsif (@Roles) {
+      @types = map { [ "CustomRole.{" . $_->Name . "}", $_->Name ] } @Roles;
+   }
    elsif ($Scope =~ /queue/) {
       @types = qw(Cc AdminCc);
    }
@@ -118,4 +121,5 @@ $Class => 'RT::Tickets'
 $Scope => $Class eq 'RT::Assets' ? 'asset' : 'ticket'
 $Name => 'WatcherType'
 $Role => undef
+ at Roles => ()
 </%ARGS>

commit adfd9efa976431df0d3650a100ff4317cd40b942
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jun 18 16:45:11 2021 +0800

    Split the select of watcher criteria into two in query builder
    
    This is because the options list is too long with one single select. Now
    the former is for watcher type(e.g. "Requestors"), the latter is for
    watcher field(e.g. "EmailAddress").

diff --git a/share/html/Search/Build.html b/share/html/Search/Build.html
index a9c2a6215f..9b78f4f7bd 100644
--- a/share/html/Search/Build.html
+++ b/share/html/Search/Build.html
@@ -277,6 +277,7 @@ foreach my $arg ( keys %ARGS ) {
 
     #figure out if it's a grouping
     my $keyword = $ARGS{ $field . "Field" } || $field;
+    $keyword .= '.' . $ARGS{ $field . "FieldSubType" } if $ARGS{ $field . "FieldSubType" };
 
     my ( @ops, @values );
     if ( ref $ARGS{ 'ValueOf' . $field } eq "ARRAY" ) {
diff --git a/share/html/Search/Elements/SelectPersonType b/share/html/Search/Elements/SelectPersonType
index 0aa0ba78ec..ffb07e3641 100644
--- a/share/html/Search/Elements/SelectPersonType
+++ b/share/html/Search/Elements/SelectPersonType
@@ -45,6 +45,9 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
+<div class="form-row my-0">
+  <div class="col-<% $Suffix ? 12 : 6 %>">
+
 <select id="<%$Name%>" name="<%$Name%>" class="form-control selectpicker">
 % if ($AllowNull) {
 <option value="">-</option>
@@ -59,12 +62,25 @@
 <option value="<% $value %><% $Suffix %>"<%$value eq $Default && qq[ selected="selected"] |n %> ><% loc($label) %> <% loc('Group') %></option>
 %   next;
 %  }
-%  foreach my $subtype (@subtypes) {
-<option value="<%"$value.$subtype"%>"<%$value eq $Default && $subtype eq 'EmailAddress' && qq[ selected="selected"] |n %> ><% loc($label) %> <% loc($subtype) %></option>
-%  }
+<option value="<%$value%>"<% $value eq $Default && qq[ selected="selected"] |n %> ><% loc($label) %></option>
 % }
 </select>
 
+  </div>
+
+% if (!$Suffix) {
+  <div class="col-6">
+%   my $Name = $Name . 'SubType';
+    <select id="<%$Name%>" name="<%$Name%>" class="form-control selectpicker">
+%   foreach my $subtype (@subtypes) {
+      <option value="<%$subtype%>"<% $subtype eq 'EmailAddress' && qq[ selected="selected"] |n %> ><% loc($subtype) %></option>
+%   }
+    </select>
+  </div>
+% }
+
+</div>
+
 <%INIT>
 my ( @types, @subtypes );
 if ( $Class eq 'RT::Assets' ) {
diff --git a/t/web/search_assets.t b/t/web/search_assets.t
index cdf36b1b27..6ef248699b 100644
--- a/t/web/search_assets.t
+++ b/t/web/search_assets.t
@@ -27,13 +27,10 @@ diag "Query builder";
     my $form = $m->form_name('BuildQuery');
     is_deeply( [$form->find_input('AttachmentField')->possible_values], [qw/Name Description/], 'AttachmentField options' );
 
-    my @watcher_options = ( '' );
-    for my $role ( qw/Owner HeldBy Contact/ ) {
-        for my $field ( qw/EmailAddress Name RealName Nickname Organization Address1 Address2 City State Zip Country WorkPhone HomePhone MobilePhone PagerPhone id/ ) {
-            push @watcher_options, "$role.$field";
-        }
-    }
+    my @watcher_options = ( '', qw/Owner HeldBy Contact/ );
     is_deeply( [ $form->find_input('WatcherField')->possible_values ], \@watcher_options, 'WatcherField options' );
+    my @watcher_sub_options = qw/EmailAddress Name RealName Nickname Organization Address1 Address2 City State Zip Country WorkPhone HomePhone MobilePhone PagerPhone id/;
+    is_deeply( [ $form->find_input('WatcherFieldSubType')->possible_values ], \@watcher_sub_options, 'WatcherFieldSubType options' );
 
     $m->field( ValueOfCatalog => 'General assets' );
     $m->click('AddClause');

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list