- Implement EmailNotifier for sending batch and test notifications via email. - Implement TelegramNotifier for sending batch and test notifications via Telegram. - Implement WahaNotifier for sending batch and test notifications via WhatsApp using WAHA API. - Create migration for client_categories table and update clients table to include category_id. - Create migration for notification_settings table to manage notification configurations. - Add ClientCategorySeeder to populate default client categories. - Create manifest.json for PWA support. - Implement service worker (sw.js) for caching static assets and offline support. - Add edit event view for modifying scheduled events. - Create search results view for displaying search queries. - Develop notification settings view for configuring notification channels and triggers.
138 lines
4.7 KiB
PHP
138 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\EventStatus;
|
|
use App\Models\Client;
|
|
use App\Models\Event;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class EventController extends Controller
|
|
{
|
|
public function index(): View
|
|
{
|
|
$events = Event::with('client')->orderBy('start_time')->get();
|
|
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
|
|
|
// Format for FullCalendar
|
|
$calendarEvents = $events->map(fn (Event $e) => [
|
|
'id' => $e->id,
|
|
'title' => ($e->is_priority ? '⭐ ' : '') . $e->title,
|
|
'start' => $e->start_time->toIso8601String(),
|
|
'end' => $e->end_time?->toIso8601String(),
|
|
'backgroundColor' => $e->color,
|
|
'borderColor' => $e->color,
|
|
'extendedProps' => [
|
|
'status' => $e->status->value,
|
|
'client' => $e->client?->name,
|
|
'type' => $e->event_type,
|
|
'priority' => $e->is_priority,
|
|
],
|
|
]);
|
|
|
|
return view('schedule.index', compact('events', 'clients', 'calendarEvents'));
|
|
}
|
|
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'title' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'client_id' => 'nullable|exists:clients,id',
|
|
'event_type' => 'required|in:task,meeting,deadline,posting',
|
|
'start_time' => 'required|date',
|
|
'end_time' => 'nullable|date|after:start_time',
|
|
'location' => 'nullable|string|max:255',
|
|
'is_priority' => 'boolean',
|
|
'is_all_day' => 'boolean',
|
|
'color' => 'nullable|string|max:20',
|
|
'notes' => 'nullable|string',
|
|
]);
|
|
|
|
$validated['is_priority'] = $request->boolean('is_priority');
|
|
$validated['is_all_day'] = $request->boolean('is_all_day');
|
|
|
|
Event::create($validated);
|
|
|
|
return redirect()->route('schedule.index')
|
|
->with('success', '🐾 Event scheduled!');
|
|
}
|
|
|
|
public function edit(Event $event): View
|
|
{
|
|
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
|
$statuses = EventStatus::cases();
|
|
|
|
return view('schedule.edit', compact('event', 'clients', 'statuses'));
|
|
}
|
|
|
|
public function update(Request $request, Event $event): RedirectResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'title' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'client_id' => 'nullable|exists:clients,id',
|
|
'event_type' => 'required|in:task,meeting,deadline,posting',
|
|
'start_time' => 'required|date',
|
|
'end_time' => 'nullable|date',
|
|
'location' => 'nullable|string|max:255',
|
|
'is_priority' => 'boolean',
|
|
'status' => 'required|in:pending,in_progress,completed,cancelled',
|
|
'color' => 'nullable|string|max:20',
|
|
'notes' => 'nullable|string',
|
|
]);
|
|
|
|
$validated['is_priority'] = $request->boolean('is_priority');
|
|
$event->update($validated);
|
|
|
|
return redirect()->route('schedule.index')
|
|
->with('success', '🐾 Event updated!');
|
|
}
|
|
|
|
public function updateDates(Request $request, Event $event): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'start_time' => 'required|date',
|
|
'end_time' => 'nullable|date',
|
|
]);
|
|
|
|
$event->update($validated);
|
|
|
|
return response()->json(['ok' => true]);
|
|
}
|
|
|
|
public function destroy(Event $event): RedirectResponse
|
|
{
|
|
$event->delete();
|
|
|
|
return redirect()->route('schedule.index')
|
|
->with('success', '🐾 Event removed.');
|
|
}
|
|
|
|
public function apiList(): JsonResponse
|
|
{
|
|
$events = Event::with('client')->get()->map(fn (Event $e) => [
|
|
'id' => $e->id,
|
|
'title' => ($e->is_priority ? '⭐ ' : '') . $e->title,
|
|
'start' => $e->start_time->toIso8601String(),
|
|
'end' => $e->end_time?->toIso8601String(),
|
|
'backgroundColor' => $e->color,
|
|
'borderColor' => $e->color,
|
|
'allDay' => $e->is_all_day,
|
|
'extendedProps' => [
|
|
'status' => $e->status->value,
|
|
'client' => $e->client?->name,
|
|
'type' => $e->event_type,
|
|
'priority' => $e->is_priority,
|
|
],
|
|
]);
|
|
|
|
return response()->json($events);
|
|
}
|
|
}
|