update: fixing admin scan (tester)
parent
e9a82f8665
commit
46229fccbb
|
@ -5,7 +5,7 @@ using eSPJ.Models;
|
||||||
namespace eSPJ.Controllers.SpjAdminController;
|
namespace eSPJ.Controllers.SpjAdminController;
|
||||||
|
|
||||||
[Route("admin")]
|
[Route("admin")]
|
||||||
public class AdminController : Controller
|
public class SpjAdminController : Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
[HttpGet("")]
|
[HttpGet("")]
|
|
@ -175,11 +175,17 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
class BarcodeScanner {
|
class BarcodeScanner {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.isScanning = false;
|
this.isScanning = false;
|
||||||
this.detectedCode = null;
|
this.detectedCode = null;
|
||||||
this.html5QrCode = null;
|
this.html5QrCode = null;
|
||||||
|
|
||||||
|
this.isProcessing = false;
|
||||||
|
this.lastCode = null;
|
||||||
|
this.lastScanTime = 0;
|
||||||
|
this.resumeTimer = null;
|
||||||
|
|
||||||
this.initializeElements();
|
this.initializeElements();
|
||||||
this.bindEvents();
|
this.bindEvents();
|
||||||
this.checkBrowserSupport();
|
this.checkBrowserSupport();
|
||||||
|
@ -297,8 +303,7 @@
|
||||||
height: qrboxSize
|
height: qrboxSize
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
aspectRatio: 1.0,
|
aspectRatio: 1.0
|
||||||
rememberLastUsedCamera: true
|
|
||||||
},
|
},
|
||||||
(decodedText, decodedResult) => {
|
(decodedText, decodedResult) => {
|
||||||
this.handleBarcodeDetected(decodedText, decodedResult);
|
this.handleBarcodeDetected(decodedText, decodedResult);
|
||||||
|
@ -346,19 +351,36 @@
|
||||||
console.log(`QR Code terdeteksi: "${decodedText}"`);
|
console.log(`QR Code terdeteksi: "${decodedText}"`);
|
||||||
console.log(`Panjang kode: ${decodedText.length}`);
|
console.log(`Panjang kode: ${decodedText.length}`);
|
||||||
|
|
||||||
if (decodedText && decodedText.length >= 5) {
|
const code = typeof decodedText === 'string' ? decodedText.trim() : '';
|
||||||
console.log(`✅ Kode valid, memproses: ${decodedText}`);
|
if (!code || code.length < 5) {
|
||||||
this.flashSuccess();
|
console.log(`❌ Kode tidak valid atau terlalu pendek: ${decodedText}`);
|
||||||
this.playSuccessSound();
|
return;
|
||||||
this.vibrate();
|
|
||||||
|
|
||||||
this.detectedCode = decodedText;
|
|
||||||
// Jangan stop scanner, biarkan tetap aktif untuk scan berikutnya
|
|
||||||
|
|
||||||
this.processScanCode(decodedText);
|
|
||||||
} else {
|
|
||||||
console.log(`❌ Kode terlalu pendek: ${decodedText}`);
|
|
||||||
}
|
}
|
||||||
|
if (this.isProcessing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const now = Date.now();
|
||||||
|
if (code === this.lastCode && (now - this.lastScanTime) < 3000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lastCode = code;
|
||||||
|
this.lastScanTime = now;
|
||||||
|
|
||||||
|
console.log(`✅ Kode valid, memproses: ${code}`);
|
||||||
|
this.flashSuccess();
|
||||||
|
this.playSuccessSound();
|
||||||
|
this.vibrate();
|
||||||
|
|
||||||
|
this.detectedCode = code;
|
||||||
|
this.isProcessing = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this.html5QrCode && typeof this.html5QrCode.pause === 'function') {
|
||||||
|
this.html5QrCode.pause(true);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
this.processScanCode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
async stopScanner() {
|
async stopScanner() {
|
||||||
|
@ -369,6 +391,13 @@
|
||||||
}
|
}
|
||||||
this.isScanning = false;
|
this.isScanning = false;
|
||||||
}
|
}
|
||||||
|
this.isProcessing = false;
|
||||||
|
this.lastCode = null;
|
||||||
|
this.lastScanTime = 0;
|
||||||
|
if (this.resumeTimer) {
|
||||||
|
clearTimeout(this.resumeTimer);
|
||||||
|
this.resumeTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.startBtn.classList.remove('hidden');
|
this.startBtn.classList.remove('hidden');
|
||||||
this.stopBtn.classList.add('hidden');
|
this.stopBtn.classList.add('hidden');
|
||||||
|
@ -642,7 +671,7 @@
|
||||||
$('#modal-icon').html(successIcon);
|
$('#modal-icon').html(successIcon);
|
||||||
$('#modal-title').html('<span class="text-2xl font-bold bg-gradient-to-r from-green-600 to-emerald-600 bg-clip-text text-transparent">Scan Berhasil!</span>');
|
$('#modal-title').html('<span class="text-2xl font-bold bg-gradient-to-r from-green-600 to-emerald-600 bg-clip-text text-transparent">Scan Berhasil!</span>');
|
||||||
$('#modal-message').html(successContent);
|
$('#modal-message').html(successContent);
|
||||||
$('#modal-close').hide(); // Sembunyikan tombol
|
$('#modal-close').hide();
|
||||||
|
|
||||||
$('#scan-modal').removeClass('hidden');
|
$('#scan-modal').removeClass('hidden');
|
||||||
$('#scan-modal').addClass('flex');
|
$('#scan-modal').addClass('flex');
|
||||||
|
@ -654,7 +683,9 @@
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.hideModal();
|
this.hideModal();
|
||||||
// Scanner tetap aktif setelah modal ditutup
|
this.hideResult();
|
||||||
|
this.manualInput.value = '';
|
||||||
|
this.resumeAfterDelay(300);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,7 +724,7 @@
|
||||||
$('#modal-icon').html(errorIcon);
|
$('#modal-icon').html(errorIcon);
|
||||||
$('#modal-title').html('<span class="text-xl font-bold bg-gradient-to-r from-red-600 to-rose-600 bg-clip-text text-transparent">Scan Gagal</span>');
|
$('#modal-title').html('<span class="text-xl font-bold bg-gradient-to-r from-red-600 to-rose-600 bg-clip-text text-transparent">Scan Gagal</span>');
|
||||||
$('#modal-message').html(errorContent);
|
$('#modal-message').html(errorContent);
|
||||||
$('#modal-close').hide(); // Sembunyikan tombol
|
$('#modal-close').hide();
|
||||||
|
|
||||||
$('#scan-modal').removeClass('hidden');
|
$('#scan-modal').removeClass('hidden');
|
||||||
$('#scan-modal').addClass('flex');
|
$('#scan-modal').addClass('flex');
|
||||||
|
@ -705,18 +736,35 @@
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.hideModal();
|
this.hideModal();
|
||||||
// Scanner tetap aktif setelah modal error ditutup
|
this.resumeAfterDelay(300);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
hideModal() {
|
hideModal() {
|
||||||
$('#scan-modal').animate({'opacity': '0'}, 200, function() {
|
$('#scan-modal').animate({'opacity': '0'}, 200, () => {
|
||||||
$('#scan-modal').addClass('hidden');
|
$('#scan-modal').addClass('hidden');
|
||||||
$('#scan-modal').removeClass('flex');
|
$('#scan-modal').removeClass('flex');
|
||||||
$('#scan-modal').css('opacity', '');
|
$('#scan-modal').css('opacity', '');
|
||||||
$('#scan-modal .bg-white').css('transform', '');
|
$('#scan-modal .bg-white').css('transform', '');
|
||||||
|
if (this.isProcessing) {
|
||||||
|
this.resumeAfterDelay(200);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resumeAfterDelay(ms = 400) {
|
||||||
|
if (this.resumeTimer) {
|
||||||
|
clearTimeout(this.resumeTimer);
|
||||||
|
}
|
||||||
|
this.resumeTimer = setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
if (this.html5QrCode && this.isScanning && typeof this.html5QrCode.resume === 'function') {
|
||||||
|
await this.html5QrCode.resume();
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
this.isProcessing = false;
|
||||||
|
}, ms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
Loading…
Reference in New Issue