[Rt-commit] rt branch, 5.0/move-rt-extension-formattedtransactions-to-core, created. rt-5.0.0-2-g2834683eec

Dianne Skoll dianne at bestpractical.com
Wed Jul 29 14:36:54 EDT 2020


The branch, 5.0/move-rt-extension-formattedtransactions-to-core has been created
        at  2834683eec6f1b779a6e067a6dd2a05441d5d1dd (commit)

- Log -----------------------------------------------------------------
commit 2834683eec6f1b779a6e067a6dd2a05441d5d1dd
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Wed Jul 29 10:09:48 2020 -0400

    Move RT::Extension::FormattedTransaction into core.

diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index b45488d4b2..e4862815f8 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1045,6 +1045,16 @@ sub _CanonicalizeRoleName {
                     $new = $date->AsString( Time => 0, Timezone => 'UTC' );
                 }
             }
+            elsif ( $cf->Type =~ /text/i) {
+                if (!defined($old) || ($old eq '')) {
+                    return ( "[_1] added", $field);   #loc()
+                }
+                if (!defined($new) || ($new eq '')) {
+                    return ( "[_1] deleted", $field);   #loc()
+                } else {
+                    return ( "[_1] changed", $field);   #loc()
+                }
+            }
         }
 
         if ( !defined($old) || $old eq '' ) {
diff --git a/share/html/Elements/JavascriptConfig b/share/html/Elements/JavascriptConfig
index 2566873126..e9cf69735e 100644
--- a/share/html/Elements/JavascriptConfig
+++ b/share/html/Elements/JavascriptConfig
@@ -78,6 +78,8 @@ my $Catalog = {
     history_scroll_error => "Could not load ticket history. Reason:", #loc
     unclip => "Show all", #loc
     clip => "Show less", #loc
+    show_details => "Show Details", #loc
+    hide_details => "Hide Details", #loc
 };
 $_ = loc($_) for values %$Catalog;
 
diff --git a/share/html/Elements/ShowHistory b/share/html/Elements/ShowHistory
index 0e32e10649..25b8b10787 100644
--- a/share/html/Elements/ShowHistory
+++ b/share/html/Elements/ShowHistory
@@ -56,6 +56,13 @@
 <& /Widgets/TitleBoxEnd &>
 % }
 </div>
+<script type="text/javascript">
+jQuery(function() {
+    jQuery('.toggle-txn-details').click(function () {
+        return toggleTransactionDetails.apply(this);
+    });
+});
+</script>
 <%ARGS>
 $Object
 $Transactions      => $Object->SortedTransactions
diff --git a/share/html/Elements/ShowTransaction b/share/html/Elements/ShowTransaction
index d89b3d5650..e509fc8a8b 100644
--- a/share/html/Elements/ShowTransaction
+++ b/share/html/Elements/ShowTransaction
@@ -83,6 +83,50 @@ $m->comp(
 ) if $ShowBody;
 </%PERL>
   </div>
+% if ($Transaction->Type eq 'CustomField' && $Transaction->Field ) {
+%     my ($old, $new);
+%     my $cf = RT::CustomField->new( $session{CurrentUser} );
+%     $cf->SetContextObject( $Transaction->Object );
+%     $cf->Load( $Transaction->Field );
+%     if ($cf->Id && $cf->Type =~ /text/i) {
+%        $old = $Transaction->OldValue // loc('(no value)');
+%        $old = $m->comp('/Elements/ScrubHTML', Content => $old);
+%        $old =~ s|\n|<br />|g;
+%        $new = $Transaction->NewValue // loc('(no value)');
+%        $new = $m->comp('/Elements/ScrubHTML', Content => $new);
+%        $new =~ s|\n|<br />|g;
+<div class="details hidden" id="txn-<% $Transaction->Id %>-details">
+  <table>
+% if ( $old eq loc('(no value)')  ) {
+    <tr>
+      <td class="label"><% loc('Added') %>:</td>
+      <td class="value"><% $new |n %></td>
+    </tr>
+% }
+% elsif ( $new eq loc('(no value)')  ) {
+    <tr>
+      <td class="label"><% loc('Deleted') %>:</td>
+      <td class="value"><% $old |n %></td>
+    </tr>
+% }
+% else {
+    <tr>
+      <td class="label"><% loc('From') %>:</td>
+      <td class="value" ><% $old |n %></td>
+    </tr>
+    <tr>
+      <td class="label"><% loc('To') %>:</td>
+      <td class="value"><% $new |n %></td>
+    </tr>
+    <tr class="diff">
+      <td class="label"><% loc('Changes') %>:</td>
+      <td class="value"><% loc('Loading...') %></td>
+    </tr>
+% }
+  </table>
+</div>
+%     }
+% }
 % $m->callback( %ARGS, Transaction => $Transaction, CallbackName => 'AfterContent' );
 </div>
 
@@ -165,7 +209,14 @@ if ( $txn_type =~ /EmailRecord$/ ) {
 
     $ShowBody = 0;
 }
-
+elsif ($txn_type eq 'CustomField' && $Transaction->Field) {
+    my $cf = RT::CustomField->new( $session{CurrentUser} );
+    $cf->SetContextObject( $Transaction->Object );
+    $cf->Load( $Transaction->Field );
+    if ($cf->Id && $cf->Type =~ /text/i) {
+        push @actions, { class => 'toggle-txn-details', title => loc('Show Details'), path => '#' };
+    }
+}
 # If the transaction has anything attached to it at all
 elsif ( %$Attachments && $ShowActions ) {
     my %has_right = map {
diff --git a/share/html/Elements/ShowHistory b/share/html/Helpers/TextDiff
similarity index 76%
copy from share/html/Elements/ShowHistory
copy to share/html/Helpers/TextDiff
index 0e32e10649..ea2beec825 100644
--- a/share/html/Elements/ShowHistory
+++ b/share/html/Helpers/TextDiff
@@ -44,27 +44,35 @@
 %# works based on those contributions, and sublicense and distribute
 %# those contributions and any derivatives thereof.
 %#
-%# END BPS TAGGED BLOCK }}}
-<& /Elements/ShowHistoryHeader, %ARGS &>
+%# END BPS TAGGED BLOCK }}}<%INIT>
 
-% $m->callback( %ARGS, Object => $Object, CallbackName => 'BeforeTransactions' );
+my ( $old, $new );
 
-<& /Elements/ShowHistoryPage, %ARGS &>
+if ($TransactionId) {
+    my $txn = RT::Transaction->new( $session{'CurrentUser'} );
+    $txn->Load($TransactionId);
+    if ( $txn->Id ) {
+        $old = $txn->OldValue;
+        $new = $txn->NewValue;
+    }
+    else {
+        RT->Logger->error("Could not load transaction #$TransactionId");
+        $m->abort;
+    }
+}
+else {
+    $m->abort;
+}
 
-</div>
-% if ($ShowDisplayModes or $ShowTitle) {
-<& /Widgets/TitleBoxEnd &>
-% }
-</div>
-<%ARGS>
-$Object
-$Transactions      => $Object->SortedTransactions
-$Attachments       => $Object->Attachments( WithHeaders => 1 )
-$AttachmentContent => $Object->TextAttachments
+use Text::WordDiff;
+my $diff = word_diff( \$old, \$new, { STYLE => 'HTML' } );
+$diff = $m->comp( '/Elements/ScrubHTML', Content => $diff );
+$diff =~ s|\n|<br />|g;
 
-$ShowHeaders       => 0
-$ShowTitle         => 1
-$ShowDisplayModes  => 1
+</%INIT>
+<% $diff |n %>
+% $m->abort();
 
-$PathPrefix        => ''
+<%ARGS>
+$TransactionId => undef
 </%ARGS>
diff --git a/share/html/Elements/ShowHistory b/share/html/SelfService/TextDiff
similarity index 79%
copy from share/html/Elements/ShowHistory
copy to share/html/SelfService/TextDiff
index 0e32e10649..e863db23e0 100644
--- a/share/html/Elements/ShowHistory
+++ b/share/html/SelfService/TextDiff
@@ -45,26 +45,4 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<& /Elements/ShowHistoryHeader, %ARGS &>
-
-% $m->callback( %ARGS, Object => $Object, CallbackName => 'BeforeTransactions' );
-
-<& /Elements/ShowHistoryPage, %ARGS &>
-
-</div>
-% if ($ShowDisplayModes or $ShowTitle) {
-<& /Widgets/TitleBoxEnd &>
-% }
-</div>
-<%ARGS>
-$Object
-$Transactions      => $Object->SortedTransactions
-$Attachments       => $Object->Attachments( WithHeaders => 1 )
-$AttachmentContent => $Object->TextAttachments
-
-$ShowHeaders       => 0
-$ShowTitle         => 1
-$ShowDisplayModes  => 1
-
-$PathPrefix        => ''
-</%ARGS>
+% $m->comp( '/Helpers/TextDiff', %ARGS );
diff --git a/share/static/js/util.js b/share/static/js/util.js
index 34dd5ec92f..3e67be520a 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -1078,3 +1078,28 @@ jQuery(function() {
         }
     }
 });
+
+function toggleTransactionDetails () {
+
+    var txn_div = jQuery(this).closest('div.transaction[data-transaction-id]');
+    var details_div = txn_div.find('div.details');
+
+    if (details_div.hasClass('hidden')) {
+        details_div.removeClass('hidden');
+        jQuery(this).text(RT.I18N.Catalog['hide_details']);
+    }
+    else {
+        details_div.addClass('hidden');
+        jQuery(this).text(RT.I18N.Catalog['show_details']);
+    }
+
+    var diff = details_div.find('.diff td.value');
+    if (!diff.children().length) {
+        diff.load(RT.Config.WebHomePath + '/Helpers/TextDiff', {
+            TransactionId: txn_div.attr('data-transaction-id')
+        });
+    }
+
+    return false;
+}
+

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


More information about the rt-commit mailing list