Skip to content

Commit

Permalink
Show list of open timers in RT menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Crome committed Mar 22, 2024
1 parent 53c71e7 commit 1788579
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
18 changes: 18 additions & 0 deletions lib/RT/Interface/Web/MenuBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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/} ) {
Expand Down
3 changes: 3 additions & 0 deletions share/html/Helpers/AddTimeWorked
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions share/html/Helpers/StopTimer
Original file line number Diff line number Diff line change
@@ -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>
25 changes: 21 additions & 4 deletions share/html/Helpers/TicketTimer
Original file line number Diff line number Diff line change
Expand Up @@ -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 &>

Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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,
Expand Down
19 changes: 18 additions & 1 deletion share/html/Ticket/Elements/PopupTimerLink
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 1788579

Please sign in to comment.