[Rt-commit] rt branch, 5.0/tweak-query-builder-criteria, created. rt-5.0.1-469-g203a1e2f58

? sunnavy sunnavy at bestpractical.com
Fri Jun 18 18:18:29 EDT 2021


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

- Log -----------------------------------------------------------------
commit c19552a13de23589d5032085a756f664be3b0e32
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 dc576ba52b..3da5b87a81 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');

commit a5eafcf8764d96188be00c564a8676c5fb5e6411
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 203a1e2f583287652da2898562b8202b4204f9c6
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..de2f1ca940 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 .. 3;
+}
+
 </%INIT>
 
 <%ARGS>
diff --git a/share/static/js/util.js b/share/static/js/util.js
index bd9cc01a5a..72c127273f 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -826,6 +826,36 @@ jQuery(function() {
             });
         });
     }
+
+    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 */

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


More information about the rt-commit mailing list