May Sale! All accounts are 40% off this week.

OneNonlyNova's avatar

Timer for TimeTracking

Hey guys,

i've just started to recode our existing application in laravel 5. We have a ticketsystem where every user can hit a Timer located in the top MenuBar. Once clicked the timer just counts upwards in HH:mm style. And if one would click the timer again he would be asked to assign the captured timeframe to a specific ticket.

How would one do that in laravel?

Any help, tips, advice is greatly appreciated

0 likes
2 replies
jhoff's avatar

Are you re-coding the entire ticketing system in laravel, or just the time tracker piece?

In general, the approach I would take with just the time tracking piece would probably look something like this:

PHP / Laravel:

  • Create a timer event model that stores the user_id, ticket_id, start_time, end_time ( nullable ) and any other metadata that you might need ( category, notes, etc )
  • Create an API to create, list and update timer events.

HTML / Javascript

( vue.js would be great for something like this, btw )

  • On your frontend, when the page loads, you could query for any active timers for that user and ticket
  • If no active timers, show a button to create one. This will generate a new timer event via the API, with now() as the start_time.
  • If there is an active timer, just get it's start time and pass it along to your javascript controller.
  • Use javascript to calculate how much time has elapsed since the start of the event and continue counting up in the browser.
  • Setup a heartbeat loop to automatically ping the server and touch the event model as long as the agent has the browser open. If they forget to end the event, you will have the option of backfilling the last updated timestamp into the end time later on for reporting purposes.
  • When the task is complete, they can have a button that will stop the event by calling the api and setting the end_time.
  • An additional API call could be made at any point to update any other data along the way ( before or after the event has ended )

The main benefit to this approach is that the timer is kept track on the server side. If the agent closes the browser accidentally, you don't have to worry about losing any of the event information. You also have some flexibility to possibly trigger changes based on actions of the ticket ( like if the agent closes the ticket, you could automatically end any events ).

I dunno if this helps at all. I hope it does. I would love to hear more specifics about the project.

OneNonlyNova's avatar

@jhoff hey there thanks for the reply. Yes i'm currently rewriting the whole project of about 2 billion lines of code. the code base is way to old and messy and is not in any way or shape able to be continue developing of - long term. so it's kinda a side project to recode everything fresh new with laravel as base.

back to topic. yeah i thought so, we did it the same way in our existing application. thought laravel might had some tricks for stuff like that. our current behavior is like -> timer click -> send ajax to create timer object and attach to user -> js starting to count up -> within a ticket there is a button besides the comment -> convert tracked time into 00,00 value for amount of attached workhour article from database.

Thanks anyways :) having a brand new problem bull will open a new post for that one :)

Please or to participate in this conversation.