[Rt-commit] rt branch, 5.0/reverse-transaction-history, updated. rt-5.0.0alpha1-99-gd2e716c0dc

Jim Brandt jbrandt at bestpractical.com
Fri Apr 10 11:01:53 EDT 2020


The branch, 5.0/reverse-transaction-history has been updated
       via  d2e716c0dcb121d82ea32ddef2ea576259c8236e (commit)
      from  1a7ca57feaefbd7a8d3148e9a920a8ef57a0fede (commit)

Summary of changes:
 lib/RT/Record.pm                             | 15 +++++++++++++--
 share/html/Elements/ShowHistoryHeader        | 16 ++++++++++++++++
 share/html/Elements/ShowHistoryPage          |  4 ++++
 share/html/Helpers/TicketHistory             |  1 +
 share/html/Ticket/Display.html               | 12 +++++++++++-
 share/html/Ticket/Elements/ScrollShowHistory | 10 ++++++++--
 6 files changed, 53 insertions(+), 5 deletions(-)

- Log -----------------------------------------------------------------
commit d2e716c0dcb121d82ea32ddef2ea576259c8236e
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Apr 10 09:39:32 2020 -0400

    Add an option to reverse the transaction history on ticket display
    
    The order of transactions on ticket display can be set globally
    and per user. This new option allows you to reverse the order
    on an individual ticket.

diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 5b2b8d2d31..99242eac13 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1729,13 +1729,24 @@ sub Transactions {
 Returns the result of L</Transactions> ordered per the
 I<OldestTransactionsFirst> preference/option.
 
+Pass an optional value 'ASC' or 'DESC' to force a specific
+order.
+
 =cut
 
 sub SortedTransactions {
     my $self  = shift;
+    my $order = shift || 0;
     my $txns  = $self->Transactions;
-    my $order = RT->Config->Get("OldestTransactionsFirst", $self->CurrentUser)
-        ? 'ASC' : 'DESC';
+
+    if ( $order && ( $order eq 'ASC' || $order eq 'DESC' ) ) {
+        # Use provided value
+    }
+    else {
+        $order = RT->Config->Get("OldestTransactionsFirst", $self->CurrentUser)
+            ? 'ASC' : 'DESC';
+    }
+
     $txns->OrderByCols(
         { FIELD => 'Created',   ORDER => $order },
         { FIELD => 'id',        ORDER => $order },
diff --git a/share/html/Elements/ShowHistoryHeader b/share/html/Elements/ShowHistoryHeader
index c12fce532e..6c8464759c 100644
--- a/share/html/Elements/ShowHistoryHeader
+++ b/share/html/Elements/ShowHistoryHeader
@@ -55,6 +55,17 @@ $ScrollShowHistory => 0
 <%INIT>
 my $record_type = $Object->RecordType;
 my $histid      = "\L$record_type\E-" . $Object->id . "-history";
+
+my $reverse_txns = $ARGS{'ReverseTxns'};
+if ( $reverse_txns ) {
+    # If we got something, reverse it for the link
+    $reverse_txns = $reverse_txns eq 'ASC' ? 'DESC' : 'ASC';
+}
+else {
+    # Default the link to the opposite of the config setting
+    # Oldest Txns first is ASC, so reverse it for this option default
+    $reverse_txns = RT->Config->Get("OldestTransactionsFirst", $session{'CurrentUser'}) ? 'DESC' : 'ASC';
+}
 </%INIT>
 <div class="history <% lc $record_type %>" id="<% $histid %>">
 <%perl>
@@ -94,6 +105,11 @@ if ( $ShowDisplayModes or $ShowTitle or $ScrollShowHistory ) {
         }
     }
 
+    push( @elements, qq{<a href="?ForceShowHistory=1;ReverseTxns=$reverse_txns;id=} .
+                     $Object->id.qq{#$histid">} .
+                     loc("Reverse History Order") .
+                     qq{</a>} );
+
     # build the new link
     my $alt = loc('Edit');
     my $titleright = qq{<div class="btn-group dropdown"><a id="history-dropdown" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="fas fa-cog icon-bordered fa-2x" alt="$alt" data-toggle="tooltip" data-placement="top" data-original-title="$alt"></span></a><ul class="dropdown-menu dropdown-menu-right">};
diff --git a/share/html/Elements/ShowHistoryPage b/share/html/Elements/ShowHistoryPage
index 51237de147..f87f9ab8f5 100644
--- a/share/html/Elements/ShowHistoryPage
+++ b/share/html/Elements/ShowHistoryPage
@@ -59,6 +59,10 @@ $PathPrefix        => ''
 my $trans_content = {};
 my $trans_attachments = {};
 
+if ( $ARGS{'ReverseTxns'} ) {
+    $Transactions = $Object->SortedTransactions($ARGS{'ReverseTxns'});
+}
+
 for my $content (@{$AttachmentContent->ItemsArrayRef()}) {
     $trans_content->{$content->TransactionId}->{$content->Id} = $content;
 }
diff --git a/share/html/Helpers/TicketHistory b/share/html/Helpers/TicketHistory
index 075598be12..be2d3faf9a 100644
--- a/share/html/Helpers/TicketHistory
+++ b/share/html/Helpers/TicketHistory
@@ -60,6 +60,7 @@ $m->callback( CallbackName => 'ExtraShowHistoryArguments', Ticket => $TicketObj,
 <& /Elements/ShowHistory,
     Object => $TicketObj,
     ShowHeaders => $ARGS{'ShowHeaders'},
+    ReverseTxns => $ARGS{'ReverseTxns'},
     Attachments => $attachments,
     AttachmentContent => $attachment_content,
     %extra_args,
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 1ad1d1c685..f6293e20bd 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -93,22 +93,26 @@ my $titleright = qq{
     <& /Ticket/Elements/ScrollShowHistory,
         Ticket => $TicketObj,
         ShowHeaders => $ARGS{'ShowHeaders'},
+        ReverseTxns => $ARGS{'ReverseTxns'},
     &>
 % } elsif ($ShowHistory eq "delay") {
     <& /Ticket/Elements/DelayShowHistory,
         Ticket => $TicketObj,
         ShowHeaders => $ARGS{'ShowHeaders'},
+        ReverseTxns => $ARGS{'ReverseTxns'},
     &>
 % } elsif (not $ForceShowHistory and $ShowHistory eq "click") {
     <& /Ticket/Elements/ClickToShowHistory,
         Ticket => $TicketObj,
         ShowHeaders => $ARGS{'ShowHeaders'},
+        ReverseTxns => $ARGS{'ReverseTxns'},
     &>
 % } else {
     <& /Elements/ShowHistory ,
           Object => $TicketObj,
           Transactions => $transactions,
           ShowHeaders => $ARGS{'ShowHeaders'},
+          ReverseTxns => $ARGS{'ReverseTxns'},
           Attachments => $attachments,
           AttachmentContent => $attachment_content
     &>
@@ -267,7 +271,13 @@ MaybeRedirectForResults(
     Arguments => { id => $TicketObj->id },
 );
 
-my $transactions = $TicketObj->SortedTransactions;
+my $transactions;
+if ( $ARGS{'ReverseTxns'} ) {
+    $transactions = $TicketObj->SortedTransactions($ARGS{'ReverseTxns'});
+}
+else {
+    $transactions = $TicketObj->SortedTransactions;
+}
 my $attachments = $TicketObj->Attachments;
 my $attachment_content = $TicketObj->TextAttachments;
 
diff --git a/share/html/Ticket/Elements/ScrollShowHistory b/share/html/Ticket/Elements/ScrollShowHistory
index d2aca08a85..d62f488a8e 100644
--- a/share/html/Ticket/Elements/ScrollShowHistory
+++ b/share/html/Ticket/Elements/ScrollShowHistory
@@ -58,11 +58,17 @@ my $url = RT->Config->Get('WebPath') . "/Helpers/TicketHistoryPage?" .
 
 my %extra_args = map { $_ => $ARGS{$_} // 1 } qw/ShowDisplayModes ShowTitle ScrollShowHistory/;
 $extra_args{ShowHeaders} = $ARGS{ShowHeaders};
+$extra_args{ReverseTxns} = $ARGS{ReverseTxns};
 
 $m->callback( CallbackName => 'ExtraShowHistoryArguments', Ticket => $Ticket, ExtraArgs => \%extra_args );
 
-
-my $oldestTransactionsFirst = RT->Config->Get("OldestTransactionsFirst", $session{CurrentUser});
+my $oldestTransactionsFirst;
+if ( $ARGS{ReverseTxns} ) {
+    $oldestTransactionsFirst = $ARGS{ReverseTxns} eq 'ASC' ? 1 : 0;
+}
+else {
+    $oldestTransactionsFirst = RT->Config->Get("OldestTransactionsFirst", $session{CurrentUser});
+}
 </%INIT>
 
 <& /Elements/ShowHistoryHeader,

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


More information about the rt-commit mailing list