fix history pengumuman

This commit is contained in:
rendygaafk 2025-05-17 02:24:00 +07:00
parent 13ac425c8c
commit b7cec503d1
3 changed files with 47 additions and 30 deletions

View File

@ -155,20 +155,31 @@ public function details($id)
public function destroy($id) public function destroy($id)
{ {
DB::beginTransaction();
try { try {
$announcement = Announcement::findOrFail($id); $announcement = Announcement::findOrFail($id);
// Hapus relasi terlebih dahulu
$announcement->ruangans()->detach();
// Kemudian hapus pengumuman
$announcement->delete(); $announcement->delete();
DB::commit();
return response()->json([ return response()->json([
'success' => true, 'success' => true,
'message' => 'Pengumuman berhasil dihapus' 'message' => 'Pengumuman berhasil dihapus'
]); ]);
} catch (\Exception $e) { } catch (\Exception $e) {
DB::rollBack();
Log::error('Failed to delete announcement: ' . $e->getMessage()); Log::error('Failed to delete announcement: ' . $e->getMessage());
return response()->json([ return response()->json([
'success' => false, 'success' => false,
'message' => 'Gagal menghapus pengumuman' 'message' => 'Gagal menghapus pengumuman: ' . $e->getMessage()
], 500); ], 500);
} }
} }

View File

@ -6,18 +6,21 @@
<div class="container mx-auto px-4 py-8"> <div class="container mx-auto px-4 py-8">
<!-- Header Section --> <!-- Header Section -->
<div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-8"> <div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-8">
<div>
<h1 class="text-2xl font-bold text-gray-800">Riwayat Pengumuman</h1> <h1 class="text-2xl font-bold text-gray-800">Riwayat Pengumuman</h1>
<p class="text-sm text-gray-600 mt-1">Daftar lengkap pengumuman yang telah dikirim</p>
</div>
<a href="{{ route('admin.announcement.index') }}" <a href="{{ route('admin.announcement.index') }}"
class="flex items-center mt-4 md:mt-0 px-4 py-2 bg-white border border-blue-500 text-blue-600 rounded-lg hover:bg-blue-50 transition-colors"> class="flex items-center mt-4 md:mt-0 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors shadow-sm">
<i class="fas fa-plus-circle mr-2"></i> Buat Pengumuman Baru <i class="fas fa-plus-circle mr-2"></i> Buat Pengumuman Baru
</a> </a>
</div> </div>
<!-- Enhanced Filter Card --> <!-- Enhanced Filter Card -->
<div class="bg-white rounded-lg shadow-sm border border-gray-200 mb-6 overflow-hidden"> <div class="bg-white rounded-lg shadow-sm border border-gray-200 mb-6 overflow-hidden">
<div class="p-4 border-b border-gray-200 bg-gray-50"> <div class="p-4 border-b border-gray-200 bg-gradient-to-r from-blue-50 to-gray-50">
<h2 class="text-lg font-medium text-gray-700 flex items-center"> <h2 class="text-lg font-medium text-gray-700 flex items-center">
<i class="fas fa-filter mr-2 text-blue-500"></i> Filter Riwayat <i class="fas fa-filter mr-2 text-blue-600"></i> Filter Riwayat
</h2> </h2>
</div> </div>
<div class="p-4"> <div class="p-4">
@ -25,7 +28,7 @@ class="flex items-center mt-4 md:mt-0 px-4 py-2 bg-white border border-blue-500
<div> <div>
<label for="mode" class="block text-sm font-medium text-gray-700 mb-1">Mode Pengumuman</label> <label for="mode" class="block text-sm font-medium text-gray-700 mb-1">Mode Pengumuman</label>
<div class="relative"> <div class="relative">
<select id="mode" name="mode" class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border"> <select id="mode" name="mode" class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border bg-white">
<option value="">Semua Mode</option> <option value="">Semua Mode</option>
<option value="tts" {{ request('mode') == 'tts' ? 'selected' : '' }}>Text-to-Speech</option> <option value="tts" {{ request('mode') == 'tts' ? 'selected' : '' }}>Text-to-Speech</option>
<option value="manual" {{ request('mode') == 'manual' ? 'selected' : '' }}>Manual</option> <option value="manual" {{ request('mode') == 'manual' ? 'selected' : '' }}>Manual</option>
@ -39,7 +42,7 @@ class="flex items-center mt-4 md:mt-0 px-4 py-2 bg-white border border-blue-500
<label for="start_date" class="block text-sm font-medium text-gray-700 mb-1">Dari Tanggal</label> <label for="start_date" class="block text-sm font-medium text-gray-700 mb-1">Dari Tanggal</label>
<div class="relative"> <div class="relative">
<input type="date" id="start_date" name="start_date" value="{{ request('start_date') }}" <input type="date" id="start_date" name="start_date" value="{{ request('start_date') }}"
class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border"> class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border bg-white">
<div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none"> <div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
<i class="fas fa-calendar-alt text-gray-400"></i> <i class="fas fa-calendar-alt text-gray-400"></i>
</div> </div>
@ -49,7 +52,7 @@ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none
<label for="end_date" class="block text-sm font-medium text-gray-700 mb-1">Sampai Tanggal</label> <label for="end_date" class="block text-sm font-medium text-gray-700 mb-1">Sampai Tanggal</label>
<div class="relative"> <div class="relative">
<input type="date" id="end_date" name="end_date" value="{{ request('end_date') }}" <input type="date" id="end_date" name="end_date" value="{{ request('end_date') }}"
class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border"> class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border bg-white">
<div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none"> <div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
<i class="fas fa-calendar-alt text-gray-400"></i> <i class="fas fa-calendar-alt text-gray-400"></i>
</div> </div>
@ -73,11 +76,8 @@ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none
<div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden"> <div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200"> <table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50"> <thead class="bg-gradient-to-r from-blue-50 to-gray-50">
<tr> <tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
#
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Waktu Pengiriman Waktu Pengiriman
</th> </th>
@ -96,27 +96,31 @@ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none
</tr> </tr>
</thead> </thead>
<tbody class="bg-white divide-y divide-gray-200"> <tbody class="bg-white divide-y divide-gray-200">
@forelse($announcements as $index => $announcement) @forelse($announcements as $announcement)
<tr class="hover:bg-gray-50 transition-colors"> <tr class="hover:bg-gray-50 transition-colors" data-id="{{ $announcement->id }}">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $index + 1 + (($announcements->currentPage() - 1) * $announcements->perPage()) }}
</td>
<td class="px-6 py-4 whitespace-nowrap"> <td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10 flex items-center justify-center rounded-full bg-blue-50 text-blue-600 mr-3">
<i class="fas fa-bullhorn"></i>
</div>
<div>
<div class="text-sm font-semibold text-gray-900"> <div class="text-sm font-semibold text-gray-900">
{{ $announcement->formatted_sent_at }} {{ $announcement->formatted_sent_at }}
</div> </div>
<div class="text-xs text-gray-500"> <div class="text-xs text-gray-500">
{{ $announcement->sent_at->diffForHumans() }} {{ $announcement->sent_at->diffForHumans() }}
</div> </div>
</div>
</div>
</td> </td>
<td class="px-6 py-4 whitespace-nowrap"> <td class="px-6 py-4 whitespace-nowrap">
@if($announcement->mode === 'tts') @if($announcement->mode === 'tts')
<span class="px-2.5 py-0.5 inline-flex text-xs leading-4 font-medium rounded-full bg-green-100 text-green-800"> <span class="px-2.5 py-0.5 inline-flex items-center text-xs leading-4 font-medium rounded-full bg-green-100 text-green-800">
<i class="fas fa-robot mr-1"></i> TTS <i class="fas fa-robot mr-1.5"></i> TTS
</span> </span>
@else @else
<span class="px-2.5 py-0.5 inline-flex text-xs leading-4 font-medium rounded-full bg-blue-100 text-blue-800"> <span class="px-2.5 py-0.5 inline-flex items-center text-xs leading-4 font-medium rounded-full bg-blue-100 text-blue-800">
<i class="fas fa-microphone-alt mr-1"></i> Manual <i class="fas fa-microphone-alt mr-1.5"></i> Manual
</span> </span>
@endif @endif
</td> </td>
@ -128,7 +132,7 @@ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none
<div class="flex flex-wrap gap-1"> <div class="flex flex-wrap gap-1">
@foreach($announcement->ruangans as $ruangan) @foreach($announcement->ruangans as $ruangan)
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-800"> <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-800">
<span class="w-1.5 h-1.5 rounded-full mr-1 {{ $announcement->mode === 'tts' ? 'bg-green-500' : 'bg-blue-500' }}"></span> <span class="w-2 h-2 rounded-full mr-1.5 {{ $announcement->mode === 'tts' ? 'bg-green-500' : 'bg-blue-500' }}"></span>
{{ $ruangan->nama_ruangan }} {{ $ruangan->nama_ruangan }}
</span> </span>
@endforeach @endforeach
@ -154,7 +158,7 @@ class="inline-flex items-center px-3 py-1.5 border border-transparent text-sm fo
<tr> <tr>
<td colspan="6" class="px-6 py-8 text-center"> <td colspan="6" class="px-6 py-8 text-center">
<div class="flex flex-col items-center justify-center"> <div class="flex flex-col items-center justify-center">
<i class="fas fa-inbox text-3xl text-gray-300 mb-3"></i> <i class="fas fa-inbox text-4xl text-gray-300 mb-3"></i>
<p class="text-gray-500 text-sm">Tidak ada riwayat pengumuman</p> <p class="text-gray-500 text-sm">Tidak ada riwayat pengumuman</p>
@if(request()->has('mode') || request()->has('start_date') || request()->has('end_date')) @if(request()->has('mode') || request()->has('start_date') || request()->has('end_date'))
<a href="{{ route('admin.announcement.history') }}" class="text-blue-600 hover:text-blue-800 mt-2 text-sm flex items-center"> <a href="{{ route('admin.announcement.history') }}" class="text-blue-600 hover:text-blue-800 mt-2 text-sm flex items-center">
@ -203,6 +207,7 @@ function showAnnouncementDetails(id) {
<div class="flex items-center"> <div class="flex items-center">
<span class="font-medium w-24">Mode:</span> <span class="font-medium w-24">Mode:</span>
<span class="px-2.5 py-0.5 inline-flex text-xs leading-4 font-medium rounded-full ${data.mode === 'tts' ? 'bg-green-100 text-green-800' : 'bg-blue-100 text-blue-800'}"> <span class="px-2.5 py-0.5 inline-flex text-xs leading-4 font-medium rounded-full ${data.mode === 'tts' ? 'bg-green-100 text-green-800' : 'bg-blue-100 text-blue-800'}">
<i class="fas ${data.mode === 'tts' ? 'fa-robot' : 'fa-microphone-alt'} mr-1"></i>
${data.mode === 'tts' ? 'Text-to-Speech' : 'Manual'} ${data.mode === 'tts' ? 'Text-to-Speech' : 'Manual'}
</span> </span>
</div> </div>
@ -215,7 +220,7 @@ function showAnnouncementDetails(id) {
<div class="flex flex-wrap gap-1 mt-1"> <div class="flex flex-wrap gap-1 mt-1">
${data.ruangans.map(r => ` ${data.ruangans.map(r => `
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-800"> <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-800">
<span class="w-1.5 h-1.5 rounded-full mr-1 ${data.mode === 'tts' ? 'bg-green-500' : 'bg-blue-500'}"></span> <span class="w-2 h-2 rounded-full mr-1.5 ${data.mode === 'tts' ? 'bg-green-500' : 'bg-blue-500'}"></span>
${r.nama_ruangan} ${r.nama_ruangan}
</span> </span>
`).join('')} `).join('')}
@ -223,7 +228,7 @@ function showAnnouncementDetails(id) {
</div> </div>
<div class="mt-4 p-3 bg-gray-50 rounded border border-gray-200"> <div class="mt-4 p-3 bg-gray-50 rounded border border-gray-200">
<p class="font-medium text-sm">Isi Pengumuman:</p> <p class="font-medium text-sm">Isi Pengumuman:</p>
<p class="mt-1 text-sm">${data.message}</p> <p class="mt-1 text-sm whitespace-pre-line">${data.message}</p>
</div> </div>
</div> </div>
`, `,

View File

@ -110,6 +110,7 @@
Route::prefix('announcement')->controller(AnnouncementController::class)->group(function () { Route::prefix('announcement')->controller(AnnouncementController::class)->group(function () {
Route::get('/', 'index')->name('admin.announcement.index'); Route::get('/', 'index')->name('admin.announcement.index');
Route::get('/history', 'history')->name('admin.announcement.history'); Route::get('/history', 'history')->name('admin.announcement.history');
Route::delete('/{id}', 'destroy')->name('announcement.destroy');
}); });
}); });