fixed badge
This commit is contained in:
@@ -4,27 +4,36 @@
|
||||
|
||||
$ticketTimeLogTable = (new TicketTimeLog())->getTable();
|
||||
|
||||
$hasEndedAtColumn = Schema::hasColumn($ticketTimeLogTable, 'ended_at');
|
||||
$hasStoppedAtColumn = Schema::hasColumn($ticketTimeLogTable, 'stopped_at');
|
||||
$hasFinishedAtColumn = Schema::hasColumn($ticketTimeLogTable, 'finished_at');
|
||||
$hasUserIdColumn = Schema::hasColumn($ticketTimeLogTable, 'user_id');
|
||||
|
||||
$runningTimerQuery = TicketTimeLog::query()
|
||||
->where('ticket_id', $ticket->getKey())
|
||||
->whereNotNull('started_at')
|
||||
->orderByDesc('started_at');
|
||||
|
||||
if (Schema::hasColumn($ticketTimeLogTable, 'user_id')) {
|
||||
if ($hasUserIdColumn) {
|
||||
$runningTimerQuery->where('user_id', auth()->id());
|
||||
}
|
||||
|
||||
if (Schema::hasColumn($ticketTimeLogTable, 'ended_at')) {
|
||||
if ($hasEndedAtColumn) {
|
||||
$runningTimerQuery->whereNull('ended_at');
|
||||
}
|
||||
|
||||
if (Schema::hasColumn($ticketTimeLogTable, 'stopped_at')) {
|
||||
if ($hasStoppedAtColumn) {
|
||||
$runningTimerQuery->whereNull('stopped_at');
|
||||
}
|
||||
|
||||
if (Schema::hasColumn($ticketTimeLogTable, 'finished_at')) {
|
||||
if ($hasFinishedAtColumn) {
|
||||
$runningTimerQuery->whereNull('finished_at');
|
||||
}
|
||||
|
||||
$runningTimer = $runningTimerQuery->first();
|
||||
$runningTimer = ($hasEndedAtColumn || $hasStoppedAtColumn || $hasFinishedAtColumn)
|
||||
? $runningTimerQuery->first()
|
||||
: null;
|
||||
|
||||
$runningTimerStartedAt = $runningTimer?->started_at;
|
||||
$runningTimerElapsedSeconds = $runningTimerStartedAt
|
||||
? max(0, now()->diffInSeconds($runningTimerStartedAt))
|
||||
@@ -55,6 +64,7 @@
|
||||
<span
|
||||
class="{{ $hasRunningTimer ? 'inline-flex' : 'hidden' }} mt-2 w-fit items-center gap-2 rounded-xl bg-emerald-400/20 px-3 py-1.5 text-xs font-black text-emerald-50 ring-1 ring-emerald-200/40"
|
||||
data-helpdesk-running-summary-badge
|
||||
data-helpdesk-started-at="{{ $runningTimerStartedAt?->toIso8601String() }}"
|
||||
data-dusk="ticket-running-timer-summary">
|
||||
<span class="relative flex h-2.5 w-2.5">
|
||||
<span class="absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-200 opacity-75"></span>
|
||||
@@ -92,6 +102,7 @@
|
||||
<p class="text-[0.68rem] font-black uppercase tracking-[0.18em] text-emerald-700 dark:text-emerald-300">
|
||||
Timer running
|
||||
</p>
|
||||
|
||||
<p class="mt-1 text-xs font-semibold text-emerald-800 dark:text-emerald-200">
|
||||
Started {{ $runningTimerStartedAt->format('d M Y H:i:s') }}
|
||||
</p>
|
||||
@@ -99,9 +110,11 @@
|
||||
|
||||
<div class="shrink-0 text-right">
|
||||
<p class="font-mono text-2xl font-black leading-none text-emerald-900 dark:text-emerald-100"
|
||||
data-helpdesk-panel-elapsed
|
||||
data-dusk="ticket-running-elapsed-time">
|
||||
{{ $runningTimerElapsedDisplay }}
|
||||
</p>
|
||||
|
||||
<p class="mt-1 text-[0.65rem] font-bold uppercase tracking-wide text-emerald-700 dark:text-emerald-300">
|
||||
Elapsed
|
||||
</p>
|
||||
@@ -110,9 +123,11 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@include('helpdesk::partials.ticket-time-timer', [
|
||||
'ticket' => $ticket,
|
||||
])
|
||||
<div data-helpdesk-timer-source>
|
||||
@include('helpdesk::partials.ticket-time-timer', [
|
||||
'ticket' => $ticket,
|
||||
])
|
||||
</div>
|
||||
|
||||
<form method="POST" action="{{ route('helpdesk.tickets.time-logs.store', $ticket) }}"
|
||||
class="mb-4 space-y-2">
|
||||
@@ -222,8 +237,9 @@
|
||||
</select>
|
||||
|
||||
@error('priority_id')
|
||||
<p class="text-xs font-bold text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
<p class="text-xs font-bold text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
|
||||
<button type="submit" dusk="update-priority"
|
||||
class="inline-flex items-center justify-center rounded-lg bg-amber-500 px-3 py-2 text-xs font-black text-white shadow-sm transition hover:bg-amber-600 focus:outline-none focus:ring-2 focus:ring-amber-300/70">
|
||||
<i class="fa-solid fa-flag mr-2" aria-hidden="true"></i>
|
||||
@@ -236,22 +252,25 @@
|
||||
(() => {
|
||||
const root = document.querySelector('[data-helpdesk-ticket-controls]');
|
||||
|
||||
if (!root || root.dataset.helpdeskTimerBadgeBound === 'true') {
|
||||
if (!root || root.dataset.helpdeskElapsedBadgeBound === 'true') {
|
||||
return;
|
||||
}
|
||||
|
||||
root.dataset.helpdeskTimerBadgeBound = 'true';
|
||||
root.dataset.helpdeskElapsedBadgeBound = 'true';
|
||||
|
||||
const source = root.querySelector('[data-helpdesk-timer-source]');
|
||||
const badge = root.querySelector('[data-helpdesk-running-summary-badge]');
|
||||
const summaryElapsed = root.querySelector('[data-helpdesk-running-summary-elapsed]');
|
||||
const panelElapsed = root.querySelector('[data-dusk="ticket-running-elapsed-time"]');
|
||||
const panelElapsed = root.querySelector('[data-helpdesk-panel-elapsed]');
|
||||
|
||||
if (!badge || !summaryElapsed) {
|
||||
if (!source || !badge || !summaryElapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
let startedAt = null;
|
||||
let interval = null;
|
||||
let startedAt = badge.dataset.helpdeskStartedAt
|
||||
? Date.parse(badge.dataset.helpdeskStartedAt)
|
||||
: null;
|
||||
|
||||
const formatElapsed = (seconds) => {
|
||||
const date = new Date(Math.max(0, seconds) * 1000);
|
||||
@@ -259,15 +278,18 @@
|
||||
return date.toISOString().substring(11, 19);
|
||||
};
|
||||
|
||||
const readElapsedSeconds = () => {
|
||||
const value = String(panelElapsed?.textContent || summaryElapsed.textContent || '00:00:00').trim();
|
||||
const parts = value.split(':').map((part) => Number.parseInt(part, 10));
|
||||
|
||||
if (parts.length !== 3 || parts.some(Number.isNaN)) {
|
||||
return 0;
|
||||
const updateElapsed = () => {
|
||||
if (!startedAt) {
|
||||
startedAt = Date.now();
|
||||
}
|
||||
|
||||
return (parts[0] * 3600) + (parts[1] * 60) + parts[2];
|
||||
const display = formatElapsed(Math.floor((Date.now() - startedAt) / 1000));
|
||||
|
||||
summaryElapsed.textContent = display;
|
||||
|
||||
if (panelElapsed) {
|
||||
panelElapsed.textContent = display;
|
||||
}
|
||||
};
|
||||
|
||||
const showBadge = () => {
|
||||
@@ -275,41 +297,38 @@
|
||||
badge.classList.add('inline-flex');
|
||||
|
||||
if (!startedAt) {
|
||||
startedAt = Date.now() - (readElapsedSeconds() * 1000);
|
||||
startedAt = Date.now();
|
||||
}
|
||||
|
||||
updateElapsed();
|
||||
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
return;
|
||||
}
|
||||
|
||||
interval = setInterval(() => {
|
||||
const display = formatElapsed(Math.floor((Date.now() - startedAt) / 1000));
|
||||
|
||||
summaryElapsed.textContent = display;
|
||||
|
||||
if (panelElapsed) {
|
||||
panelElapsed.textContent = display;
|
||||
}
|
||||
}, 1000);
|
||||
interval = window.setInterval(updateElapsed, 1000);
|
||||
};
|
||||
|
||||
const hideBadge = () => {
|
||||
badge.classList.add('hidden');
|
||||
badge.classList.remove('inline-flex');
|
||||
summaryElapsed.textContent = '00:00:00';
|
||||
startedAt = null;
|
||||
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
window.clearInterval(interval);
|
||||
interval = null;
|
||||
}
|
||||
};
|
||||
|
||||
const syncRunningState = () => {
|
||||
const hasTimerPanel = Boolean(root.querySelector('[data-helpdesk-running-timer]'));
|
||||
const text = root.textContent.toLowerCase();
|
||||
const running = hasTimerPanel || text.includes('timer started') || text.includes('running');
|
||||
const sourceShowsRunning = () => {
|
||||
const text = source.textContent.trim().toLowerCase();
|
||||
|
||||
if (running) {
|
||||
return text.includes('running') || text.includes('timer started');
|
||||
};
|
||||
|
||||
const sync = () => {
|
||||
if (sourceShowsRunning()) {
|
||||
showBadge();
|
||||
return;
|
||||
}
|
||||
@@ -317,17 +336,13 @@
|
||||
hideBadge();
|
||||
};
|
||||
|
||||
new MutationObserver(syncRunningState).observe(root, {
|
||||
new MutationObserver(sync).observe(source, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
characterData: true,
|
||||
});
|
||||
|
||||
document.addEventListener('livewire:navigated', syncRunningState);
|
||||
document.addEventListener('livewire:update', syncRunningState);
|
||||
document.addEventListener('livewire:updated', syncRunningState);
|
||||
|
||||
syncRunningState();
|
||||
sync();
|
||||
})();
|
||||
</script>
|
||||
@endcan
|
||||
|
||||
Reference in New Issue
Block a user