[Rt-commit] rt branch, 4.4/attachments-list, updated. rt-4.4.0-52-g588482f

Shawn Moore shawn at bestpractical.com
Wed Feb 17 00:29:58 EST 2016


The branch, 4.4/attachments-list has been updated
       via  588482ffa00995302a466c1ba25403f930ae1ac6 (commit)
       via  a278d423a386b18f3af391934021e1b8d93c898f (commit)
       via  95bcd0c3fd77701a75afaf1b280b2c3d28e7928d (commit)
       via  d1ea5a604027c3c1d05f3298b6ec69461680ec46 (commit)
       via  3530501d7919056665d3e2d6b04cefafd77daa8e (commit)
      from  9de4ca7675f8398d7ef78992d1817f91b8d050b1 (commit)

Summary of changes:
 .../{Toggle/TicketBookmark => TicketAttachments}   | 16 ++++--
 share/html/Ticket/Elements/AddAttachments          |  1 +
 share/html/Ticket/Elements/ShowAttachments         | 62 ++++++++++++++++++++--
 share/html/Ticket/Elements/ShowSummary             |  2 +-
 4 files changed, 73 insertions(+), 8 deletions(-)
 copy share/html/Helpers/{Toggle/TicketBookmark => TicketAttachments} (85%)

- Log -----------------------------------------------------------------
commit 3530501d7919056665d3e2d6b04cefafd77daa8e
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Feb 17 04:41:53 2016 +0000

    Filter out empty attachment names in SQL rather than Perl
    
        Cloning is necessary when you ShowHistory is set to immediate,
        as the Attachments object is shared across this template and
        the transaction log; without ->Clone, all messages are filtered
        away.

diff --git a/share/html/Ticket/Elements/ShowAttachments b/share/html/Ticket/Elements/ShowAttachments
index d9432b7..b6a9d85 100644
--- a/share/html/Ticket/Elements/ShowAttachments
+++ b/share/html/Ticket/Elements/ShowAttachments
@@ -95,11 +95,20 @@
 # then we need to find one
 $Attachments ||= $Ticket->Attachments;
 
-# XXX PERF: why doesn't this Limit on Filename to avoid fetching *all* the
-# attachments?
+# Avoid applying limits to this collection that may be used elsewhere
+# (e.g. transaction display)
+$Attachments = $Attachments->Clone;
+
+# Remember, each message in a transaction is an attachment; we only
+# want named attachments (real files)
+$Attachments->Limit(
+    FIELD    => 'Filename',
+    OPERATOR => '!=',
+    VALUE    => '',
+);
+
 my %documents;
 while ( my $attach = $Attachments->Next() ) {
-    next unless defined $attach->Filename && length $attach->Filename;
    unshift( @{ $documents{ $attach->Filename } }, $attach );
 }
 

commit d1ea5a604027c3c1d05f3298b6ec69461680ec46
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Feb 17 04:57:44 2016 +0000

    Add a way to display just the last N attachments

diff --git a/share/html/Ticket/Elements/AddAttachments b/share/html/Ticket/Elements/AddAttachments
index 34798e2..fb4ec23 100644
--- a/share/html/Ticket/Elements/AddAttachments
+++ b/share/html/Ticket/Elements/AddAttachments
@@ -172,6 +172,7 @@ jQuery( function() {
       Selectable   => 1,
       HideTitleBox => 1,
       Checked      => \@AttachExisting,
+      Count        => 5,
     &>
   </td>
 </tr>
diff --git a/share/html/Ticket/Elements/ShowAttachments b/share/html/Ticket/Elements/ShowAttachments
index b6a9d85..3ff586e 100644
--- a/share/html/Ticket/Elements/ShowAttachments
+++ b/share/html/Ticket/Elements/ShowAttachments
@@ -108,7 +108,20 @@ $Attachments->Limit(
 );
 
 my %documents;
+
+# if we're limiting the number of attachments, show only the most recent
+# if we're not limiting the number, order doesn't much matter
+if (defined($Count)) {
+    $Attachments->OrderByCols(
+        { FIELD => 'Created', ORDER => 'DESC' },
+        { FIELD => 'id', ORDER => 'DESC' },
+    );
+}
+
 while ( my $attach = $Attachments->Next() ) {
+   if (defined($Count) && --$Count < 0) {
+       last;
+   }
    unshift( @{ $documents{ $attach->Filename } }, $attach );
 }
 
@@ -120,6 +133,7 @@ $Attachments => undef
 $DisplayPath => $session{'CurrentUser'}->Privileged ? 'Ticket' : 'SelfService'
 $HideTitleBox => 0
 $Selectable => 0
+$Count => undef
 @Checked => ()
 </%ARGS>
 
diff --git a/share/html/Ticket/Elements/ShowSummary b/share/html/Ticket/Elements/ShowSummary
index f891631..4183dab 100644
--- a/share/html/Ticket/Elements/ShowSummary
+++ b/share/html/Ticket/Elements/ShowSummary
@@ -64,7 +64,7 @@
         class => 'ticket-info-people',
     &><& /Ticket/Elements/ShowPeople, Ticket => $Ticket &></&>
 % $m->callback( %ARGS, CallbackName => 'AfterPeople' );
-    <& /Ticket/Elements/ShowAttachments, Ticket => $Ticket, Attachments => $Attachments &>
+    <& /Ticket/Elements/ShowAttachments, Ticket => $Ticket, Attachments => $Attachments, Count => 5 &>
 % $m->callback( %ARGS, CallbackName => 'AfterAttachments' );
     <& /Ticket/Elements/ShowRequestor, Ticket => $Ticket &>
 % $m->callback( %ARGS, CallbackName => 'LeftColumn' );

commit 95bcd0c3fd77701a75afaf1b280b2c3d28e7928d
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Feb 17 05:08:24 2016 +0000

    Add ajaxified "Show all attachments" button
    
    Fixes: I#31710

diff --git a/share/html/Helpers/TicketAttachments b/share/html/Helpers/TicketAttachments
new file mode 100644
index 0000000..2292a45
--- /dev/null
+++ b/share/html/Helpers/TicketAttachments
@@ -0,0 +1,63 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
+%#                                          <sales 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 }}}
+<%ARGS>
+$id
+$Selectable => undef
+$Count => undef
+</%ARGS>
+<%INIT>
+my $TicketObj = RT::Ticket->new($session{'CurrentUser'});
+$TicketObj->Load($id);
+</%INIT>
+<& /Ticket/Elements/ShowAttachments,
+  Ticket       => $TicketObj,
+  HideTitleBox => 1,
+  Selectable   => $Selectable,
+  Count        => $Count,
+&>
+% $m->abort();
diff --git a/share/html/Ticket/Elements/ShowAttachments b/share/html/Ticket/Elements/ShowAttachments
index 3ff586e..f878381 100644
--- a/share/html/Ticket/Elements/ShowAttachments
+++ b/share/html/Ticket/Elements/ShowAttachments
@@ -52,6 +52,8 @@
         color => "#336699",
         hide_chrome => $HideTitleBox &>
 
+<div class="attachment-list">
+
 % foreach my $key (sort { lc($a) cmp lc($b) } keys %documents) {
 
 <%$key%><br />
@@ -85,6 +87,21 @@
 </ul>
 
 % }
+
+% if ($show_more) {
+<span class="show-more-link">
+% my %params = %ARGS;
+% delete $params{Ticket};
+% delete $params{Attachments};
+% delete $params{Count};
+
+% my $query = $m->comp('/Elements/QueryString', %params, id => $Ticket->id );
+% my $url   = RT->Config->Get('WebPath')."/Helpers/TicketAttachments?$query";
+<a href="#" onclick="jQuery(this).parent().text(<% loc('Loading...') | n,j%>).closest('.attachment-list').load(<% $url |n,j %>); return false;" ><% loc('Show all attachments') %></a>
+</span>
+% }
+
+</div>
 </&>
 
 % }
@@ -107,6 +124,7 @@ $Attachments->Limit(
     VALUE    => '',
 );
 
+my $show_more = 0;
 my %documents;
 
 # if we're limiting the number of attachments, show only the most recent
@@ -119,7 +137,9 @@ if (defined($Count)) {
 }
 
 while ( my $attach = $Attachments->Next() ) {
+   # display "show more" only when there will be more attachments
    if (defined($Count) && --$Count < 0) {
+       $show_more = 1;
        last;
    }
    unshift( @{ $documents{ $attach->Filename } }, $attach );

commit a278d423a386b18f3af391934021e1b8d93c898f
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Feb 17 05:25:32 2016 +0000

    Preserve selected attachments when loading the rest in via ajax

diff --git a/share/html/Helpers/TicketAttachments b/share/html/Helpers/TicketAttachments
index 2292a45..c4de7e9 100644
--- a/share/html/Helpers/TicketAttachments
+++ b/share/html/Helpers/TicketAttachments
@@ -49,6 +49,7 @@
 $id
 $Selectable => undef
 $Count => undef
+ at AttachExisting => ()
 </%ARGS>
 <%INIT>
 my $TicketObj = RT::Ticket->new($session{'CurrentUser'});
@@ -59,5 +60,6 @@ $TicketObj->Load($id);
   HideTitleBox => 1,
   Selectable   => $Selectable,
   Count        => $Count,
+  Checked      => \@AttachExisting,
 &>
 % $m->abort();
diff --git a/share/html/Ticket/Elements/ShowAttachments b/share/html/Ticket/Elements/ShowAttachments
index f878381..5c8022f 100644
--- a/share/html/Ticket/Elements/ShowAttachments
+++ b/share/html/Ticket/Elements/ShowAttachments
@@ -94,10 +94,24 @@
 % delete $params{Ticket};
 % delete $params{Attachments};
 % delete $params{Count};
-
 % my $query = $m->comp('/Elements/QueryString', %params, id => $Ticket->id );
 % my $url   = RT->Config->Get('WebPath')."/Helpers/TicketAttachments?$query";
-<a href="#" onclick="jQuery(this).parent().text(<% loc('Loading...') | n,j%>).closest('.attachment-list').load(<% $url |n,j %>); return false;" ><% loc('Show all attachments') %></a>
+
+<script type="text/javascript">
+    function showAllAttachments(node) {
+        var container = node.closest('.attachment-list');
+        var params = node.closest('form').find('input[name=AttachExisting]').serialize();
+
+        node.parent().text(<% loc('Loading...') | n,j%>);
+
+        var url = <% $url |n,j %>;
+        if (params) url += '&' + params;
+        container.load(url);
+    }
+</script>
+
+<a href="#" onclick="showAllAttachments(jQuery(this)); return false;" ><% loc('Show all attachments') %></a>
+
 </span>
 % }
 

commit 588482ffa00995302a466c1ba25403f930ae1ac6
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Feb 17 05:28:37 2016 +0000

    Always pull out attachments in newest-first order
    
        Without this change, the order of attachments with the
        same name would reverse based on whether you provided a $Count
        or not.

diff --git a/share/html/Ticket/Elements/ShowAttachments b/share/html/Ticket/Elements/ShowAttachments
index 5c8022f..ac663a9 100644
--- a/share/html/Ticket/Elements/ShowAttachments
+++ b/share/html/Ticket/Elements/ShowAttachments
@@ -141,14 +141,11 @@ $Attachments->Limit(
 my $show_more = 0;
 my %documents;
 
-# if we're limiting the number of attachments, show only the most recent
-# if we're not limiting the number, order doesn't much matter
-if (defined($Count)) {
-    $Attachments->OrderByCols(
-        { FIELD => 'Created', ORDER => 'DESC' },
-        { FIELD => 'id', ORDER => 'DESC' },
-    );
-}
+# show newest first
+$Attachments->OrderByCols(
+    { FIELD => 'Created', ORDER => 'DESC' },
+    { FIELD => 'id',      ORDER => 'DESC' },
+);
 
 while ( my $attach = $Attachments->Next() ) {
    # display "show more" only when there will be more attachments
@@ -156,7 +153,7 @@ while ( my $attach = $Attachments->Next() ) {
        $show_more = 1;
        last;
    }
-   unshift( @{ $documents{ $attach->Filename } }, $attach );
+   push @{ $documents{ $attach->Filename } }, $attach;
 }
 
 my %is_checked = map { $_ => 1 } @Checked;

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


More information about the rt-commit mailing list