[Bps-public-commit] rt-extension-announce branch, rt5-style, created. 1.03-5-gb2452c5

? sunnavy sunnavy at bestpractical.com
Thu Apr 22 18:16:13 EDT 2021


The branch, rt5-style has been created
        at  b2452c50b00adfc812a9460e37e1f9952726d6b9 (commit)

- Log -----------------------------------------------------------------
commit 1d8d9478c7f0caf7aa9019605a74e7d6a8f69fbb
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 23 04:36:21 2021 +0800

    Move content generate code out of HTML block
    
    Thus we can reuse it when rendering different HTML for RT 5.

diff --git a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
index 2c8a47c..2a6baa2 100644
--- a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
+++ b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
@@ -60,31 +60,11 @@
 % }
   </td>
   <td class="announce_cell">
-<%perl>
-  my $txns = $ticket->Transactions;
-  for my $type ( qw(Create Correspond) ){
-      $txns->Limit( FIELD => 'Type', VALUE => $type );
-  }
-  $txns->OrderBy( FIELD => 'Created', ORDER => 'DESC' );
-  $txns->RowsPerPage(1);
-
-  my $show_html = RT::Config->Get('RTAnnounceAllowHTML') || 0;
-  my $advanced_mode = RT::Config->Get('RTAnnounceAdvancedMode') || 0;
-  my $content = $show_html ? $txns->First->Content(Type => 'text/html') : $txns->First->Content(Type => 'text/plain');
-
-  if( length $content > $MaxMessageLength ){
-    $content = substr($content, 0, $MaxMessageLength);
-    # Try to break at a word boundary.
-    $content =~ s/^(.*)\b\w+$/$1/g;
-    $content =~ s/\s+$//g; # Remove trailing space
-    $content .= chr(8230); # Ellipsis character
-  }
-</%perl>
 <div id="RTAnnounceScrollable" class="RTAnnounceScrollable">
 % if ( $show_html ) {
-  <% $content |n %>
+  <% $content{$ticket->Id} |n %>
 % } else {
-  <% $content %>
+  <% $content{$ticket->Id} %>
 % }
 </div>
 %if( $show_ticket_links{$ticket->Id} ){
@@ -126,6 +106,9 @@ return if @tickets == 0;
 
 # Don't show links if users can't view the announce tickets.
 my %show_ticket_links;
+my %content;
+my $show_html     = RT::Config->Get('RTAnnounceAllowHTML')    || 0;
+my $advanced_mode = RT::Config->Get('RTAnnounceAdvancedMode') || 0;
 
 my $who = $session{CurrentUser}->Name;
 foreach my $ticket ( @tickets ){
@@ -138,6 +121,25 @@ foreach my $ticket ( @tickets ){
           . "the ShowTicket right for ticket " . $ticket->Id . "  and will not see links to "
           . 'this announcement ticket.');
     }
+
+    my $txns = $ticket->Transactions;
+    for my $type (qw(Create Correspond)) {
+        $txns->Limit( FIELD => 'Type', VALUE => $type );
+    }
+    $txns->OrderBy( FIELD => 'Created', ORDER => 'DESC' );
+    $txns->RowsPerPage(1);
+
+    my $content
+        = $show_html ? $txns->First->Content( Type => 'text/html' ) : $txns->First->Content( Type => 'text/plain' );
+
+    if ( length $content > $MaxMessageLength ) {
+        $content = substr( $content, 0, $MaxMessageLength );
+        # Try to break at a word boundary.
+        $content =~ s/^(.*)\b\w+$/$1/g;
+        $content =~ s/\s+$//g;            # Remove trailing space
+        $content .= chr(8230);            # Ellipsis character
+    }
+    $content{$ticket->Id} = $content;
 }
 
 </%INIT>

commit ae80103eca901ec9802eb5c43d0b304f618b8b62
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 23 05:44:34 2021 +0800

    Drop unused RTAnnounceAdvancedMode code

diff --git a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
index 2a6baa2..71916e6 100644
--- a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
+++ b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
@@ -108,7 +108,6 @@ return if @tickets == 0;
 my %show_ticket_links;
 my %content;
 my $show_html     = RT::Config->Get('RTAnnounceAllowHTML')    || 0;
-my $advanced_mode = RT::Config->Get('RTAnnounceAdvancedMode') || 0;
 
 my $who = $session{CurrentUser}->Name;
 foreach my $ticket ( @tickets ){

commit 86bddd6046b1a9b8cd5f21552604c87b3c1c56cd
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 23 06:02:13 2021 +0800

    Fix the logic to determine if we need </tbody> or not
    
    We only need it when there are extra announcements hidden. Note that
    $rows is not the announcements count but +1(it starts with 1 and
    increase by 1 after each loop).

diff --git a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
index 71916e6..0b57829 100644
--- a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
+++ b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
@@ -85,7 +85,7 @@
 % }
 %$rows++;
 %}
-%if( $rows >= $ShowTickets ){
+%if( scalar @tickets > $ShowTickets ){
 </tbody>
 %}
 </table></div>

commit 41424e1c9dcba9d70881bd41c31d6925ca51022b
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 23 06:07:14 2021 +0800

    Localize toggle link text

diff --git a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
index 0b57829..48770cf 100644
--- a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
+++ b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
@@ -78,7 +78,7 @@
 % if( $rows == $ShowTickets && (scalar @tickets) > $ShowTickets ){
 %   # More announcements, initially hidden.
 <tr><td colspan=2 class="toggle_announcements">
-<a href='#' class="toggle_announcements" id="toggle_announcements">More Announcements</a>
+<a data-text-more="<% loc('More Announcements') %>" data-text-less="<% loc('Less Announcements') %>" href='#' class="toggle_announcements" id="toggle_announcements">More Announcements</a>
 </td>
 </tr>
 <tbody id="more_announcements">
diff --git a/static/js/announce.js b/static/js/announce.js
index 588f503..98560f8 100644
--- a/static/js/announce.js
+++ b/static/js/announce.js
@@ -5,12 +5,12 @@ jQuery(document).ready(function() {
     jQuery('#toggle_announcements').click( function() {
         if ( hide == true ) {
             jQuery('#more_announcements').show();
-            jQuery('#toggle_announcements').html('Less Announcements');
+            jQuery('#toggle_announcements').text(jQuery('#toggle_announcements').data('text-less'));
             hide = false;
         }
         else if ( hide == false ) {
             jQuery('#more_announcements').hide();
-            jQuery('#toggle_announcements').html('More Announcements');
+            jQuery('#toggle_announcements').text(jQuery('#toggle_announcements').data('text-more'));
             hide = true;
         }
     });

commit b2452c50b00adfc812a9460e37e1f9952726d6b9
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 23 06:15:54 2021 +0800

    Add bootstrap style for RT 5

diff --git a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
index 48770cf..4e22be8 100644
--- a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
+++ b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
@@ -47,6 +47,53 @@
 %# END BPS TAGGED BLOCK }}}
 
 <div id="announce">
+
+% if ( RT::Handle::cmp_version($RT::VERSION, '5.0.0') >= 0 ) {
+% my $rows = 1;
+% foreach my $ticket ( @tickets ){
+  <div class="alert alert-danger" role="alert">
+    <div class="row">
+      <div class="col-3 announce_subject announce_cell">
+%     if( $show_ticket_links{$ticket->Id} ){
+        <a class="announce_subject" href="<% RT->Config->Get('WebPath') %>/Ticket/Display.html?id=<% $ticket->Id %>">
+          <% $ticket->Subject %>
+        </a>
+%     } else {
+        <% $ticket->Subject %>
+%     }
+      </div>
+      <div class="col-7 announce_cell">
+%     if ( $show_html ) {
+        <% $content{$ticket->Id} |n %>
+%     } else {
+        <% $content{$ticket->Id} %>
+%     }
+%     if ( $show_ticket_links{$ticket->Id} ) {
+        (<a class="announcements_detail" href="<% RT->Config->Get('WebPath') %>/Ticket/Display.html?id=<% $ticket->Id %>"><% loc('more') %></a>)
+%     }
+      </div>
+      <div class="col-2 date announce_cell text-secondary">
+        <% $ticket->LastUpdatedObj->AsString %>
+      </div>
+    </div>
+  </div>
+% if ( $rows == $ShowTickets && (scalar @tickets) > $ShowTickets ) {
+%   # More announcements, initially hidden.
+  <div id="more_announcements" class="collapse">
+% }
+% $rows++;
+% }
+
+% if ( scalar @tickets > $ShowTickets ){
+    </div>
+    <div class="row mb-3">
+      <div class="col-12 toggle_announcements text-center">
+        <a data-text-more="<% loc('More Announcements') %>" data-text-less="<% loc('Less Announcements') %>" class="button btn btn-default btn-sm" data-toggle="collapse" href="#more_announcements" id="toggle_announcements"><% loc('More Announcements') %></a>
+      </div>
+    </div>
+% }
+
+% } else {
 <table class="announce">
 %my $rows = 1;
 %foreach my $ticket ( @tickets ){
@@ -88,7 +135,10 @@
 %if( scalar @tickets > $ShowTickets ){
 </tbody>
 %}
-</table></div>
+</table>
+
+% }
+</div>
 <%INIT>
 # Only display on Homepage
 if ( RT->Config->Get('ShowAnnouncementsInSelfService') ) {
diff --git a/static/css/announce.css b/static/css/announce.css
index 8f69748..1f6904b 100644
--- a/static/css/announce.css
+++ b/static/css/announce.css
@@ -109,3 +109,9 @@ table.announce td.date {
 /*  width: 0px;  */ /* Remove scrollbar space */
 /*  background: #fcc;  */ /* Optional: just make scrollbar invisible */
 }
+
+/* RT 5 */
+
+#toggle_announcements.btn:hover {
+  color: white;
+}
diff --git a/static/js/announce.js b/static/js/announce.js
index 98560f8..44ecee7 100644
--- a/static/js/announce.js
+++ b/static/js/announce.js
@@ -1,8 +1,8 @@
 
 jQuery(document).ready(function() {
-    jQuery('#more_announcements').hide();
+    jQuery('table #more_announcements').hide();
     var hide = true;
-    jQuery('#toggle_announcements').click( function() {
+    jQuery('table #toggle_announcements').click( function() {
         if ( hide == true ) {
             jQuery('#more_announcements').show();
             jQuery('#toggle_announcements').text(jQuery('#toggle_announcements').data('text-less'));
@@ -14,4 +14,11 @@ jQuery(document).ready(function() {
             hide = true;
         }
     });
+
+    jQuery('#more_announcements').on('hide.bs.collapse', function () {
+        jQuery('#toggle_announcements').text(jQuery('#toggle_announcements').data('text-more'));
+    });
+    jQuery('#more_announcements').on('show.bs.collapse', function () {
+        jQuery('#toggle_announcements').text(jQuery('#toggle_announcements').data('text-less'));
+    });
 });

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


More information about the Bps-public-commit mailing list