[Rt-commit] rt branch, 4.6/reverse-transaction-order, created. rt-5.0.0alpha1-28-g394f5421c9

Michel Rodriguez michel at bestpractical.com
Wed Apr 8 07:29:08 EDT 2020


The branch, 4.6/reverse-transaction-order has been created
        at  394f5421c9353c1f58c5ea49ae5f749947ff26b2 (commit)

- Log -----------------------------------------------------------------
commit 675bcecd4c143e73253332544ec128d5bb81c16e
Author: michel <michel at bestpractical.com>
Date:   Tue Apr 7 17:36:35 2020 +0200

    Use $ShowHeaders in all templates.
    
    Do not use $ARGS{'ShowHeaders'}.
    This lead to warnings when the arg was not passed to a template.

diff --git a/share/html/Helpers/TicketHistory b/share/html/Helpers/TicketHistory
index 075598be12..dca10a2416 100644
--- a/share/html/Helpers/TicketHistory
+++ b/share/html/Helpers/TicketHistory
@@ -47,6 +47,7 @@
 %# END BPS TAGGED BLOCK }}}
 <%ARGS>
 $id
+$ShowHeaders => 0
 </%ARGS>
 <%INIT>
 my $TicketObj = RT::Ticket->new($session{'CurrentUser'});
@@ -59,7 +60,7 @@ $m->callback( CallbackName => 'ExtraShowHistoryArguments', Ticket => $TicketObj,
 </%INIT>
 <& /Elements/ShowHistory,
     Object => $TicketObj,
-    ShowHeaders => $ARGS{'ShowHeaders'},
+    ShowHeaders => $ShowHeaders,
     Attachments => $attachments,
     AttachmentContent => $attachment_content,
     %extra_args,
diff --git a/share/html/Helpers/TicketHistoryPage b/share/html/Helpers/TicketHistoryPage
index 41b0a70cb5..aac0e39283 100644
--- a/share/html/Helpers/TicketHistoryPage
+++ b/share/html/Helpers/TicketHistoryPage
@@ -51,6 +51,7 @@ $oldestTransactionsFirst => RT->Config->Get("OldestTransactionsFirst", $session{
 $lastTransactionId => undef
 $focusTransactionId => undef
 $loadAll => 0
+$ShowHeaders => 0
 </%ARGS>
 <%INIT>
 my $TicketObj = RT::Ticket->new($session{'CurrentUser'});
@@ -90,7 +91,7 @@ if ($focusTransactionId) { # make sure we load enough if we need to focus a tran
 </%INIT>
 <& /Elements/ShowHistoryPage,
     Object => $TicketObj,
-    ShowHeaders => $ARGS{'ShowHeaders'},
+    ShowHeaders => $ShowHeaders,
     Transactions => $transactions,
     %extra_args,
     &>
diff --git a/share/html/SelfService/Display.html b/share/html/SelfService/Display.html
index a9edfa4a90..34e66a2df2 100644
--- a/share/html/SelfService/Display.html
+++ b/share/html/SelfService/Display.html
@@ -87,7 +87,7 @@
 
 <& /Elements/ShowHistory,
       Object => $Ticket,
-      ShowHeaders => $ARGS{'ShowHeaders'},
+      ShowHeaders => $ShowHeaders,
       DownloadableHeaders => 0,
 &>
 
@@ -174,4 +174,5 @@ $m->callback(CallbackName => 'BeforeDisplay', Ticket => \$Ticket, ARGSRef => \%A
 
 <%ARGS>
 $id => undef
+$ShowHeaders => 0
 </%ARGS>
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 1ad1d1c685..a6e6552b05 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -92,23 +92,23 @@ my $titleright = qq{
 % if ($ShowHistory eq "scroll") {
     <& /Ticket/Elements/ScrollShowHistory,
         Ticket => $TicketObj,
-        ShowHeaders => $ARGS{'ShowHeaders'},
+        ShowHeaders => $ShowHeaders,
     &>
 % } elsif ($ShowHistory eq "delay") {
     <& /Ticket/Elements/DelayShowHistory,
         Ticket => $TicketObj,
-        ShowHeaders => $ARGS{'ShowHeaders'},
+        ShowHeaders => $ShowHeaders,
     &>
 % } elsif (not $ForceShowHistory and $ShowHistory eq "click") {
     <& /Ticket/Elements/ClickToShowHistory,
         Ticket => $TicketObj,
-        ShowHeaders => $ARGS{'ShowHeaders'},
+        ShowHeaders => $ShowHeaders,
     &>
 % } else {
     <& /Elements/ShowHistory ,
           Object => $TicketObj,
           Transactions => $transactions,
-          ShowHeaders => $ARGS{'ShowHeaders'},
+          ShowHeaders => $ShowHeaders,
           Attachments => $attachments,
           AttachmentContent => $attachment_content
     &>
diff --git a/share/html/Ticket/Elements/ScrollShowHistory b/share/html/Ticket/Elements/ScrollShowHistory
index d2aca08a85..757c172ef3 100644
--- a/share/html/Ticket/Elements/ScrollShowHistory
+++ b/share/html/Ticket/Elements/ScrollShowHistory
@@ -47,6 +47,7 @@
 %# END BPS TAGGED BLOCK }}}
 <%ARGS>
 $Ticket
+$ShowHeaders => 0
 </%ARGS>
 
 <%INIT>
@@ -57,7 +58,7 @@ my $url = RT->Config->Get('WebPath') . "/Helpers/TicketHistoryPage?" .
         $m->comp('/Elements/QueryString', %params, id => $Ticket->id );
 
 my %extra_args = map { $_ => $ARGS{$_} // 1 } qw/ShowDisplayModes ShowTitle ScrollShowHistory/;
-$extra_args{ShowHeaders} = $ARGS{ShowHeaders};
+$extra_args{ShowHeaders} = $ShowHeaders;
 
 $m->callback( CallbackName => 'ExtraShowHistoryArguments', Ticket => $Ticket, ExtraArgs => \%extra_args );
 
diff --git a/share/html/Ticket/History.html b/share/html/Ticket/History.html
index 239d4e15f1..607c2bf88d 100644
--- a/share/html/Ticket/History.html
+++ b/share/html/Ticket/History.html
@@ -52,7 +52,7 @@
 
 <& /Elements/ShowHistory,
     Object => $Ticket,
-    ShowHeaders => $ARGS{'ShowHeaders'}, 
+    ShowHeaders => $ShowHeaders, 
     Attachments => $attachments,
     AttachmentContent => $attachment_content,
     DisplayPath => 'History.html',
@@ -62,6 +62,7 @@
 
 <%ARGS>
 $id => undef
+$ShowHeaders => 0
 </%ARGS>
 
 <%INIT>

commit 394f5421c9353c1f58c5ea49ae5f749947ff26b2
Author: michel <michel at bestpractical.com>
Date:   Fri Mar 13 13:03:06 2020 +0100

    Add a control to reverse the current time order in ticket history
    
    The default transaction order can be set globally or as a user
    preference, but this allows a user to reverse the order just
    for the currently viewed ticket without changing their default
    setting.

diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 5b2b8d2d31..1da32d090d 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1729,13 +1729,19 @@ sub Transactions {
 Returns the result of L</Transactions> ordered per the
 I<OldestTransactionsFirst> preference/option.
 
+The second argument reverses the order if true, to 
+provide the "Reverse Transaction Order" feature.
+
 =cut
 
 sub SortedTransactions {
     my $self  = shift;
+    my $reverse_order = shift || 0;
+
     my $txns  = $self->Transactions;
-    my $order = RT->Config->Get("OldestTransactionsFirst", $self->CurrentUser)
-        ? 'ASC' : 'DESC';
+    # parens required because the priority of 'xor' is lower than the one of '='
+    my $order_param = ( RT->Config->Get("OldestTransactionsFirst", $self->CurrentUser) xor $reverse_order );
+    my $order = $order_param ? 'ASC' : 'DESC';
     $txns->OrderByCols(
         { FIELD => 'Created',   ORDER => $order },
         { FIELD => 'id',        ORDER => $order },
diff --git a/share/html/Elements/ShowHistory b/share/html/Elements/ShowHistory
index 5622649967..b157e3c8d2 100644
--- a/share/html/Elements/ShowHistory
+++ b/share/html/Elements/ShowHistory
@@ -58,7 +58,8 @@
 </div>
 <%ARGS>
 $Object
-$Transactions      => $Object->SortedTransactions
+$ReverseTransactionOrder => 0
+$Transactions      => $Object->SortedTransactions( $ReverseTransactionOrder )
 $Attachments       => $Object->Attachments( WithHeaders => 1 )
 $AttachmentContent => $Object->TextAttachments
 
diff --git a/share/html/Elements/ShowHistoryHeader b/share/html/Elements/ShowHistoryHeader
index c12fce532e..524972d03f 100644
--- a/share/html/Elements/ShowHistoryHeader
+++ b/share/html/Elements/ShowHistoryHeader
@@ -48,6 +48,7 @@
 <%ARGS>
 $Object
 $ShowHeaders       => 0
+$ReverseTransactionOrder  => 0
 $ShowTitle         => 1
 $ShowDisplayModes  => 1
 $ScrollShowHistory => 0
@@ -94,6 +95,16 @@ if ( $ShowDisplayModes or $ShowTitle or $ScrollShowHistory ) {
         }
     }
 
+    my @TransactionHeaders= ( loc( 'Oldest transaction first' ), loc( 'Newest transaction first' ) );
+    my $Order = ( RT->Config->Get( "OldestTransactionsFirst", $Object->CurrentUser ) xor $ReverseTransactionOrder );
+    my $TransactionHeader= $TransactionHeaders[$Order];
+
+    my $switched_order = 1 - $ReverseTransactionOrder;
+    push( @elements, qq{<a href="?ReverseTransactionOrder=$switched_order;ForceShowHistory=1;ShowHeaders=$ShowHeaders;id=} .
+                     $Object->id.qq{#$histid">} .
+                     $TransactionHeader .
+                     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..89a353a0a5 100644
--- a/share/html/Elements/ShowHistoryPage
+++ b/share/html/Elements/ShowHistoryPage
@@ -47,7 +47,8 @@
 %# END BPS TAGGED BLOCK }}}
 <%ARGS>
 $Object
-$Transactions      => $Object->SortedTransactions
+$ReverseTransactionOrder => 0
+$Transactions      => $Object->SortedTransactions( $ReverseTransactionOrder )
 $Attachments       => $Object->Attachments( WithHeaders => 1 )
 $AttachmentContent => $Object->TextAttachments
 
diff --git a/share/html/Helpers/TicketHistory b/share/html/Helpers/TicketHistory
index dca10a2416..84b4ce6569 100644
--- a/share/html/Helpers/TicketHistory
+++ b/share/html/Helpers/TicketHistory
@@ -48,6 +48,7 @@
 <%ARGS>
 $id
 $ShowHeaders => 0
+$ReverseTransactionOrder => 0
 </%ARGS>
 <%INIT>
 my $TicketObj = RT::Ticket->new($session{'CurrentUser'});
@@ -61,6 +62,7 @@ $m->callback( CallbackName => 'ExtraShowHistoryArguments', Ticket => $TicketObj,
 <& /Elements/ShowHistory,
     Object => $TicketObj,
     ShowHeaders => $ShowHeaders,
+    ReverseTransactionOrder => $ReverseTransactionOrder,
     Attachments => $attachments,
     AttachmentContent => $attachment_content,
     %extra_args,
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index a6e6552b05..4983e5e71b 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 => $ShowHeaders,
+        ReverseTransactionOrder => $ReverseTransactionOrder,
     &>
 % } elsif ($ShowHistory eq "delay") {
     <& /Ticket/Elements/DelayShowHistory,
         Ticket => $TicketObj,
         ShowHeaders => $ShowHeaders,
+        ReverseTransactionOrder => $ReverseTransactionOrder,
     &>
 % } elsif (not $ForceShowHistory and $ShowHistory eq "click") {
     <& /Ticket/Elements/ClickToShowHistory,
         Ticket => $TicketObj,
         ShowHeaders => $ShowHeaders,
+        ReverseTransactionOrder => $ReverseTransactionOrder,
     &>
 % } else {
     <& /Elements/ShowHistory ,
           Object => $TicketObj,
           Transactions => $transactions,
           ShowHeaders => $ShowHeaders,
+          ReverseTransactionOrder => $ReverseTransactionOrder,
           Attachments => $attachments,
           AttachmentContent => $attachment_content
     &>
@@ -124,6 +128,7 @@ my $titleright = qq{
 <%ARGS>
 $TicketObj => undef
 $ShowHeaders => 0
+$ReverseTransactionOrder => 0
 $HideUnsetFields => RT->Config->Get('HideUnsetFieldsOnDisplay', $session{CurrentUser})
 $ForceShowHistory => 0
 $InlineEdit => RT->Config->Get('InlineEdit', $session{CurrentUser})
@@ -267,7 +272,7 @@ MaybeRedirectForResults(
     Arguments => { id => $TicketObj->id },
 );
 
-my $transactions = $TicketObj->SortedTransactions;
+my $transactions = $TicketObj->SortedTransactions( $ReverseTransactionOrder );
 my $attachments = $TicketObj->Attachments;
 my $attachment_content = $TicketObj->TextAttachments;
 
diff --git a/share/html/Ticket/Elements/ScrollShowHistory b/share/html/Ticket/Elements/ScrollShowHistory
index 757c172ef3..d5a8d5c4e7 100644
--- a/share/html/Ticket/Elements/ScrollShowHistory
+++ b/share/html/Ticket/Elements/ScrollShowHistory
@@ -48,6 +48,7 @@
 <%ARGS>
 $Ticket
 $ShowHeaders => 0
+$ReverseTransactionOrder => 0
 </%ARGS>
 
 <%INIT>
@@ -59,11 +60,12 @@ my $url = RT->Config->Get('WebPath') . "/Helpers/TicketHistoryPage?" .
 
 my %extra_args = map { $_ => $ARGS{$_} // 1 } qw/ShowDisplayModes ShowTitle ScrollShowHistory/;
 $extra_args{ShowHeaders} = $ShowHeaders;
+$extra_args{ReverseTransactionOrder} = $ReverseTransactionOrder;
 
 $m->callback( CallbackName => 'ExtraShowHistoryArguments', Ticket => $Ticket, ExtraArgs => \%extra_args );
 
-
-my $oldestTransactionsFirst = RT->Config->Get("OldestTransactionsFirst", $session{CurrentUser});
+# parens on the right side are required because 'xor' has a lower priority than '='
+my $oldestTransactionsFirst = ( RT->Config->Get( "OldestTransactionsFirst", $session{CurrentUser} ) xor $ReverseTransactionOrder );
 </%INIT>
 
 <& /Elements/ShowHistoryHeader,

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


More information about the rt-commit mailing list