Mailing List Archive

rt branch 5.0/show-list-of-open-timers updated. rt-5.0.5-167-g17885798f1
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 updated
via 17885798f182765b6e6398da17ddb812ce501545 (commit)
from 53c71e745b73f877f8051e627f3247de9547033c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 17885798f182765b6e6398da17ddb812ce501545
Author: Jason Crome <jcrome@bestpractical.com>
Date: Fri Mar 22 19:40:08 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/StopTimer b/share/html/Helpers/StopTimer
new file mode 100644
index 0000000000..ae7664a666
--- /dev/null
+++ b/share/html/Helpers/StopTimer
@@ -0,0 +1,9 @@
+<%ARGS>
+$id
+</%ARGS>
+<%INIT>
+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..c337f274e6 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,
diff --git a/share/html/Ticket/Elements/PopupTimerLink b/share/html/Ticket/Elements/PopupTimerLink
index 11b56abb81..43c867ffc4 100644
--- a/share/html/Ticket/Elements/PopupTimerLink
+++ b/share/html/Ticket/Elements/PopupTimerLink
@@ -51,7 +51,24 @@ $id
<%INIT>
my $url = RT->Config->Get('WebPath') . "/Helpers/TicketTimer?id=" . $id;
my $alt = loc('Open Timer');
+my $CancelURL = RT->Config->Get('WebPath') . '/Helpers/StopTimer';
</%INIT>
-<a href="<% $url %>" onclick="window.open(<% $url |n,j %>, '_blank', 'height=200,width=200'); return false;" >
+<script>
+function openTimer() {
+ var timerWindow = window.open(<% $url |n,j %>, '_blank', 'height=200,width=200');
+ var timerClosed = setInterval( function() {
+ if( timerWindow.closed ) {
+ clearInterval( timerClosed );
+ var Payload = { id: <% $id %> };
+ jQuery.ajax({
+ url: <% $CancelURL |n,j %>,
+ data: Payload,
+ timeout: 30000, /* 30 seconds */
+ });
+ }
+ }, 1000 ); // Check every second
+}
+</script>
+<a href="<% $url %>" onclick="openTimer(); return false;" >
<span class="far fa-clock" alt="<% $alt %>" data-toggle="tooltip" data-placement="top" data-original-title="<% $alt %>"></span>
</a>

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

Summary of changes:
lib/RT/Interface/Web/MenuBuilder.pm | 18 ++++++++++++++++++
share/html/Helpers/AddTimeWorked | 3 +++
share/html/Helpers/StopTimer | 9 +++++++++
share/html/Helpers/TicketTimer | 25 +++++++++++++++++++++----
share/html/Ticket/Elements/PopupTimerLink | 19 ++++++++++++++++++-
5 files changed, 69 insertions(+), 5 deletions(-)
create mode 100644 share/html/Helpers/StopTimer


hooks/post-receive
--
rt
_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
https://lists.bestpractical.com/mailman/listinfo/rt-commit