[Rt-commit] rt branch 5.0/statement-timeout2 created. rt-5.0.3-148-ga27870c41b

BPS Git Server git at git.bestpractical.com
Tue Dec 20 18:28:24 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/statement-timeout2 has been created
        at  a27870c41b6beeca0637a77769bd89f6ca226c79 (commit)

- Log -----------------------------------------------------------------
commit a27870c41b6beeca0637a77769bd89f6ca226c79
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 16 16:28:55 2022 -0500

    Provide a simple framework for showing user messages
    
    During processing, messages can be stashed in notes,
    then Footer writes any messages to the page at the end
    for growl to then show to the user.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 2c06b49972..6e4341f280 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2914,7 +2914,7 @@ sub SimpleQuery {
 
     # Show end user something if query failed.
     if ($HTML::Mason::Commands::m) {
-        $HTML::Mason::Commands::m->notes( 'SQLError' => 1 );
+        $HTML::Mason::Commands::m->notes('Message:SQLTimeout' => 1 );
     }
     return $ret;
 }
diff --git a/lib/RT/System.pm b/lib/RT/System.pm
index b07ea86abf..ee526718fa 100644
--- a/lib/RT/System.pm
+++ b/lib/RT/System.pm
@@ -448,6 +448,58 @@ sub ExternalStorageURLFor {
     return $self->ExternalStorage->DownloadURLFor($Object);
 }
 
+# Catalog of message codes and user messages
+our %MESSAGES;
+%MESSAGES = (
+    'SQLTimeout' => 'Your query exceeded the maximum run time and was stopped. Try modifying your query to improve the performance or contact your RT admin.',
+);
+
+=head1 UserMessages
+
+Accepts CurrentUser => $user_obj to use for localizing messages. If not
+passed, messages are in English.
+
+Returns a hash with keys of message codes and values with corresonding user messages
+localized for the currently logged in user.
+
+To add messages, create entries in C<%MESSAGES> with an appropriate message code
+as the key.
+
+To trigger display of that message, add an entry to notes, prefixed with
+C<Message:>, like:
+
+    if ( $something_happened ) {
+        $HTML::Mason::Commands::m->notes('Message:SQLTimeout' => 1 );
+    }
+
+For the web UI, C<Elements/Footer> will pick that up and display the message
+to the user in the browser.
+
+=cut
+
+sub UserMessages {
+    my $self = shift;
+    my %args     = (
+        CurrrentUser => undef,
+        @_
+    );
+
+    my %messages;
+
+    foreach my $entry ( keys %MESSAGES ) {
+        if ( $args{CurrentUser}
+             && ref $args{CurrentUser} eq 'RT::User'
+             && $args{CurrentUser}->Id ) {
+            $messages{$entry} = $args{CurrentUser}->loc($MESSAGES{$entry});
+        }
+        else {
+            $messages{$entry} = $MESSAGES{$entry};
+        }
+    }
+
+    return \%messages;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/share/html/Elements/Footer b/share/html/Elements/Footer
index 556efcc950..9adbecc24d 100644
--- a/share/html/Elements/Footer
+++ b/share/html/Elements/Footer
@@ -78,8 +78,28 @@
 </pre>
 % }
     </div>
+<script type="text/javascript">
+RT.UserMessages = <% JSON( \%UserMessages ) |n%>;
+</script>
   </body>
 </html>
+<%init>
+my $messages;
+my %UserMessages;
+
+unless ( RT->InstallMode ) {
+    $messages = RT->System->UserMessages( CurrentUser => $session{'CurrentUser'} );
+}
+
+# Check for any messages from the page processing stashed in notes.
+# We'll write them to the page so growl can find and display them.
+
+foreach my $note ( keys %{$m->notes} ) {
+    if ( my ($message) = $note =~ /^Message\:(\w+)/ ) {
+        $UserMessages{$message} = $messages->{$message};
+    }
+}
+</%init>
 <%ARGS>
 $Debug => 0
 $Menu => 1
diff --git a/share/static/js/util.js b/share/static/js/util.js
index 25ba76a20e..89cdb658c7 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -1246,3 +1246,11 @@ function toggleTransactionDetails () {
 
     return false;
 }
+
+// Use Growl to show any UserMessages written to the page
+jQuery( function() {
+    var userMessages = RT.UserMessages;
+    for (var key in userMessages) {
+        jQuery.jGrowl(userMessages[key], { sticky: true, themeState: 'none' });
+    }
+} );

commit a81ff4c21dba333953140108fdfd9508e9a006bc
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 16 16:24:38 2022 -0500

    Remove End template

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 45aae2af2c..da6382ec27 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -422,8 +422,6 @@ sub HandleRequest {
         Path => $HTML::Mason::Commands::m->request_path,
     });
 
-    $HTML::Mason::Commands::m->comp( '/Elements/End', %$ARGS );
-
     # Process per-page final cleanup callbacks
     $HTML::Mason::Commands::m->callback( %$ARGS, CallbackName => 'Final', CallbackPage => '/autohandler' );
 
diff --git a/share/html/Elements/End b/share/html/Elements/End
deleted file mode 100644
index ba1c64cd45..0000000000
--- a/share/html/Elements/End
+++ /dev/null
@@ -1,54 +0,0 @@
-%# BEGIN BPS TAGGED BLOCK {{{
-%#
-%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2022 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 }}}
-% if ( $m->notes('SQLError') ) {
-<script type="text/javascript">
-jQuery( function() {
-  jQuery.jGrowl(<% loc('Page content might be inaccurate because of SQL error. Please contact your admin, they can find more details in the logs.') |j %>, { sticky: true, themeState: 'none' });
-} );
-</script>
-% }

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list