Files
timebank-cc-public/resources/views/livewire/admin/search-metrics.blade.php
T

102 lines
5.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<div>
<div class="mb-3 flex items-center justify-between">
<h3 class="text-lg font-semibold text-theme-text-primary">{{ __('Search Metrics') }}</h3>
<div class="flex items-center gap-2">
<select wire:model.live="period" class="rounded border border-theme-border bg-transparent py-1 text-xs text-theme-text-primary focus:outline-none focus:ring-1 focus:ring-theme-brand focus:border-theme-brand">
@foreach ($periods as $value => $label)
<option value="{{ $value }}">{{ __($label) }}</option>
@endforeach
</select>
<x-jetstream.secondary-button type="button" wire:click="refresh" wire:loading.attr="disabled">
<span wire:loading.remove wire:target="refresh">{{ __('Refresh') }}</span>
<span wire:loading wire:target="refresh">{{ __('Refreshing...') }}</span>
</x-jetstream.secondary-button>
</div>
</div>
<!-- Summary -->
<div class="mb-4 grid grid-cols-2 gap-3 sm:grid-cols-4">
<div class="rounded-lg border border-theme-brand p-3 text-center">
<div class="text-2xl font-bold text-theme-text-primary">{{ $metrics['searches_last_24h'] ?? 0 }}</div>
<div class="mt-1 text-xs">{{ __('Searches Last 24h') }}</div>
</div>
<div class="rounded-lg border border-theme-brand p-3 text-center">
<div class="text-2xl font-bold text-theme-text-primary">{{ $metrics['avg_results'] ?? 0 }}</div>
<div class="mt-1 text-xs">{{ __('Avg Results') }}</div>
</div>
<div class="rounded-lg border border-theme-brand p-3 text-center">
<div class="text-2xl font-bold text-theme-text-primary">{{ $metrics['avg_execution_time'] ?? 0 }}s</div>
<div class="mt-1 text-xs">{{ __('Avg Exec Time') }}</div>
</div>
<div class="rounded-lg border border-theme-brand p-3 text-center">
<div class="text-2xl font-bold text-theme-text-primary">{{ $metrics['avg_searches_per_day'] ?? 0 }}</div>
<div class="mt-1 text-xs">{{ __('Avg Searches / Day') }}</div>
</div>
</div>
@if (!empty($metrics['popular_categories']))
<!-- Popular Categories -->
<div class="mb-4">
<div class="mb-2 text-xs font-semibold uppercase tracking-wide">{{ __('Top Categories') }}</div>
<div class="flex flex-wrap gap-2">
@foreach ($metrics['popular_categories'] as $categoryName => $count)
<a href="{{ route('search.show') }}?category={{ $metrics['popular_category_ids'][$categoryName] ?? '' }}"
class="bg-{{ $metrics['popular_category_colors'][$categoryName] ?? 'gray' }}-400 inline-flex items-center rounded-md px-2 py-1 text-sm font-normal text-black hover:opacity-80">
{{ $categoryName }} ×{{ $count }}
</a>
@endforeach
</div>
</div>
@endif
@if (!empty($recentSearches))
<!-- Recent Searches Table -->
<div class="mb-2 text-xs font-semibold uppercase tracking-wide">{{ __('Recent Search Log') }}</div>
<div class="box-border max-h-[200px] overflow-x-auto overflow-y-auto rounded-lg bg-black pb-2 font-mono text-xs text-gray-200">
<table class="w-full">
<thead class="sticky top-0 bg-black">
<tr class="border-b border-gray-700 text-left text-gray-400">
<th class="px-3 py-2">{{ __('Date') }}</th>
<th class="px-3 py-2">{{ __('Query') }}</th>
<th class="px-3 py-2">{{ __('Categories') }}</th>
<th class="px-3 py-2 text-right">{{ __('Results') }}</th>
<th class="px-3 py-2 text-right">{{ __('Exec (s)') }}</th>
<th class="px-3 py-2">{{ __('Lang.') }}</th>
<th class="px-3 py-2">{{ __('Type') }}</th>
<th class="px-3 py-2">{{ __('Location') }}</th>
</tr>
</thead>
<tbody>
@foreach ($recentSearches as $search)
<tr class="border-b border-gray-800 hover:bg-white/5">
<td class="px-3 py-1 text-gray-400">
{{ \Carbon\Carbon::parse($search['timestamp'])->format('Y-m-d') }}
</td>
<td class="px-3 py-1">
{{ $search['search_string'] ?? '—' ?: '—' }}
</td>
<td class="px-3 py-1">
{{ implode(', ', array_column($search['category_tags'] ?? [], 'name')) ?: '—' }}
</td>
<td class="px-3 py-1 text-right">{{ $search['total_results'] ?? 0 }}</td>
<td class="px-3 py-1 text-right">{{ number_format($search['execution_time'] ?? 0, 4) }}</td>
<td class="px-3 py-1">{{ $search['locale'] ?? '—' }}</td>
<td class="px-3 py-1">{{ $search['user_type'] ?? 'guest' }}</td>
<td class="px-3 py-1 text-gray-400">{{ $search['location_label'] ?? '—' }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="mt-3 flex w-full justify-end">
<x-jetstream.button type="button" wire:click="downloadLog" wire:loading.attr="disabled">
{{ __('Download log') }}
</x-jetstream.button>
</div>
@else
<div class="py-4 text-center text-xs">
{{ __('No recent search data available.') }}
</div>
@endif
</div>