misc updates

This commit is contained in:
Mark Gregory
2026-06-23 08:14:35 +01:00
parent 39ba020951
commit 90ba0bfafa
3 changed files with 120 additions and 3 deletions
+29 -3
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Modules\Helpdesk\Livewire;
use Carbon\Carbon;
@@ -33,6 +35,14 @@ class TicketTimer extends Component
$this->refreshActiveTimer();
}
/**
* Refresh the timer every poll cycle while the timer is running.
*/
public function refreshTimer(): void
{
$this->refreshActiveTimer();
}
/**
* Start a database-backed timer for the current authenticated user.
*
@@ -61,7 +71,7 @@ class TicketTimer extends Component
'ended_at' => null,
'logged_at' => $startedAt,
]);
} catch (QueryException $exception) {
} catch (QueryException) {
throw ValidationException::withMessages([
'timer' => 'You already have a running timer.',
]);
@@ -94,7 +104,6 @@ class TicketTimer extends Component
$endedAt = Carbon::now();
$description = trim($this->description) !== '' ? trim($this->description) : $timer->description;
$seconds = max(1, (int) $timer->started_at->diffInSeconds($endedAt));
$minutes = (int) ceil($seconds / 60);
$timer->forceFill([
@@ -122,6 +131,22 @@ class TicketTimer extends Component
$this->dispatch('timer-ended');
}
/**
* Get the currently elapsed timer duration.
*/
public function getElapsedTimeProperty(): string
{
return gmdate('H:i:s', $this->elapsedSeconds);
}
/**
* Determine whether the current user has a running timer.
*/
public function getIsRunningProperty(): bool
{
return $this->activeTimer instanceof TicketTimeLog;
}
/**
* Render the timer view.
*/
@@ -145,8 +170,9 @@ class TicketTimer extends Component
}
$this->activeTimer = $this->activeUserTimerQuery($user)->first();
$this->elapsedSeconds = $this->activeTimer instanceof TicketTimeLog
? $this->activeTimer->started_at->diffInSeconds(Carbon::now())
? max(0, (int) $this->activeTimer->started_at->diffInSeconds(Carbon::now()))
: 0;
}