[Rt-commit] rt branch 5.0/show-list-of-open-timers created. rt-5.0.5-247-g5bee01fc38

BPS Git Server git at git.bestpractical.com
Fri Apr 12 15:04:46 UTC 2024


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/show-list-of-open-timers has been created
        at  5bee01fc381c1b487de787cc9ba94be4adcb3c0e (commit)

- Log -----------------------------------------------------------------
commit 5bee01fc381c1b487de787cc9ba94be4adcb3c0e
Author: Jason Crome <jcrome at bestpractical.com>
Date:   Thu Mar 28 10:59:47 2024 -0400

    Show list of open timers in RT menu

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 930dd524c8..9966dbd188 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -358,6 +358,24 @@ sub BuildMainNav {
         }
     }
 
+    my $timer_list = $HTML::Mason::Commands::session{'CurrentUser'}{'timers'};
+    if( keys %{ $timer_list } ) {
+        my $timers = $top->child( 'timers' =>
+            title        => loc('Timers'),
+            escape_title => 0,
+            path         => '/',
+            sort_order   => 100,
+        );
+        if( my @tickets = sort keys %{ $timer_list } ) {
+            foreach my $id( @tickets ) {
+                my $timed_ticket = RT::Ticket->new( $current_user );
+                $timed_ticket->Load($id);
+
+                my $description = "$id - " . $timed_ticket->Subject;
+                $timers->child( "ticket_$id" => title => $description, path => "/Ticket/Display.html?id=$id" );
+            }
+        }
+    }
 
     my $search_results_page_menu;
     if ( $request_path =~ m{^/Ticket/} ) {
diff --git a/share/html/Helpers/AddTimeWorked b/share/html/Helpers/AddTimeWorked
index db89ae92b8..6fecf2f5a5 100644
--- a/share/html/Helpers/AddTimeWorked
+++ b/share/html/Helpers/AddTimeWorked
@@ -92,6 +92,9 @@ else {
     }
 }
 
+delete $session{'CurrentUser'}{'timers'}{$id};
+$session{'i'}++;
+
 $r->content_type('application/json; charset=utf-8');
 $m->print(JSON({ ok => $ok, msg => $msg }));
 $m->abort;
diff --git a/share/html/Helpers/AddTimeWorked b/share/html/Helpers/StopTimer
similarity index 61%
copy from share/html/Helpers/AddTimeWorked
copy to share/html/Helpers/StopTimer
index db89ae92b8..155217e32c 100644
--- a/share/html/Helpers/AddTimeWorked
+++ b/share/html/Helpers/StopTimer
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2024 Best Practical Solutions, LLC
 %#                                          <sales at bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -47,52 +47,10 @@
 %# END BPS TAGGED BLOCK }}}
 <%ARGS>
 $id
-$seconds => 0
-$comment => undef
 </%ARGS>
 <%INIT>
-my $Ticket = RT::Ticket->new($session{'CurrentUser'});
-$Ticket->Load( $id );
-
-# round up 30s or more
-my $minutes = int(0.5 + $seconds / 60);
-
-my ($ok, $msg);
-if ($minutes == 0) {
-    # avoid "That is already the current value" error
-    $ok = 1;
-    $msg = loc("Worked [quant,_1,minute,minutes]", 0);
-
-    if ($comment) {
-        my ($comment_ok, $comment_msg) = $Ticket->Comment(Content => $comment);
-        if (!$comment_ok) {
-            ($ok, $msg) = ($comment_ok, $comment_msg);
-        }
-    }
-}
-else {
-    if ($comment) {
-        ($ok, $msg) = $Ticket->Comment(
-            Content   => $comment,
-            TimeTaken => $minutes,
-        );
-    }
-    else {
-        my $total_worked = $Ticket->TimeWorked + $minutes;
-        ($ok, $msg) = $Ticket->SetTimeWorked($total_worked);
-    }
-
-    if ($ok) {
-        if ($minutes < 60) {
-            $msg = loc("Worked [quant,_1,minute,minutes]", $minutes);
-        }
-        else {
-            $msg = loc("Worked [quant,_1,hour,hours] ([quant,_2,minute,minutes])", sprintf("%.2f", $minutes / 60), $minutes);
-        }
-    }
-}
-
-$r->content_type('application/json; charset=utf-8');
-$m->print(JSON({ ok => $ok, msg => $msg }));
+RT->Logger->debug( "Stopping timer for Ticket $id" );
+delete $session{'CurrentUser'}{'timers'}{$id};
+$session{'i'}++;
 $m->abort;
 </%INIT>
diff --git a/share/html/Helpers/TicketTimer b/share/html/Helpers/TicketTimer
index 747c6fbcb6..f73c771adb 100644
--- a/share/html/Helpers/TicketTimer
+++ b/share/html/Helpers/TicketTimer
@@ -56,6 +56,10 @@ my $Now = RT::Date->new($session{'CurrentUser'});
 $Now->SetToNow;
 
 my $SubmitURL = RT->Config->Get('WebPath') . '/Helpers/AddTimeWorked';
+
+my $CancelURL = RT->Config->Get('WebPath') . '/Helpers/StopTimer';
+$session{'CurrentUser'}{'timers'}{$id} = 1;
+$session{'i'}++;
 </%INIT>
 <& /Elements/Header, Title => loc('Timer for #[_1]: [_2]', $Ticket->Id, $Ticket->Subject), RichText => 0, ShowBar => 0, ShowTitle => 0 &>
 
@@ -155,7 +159,6 @@ jQuery( function() {
                 if (Response.ok) {
                     Readout.addClass('response');
                     Readout.text(Response.msg);
-                    jQuery('.control-line .close-popup').removeClass('hidden');
                 }
                 else {
                     RenderSubmitError(Response.msg);
@@ -170,8 +173,22 @@ jQuery( function() {
     });
 
     jQuery('.close-popup').click(function () {
-        window.close();
-        return false;
+        var Payload = { id: <% $Ticket->id %> };
+
+        jQuery.ajax({
+            url: <% $CancelURL |n,j %>,
+            data: Payload,
+            timeout: 30000, /* 30 seconds */
+            // The window closes before the ajax call happens if we close the window outside the callbacks
+            success: function (Response) {
+                window.close();
+                return false;
+            },
+            error: function (xhr, reason) {
+                window.close();
+                return false;
+            }
+        });
     });
 
     Tick();
@@ -193,7 +210,7 @@ jQuery( function() {
             <a href="#" class="playpause pause"><span class="far fa-pause-circle" alt="<% loc('Pause Timer') %>" data-toggle="tooltip" data-placement="bottom" data-original-title="<% loc('Pause Timer') %>"></span></a>
             <a href="#" class="playpause play hidden"><span class="far fa-play-circle" alt="<% loc('Resume Timer') %>" data-toggle="tooltip" data-placement="bottom" data-original-title="<% loc('Resume Timer') %>"></span></a>
             <a href="#" class="submit-time"><span class="far fa-arrow-alt-circle-up" alt="<% loc('Submit Timer') %>" data-toggle="tooltip" data-placement="bottom" data-original-title="<% loc('Submit Timer') %>"></span></a>
-            <a href="#" class="close-popup hidden"><span class="far fa-times-circle" alt="<% loc('Close Window') %>" data-toggle="tooltip" data-placement="bottom" data-original-title="<% loc('Close Window') %>"></span></a>
+            <a href="#" class="close-popup"><span class="far fa-times-circle" alt="<% loc('Close Window') %>" data-toggle="tooltip" data-placement="bottom" data-original-title="<% loc('Close Window') %>"></span></a>
         </div>
 
         <& /Elements/MessageBox,

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list