[Bps-public-commit] rt-extension-timetracking branch, auto-time-tracking, created. 0.21-1-g6e06078

Steve Burr steve at bestpractical.com
Wed May 5 17:30:06 EDT 2021


The branch, auto-time-tracking has been created
        at  6e060786b6cf45449750dc8746b7ab23dcb96b8e (commit)

- Log -----------------------------------------------------------------
commit 6e060786b6cf45449750dc8746b7ab23dcb96b8e
Author: Steven Burr <steve at bestpractical.com>
Date:   Wed May 5 17:28:31 2021 -0400

    Add basic automatic time tracking
    
    Visit a ticket display page and update via the Actions menu.
    The time spent on the display page will pre-populate the TimeWorked
    textbox.

diff --git a/html/Callbacks/RT-Extension-TimeTracking/Ticket/Elements/ShowBasics/EndOfList b/html/Callbacks/RT-Extension-TimeTracking/Ticket/Elements/ShowBasics/EndOfList
index f263638..94b2c2d 100644
--- a/html/Callbacks/RT-Extension-TimeTracking/Ticket/Elements/ShowBasics/EndOfList
+++ b/html/Callbacks/RT-Extension-TimeTracking/Ticket/Elements/ShowBasics/EndOfList
@@ -55,6 +55,61 @@ $today->SetToNow();
     </form>
   </div>
 </div>
+<script>
+var timeTrackingStart = Date.now()
+var timeTrackerTimer
+
+window.timeSpent = function() {
+    // time worked in minutes
+    return Math.ceil( (Date.now() - timeTrackingStart) / (1000 * 60) )
+}
+
+window.parseUrl = function(url) {
+    url = url || ''
+    var parts = url.split("?")
+    return {href: url, path: parts[0], query: parts.length > 1 ? parts[1] : ''}
+}
+
+
+window.parseQuery = function(str) {
+    var params = {}
+    str = str || ''
+    var parts = str.split("?")
+    str = parts.length < 2 ? str : parts[1]
+    var pairs = str.split(/[&;]/)  // NB: RT sometimes uses nonstandard param sep!
+    pairs.forEach(function(pair) {
+        var parts = pair.split("=")
+        if (parts.length === 2) {
+            var key = decodeURIComponent(parts[0])
+            var val = decodeURIComponent(parts[1])
+            params[key] = val
+        }
+    })
+    return params
+}
+
+jQuery(document).ready(function() {
+    var fn = function() {
+        var tm = timeSpent()
+
+        // uncomment to have time auto-increment visibly on the Display page
+        jQuery('input[name="UpdateTimeWorked"]').val(tm)
+        jQuery('select[name="UpdateTimeWorked-TimeUnits"]').val("minutes")
+
+        // loop over the actions menu links and append UpdateTimeWorked value
+        jQuery("#li-page-actions li a").each(function() {
+            var el = jQuery(this)
+            var url = parseUrl(el.attr("href"))
+            var qry = parseQuery(url.href)
+            qry.UpdateTimeWorked = tm
+            el.attr("href", url.path + '?' + jQuery.param(qry))
+        })
+    }
+
+    // auto-update every 10 seconds
+    timeTrackerTimer = setInterval(fn, 10 * 1000)
+})
+</script>
 
 <%args>
 $TicketObj

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


More information about the Bps-public-commit mailing list