phase 8 and 9

This commit is contained in:
Stefanescu Mihai
2026-03-19 18:42:19 +02:00
parent d75cabfeec
commit 82ebb697f3
94 changed files with 4498 additions and 749 deletions
+63
View File
@@ -0,0 +1,63 @@
<div class="space-y-6">
<div>
<label for="name" class="block text-sm font-medium text-gray-700 mb-1">Alert Name</label>
<input type="text" name="name" id="name" value="{{ old('name', $alert->name ?? '') }}" required
placeholder="e.g. Traffic spike alert"
class="block w-full rounded-lg border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
@error('name') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="metric" class="block text-sm font-medium text-gray-700 mb-1">Metric</label>
<select name="metric" id="metric" class="block w-full rounded-lg border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
@foreach (\App\Models\Alert::$metrics as $value => $label)
<option value="{{ $value }}" @selected(old('metric', $alert->metric ?? '') === $value)>{{ $label }}</option>
@endforeach
</select>
</div>
<div>
<label for="condition" class="block text-sm font-medium text-gray-700 mb-1">Condition</label>
<select name="condition" id="condition" class="block w-full rounded-lg border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
@foreach (\App\Models\Alert::$conditions as $value => $label)
<option value="{{ $value }}" @selected(old('condition', $alert->condition ?? '') === $value)>{{ $label }}</option>
@endforeach
</select>
</div>
</div>
<div>
<label for="threshold" class="block text-sm font-medium text-gray-700 mb-1">Threshold</label>
<input type="number" name="threshold" id="threshold" value="{{ old('threshold', $alert->threshold ?? '') }}" required step="0.01" min="0"
class="block w-full rounded-lg border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
placeholder="e.g. 1000">
@error('threshold') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="period" class="block text-sm font-medium text-gray-700 mb-1">Check Period</label>
<select name="period" id="period" class="block w-full rounded-lg border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value="daily" @selected(old('period', $alert->period ?? 'daily') === 'daily')>Daily</option>
<option value="hourly" @selected(old('period', $alert->period ?? '') === 'hourly')>Hourly</option>
</select>
</div>
<div>
<label for="channel" class="block text-sm font-medium text-gray-700 mb-1">Notification Channel</label>
<select name="channel" id="channel" class="block w-full rounded-lg border-gray-300 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value="email" @selected(old('channel', $alert->channel ?? 'email') === 'email')>Email</option>
<option value="in_app" @selected(old('channel', $alert->channel ?? '') === 'in_app')>In-App Only</option>
<option value="both" @selected(old('channel', $alert->channel ?? '') === 'both')>Both</option>
</select>
</div>
</div>
<div class="flex items-center gap-3 pt-2">
<button type="submit" class="inline-flex items-center px-4 py-2 bg-indigo-600 rounded-lg text-sm font-medium text-white hover:bg-indigo-500 transition">
{{ isset($alert->id) ? 'Update Alert' : 'Create Alert' }}
</button>
<a href="{{ route('alerts.index', $website) }}" class="text-sm text-gray-500 hover:text-gray-700 transition">Cancel</a>
</div>
</div>
+10
View File
@@ -0,0 +1,10 @@
<x-analytics-layout :website="$website" title="Create Alert">
<div class="max-w-2xl">
<div class="bg-white rounded-xl border border-gray-200 p-6">
<form method="POST" action="{{ route('alerts.store', $website) }}">
@csrf
@include('alerts._form', ['alert' => new \App\Models\Alert])
</form>
</div>
</div>
</x-analytics-layout>
+23
View File
@@ -0,0 +1,23 @@
<x-analytics-layout :website="$website" title="Edit Alert">
<div class="max-w-2xl">
<div class="bg-white rounded-xl border border-gray-200 p-6">
<form method="POST" action="{{ route('alerts.update', [$website, $alert]) }}">
@csrf
@method('PUT')
@include('alerts._form', ['alert' => $alert])
</form>
</div>
<div class="mt-6 bg-white rounded-xl border border-red-200 p-6">
<h3 class="text-sm font-semibold text-red-700 mb-1">Danger Zone</h3>
<p class="text-sm text-gray-500 mb-4">Permanently delete this alert and all its notification history.</p>
<form method="POST" action="{{ route('alerts.destroy', [$website, $alert]) }}" onsubmit="return confirm('Delete this alert?')">
@csrf
@method('DELETE')
<button type="submit" class="inline-flex items-center px-4 py-2 bg-red-600 rounded-lg text-sm font-medium text-white hover:bg-red-500 transition">
Delete Alert
</button>
</form>
</div>
</div>
</x-analytics-layout>
+70
View File
@@ -0,0 +1,70 @@
<x-analytics-layout :website="$website" title="Alerts">
<x-slot name="headerActions">
<div class="flex items-center gap-2">
<a href="{{ route('alerts.notifications', $website) }}" class="inline-flex items-center gap-2 px-3 py-2 rounded-lg border border-gray-300 text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 transition relative">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M14.857 17.082a23.848 23.848 0 0 0 5.454-1.31A8.967 8.967 0 0 1 18 9.75V9A6 6 0 0 0 6 9v.75a8.967 8.967 0 0 1-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 0 1-5.714 0m5.714 0a3 3 0 1 1-5.714 0" /></svg>
Notifications
@if ($unreadCount > 0)
<span class="absolute -top-1 -right-1 flex items-center justify-center w-5 h-5 rounded-full bg-red-500 text-white text-xs font-bold">{{ $unreadCount }}</span>
@endif
</a>
<a href="{{ route('alerts.create', $website) }}" class="inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 rounded-lg text-sm font-medium text-white hover:bg-indigo-500 transition">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" /></svg>
Create Alert
</a>
</div>
</x-slot>
@if (session('success'))
<div class="mb-6 rounded-xl bg-emerald-50 border border-emerald-200 p-4">
<p class="text-sm font-medium text-emerald-800">{{ session('success') }}</p>
</div>
@endif
@if ($alerts->isEmpty())
<x-empty-state
icon='<svg class="w-10 h-10" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M14.857 17.082a23.848 23.848 0 0 0 5.454-1.31A8.967 8.967 0 0 1 18 9.75V9A6 6 0 0 0 6 9v.75a8.967 8.967 0 0 1-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 0 1-5.714 0m5.714 0a3 3 0 1 1-5.714 0" /></svg>'
title="No alerts yet"
message="Create alerts to get notified when metrics spike, drop, or cross a threshold."
/>
@else
<div class="bg-white rounded-xl border border-gray-200 overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Condition</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Channel</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Last Triggered</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
@foreach ($alerts as $alert)
<tr>
<td class="px-6 py-3 text-sm font-medium text-gray-900">{{ $alert->name }}</td>
<td class="px-6 py-3 text-sm text-gray-600">
{{ \App\Models\Alert::$metrics[$alert->metric] ?? $alert->metric }}
{{ \App\Models\Alert::$conditions[$alert->condition] ?? $alert->condition }}
{{ $alert->threshold }}
</td>
<td class="px-6 py-3 text-sm text-gray-600 capitalize">{{ $alert->channel }}</td>
<td class="px-6 py-3 text-sm text-gray-500">
{{ $alert->last_triggered_at ? $alert->last_triggered_at->diffForHumans() : 'Never' }}
</td>
<td class="px-6 py-3">
<span class="inline-flex px-2 py-0.5 rounded-full text-xs font-medium {{ $alert->is_active ? 'bg-emerald-100 text-emerald-700' : 'bg-gray-100 text-gray-500' }}">
{{ $alert->is_active ? 'Active' : 'Paused' }}
</span>
</td>
<td class="px-6 py-3 text-right">
<a href="{{ route('alerts.edit', [$website, $alert]) }}" class="text-sm text-indigo-600 hover:text-indigo-800 font-medium">Edit</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</x-analytics-layout>
@@ -0,0 +1,32 @@
<x-analytics-layout :website="$website" title="Alert Notifications">
<x-slot name="headerActions">
<a href="{{ route('alerts.index', $website) }}" class="inline-flex items-center gap-2 px-3 py-2 rounded-lg border border-gray-300 text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 transition">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M10.5 19.5 3 12m0 0 7.5-7.5M3 12h18" /></svg>
Back to Alerts
</a>
</x-slot>
@if ($notifications->isEmpty())
<x-empty-state title="No notifications" message="Alert notifications will appear here when triggered." />
@else
<div class="bg-white rounded-xl border border-gray-200 overflow-hidden">
<div class="divide-y divide-gray-200">
@foreach ($notifications as $notification)
<div class="px-6 py-4">
<div class="flex items-start justify-between">
<div>
<p class="text-sm font-medium text-gray-900">{{ $notification->alert->name }}</p>
<p class="text-sm text-gray-600 mt-0.5">{{ $notification->message }}</p>
</div>
<span class="text-xs text-gray-400 whitespace-nowrap ml-4">{{ $notification->created_at->diffForHumans() }}</span>
</div>
</div>
@endforeach
</div>
</div>
<div class="mt-4">
{{ $notifications->links() }}
</div>
@endif
</x-analytics-layout>