diff --git a/app/Providers/FirebaseServiceProvider.php b/app/Providers/FirebaseServiceProvider.php index 736a2fa..27eba0f 100644 --- a/app/Providers/FirebaseServiceProvider.php +++ b/app/Providers/FirebaseServiceProvider.php @@ -13,8 +13,8 @@ public function register() { $this->app->singleton(FirebaseAuth::class, function ($app) { $factory = (new Factory) - ->withServiceAccount(json_decode(env('FIREBASE_CREDENTIALS'), true)) - ->withDatabaseUri(env('FIREBASE_DATABASE_URL')); + ->withServiceAccount(config('firebase.credentials')) + ->withDatabaseUri(config('firebase.database_url')); return $factory->createAuth(); }); diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 60e6aa1..30d38e9 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -9,6 +9,7 @@ + @@ -25,9 +26,9 @@
- + {{-- AI - + --}}
@@ -531,6 +531,33 @@ class="p-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text- + + + @@ -932,84 +959,142 @@ function setupRestartButtons() { const restartWemos = document.getElementById('restartWemos'); if (restartWemos) { restartWemos.addEventListener('click', function() { - if (confirm('Apakah Anda yakin ingin me-restart Wemos D1 Mini?')) { - // Perbarui status restart di UI terlebih dahulu - document.querySelectorAll('#wemos-status').forEach(el => { - el.textContent = 'Restarting...'; - el.className = 'text-sm sm:text-lg font-semibold text-yellow-500'; - }); - - // Perbarui status di Firebase - database.ref('logs/systemWemos').set('Device auto-restarting...') - .then(() => { - console.log('Status Wemos diperbarui ke restarting'); - - // Kirim perintah restart - return database.ref('control/restartWemos').set(true); - }) - .then(() => { - alert('Perintah restart Wemos D1 Mini berhasil dikirim'); - - // Reset perintah restart setelah 5 detik - setTimeout(() => { - database.ref('control/restartWemos').set(false); - }, 5000); - }) - .catch(error => { - console.error('Error restarting Wemos:', error); - alert('Gagal mengirim perintah restart'); - - // Kembalikan status jika gagal - database.ref('logs/systemWemos').once('value', (snapshot) => { - const previousStatus = snapshot.val(); - if (previousStatus === 'Device auto-restarting...') { - database.ref('logs/systemWemos').set('Device Online'); - } - }); - }); + // Cek status Wemos sebelum menampilkan dialog + const wemosStatus = document.querySelector('#wemos-status').textContent; + if (wemosStatus === 'Offline') { + Swal.fire( + 'Tidak Dapat Melakukan Restart', + 'Perangkat Wemos D1 Mini sedang offline.', + 'error' + ); + return; } + + Swal.fire({ + title: 'Apakah Anda yakin?', + text: "Anda ingin me-restart Wemos D1 Mini?", + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: 'Ya, restart!' + }).then((result) => { + if (result.isConfirmed) { + // Perbarui status restart di UI terlebih dahulu + document.querySelectorAll('#wemos-status').forEach(el => { + el.textContent = 'Restarting...'; + el.className = 'text-sm sm:text-lg font-semibold text-yellow-500'; + }); + + // Perbarui status di Firebase + database.ref('logs/systemWemos').set('Device auto-restarting...') + .then(() => { + console.log('Status Wemos diperbarui ke restarting'); + + // Kirim perintah restart + return database.ref('control/restartWemos').set(true); + }) + .then(() => { + Swal.fire( + 'Berhasil!', + 'Perintah restart Wemos D1 Mini berhasil dikirim.', + 'success' + ); + + // Reset perintah restart setelah 5 detik + setTimeout(() => { + database.ref('control/restartWemos').set(false); + }, 5000); + }) + .catch(error => { + console.error('Error restarting Wemos:', error); + Swal.fire( + 'Gagal!', + 'Gagal mengirim perintah restart.', + 'error' + ); + + // Kembalikan status jika gagal + database.ref('logs/systemWemos').once('value', (snapshot) => { + const previousStatus = snapshot.val(); + if (previousStatus === 'Device auto-restarting...') { + database.ref('logs/systemWemos').set('Device Online'); + } + }); + }); + } + }); }); } const restartESP = document.getElementById('restartESP'); if (restartESP) { restartESP.addEventListener('click', function() { - if (confirm('Apakah Anda yakin ingin me-restart NodeMCU ESP8266?')) { - // Perbarui status restart di UI terlebih dahulu - document.querySelectorAll('#esp-status').forEach(el => { - el.textContent = 'Restarting...'; - el.className = 'text-sm sm:text-lg font-semibold text-yellow-500'; - }); - - // Perbarui status di Firebase - database.ref('logs/systemESP').set('Device restarting by command...') - .then(() => { - console.log('Status ESP diperbarui ke restarting'); - - // Kirim perintah restart - return database.ref('control/restartESP').set(true); - }) - .then(() => { - alert('Perintah restart NodeMCU ESP8266 berhasil dikirim'); - - // Reset perintah restart setelah 5 detik - setTimeout(() => { - database.ref('control/restartESP').set(false); - }, 5000); - }) - .catch(error => { - console.error('Error restarting ESP:', error); - alert('Gagal mengirim perintah restart'); - - // Kembalikan status jika gagal - database.ref('logs/systemESP').once('value', (snapshot) => { - const previousStatus = snapshot.val(); - if (previousStatus === 'Device restarting by command...') { - database.ref('logs/systemESP').set('Device online'); - } - }); - }); + // Cek status ESP sebelum menampilkan dialog + const espStatus = document.querySelector('#esp-status').textContent; + if (espStatus === 'Offline') { + Swal.fire( + 'Tidak Dapat Melakukan Restart', + 'Perangkat NodeMCU ESP8266 sedang offline.', + 'error' + ); + return; } + + Swal.fire({ + title: 'Apakah Anda yakin?', + text: "Anda ingin me-restart NodeMCU ESP8266?", + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: 'Ya, restart!' + }).then((result) => { + if (result.isConfirmed) { + // Perbarui status restart di UI terlebih dahulu + document.querySelectorAll('#esp-status').forEach(el => { + el.textContent = 'Restarting...'; + el.className = 'text-sm sm:text-lg font-semibold text-yellow-500'; + }); + + // Perbarui status di Firebase + database.ref('logs/systemESP').set('Device restarting by command...') + .then(() => { + console.log('Status ESP diperbarui ke restarting'); + + // Kirim perintah restart + return database.ref('control/restartESP').set(true); + }) + .then(() => { + Swal.fire( + 'Berhasil!', + 'Perintah restart NodeMCU ESP8266 berhasil dikirim.', + 'success' + ); + + // Reset perintah restart setelah 5 detik + setTimeout(() => { + database.ref('control/restartESP').set(false); + }, 5000); + }) + .catch(error => { + console.error('Error restarting ESP:', error); + Swal.fire( + 'Gagal!', + 'Gagal mengirim perintah restart.', + 'error' + ); + + // Kembalikan status jika gagal + database.ref('logs/systemESP').once('value', (snapshot) => { + const previousStatus = snapshot.val(); + if (previousStatus === 'Device restarting by command...') { + database.ref('logs/systemESP').set('Device online'); + } + }); + }); + } + }); }); } } @@ -1280,9 +1365,20 @@ function initializeSecurityToggle() { } }); }, 5000); + + // Function to toggle the guide modal + function toggleGuideModal() { + const guideModal = document.getElementById('guideModal'); + if (guideModal) { + guideModal.classList.toggle('hidden'); + } + } + + // Add event listener to the guide button + document.getElementById('openGuide').addEventListener('click', function(event) { + event.preventDefault(); + toggleGuideModal(); + }); - - - \ No newline at end of file