update: fixing admin scan (tester)
parent
e9a82f8665
commit
46229fccbb
|
@ -5,7 +5,7 @@ using eSPJ.Models;
|
|||
namespace eSPJ.Controllers.SpjAdminController;
|
||||
|
||||
[Route("admin")]
|
||||
public class AdminController : Controller
|
||||
public class SpjAdminController : Controller
|
||||
{
|
||||
|
||||
[HttpGet("")]
|
|
@ -180,6 +180,12 @@
|
|||
this.isScanning = false;
|
||||
this.detectedCode = null;
|
||||
this.html5QrCode = null;
|
||||
|
||||
this.isProcessing = false;
|
||||
this.lastCode = null;
|
||||
this.lastScanTime = 0;
|
||||
this.resumeTimer = null;
|
||||
|
||||
this.initializeElements();
|
||||
this.bindEvents();
|
||||
this.checkBrowserSupport();
|
||||
|
@ -297,8 +303,7 @@
|
|||
height: qrboxSize
|
||||
};
|
||||
},
|
||||
aspectRatio: 1.0,
|
||||
rememberLastUsedCamera: true
|
||||
aspectRatio: 1.0
|
||||
},
|
||||
(decodedText, decodedResult) => {
|
||||
this.handleBarcodeDetected(decodedText, decodedResult);
|
||||
|
@ -346,19 +351,36 @@
|
|||
console.log(`QR Code terdeteksi: "${decodedText}"`);
|
||||
console.log(`Panjang kode: ${decodedText.length}`);
|
||||
|
||||
if (decodedText && decodedText.length >= 5) {
|
||||
console.log(`✅ Kode valid, memproses: ${decodedText}`);
|
||||
const code = typeof decodedText === 'string' ? decodedText.trim() : '';
|
||||
if (!code || code.length < 5) {
|
||||
console.log(`❌ Kode tidak valid atau terlalu pendek: ${decodedText}`);
|
||||
return;
|
||||
}
|
||||
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 = decodedText;
|
||||
// Jangan stop scanner, biarkan tetap aktif untuk scan berikutnya
|
||||
this.detectedCode = code;
|
||||
this.isProcessing = true;
|
||||
|
||||
this.processScanCode(decodedText);
|
||||
} else {
|
||||
console.log(`❌ Kode terlalu pendek: ${decodedText}`);
|
||||
try {
|
||||
if (this.html5QrCode && typeof this.html5QrCode.pause === 'function') {
|
||||
this.html5QrCode.pause(true);
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
this.processScanCode(code);
|
||||
}
|
||||
|
||||
async stopScanner() {
|
||||
|
@ -369,6 +391,13 @@
|
|||
}
|
||||
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.stopBtn.classList.add('hidden');
|
||||
|
@ -642,7 +671,7 @@
|
|||
$('#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-message').html(successContent);
|
||||
$('#modal-close').hide(); // Sembunyikan tombol
|
||||
$('#modal-close').hide();
|
||||
|
||||
$('#scan-modal').removeClass('hidden');
|
||||
$('#scan-modal').addClass('flex');
|
||||
|
@ -654,7 +683,9 @@
|
|||
|
||||
setTimeout(() => {
|
||||
this.hideModal();
|
||||
// Scanner tetap aktif setelah modal ditutup
|
||||
this.hideResult();
|
||||
this.manualInput.value = '';
|
||||
this.resumeAfterDelay(300);
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
|
@ -693,7 +724,7 @@
|
|||
$('#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-message').html(errorContent);
|
||||
$('#modal-close').hide(); // Sembunyikan tombol
|
||||
$('#modal-close').hide();
|
||||
|
||||
$('#scan-modal').removeClass('hidden');
|
||||
$('#scan-modal').addClass('flex');
|
||||
|
@ -705,18 +736,35 @@
|
|||
|
||||
setTimeout(() => {
|
||||
this.hideModal();
|
||||
// Scanner tetap aktif setelah modal error ditutup
|
||||
this.resumeAfterDelay(300);
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
hideModal() {
|
||||
$('#scan-modal').animate({'opacity': '0'}, 200, function() {
|
||||
$('#scan-modal').animate({'opacity': '0'}, 200, () => {
|
||||
$('#scan-modal').addClass('hidden');
|
||||
$('#scan-modal').removeClass('flex');
|
||||
$('#scan-modal').css('opacity', '');
|
||||
$('#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() {
|
||||
|
|
Loading…
Reference in New Issue