[Rt-commit] rt branch, 4.4/ticket-timer, updated. rt-4.2.11-186-g67e030d

Shawn Moore shawn at bestpractical.com
Mon Sep 21 19:21:23 EDT 2015


The branch, 4.4/ticket-timer has been updated
       via  67e030d6e7164edb69d44858d675fe15f6d9439b (commit)
      from  8a4f8b18344d93a02c932a4ca7f4eb558c50447d (commit)

Summary of changes:
 share/html/Helpers/{TicketTimer => AddTimeWorked} |  19 ++--
 share/html/Helpers/TicketTimer                    | 101 +++++++++++++++++++++-
 share/html/Ticket/Elements/PopupTimerLink         |   4 +-
 share/static/css/base/misc.css                    |  46 ++++++++++
 4 files changed, 161 insertions(+), 9 deletions(-)
 copy share/html/Helpers/{TicketTimer => AddTimeWorked} (84%)

- Log -----------------------------------------------------------------
commit 67e030d6e7164edb69d44858d675fe15f6d9439b
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Sep 21 23:21:06 2015 +0000

    WIP

diff --git a/share/html/Helpers/TicketTimer b/share/html/Helpers/AddTimeWorked
similarity index 84%
copy from share/html/Helpers/TicketTimer
copy to share/html/Helpers/AddTimeWorked
index f70f86e..ba7a0f2 100644
--- a/share/html/Helpers/TicketTimer
+++ b/share/html/Helpers/AddTimeWorked
@@ -47,13 +47,22 @@
 %# END BPS TAGGED BLOCK }}}
 <%ARGS>
 $id
+$seconds => 0
 </%ARGS>
 <%INIT>
-my $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
+my $Ticket = RT::Ticket->new($session{'CurrentUser'});
 $Ticket->Load( $id );
-</%INIT>
-<& /Elements/Header, Title => loc('Timer for #[_1]: [_2]', $Ticket->Id, $Ticket->Subject), RichText => 0, ShowBar => 0, ShowTitle => 0 &>
 
-<a href="<%RT->Config->Get('WebPath')%>/Ticket/Display.html?id=<%$Ticket->Id%>"><%$Ticket->Id%>: <%$Ticket->Subject%></a>
+my $minutes = int($seconds / 60);
+
+my $total_worked = $Ticket->TimeWorked + $minutes;
 
-% $m->abort();
+if ($minutes < 60) {
+    $m->print(loc("Worked [quant,_1,minute,minutes]", $minutes));
+}
+else {
+    $m->print(loc("Worked [quant,_1,hour,hours] ([quant,_2,minute,minutes])", sprintf("%.2f", $minutes / 60), $minutes));
+}
+
+$m->abort;
+</%INIT>
diff --git a/share/html/Helpers/TicketTimer b/share/html/Helpers/TicketTimer
index f70f86e..8f63c6b 100644
--- a/share/html/Helpers/TicketTimer
+++ b/share/html/Helpers/TicketTimer
@@ -49,11 +49,108 @@
 $id
 </%ARGS>
 <%INIT>
-my $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
+my $Ticket = RT::Ticket->new($session{'CurrentUser'});
 $Ticket->Load( $id );
+
+my $unpause_img = RT->Config->Get('WebPath') . '/static/images/unpause.png';
+my $pause_img   = RT->Config->Get('WebPath') . '/static/images/pause.png';
+
+my $now = RT::Date->new($session{'CurrentUser'});
+$now->SetToNow;
+
+my $submit_url = RT->Config->Get('WebPath') . '/Helpers/AddTimeWorked';
 </%INIT>
 <& /Elements/Header, Title => loc('Timer for #[_1]: [_2]', $Ticket->Id, $Ticket->Subject), RichText => 0, ShowBar => 0, ShowTitle => 0 &>
 
-<a href="<%RT->Config->Get('WebPath')%>/Ticket/Display.html?id=<%$Ticket->Id%>"><%$Ticket->Id%>: <%$Ticket->Subject%></a>
+<script type="text/javascript">
+jQuery( function() {
+    var Interval;
+    var Seconds = 0;
+
+    var readout = jQuery('.readout');
+    var playpause = jQuery('.playpause');
+
+    var pause_alt = playpause.attr('alt');
+    var unpause_alt = playpause.data('toggle-alt');
+
+    var toHHMMSS = function (total) {
+        var hours   = Math.floor(total / 3600);
+        var minutes = Math.floor((total - (hours * 3600)) / 60);
+        var seconds = total - (hours * 3600) - (minutes * 60);
+    
+        if (minutes < 10) { minutes = "0" + minutes; }
+        if (seconds < 10) { seconds = "0" + seconds; }
+
+        return hours + ':' + minutes + ':' + seconds;
+    };
+
+    var renderReadout = function (seconds) {
+        readout.text(toHHMMSS(seconds));
+    };
+
+    var tick = function () {
+        Seconds++;
+        renderReadout(Seconds);
+    };
+
+    jQuery('.playpause').click(function () {
+        if (Interval) {
+            // pause
+            clearInterval(Interval);
+            Interval = false;
+            playpause.attr('src', <% $unpause_img |n,j %>);
+            playpause.attr('alt', unpause_alt);
+        }
+        else {
+            // unpause
+            Interval = setInterval(tick, 1000);
+            playpause.attr('src', <% $pause_img |n,j %>);
+            playpause.attr('alt', pause_alt);
+        }
+    });
+
+    jQuery('.submit-time').click(function () {
+        clearInterval(Interval);
+        jQuery('.control-line img, .control-line .playpause-container').hide();
+
+        readout.text('<% loc("Submitting...") %>');
+        jQuery.get(<% $submit_url |n,j %>, {
+            id: <% $Ticket->id %>,
+            seconds: Seconds
+        }, function (data) {
+            readout.text(data);
+            jQuery('.control-line .close-popup').removeClass('hidden');
+        });
+    });
+
+    jQuery('.close-popup').click(function () {
+        window.close();
+    });
+
+    renderReadout(Seconds);
+    Interval = setInterval(tick, 1000);
+});
+</script>
+
+<div class="ticket-timer">
+    <div class="ticket-link"><a href="<%RT->Config->Get('WebPath')%>/Ticket/Display.html?id=<%$Ticket->Id%>"><%$Ticket->Id%>: <%$Ticket->Subject%></a></div>
+
+    <div class="readout"></div>
+
+    <div class="control-line">
+        <div class="playpause-container">
+            <img class="playpause" src="<% $pause_img %>" alt="<% loc('Pause Timer') %>" data-toggle-alt="<% loc('Unpause Timer') %>" />
+        </div>
+        <img class="submit-time" src="<% RT->Config->Get('WebPath') %>/static/images/stopwatch.png" alt="<% loc('Submit Timer') %>" />
+        <img class="close-popup hidden" src="<% RT->Config->Get('WebPath') %>/static/images/close.png" alt="<% loc('Close Window') %>" />
+    </div>
+
+    <div class="extra"><&|/l, $now->AsString &>Started at [_1].</&></div>
+
+% if ($Ticket->TimeEstimated) {
+    <div class="extra"><&|/l&>Time estimated</&>: <& /Ticket/Elements/ShowTime, minutes => $Ticket->TimeEstimated &></div>
+% }
+
+</div>
 
 % $m->abort();
diff --git a/share/html/Ticket/Elements/PopupTimerLink b/share/html/Ticket/Elements/PopupTimerLink
index f0fd384..bcfe4e7 100644
--- a/share/html/Ticket/Elements/PopupTimerLink
+++ b/share/html/Ticket/Elements/PopupTimerLink
@@ -2,10 +2,10 @@
 $id
 </%ARGS>
 <%INIT>
-my $url = RT->Config->Get('WebPath') ."/Helpers/TicketTimer?id=". $id;
+my $url = RT->Config->Get('WebPath') . "/Helpers/TicketTimer?id=" . $id;
 </%INIT>
 <span class="timer-link">
     <a href="<% $url %>" onclick="window.open(<% $url |n,j %>, '_blank', 'height=200,width=200'); return false;" >
-        <img src="<% RT->Config->Get('WebPath') %>/static/images/stopwatch.png" alt="<% loc('Open Timer') %>" />
+        <img src="<% RT->Config->Get('WebPath') %>/static/images/stopwatch.png" alt="<% loc('Open Timer') %>" title="<% loc('Open Timer') %>" />
     </a>
 </span>
diff --git a/share/static/css/base/misc.css b/share/static/css/base/misc.css
index 7fbc32f..523b397 100644
--- a/share/static/css/base/misc.css
+++ b/share/static/css/base/misc.css
@@ -83,3 +83,49 @@ textarea.messagebox, #cke_Content, #cke_UpdateContent {
 .timer-link img {
     height: 1.5em;
 }
+
+.ticket-timer {
+    padding: 1em;
+}
+
+.ticket-timer img {
+    height: 1.5em;
+}
+
+.ticket-timer .ticket-link {
+    width: 100%;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+}
+
+.ticket-timer .readout {
+    font-size: 2em;
+    text-align: center;
+    width: 100%;
+}
+
+.ticket-timer .control-line {
+    text-align: center;
+}
+
+.ticket-timer .control-line > div,
+.ticket-timer .control-line > img {
+    margin: 0 1em;
+}
+
+/* make sure play and pause icons have the same width */
+.ticket-timer .playpause-container {
+    display: inline-block;
+    text-align: center;
+    height: 1.5em;
+    width: 1.5em;
+}
+
+.ticket-timer .extra {
+    color: #aaa;
+}
+
+.ticket-timer > div {
+    margin-bottom: 0.5em;
+}

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


More information about the rt-commit mailing list