From eec7efb9c998aa1a3cd3d60de4cc86849f458329 Mon Sep 17 00:00:00 2001 From: Vckynando12 Date: Sat, 22 Feb 2025 05:10:17 +0700 Subject: [PATCH] add page reports trial to collect from reports.json --- app/Http/Controllers/ReportController.php | 62 +++++++++++++++ resources/views/reports.blade.php | 92 +++++++++++++++++++++++ routes/web.php | 4 +- 3 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/ReportController.php create mode 100644 resources/views/reports.blade.php diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php new file mode 100644 index 0000000..813b55a --- /dev/null +++ b/app/Http/Controllers/ReportController.php @@ -0,0 +1,62 @@ +json([]); + } + + $jsonData = json_decode(File::get($jsonPath), true); + + if (!$jsonData) { + return response()->json([]); + } + + foreach ($jsonData as &$report) { + $carbonTime = Carbon::parse($report['timestamp'])->setTimezone('Asia/Jakarta'); + $report['tanggal'] = $carbonTime->format('d M Y'); // Format tanggal + $report['waktu'] = $carbonTime->format('H:i:s'); // Format waktu + } + + return response()->json($jsonData); +} + + public function index() + { + // Path file JSON (sesuaikan dengan lokasi yang benar) + $jsonPath = storage_path('app/reports.json'); + + // Cek apakah file JSON ada + if (!File::exists($jsonPath)) { + return view('reports', ['reports' => []]); + } + + // Ambil isi file JSON dan decode + $jsonData = json_decode(File::get($jsonPath), true); + + // Jika tidak ada data, kirim array kosong + if (!$jsonData) { + return view('reports', ['reports' => []]); + } + + // Konversi timestamp ke Waktu Indonesia Barat (WIB) dan pisahkan tanggal & waktu + foreach ($jsonData as &$report) { + $carbonTime = Carbon::parse($report['timestamp'])->setTimezone('Asia/Jakarta'); + $report['tanggal'] = $carbonTime->format('d M Y'); // Format tanggal + $report['waktu'] = $carbonTime->format('H:i:s'); // Format waktu + } + + // Kirim data ke view + return view('reports', ['reports' => $jsonData]); + } +} diff --git a/resources/views/reports.blade.php b/resources/views/reports.blade.php new file mode 100644 index 0000000..6d16c7d --- /dev/null +++ b/resources/views/reports.blade.php @@ -0,0 +1,92 @@ + + + + + + Report Data + + + + +
+

Laporan Keamanan dan Monitoring

+ + @if(count($reports) > 0) + + + + + + + + + + + + + + + + + @foreach($reports as $key => $report) + + + + + + + + + + + + + @endforeach + +
#TanggalWaktuGerakanStatus KeamananAkses TerakhirStatus ServoStatus PerangkatKelembabanSuhu
{{ $key + 1 }}{{ $report['tanggal'] }} {{ $report['waktu'] }} {{ ucfirst($report['security']['motion']) }}{{ ucfirst($report['security']['status']) }}{{ $report['smartcab']['last_access'] }}{{ ucfirst($report['smartcab']['servo_status']) }}{{ ucfirst($report['smartcab']['status_device']) }}{{ $report['dht11']['humidity'] }}%{{ $report['dht11']['temperature'] }}°C
+ @else +
+ Tidak ada data laporan. +
+ @endif +
+ + + + + + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 1dd4b9a..164ed92 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,9 +3,9 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\Auth\FirebaseAuthController; use App\Http\Controllers\AIChatController; -use App\Http\Controllers\FirebaseController; use App\Http\Controllers\WelcomeController; use App\Http\Controllers\ProfileController; +use App\Http\Controllers\ReportController; Route::get('/login', [FirebaseAuthController::class, 'showLogin']) ->name('login') @@ -35,4 +35,4 @@ Route::get('/profile', [ProfileController::class, 'index'])->name('profile'); Route::post('/profile/update', [ProfileController::class, 'update'])->name('profile.update'); -Route::get('/save-firebase', [FirebaseController::class, 'saveFirebaseData']); \ No newline at end of file +Route::get('/reports', [ReportController::class, 'index']); \ No newline at end of file