Files
WMS/Modules/Helpdesk/Resources/views/partials/ticket-controls.blade.php
T
2026-06-22 17:09:36 +01:00

349 lines
16 KiB
PHP

@php
use Illuminate\Support\Facades\Schema;
use Modules\Helpdesk\Models\TicketTimeLog;
$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 ($hasUserIdColumn) {
$runningTimerQuery->where('user_id', auth()->id());
}
if ($hasEndedAtColumn) {
$runningTimerQuery->whereNull('ended_at');
}
if ($hasStoppedAtColumn) {
$runningTimerQuery->whereNull('stopped_at');
}
if ($hasFinishedAtColumn) {
$runningTimerQuery->whereNull('finished_at');
}
$runningTimer = ($hasEndedAtColumn || $hasStoppedAtColumn || $hasFinishedAtColumn)
? $runningTimerQuery->first()
: null;
$runningTimerStartedAt = $runningTimer?->started_at;
$runningTimerElapsedSeconds = $runningTimerStartedAt
? max(0, now()->diffInSeconds($runningTimerStartedAt))
: 0;
$runningTimerElapsedDisplay = gmdate('H:i:s', $runningTimerElapsedSeconds);
$hasRunningTimer = $runningTimerStartedAt !== null;
@endphp
@can('update', $ticket)
<details
class="group rounded-xl border border-zinc-200 bg-white p-4 shadow-sm dark:border-zinc-700 dark:bg-zinc-900"
data-helpdesk-ticket-controls>
<summary
class="-mx-4 -mt-4 mb-4 flex cursor-pointer list-none items-center justify-between gap-3 rounded-t-xl bg-indigo-700 px-4 py-4 text-white marker:hidden">
<div class="flex min-w-0 items-center gap-3">
<span
class="inline-flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-indigo-950 text-white ring-1 ring-indigo-300/60 shadow-lg">
<i class="fa-solid fa-sliders text-lg" aria-hidden="true"></i>
</span>
<div class="min-w-0">
<h2 class="text-lg font-black uppercase tracking-wide">Ticket controls</h2>
<p class="text-xs font-semibold text-indigo-100">
Log time, assignment, status and priority
</p>
<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>
<span class="relative inline-flex h-2.5 w-2.5 rounded-full bg-emerald-300"></span>
</span>
<span>Running</span>
<span class="font-mono" data-helpdesk-running-summary-elapsed data-dusk="ticket-running-elapsed-summary">
{{ $runningTimerElapsedDisplay }}
</span>
</span>
</div>
</div>
<span
class="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-white/15 text-white ring-1 ring-white/20">
<i class="fa-solid fa-chevron-right text-xs transition group-open:rotate-90" aria-hidden="true"></i>
</span>
</summary>
@if (session('ticket-action-updated'))
<div
class="mb-4 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs font-bold text-emerald-800 dark:border-emerald-800 dark:bg-emerald-950 dark:text-emerald-100">
{{ session('ticket-action-updated') }}
</div>
@endif
@if ($hasRunningTimer)
<div
class="mb-4 rounded-xl border border-emerald-300 bg-emerald-50 p-3 text-emerald-950 shadow-sm dark:border-emerald-800 dark:bg-emerald-950 dark:text-emerald-100"
data-helpdesk-running-timer>
<div class="flex items-center justify-between gap-3">
<div class="min-w-0">
<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>
</div>
<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>
</div>
</div>
</div>
@endif
<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">
@csrf
<label class="block text-xs font-bold text-zinc-700 dark:text-zinc-200"
for="ticket_time_minutes">Log time</label>
<div class="grid grid-cols-[1fr_auto] gap-2">
<input id="ticket_time_minutes" name="minutes" type="number" min="1" max="1440"
placeholder="Minutes"
class="block w-full rounded-lg border border-zinc-300 bg-white p-2 text-xs font-semibold text-zinc-900 shadow-sm focus:border-emerald-500 focus:ring-emerald-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
data-dusk="ticket-time-minutes">
<button type="submit" dusk="log-ticket-time" data-dusk="log-ticket-time"
class="inline-flex items-center justify-center rounded-lg bg-emerald-600 px-3 py-2 text-xs font-black text-white shadow-sm transition hover:bg-emerald-700 focus:outline-none focus:ring-2 focus:ring-emerald-400/70">
<i class="fa-solid fa-clock mr-2" aria-hidden="true"></i>
<span>Log</span>
</button>
</div>
<textarea name="description" rows="2" placeholder="Optional work note"
class="block w-full rounded-lg border border-zinc-300 bg-white p-2 text-xs font-semibold text-zinc-900 shadow-sm focus:border-emerald-500 focus:ring-emerald-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
data-dusk="ticket-time-description"></textarea>
@error('minutes')
<p class="text-xs font-bold text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
@error('description')
<p class="text-xs font-bold text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
</form>
<form method="POST" action="{{ route('helpdesk.tickets.agent.update', $ticket) }}"
class="mb-4 space-y-2">
@csrf
<label class="block text-xs font-bold text-zinc-700 dark:text-zinc-200"
for="show_agent_id">Assigned agent</label>
<select id="show_agent_id" name="agent_id"
class="hd-select block w-full rounded-lg border border-zinc-300 bg-white p-2 text-xs font-semibold text-zinc-900 shadow-sm focus:border-emerald-500 focus:ring-emerald-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
data-dusk="ticket-show-agent">
<option value="" @selected($agent_id === null)>Unassigned</option>
@forelse ($agents as $agent)
<option
value="{{ $agent->id }}" @selected((int) $agent_id === (int) $agent->id)>{{ $agent->name }}
·
{{ $agent->email }}</option>
@empty
<option value="" disabled>No users available for assignment</option>
@endforelse
</select>
@error('agent_id')
<p class="text-xs font-bold text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
<button type="submit" dusk="update-agent" data-dusk="update-agent"
class="inline-flex items-center justify-center rounded-lg bg-emerald-600 px-3 py-2 text-xs font-black text-white shadow-sm transition hover:bg-emerald-700 focus:outline-none focus:ring-2 focus:ring-emerald-400/70">
<i class="fa-solid fa-user-check mr-2" aria-hidden="true"></i>
<span>Assign agent</span>
</button>
</form>
<form method="POST" action="{{ route('helpdesk.tickets.status.update', $ticket) }}"
class="mb-4 space-y-2">
@csrf
<label class="block text-xs font-bold text-zinc-700 dark:text-zinc-200"
for="show_status_id">Status</label>
<select id="show_status_id" name="status_id"
class="hd-select block min-h-10 w-full rounded-lg border border-zinc-300 bg-white px-3 py-2 text-xs font-semibold text-zinc-900 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
data-dusk="ticket-show-status">
@foreach ($statuses as $status)
<option
value="{{ $status->id }}" @selected((int) $status_id === (int) $status->id)>{{ $status->name }}
</option>
@endforeach
</select>
@error('status_id')
<p class="text-xs font-bold text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
<button type="submit" dusk="update-status"
class="inline-flex items-center justify-center rounded-lg bg-blue-600 px-3 py-2 text-xs font-black text-white shadow-sm transition hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400/70">
<i class="fa-solid fa-circle-check mr-2" aria-hidden="true"></i>
<span>Update status</span>
</button>
</form>
<form method="POST" action="{{ route('helpdesk.tickets.priority.update', $ticket) }}"
class="space-y-2">
@csrf
<label class="block text-xs font-bold text-zinc-700 dark:text-zinc-200"
for="show_priority_id">Priority</label>
<select id="show_priority_id" name="priority_id"
class="hd-select block w-full rounded-lg border border-zinc-300 bg-white p-2 text-xs font-semibold text-zinc-900 shadow-sm focus:border-amber-500 focus:ring-amber-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
data-dusk="ticket-show-priority">
@foreach ($priorities as $priority)
<option
value="{{ $priority->id }}" @selected((int) $priority_id === (int) $priority->id)>{{ $priority->name }}
</option>
@endforeach
</select>
@error('priority_id')
<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>
<span>Update priority</span>
</button>
</form>
</details>
<script>
(() => {
const root = document.querySelector('[data-helpdesk-ticket-controls]');
if (!root || root.dataset.helpdeskElapsedBadgeBound === 'true') {
return;
}
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-helpdesk-panel-elapsed]');
if (!source || !badge || !summaryElapsed) {
return;
}
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);
return date.toISOString().substring(11, 19);
};
const updateElapsed = () => {
if (!startedAt) {
startedAt = Date.now();
}
const display = formatElapsed(Math.floor((Date.now() - startedAt) / 1000));
summaryElapsed.textContent = display;
if (panelElapsed) {
panelElapsed.textContent = display;
}
};
const showBadge = () => {
badge.classList.remove('hidden');
badge.classList.add('inline-flex');
if (!startedAt) {
startedAt = Date.now();
}
updateElapsed();
if (interval) {
return;
}
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) {
window.clearInterval(interval);
interval = null;
}
};
const sourceShowsRunning = () => {
const text = source.textContent.trim().toLowerCase();
return text.includes('running') || text.includes('timer started');
};
const sync = () => {
if (sourceShowsRunning()) {
showBadge();
return;
}
hideBadge();
};
new MutationObserver(sync).observe(source, {
childList: true,
subtree: true,
characterData: true,
});
sync();
})();
</script>
@endcan