add page reports trial to collect from reports.json
This commit is contained in:
parent
72cf317483
commit
eec7efb9c9
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class ReportController extends Controller
|
||||||
|
{
|
||||||
|
public function getReports()
|
||||||
|
{
|
||||||
|
$jsonPath = storage_path('app/reports.json');
|
||||||
|
|
||||||
|
if (!File::exists($jsonPath)) {
|
||||||
|
return response()->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]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="id">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Report Data</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h2 class="mb-4">Laporan Keamanan dan Monitoring</h2>
|
||||||
|
|
||||||
|
@if(count($reports) > 0)
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Tanggal</th>
|
||||||
|
<th>Waktu</th>
|
||||||
|
<th>Gerakan</th>
|
||||||
|
<th>Status Keamanan</th>
|
||||||
|
<th>Akses Terakhir</th>
|
||||||
|
<th>Status Servo</th>
|
||||||
|
<th>Status Perangkat</th>
|
||||||
|
<th>Kelembaban</th>
|
||||||
|
<th>Suhu</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($reports as $key => $report)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $key + 1 }}</td>
|
||||||
|
<td>{{ $report['tanggal'] }}</td> <!-- Menampilkan tanggal -->
|
||||||
|
<td>{{ $report['waktu'] }}</td> <!-- Menampilkan waktu -->
|
||||||
|
<td>{{ ucfirst($report['security']['motion']) }}</td>
|
||||||
|
<td>{{ ucfirst($report['security']['status']) }}</td>
|
||||||
|
<td>{{ $report['smartcab']['last_access'] }}</td>
|
||||||
|
<td>{{ ucfirst($report['smartcab']['servo_status']) }}</td>
|
||||||
|
<td>{{ ucfirst($report['smartcab']['status_device']) }}</td>
|
||||||
|
<td>{{ $report['dht11']['humidity'] }}%</td>
|
||||||
|
<td>{{ $report['dht11']['temperature'] }}°C</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@else
|
||||||
|
<div class="alert alert-warning text-center">
|
||||||
|
Tidak ada data laporan.
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script>
|
||||||
|
function loadReports() {
|
||||||
|
$.ajax({
|
||||||
|
url: "/get-reports",
|
||||||
|
type: "GET",
|
||||||
|
success: function (data) {
|
||||||
|
let html = "";
|
||||||
|
data.forEach((report, index) => {
|
||||||
|
html += `
|
||||||
|
<tr>
|
||||||
|
<td>${index + 1}</td>
|
||||||
|
<td>${report.tanggal}</td>
|
||||||
|
<td>${report.waktu}</td>
|
||||||
|
<td>${report.security.motion.charAt(0).toUpperCase() + report.security.motion.slice(1)}</td>
|
||||||
|
<td>${report.security.status.charAt(0).toUpperCase() + report.security.status.slice(1)}</td>
|
||||||
|
<td>${report.smartcab.last_access}</td>
|
||||||
|
<td>${report.smartcab.servo_status.charAt(0).toUpperCase() + report.smartcab.servo_status.slice(1)}</td>
|
||||||
|
<td>${report.smartcab.status_device.charAt(0).toUpperCase() + report.smartcab.status_device.slice(1)}</td>
|
||||||
|
<td>${report.dht11.humidity}%</td>
|
||||||
|
<td>${report.dht11.temperature}°C</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
$("#reportsBody").html(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muat data pertama kali
|
||||||
|
loadReports();
|
||||||
|
|
||||||
|
// Perbarui setiap 5 detik
|
||||||
|
setInterval(loadReports, 5000);
|
||||||
|
</script>
|
|
@ -3,9 +3,9 @@
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\Auth\FirebaseAuthController;
|
use App\Http\Controllers\Auth\FirebaseAuthController;
|
||||||
use App\Http\Controllers\AIChatController;
|
use App\Http\Controllers\AIChatController;
|
||||||
use App\Http\Controllers\FirebaseController;
|
|
||||||
use App\Http\Controllers\WelcomeController;
|
use App\Http\Controllers\WelcomeController;
|
||||||
use App\Http\Controllers\ProfileController;
|
use App\Http\Controllers\ProfileController;
|
||||||
|
use App\Http\Controllers\ReportController;
|
||||||
|
|
||||||
Route::get('/login', [FirebaseAuthController::class, 'showLogin'])
|
Route::get('/login', [FirebaseAuthController::class, 'showLogin'])
|
||||||
->name('login')
|
->name('login')
|
||||||
|
@ -35,4 +35,4 @@
|
||||||
|
|
||||||
Route::get('/profile', [ProfileController::class, 'index'])->name('profile');
|
Route::get('/profile', [ProfileController::class, 'index'])->name('profile');
|
||||||
Route::post('/profile/update', [ProfileController::class, 'update'])->name('profile.update');
|
Route::post('/profile/update', [ProfileController::class, 'update'])->name('profile.update');
|
||||||
Route::get('/save-firebase', [FirebaseController::class, 'saveFirebaseData']);
|
Route::get('/reports', [ReportController::class, 'index']);
|
Loading…
Reference in New Issue