[Rt-commit] rt branch, 4.4/txn-text-cf-ui, created. rt-4.4.4-92-g92209a4d3

? sunnavy sunnavy at bestpractical.com
Fri Mar 13 18:43:25 EDT 2020


The branch, 4.4/txn-text-cf-ui has been created
        at  92209a4d34bb0715ad02b5d9d5770590f914507f (commit)

- Log -----------------------------------------------------------------
commit 98858ac65fb8f0083935ec3987c3c9ccf35c67cd
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Mar 13 06:06:23 2020 +0800

    Friendly transaction UI of text CF changes especially for large contents
    
    Previously the single-line description was hardly readable for large
    contents, e.g.
    
      intro RT is an enterprise-grade issue tracking system. It allows
      organizations to keep track of their to-do lists, who is working on
      which tasks, what's already been done, and when tasks were completed. It
      is available under the terms of version 2 of the GNU General Public
      License (GPL), so it doesn't cost anything to set up and use. changed to
      RT is commercially-supported software. To purchase support, training,
      custom development, or professional services, please get in touch with
      us at <sales at bestpractical.com>.
    
    Now it's like:
    
      intro changed
    
      From: RT is an enterprise-grade issue tracking system. It allows
            organizations to keep track of their to-do lists, who is working on
            which tasks, what's already been done, and when tasks were completed.
            It is available under the terms of version 2 of the GNU General
            Public License (GPL), so it doesn't cost anything to set up and use.
    
      To:   RT is commercially-supported software. To purchase support,
            training, custom development, or professional services, please get in
            touch with us at <sales at bestpractical.com>.
    
    Which is way more clear and friendly.

diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 914fe51ca..7cadfbc39 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1045,6 +1045,17 @@ 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 1254d838b..20fe3fb75 100644
--- a/share/html/Elements/JavascriptConfig
+++ b/share/html/Elements/JavascriptConfig
@@ -73,6 +73,8 @@ my $Catalog = {
     loading => "Loading...", #loc
     try_again => "Try again", #loc
     history_scroll_error => "Could not load ticket history. Reason:", #loc
+    show_details => "Show Details", #loc
+    hide_details => "Hide Details", #loc
 };
 $_ = loc($_) for values %$Catalog;
 
diff --git a/share/html/Elements/ShowTransaction b/share/html/Elements/ShowTransaction
index 790d026b1..843f36367 100644
--- a/share/html/Elements/ShowTransaction
+++ b/share/html/Elements/ShowTransaction
@@ -77,6 +77,33 @@ $m->comp(
     Parent => 0
 ) if $ShowBody;
 </%PERL>
+
+% if ( $old || $new ) {
+    <div class="details hidden %>" id="txn-<% $Transaction->Id %>-details">
+      <table>
+%     if ( $old eq loc('(no value)')  ) {
+        <tr>
+          <td class="value"><% $new |n %></td>
+        </tr>
+%     }
+%     elsif ( $new eq loc('(no value)')  ) {
+        <tr>
+          <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>
+%     }
+      </table>
+    </div>
+% }
   </div>
 % $m->callback( %ARGS, Transaction => $Transaction, CallbackName => 'AfterContent' );
 </div>
@@ -227,6 +254,33 @@ elsif ( %$Attachments && $ShowActions ) {
     }
 }
 
+my ( $old, $new );
+if ( $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 ) {
+        $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;
+
+        my $id = $Transaction->Id;
+
+        # Ignore $ShowActions as it's a page helper, not a real action.
+        push @actions,
+            {
+            class   => "toggle-txn-details",
+            title   => loc('Show Details'),
+            onclick => "return toggleTransactionDetails('txn-$id-details', this)",
+            path    => '#',
+            };
+    }
+}
+
 my $CreatorObj = $Transaction->CreatorObj;
 
 $m->callback(
@@ -258,6 +312,10 @@ if ( @actions ) {
                 ? ' class="'. $i->apply_escapes( $a->{'class'}, 'h' ) .'"'
                 : ''
             )
+            . ($a->{'onclick'}
+                ? ' onclick="'. $i->apply_escapes( $a->{'onclick'}, 'h' ) .'"'
+                : ''
+            )
             .'>'. $i->apply_escapes( $a->{'title'}, 'h' ) .'</a>'
         ;
     }
diff --git a/share/static/css/base/history.css b/share/static/css/base/history.css
index 7fa086737..bff1e93a8 100644
--- a/share/static/css/base/history.css
+++ b/share/static/css/base/history.css
@@ -164,3 +164,11 @@ padding-right:0.25em;
 .transaction .message-header-value.verify.done.trust-FULL      { color: #060; }
 .transaction .message-header-value.verify.done.trust-FULLY     { color: #060; }
 .transaction .message-header-value.verify.done.trust-ULTIMATE  { color: #060; }
+
+.transaction.other .content .details {
+  margin-top: 0.5em;
+}
+
+.transaction.other .content .details tr:not(:first-child) td.value {
+  border-top: 1px solid #ccc;
+}
diff --git a/share/static/css/rudder/history.css b/share/static/css/rudder/history.css
index b9949c39e..f271638a2 100644
--- a/share/static/css/rudder/history.css
+++ b/share/static/css/rudder/history.css
@@ -2,6 +2,7 @@ div.history-container {
     border: 0
 }
 
+.history .transaction.details div.content,
 .history .transaction.message div.content {
     padding-right: 0;
     padding-bottom: 3em;
diff --git a/share/static/css/rudder/misc.css b/share/static/css/rudder/misc.css
index dab61c7c5..fdf1bb768 100644
--- a/share/static/css/rudder/misc.css
+++ b/share/static/css/rudder/misc.css
@@ -25,6 +25,10 @@ td.labeltop {
     min-width: 6em;
 }
 
+.transaction.other .content .details td.label {
+    min-width: 0;
+}
+
 span.cflabel .type,
 td.cflabel .type {
     font-weight: normal;
diff --git a/share/static/js/util.js b/share/static/js/util.js
index d5bf84562..ea45cc473 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -591,3 +591,13 @@ function toggle_hide_unset(e) {
 
     return false;
 }
+
+function toggleTransactionDetails (id, link) {
+    hideshow(id);
+
+    if (link) {
+        jQuery(link).text(RT.I18N.Catalog[jQuery('#'+id).is(':visible') ? 'hide_details' : 'show_details']);
+    }
+
+    return false;
+}

commit 9dd112ca016678c33e2ae587410e6a56f8208953
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Mar 14 04:53:45 2020 +0800

    Highlight changes of text CF contents in transaction UI
    
    With it, changes could be more prominent.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index b6ccf6ff7..2bc3e3c18 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -4543,7 +4543,7 @@ following:
 
 our @SCRUBBER_ALLOWED_TAGS = qw(
     A B U P BR I HR BR SMALL EM FONT SPAN STRONG SUB SUP S DEL STRIKE H1 H2 H3 H4 H5
-    H6 DIV UL OL LI DL DT DD PRE BLOCKQUOTE BDO
+    H6 DIV UL OL LI DL DT DD PRE BLOCKQUOTE BDO INS
 );
 
 our %SCRUBBER_ALLOWED_ATTRIBUTES = (
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index 1f05a69c3..bc5c88057 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -188,6 +188,7 @@ Text::Quoted 2.07
 Text::Template 1.44
 Text::WikiFormat 0.76
 Text::Wrapper
+Text::WordDiff
 Time::HiRes
 Time::ParseDate
 Tree::Simple 1.04
diff --git a/share/html/Elements/ShowTransaction b/share/html/Elements/ShowTransaction
index 843f36367..f88023c0f 100644
--- a/share/html/Elements/ShowTransaction
+++ b/share/html/Elements/ShowTransaction
@@ -100,6 +100,10 @@ $m->comp(
           <td class="label"><% loc('To') %>:</td>
           <td class="value"><% $new |n %></td>
         </tr>
+        <tr class="diff">
+          <td class="label"><% loc('Diff') %>:</td>
+          <td class="value"><% loc('Loading...') %></td>
+        </tr>
 %     }
       </table>
     </div>
diff --git a/share/html/Helpers/TextDiff b/share/html/Helpers/TextDiff
new file mode 100644
index 000000000..b7990195a
--- /dev/null
+++ b/share/html/Helpers/TextDiff
@@ -0,0 +1,78 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2019 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>
+$TransactionId => undef
+</%ARGS>
+<%INIT>
+
+my ( $old, $new );
+
+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;
+}
+
+use Text::WordDiff;
+my $diff = word_diff( \$old, \$new, { STYLE => 'HTML' } );
+$diff = $m->comp( '/Elements/ScrubHTML', Content => $diff );
+$diff =~ s|\n|<br />|g;
+
+</%INIT>
+<% $diff |n %>
+% $m->abort();
diff --git a/share/html/SelfService/Helpers/TextDiff b/share/html/SelfService/Helpers/TextDiff
new file mode 100644
index 000000000..ede6798ae
--- /dev/null
+++ b/share/html/SelfService/Helpers/TextDiff
@@ -0,0 +1,48 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2019 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 }}}
+% $m->comp( '/Helpers/TextDiff', %ARGS );
diff --git a/share/static/css/base/misc.css b/share/static/css/base/misc.css
index 25ec20c69..7276d7f5e 100644
--- a/share/static/css/base/misc.css
+++ b/share/static/css/base/misc.css
@@ -127,3 +127,15 @@ td.current-recipients {
     vertical-align: top;
     padding-left: 50px;
 }
+
+.diff del {
+    color: #a00;
+}
+
+.diff {
+    color: #888;
+}
+
+.diff ins {
+    color: #080;
+}
diff --git a/share/static/js/util.js b/share/static/js/util.js
index ea45cc473..656d668d4 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -599,5 +599,12 @@ function toggleTransactionDetails (id, link) {
         jQuery(link).text(RT.I18N.Catalog[jQuery('#'+id).is(':visible') ? 'hide_details' : 'show_details']);
     }
 
+    var diff = jQuery('#' + id + ' .diff td.value');
+    if (!diff.children().length) {
+        diff.load(RT.Config.WebHomePath + '/Helpers/TextDiff', {
+            TransactionId: diff.closest('div[data-transaction-id]').attr('data-transaction-id')
+        });
+    }
+
     return false;
 }

commit 92209a4d34bb0715ad02b5d9d5770590f914507f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Mar 14 06:03:38 2020 +0800

    Test the new transaction UI of text CF changes

diff --git a/t/web/cf_textarea.t b/t/web/cf_textarea.t
index 50b00c57d..a15aa5edc 100644
--- a/t/web/cf_textarea.t
+++ b/t/web/cf_textarea.t
@@ -82,4 +82,51 @@ $m->content_lacks("<li>TheTextarea $content changed to $content</li>", 'textarea
 # #32440: Spurious "CF changed from 0 to 0"
 $m->content_lacks("<li>Zero 0 changed to 0</li>", "Zero wasn't updated");
 
+my $new_content = 'The quick brown fox jumps over the lazy dog.';
+
+$m->submit_form_ok({
+    with_fields => {
+        $cfs->{area}{input}            => $new_content,
+        $cfs->{area}{input} . '-Magic' => "1",
+    },
+}, 'submitted form to update textarea CF');
+
+$m->content_contains( "<li>TheTextarea $content changed to $new_content</li>", 'textarea was updated' );
+
+my $newer_content = 'The quick yellow fox jumps over the lazy dog.';
+
+$m->submit_form_ok({
+    with_fields => {
+        $cfs->{area}{input}            => $newer_content,
+        $cfs->{area}{input} . '-Magic' => "1",
+    },
+}, 'submitted form to update textarea CF');
+
+$m->content_contains( "<li>TheTextarea $new_content changed to $newer_content</li>", 'textarea was updated' );
+
+my $txn = $ticket->Transactions->Last;
+$m->get_ok( '/Helpers/TextDiff?TransactionId=' . $txn->id );
+$m->content_like( qr{<del>brown\s*</del><ins>yellow\s*</ins>}, 'text diff has the brown => yellow change' );
+
+$m->back;
+$m->submit_form_ok({
+    with_fields => {
+        $cfs->{area}{input}            => '',
+        $cfs->{area}{input} . '-Magic' => "1",
+    },
+}, 'submitted form to update textarea CF');
+
+$m->content_contains( "<li>$newer_content is no longer a value for custom field TheTextarea</li>",
+    'textarea was deleted' );
+
+$m->follow_link_ok( { text => 'Display' } );
+$content =~ s!\n+!!g;
+$m->text_like(
+    qr/TheTextarea\sadded.+\Q$content\E.+
+       TheTextarea\schanged.+From:\Q$content\ETo:\Q$new_content\E.+
+       TheTextarea\schanged.+From:\Q$new_content\ETo:\Q$newer_content\E.+
+       TheTextarea\sdeleted.+\Q$newer_content\E/xs,
+    'textarea change details'
+);
+
 done_testing;

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


More information about the rt-commit mailing list