[Rt-commit] rt branch, 4.2/autocomplete-links, created. rt-4.0.0rc6-174-gda32fad

Shawn Moore sartak at bestpractical.com
Fri Mar 11 12:13:05 EST 2011


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

- Log -----------------------------------------------------------------
commit 93b447a96a8601fdf4c43c6e131cd0d0b5620287
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Mon Jan 3 20:38:02 2011 -0500

    Allow = and != relations for User autocomplete

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index fc755c9..3aade41 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1690,7 +1690,7 @@ Set($OnlySearchActiveTicketsInSimpleSearch, 1);
 
 Specifies which fields of L<RT::User> to match against and how to match each
 field when autocompleting users.  Valid match methods are LIKE, STARTSWITH,
-ENDSWITH, =, and !=.
+ENDSWITH, C<=>, and C<!=>.
 
 Not all User fields are publically accessible and hence won't work for
 autocomplete unless you override their accessibility using a local overlay or a

commit 1690bdb8672e247e8cf9485ae187bd68a8940c0c
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/EditLinks b/share/html/Elements/EditLinks
index 05a9280..993a98f 100755
--- a/share/html/Elements/EditLinks
+++ b/share/html/Elements/EditLinks
@@ -131,32 +131,32 @@
 % if ($Merge) {
   <tr>
     <td class="label"><&|/l&>Merge into</&>:</td>
-    <td class="entry"><input name="<%$id%>-MergeInto" /> <i><&|/l&>(only one ticket)</&></i></td>
+    <td class="entry"><input name="<%$id%>-MergeInto" class="link_entry" /> <i><&|/l&>(only one ticket)</&></i></td>
   </tr>
 % }
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Depends on'), Relation => 'DependsOn' &>:</td>
-    <td class="entry"><input name="<%$id%>-DependsOn" /></td>
+    <td class="entry"><input name="<%$id%>-DependsOn" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Depended on by'), Relation => 'DependedOnBy' &>:</td>
-    <td class="entry"><input name="DependsOn-<%$id%>" /></td>
+    <td class="entry"><input name="DependsOn-<%$id%>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Parents'), Relation => 'Parents' &>:</td>
-    <td class="entry"><input name="<%$id%>-MemberOf" /></td>
+    <td class="entry"><input name="<%$id%>-MemberOf" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Children'), Relation => 'Children' &>:</td>
-    <td class="entry"> <input name="MemberOf-<%$id%>" /></td>
+    <td class="entry"> <input name="MemberOf-<%$id%>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Refers to'), Relation => 'RefersTo' &>:</td>
-    <td class="entry"><input name="<%$id%>-RefersTo" /></td>
+    <td class="entry"><input name="<%$id%>-RefersTo" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Referred to by'), Relation => 'ReferredToBy' &>:</td>
-    <td class="entry"> <input name="RefersTo-<%$id%>" /></td>
+    <td class="entry"> <input name="RefersTo-<%$id%>" class="link_entry" /></td>
   </tr>
 % $m->callback( CallbackName => 'NewLink' );
 </table>
@@ -164,6 +164,11 @@
 </tr>
 </table>
 
+<script type="text/javascript">
+    jQuery(".link_entry").autocomplete({
+        source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Tickets"
+    });
+</script>
 <%INIT>
 my $id;
 if ($Object && $Object->Id) {
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 2663768aca4e3a501fbbbc10c52ac7c2249330ee
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 3aade41..0c09f83 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1719,6 +1719,24 @@ Default: C<< Set( $AllowUserAutocompleteForUnprivileged, 0 ) >>
 
 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 automatically

commit e268c3f7fe0f6bddb8f7da6494dc4b084d3ae212
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 d41d6acb6982197506c672240a1859a2a7a159b3
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 0c09f83..f88fd6a 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1729,12 +1729,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 a348b61432294ce495fd6adca990004a0a164f0f
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 692454ce469ed75136ddd25a9ee2575f96e828d8
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 3b01bdd..b5144dc 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -384,9 +384,6 @@ Meta Data:
 sub _IntLimit {
     my ( $sb, $field, $op, $value, @rest ) = @_;
 
-    die "Invalid Operator $op for $field"
-        unless $op =~ /^(=|!=|>|<|>=|<=)$/;
-
     $sb->_SQLLimit(
         FIELD    => $field,
         VALUE    => $value,

commit da32fad1f8458d36c2a73c9afe7b06ae85eb09de
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 b5144dc..4a0ea08 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -384,6 +384,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->_SQLLimit(
         FIELD    => $field,
         VALUE    => $value,

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


More information about the Rt-commit mailing list