[Rt-commit] rt branch, 4.2/autocomplete-links, created. rt-4.1.13-27-g1b1fc42

? sunnavy sunnavy at bestpractical.com
Mon Jun 17 12:13:33 EDT 2013


The branch, 4.2/autocomplete-links has been created
        at  1b1fc4235139bc25a6d1ea1a90792715323ea440 (commit)

- Log -----------------------------------------------------------------
commit e0637e249a162a0185dc40ef3a09054f9b9e680f
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Mon Jan 3 20:39:09 2011 -0500

    Add ticket autocompleting for links

diff --git a/share/html/Elements/AddLinks b/share/html/Elements/AddLinks
index a859e8a..c2a2db8 100644
--- a/share/html/Elements/AddLinks
+++ b/share/html/Elements/AddLinks
@@ -71,32 +71,32 @@ my $id = ($Object and $Object->id)
 % if ($Merge) {
   <tr>
     <td class="label"><&|/l&>Merge into</&>:</td>
-    <td class="entry"><input name="<%$id%>-MergeInto" value="<% $ARGSRef->{"$id-MergeInto"} || '' %>" /> <i><&|/l&>(only one ticket)</&></i></td>
+    <td class="entry"><input name="<%$id%>-MergeInto" value="<% $ARGSRef->{"$id-MergeInto"} || '' %>" class="link_entry" /> <i><&|/l&>(only one ticket)</&></i></td>
   </tr>
 % }
   <tr>
     <td class="label"><& ShowRelationLabel, Object => $Object, Label => loc('Depends on').':', Relation => 'DependsOn' &></td>
-    <td class="entry"><input name="<%$id%>-DependsOn" value="<% $ARGSRef->{"$id-DependsOn"} || '' %>" /></td>
+    <td class="entry"><input name="<%$id%>-DependsOn" value="<% $ARGSRef->{"$id-DependsOn"} || '' %>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, Object => $Object, Label => loc('Depended on by').':', Relation => 'DependedOnBy' &></td>
-    <td class="entry"><input name="DependsOn-<%$id%>" value="<% $ARGSRef->{"DependsOn-$id"} || '' %>" /></td>
+    <td class="entry"><input name="DependsOn-<%$id%>" value="<% $ARGSRef->{"DependsOn-$id"} || '' %>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, Object => $Object, Label => loc('Parents').':', Relation => 'Parents' &></td>
-    <td class="entry"><input name="<%$id%>-MemberOf" value="<% $ARGSRef->{"$id-MemberOf"} || '' %>" /></td>
+    <td class="entry"><input name="<%$id%>-MemberOf" value="<% $ARGSRef->{"$id-MemberOf"} || '' %>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, Object => $Object, Label => loc('Children').':', Relation => 'Children' &></td>
-    <td class="entry"> <input name="MemberOf-<%$id%>" value="<% $ARGSRef->{"MemberOf-$id"} || '' %>" /></td>
+    <td class="entry"> <input name="MemberOf-<%$id%>" value="<% $ARGSRef->{"MemberOf-$id"} || '' %>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, Object => $Object, Label => loc('Refers to').':', Relation => 'RefersTo' &></td>
-    <td class="entry"><input name="<%$id%>-RefersTo" value="<% $ARGSRef->{"$id-RefersTo"} || '' %>" /></td>
+    <td class="entry"><input name="<%$id%>-RefersTo" value="<% $ARGSRef->{"$id-RefersTo"} || '' %>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, Object => $Object, Label => loc('Referred to by').':', Relation => 'ReferredToBy' &></td>
-    <td class="entry"> <input name="RefersTo-<%$id%>" value="<% $ARGSRef->{"RefersTo-$id"} || '' %>" /></td>
+    <td class="entry"> <input name="RefersTo-<%$id%>" value="<% $ARGSRef->{"RefersTo-$id"} || '' %>" class="link_entry" /></td>
   </tr>
   <& /Elements/EditCustomFields,
         Object          => $Object,
@@ -108,3 +108,11 @@ my $id = ($Object and $Object->id)
         &>
 % $m->callback( CallbackName => 'NewLink' );
 </table>
+
+% if (ref($Object) eq 'RT::Ticket') {
+<script type="text/javascript">
+    jQuery(".link_entry").autocomplete({
+        source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Tickets"
+    });
+</script>
+% }
diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
new file mode 100644
index 0000000..49c8bb6
--- /dev/null
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -0,0 +1,116 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2010 Best Practical Solutions, LLC
+%#                                          <jesse at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<% JSON::to_json( \@suggestions ) |n %>
+% $m->abort;
+<%ARGS>
+$return => ''
+$term => undef
+$delim => undef
+$max => 10
+$exclude => ''
+</%ARGS>
+<%INIT>
+require JSON;
+
+# Only allow certain return fields
+$return = 'id'
+    unless $return =~ /^(?:id|Subject)$/;
+
+$m->abort unless defined $return
+             and defined $term
+             and length $term;
+
+# Use our delimeter if we have one
+if ( defined $delim and length $delim ) {
+    if ( $delim eq ',' ) {
+        $delim = qr/,\s*/;
+    } else {
+        $delim = qr/\Q$delim\E/;
+    }
+
+    # If the field handles multiple values, pop the last one off
+    $term = (split $delim, $term)[-1] if $term =~ $delim;
+}
+
+my $CurrentUser = $session{'CurrentUser'};
+
+# Require privileged users
+$m->abort unless $CurrentUser->Privileged;
+
+my %fields = %{ RT->Config->Get('TicketAutocompleteFields')
+                || { id => '=' } };
+
+my $tickets = RT::Tickets->new( $CurrentUser );
+$tickets->RowsPerPage( $max );
+
+while (my ($name, $op) = each %fields) {
+    $op = 'STARTSWITH'
+        unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
+
+    $tickets->Limit(
+        FIELD           => $name,
+        OPERATOR        => $op,
+        VALUE           => $term,
+        ENTRYAGGREGATOR => 'OR',
+        SUBCLAUSE       => 'autocomplete',
+    );
+}
+
+# Exclude tickets we don't want
+foreach (split /\s*,\s*/, $exclude) {
+    $tickets->Limit(FIELD => 'id', VALUE => $_, OPERATOR => '!=');
+}
+
+my @suggestions;
+
+while ( my $ticket = $tickets->Next ) {
+    my $formatted = loc("#[_1]: [_2]", $ticket->Id, $ticket->Subject);
+    push @suggestions, { label => $formatted, value => $ticket->$return };
+}
+
+</%INIT>

commit 409cd68cbde1139a87ae668c4f89ccd1d5374843
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Mon Jan 3 20:41:34 2011 -0500

    Document $TicketAutocompleteFields

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 345a747..327917e 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1490,6 +1490,24 @@ your users.
 
 Set($AllowUserAutocompleteForUnprivileged, 0);
 
+=item C<$TicketAutocompleteFields>
+
+Specifies which fields of L<RT::Ticket> to match against and how to match each
+field when autocompleting users.  Valid match methods are LIKE, STARTSWITH,
+ENDSWITH, C<=>, and C<!=>.
+
+Not all Ticket fields are publically accessible and hence won't work for
+autocomplete unless you override their accessibility using a local overlay or a
+plugin.  Out of the box the following fields are public: id, Subject.
+
+Default: C<< Set( $TicketAutocompleteFields, { id => '=' })] ) >>
+
+=cut
+
+Set( $TicketAutocompleteFields, {
+    id => '=',
+});
+
 =item C<$DisplayTicketAfterQuickCreate>
 
 Enable this to redirect to the created ticket display page

commit 5e65675a8abd902cbb88d1e093fee5abb8047069
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Jan 4 18:13:33 2011 -0500

    Use STARTSWITH for Ticket id

diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
index 49c8bb6..190cca6 100644
--- a/share/html/Helpers/Autocomplete/Tickets
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -83,7 +83,7 @@ my $CurrentUser = $session{'CurrentUser'};
 $m->abort unless $CurrentUser->Privileged;
 
 my %fields = %{ RT->Config->Get('TicketAutocompleteFields')
-                || { id => '=' } };
+                || { id => 'STARTSWITH' } };
 
 my $tickets = RT::Tickets->new( $CurrentUser );
 $tickets->RowsPerPage( $max );

commit 3d27e68385f5b100834cceb9b8ba0d31606a8050
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Jan 4 18:15:59 2011 -0500

    Document and default ticket id autocomplete to use STARTSWITH

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 327917e..b0c6603 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1500,12 +1500,12 @@ Not all Ticket fields are publically accessible and hence won't work for
 autocomplete unless you override their accessibility using a local overlay or a
 plugin.  Out of the box the following fields are public: id, Subject.
 
-Default: C<< Set( $TicketAutocompleteFields, { id => '=' })] ) >>
+Default: C<< Set( $TicketAutocompleteFields, { id => 'STARTSWITH' })] ) >>
 
 =cut
 
 Set( $TicketAutocompleteFields, {
-    id => '=',
+    id => 'STARTSWITH',
 });
 
 =item C<$DisplayTicketAfterQuickCreate>

commit 4d38b32b22619a625265d26562b4fc7730ff4972
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Jan 5 16:56:05 2011 -0500

    Set Content-Type to application/json

diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
index 190cca6..332719f 100644
--- a/share/html/Helpers/Autocomplete/Tickets
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -45,6 +45,7 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
+% $r->content_type('application/json');
 <% JSON::to_json( \@suggestions ) |n %>
 % $m->abort;
 <%ARGS>

commit b8e12ab30bcf36ff37ca828ce1afe8758f80b718
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Mar 10 11:40:54 2011 -0500

    Lift the only-math-relations constraint on _IntLimit
    
        You can use LIKE on integers in SQLite, Postgres, and MySQL. This
        makes autocomplete on ticket IDs much more useful.
    
        And if you're using a database that doesn't support them, well,
        you'll still get an error, it'll just originate from a different layer.

diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 126bdc3..1ada41c 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -394,9 +394,6 @@ Meta Data:
 sub _IntLimit {
     my ( $sb, $field, $op, $value, @rest ) = @_;
 
-    die "Invalid Operator $op for $field"
-        unless $op =~ /^(=|!=|>|<|>=|<=)$/;
-
     $sb->Limit(
         FIELD    => $field,
         VALUE    => $value,

commit 5c3b44377795b721ca64965b71a89695785e0609
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Mar 10 12:13:39 2011 -0500

    Support limiting int ticket fields by LIKE on Postgres

diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 1ada41c..8fbc462 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -394,6 +394,21 @@ Meta Data:
 sub _IntLimit {
     my ( $sb, $field, $op, $value, @rest ) = @_;
 
+    my $is_a_like = $op =~ /MATCHES|ENDSWITH|STARTSWITH|LIKE/;
+
+    # We want to support <id LIKE '1%'> for ticket autocomplete,
+    # but we need to explicitly typecast on Postgres
+    if ( $is_a_like && RT->Config->Get('DatabaseType') eq 'Pg' ) {
+        return $sb->_SQLLimit(
+            # XXX: Nasty hack
+            ALIAS    => 'CAST( main',
+            FIELD    => $field . ' AS TEXT)',
+            OPERATOR => $op,
+            VALUE    => $value,
+            @rest,
+        );
+    }
+
     $sb->Limit(
         FIELD    => $field,
         VALUE    => $value,

commit c0befa14b6b39730552416cd39caf266d646ac2e
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Mar 11 12:37:23 2011 -0500

    Include Subject as a field to autocomplete tickets on
    
        Though right now ENTRYAGGREGATOR => 'OR' is not working, the query
        is getting AND..

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index b0c6603..82d4b01 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1500,12 +1500,11 @@ Not all Ticket fields are publically accessible and hence won't work for
 autocomplete unless you override their accessibility using a local overlay or a
 plugin.  Out of the box the following fields are public: id, Subject.
 
-Default: C<< Set( $TicketAutocompleteFields, { id => 'STARTSWITH' })] ) >>
-
 =cut
 
 Set( $TicketAutocompleteFields, {
-    id => 'STARTSWITH',
+    id      => 'STARTSWITH',
+    Subject => 'LIKE',
 });
 
 =item C<$DisplayTicketAfterQuickCreate>
diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
index 332719f..f9cc0e1 100644
--- a/share/html/Helpers/Autocomplete/Tickets
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -84,7 +84,7 @@ my $CurrentUser = $session{'CurrentUser'};
 $m->abort unless $CurrentUser->Privileged;
 
 my %fields = %{ RT->Config->Get('TicketAutocompleteFields')
-                || { id => 'STARTSWITH' } };
+                || { id => 'STARTSWITH', Subject => 'LIKE' } };
 
 my $tickets = RT::Tickets->new( $CurrentUser );
 $tickets->RowsPerPage( $max );

commit 15ec3ac2c7d04b96e0e608239ce4b5109bf0b70f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 14 23:33:22 2013 +0800

    use FromSQL to avoid the not working "ENTRYAGGREGATOR => 'OR'"
    
    see also c50c221

diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
index f9cc0e1..6f61766 100644
--- a/share/html/Helpers/Autocomplete/Tickets
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -87,21 +87,16 @@ my %fields = %{ RT->Config->Get('TicketAutocompleteFields')
                 || { id => 'STARTSWITH', Subject => 'LIKE' } };
 
 my $tickets = RT::Tickets->new( $CurrentUser );
-$tickets->RowsPerPage( $max );
 
+my @clauses;
 while (my ($name, $op) = each %fields) {
     $op = 'STARTSWITH'
         unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
-
-    $tickets->Limit(
-        FIELD           => $name,
-        OPERATOR        => $op,
-        VALUE           => $term,
-        ENTRYAGGREGATOR => 'OR',
-        SUBCLAUSE       => 'autocomplete',
-    );
+    push @clauses, qq{$name $op '$term'};
 }
-
+my $sql = join ' OR ', @clauses;
+$tickets->FromSQL($sql);
+$tickets->RowsPerPage( $max );
 # Exclude tickets we don't want
 foreach (split /\s*,\s*/, $exclude) {
     $tickets->Limit(FIELD => 'id', VALUE => $_, OPERATOR => '!=');

commit 234ff982046352067b861ce5ad627277b8c254f4
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 14 23:35:24 2013 +0800

    use \s+ as default delimiter since it's the one we use in EditLinks

diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
index 6f61766..5e463c5 100644
--- a/share/html/Helpers/Autocomplete/Tickets
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -77,6 +77,9 @@ if ( defined $delim and length $delim ) {
     # If the field handles multiple values, pop the last one off
     $term = (split $delim, $term)[-1] if $term =~ $delim;
 }
+else {
+    $term = (split /\s+/, $term)[-1];
+}
 
 my $CurrentUser = $session{'CurrentUser'};
 

commit e427967e43e9c79a98752dc8ef6c640ddedf3fe0
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 14 23:37:30 2013 +0800

    enhance autocomplete in EditLinks so we can keep multiple values

diff --git a/share/html/Elements/AddLinks b/share/html/Elements/AddLinks
index c2a2db8..00366eb 100644
--- a/share/html/Elements/AddLinks
+++ b/share/html/Elements/AddLinks
@@ -111,8 +111,20 @@ my $id = ($Object and $Object->id)
 
 % if (ref($Object) eq 'RT::Ticket') {
 <script type="text/javascript">
-    jQuery(".link_entry").autocomplete({
-        source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Tickets"
-    });
+    function split( val ) {
+        return val.split( /\s+/ );
+    }
+    var options = {
+        source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Tickets",
+        select: function( event, ui ) {
+            var terms = split( this.value );
+            terms.pop();
+            terms.push( ui.item.value );
+            terms.push( "" );
+            this.value = terms.join( " " );
+            return false;
+        }
+    };
+    jQuery(".link_entry").autocomplete( options );
 </script>
 % }

commit 1b1fc4235139bc25a6d1ea1a90792715323ea440
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 18 00:11:54 2013 +0800

    take care of "Merge into" link, which is for a *single* ticket only

diff --git a/share/html/Elements/AddLinks b/share/html/Elements/AddLinks
index 00366eb..4faffc5 100644
--- a/share/html/Elements/AddLinks
+++ b/share/html/Elements/AddLinks
@@ -71,7 +71,7 @@ my $id = ($Object and $Object->id)
 % if ($Merge) {
   <tr>
     <td class="label"><&|/l&>Merge into</&>:</td>
-    <td class="entry"><input name="<%$id%>-MergeInto" value="<% $ARGSRef->{"$id-MergeInto"} || '' %>" class="link_entry" /> <i><&|/l&>(only one ticket)</&></i></td>
+    <td class="entry"><input name="<%$id%>-MergeInto" value="<% $ARGSRef->{"$id-MergeInto"} || '' %>" class="link_entry single" /> <i><&|/l&>(only one ticket)</&></i></td>
   </tr>
 % }
   <tr>
@@ -117,12 +117,14 @@ my $id = ($Object and $Object->id)
     var options = {
         source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Tickets",
         select: function( event, ui ) {
-            var terms = split( this.value );
-            terms.pop();
-            terms.push( ui.item.value );
-            terms.push( "" );
-            this.value = terms.join( " " );
-            return false;
+            if ( jQuery(event.target).is(':not(.single)') ) {
+                var terms = split( this.value );
+                terms.pop();
+                terms.push( ui.item.value );
+                terms.push( "" );
+                this.value = terms.join( " " );
+                return false;
+            }
         }
     };
     jQuery(".link_entry").autocomplete( options );

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


More information about the Rt-commit mailing list