- Memindahkan fungsi showLoadingSwal() dan hideLoadingSwal() ke resources/assets/js/app.js - Menambahkan fitur timer dan progress bar pada fungsi global loading - Menghapus duplikasi fungsi showLoadingSwal() dari penilai/index.blade.php (~18 baris) - Menghapus duplikasi fungsi dari penilaian/otorisator/index-sla.blade.php (~18 baris) - Menghapus duplikasi fungsi dari penilaian/otorisator/index.blade.php (~18 baris) - Menghapus duplikasi fungsi dari penilaian/paparan-so.blade.php (~18 baris) - Memperbaiki syntax error tag HTML di surveyor/components/informasi.blade.php - Membersihkan duplikasi fungsi & memperbaiki escape string di surveyor/js/utils.blade.php - Mengurangi ±90 baris kode duplikat, meningkatkan maintainability & UX (loading dialog lebih informatif)
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
function hitungHariKerja(tanggalMulai, tanggalSelesai) {
|
|
tanggalMulai = new Date(tanggalMulai);
|
|
tanggalMulai.setHours(0, 0, 0, 0);
|
|
tanggalSelesai = new Date(tanggalSelesai);
|
|
tanggalSelesai.setHours(23, 59, 59, 999);
|
|
|
|
let hariKerja = 0;
|
|
let tanggalSekarang = new Date(tanggalMulai);
|
|
|
|
// You'll need to implement a way to get holiday dates from your server
|
|
// For this example, we'll assume you have a global variable holidayDates
|
|
// that contains an array of holiday date strings in 'YYYY-MM-DD' format
|
|
const tanggalLibur = window.holidayDates || [];
|
|
|
|
while (tanggalSekarang <= tanggalSelesai) {
|
|
const dayOfWeek = tanggalSekarang.getDay();
|
|
const dateString = tanggalSekarang.toISOString().split("T")[0];
|
|
|
|
// Check if it's not Saturday (6) or Sunday (0) and not a holiday
|
|
if (
|
|
dayOfWeek !== 0 &&
|
|
dayOfWeek !== 6 &&
|
|
!tanggalLibur.includes(dateString)
|
|
) {
|
|
hariKerja++;
|
|
}
|
|
|
|
tanggalSekarang.setDate(tanggalSekarang.getDate() + 1);
|
|
}
|
|
|
|
return hariKerja;
|
|
}
|
|
|
|
function showLoadingSwal(message, duration = 5000) {
|
|
Swal.fire({
|
|
title: message,
|
|
allowOutsideClick: false,
|
|
didOpen: () => {
|
|
Swal.showLoading();
|
|
},
|
|
timer: duration, // Durasi dalam milidetik
|
|
timerProgressBar: true, // Menampilkan progres bar timer
|
|
}).then((result) => {
|
|
if (result.dismiss === Swal.DismissReason.timer) {
|
|
console.log("Dialog loading otomatis ditutup.");
|
|
}
|
|
});
|
|
}
|
|
|
|
function hideLoadingSwal() {
|
|
Swal.close();
|
|
}
|
|
|
|
// Make the function available globally
|
|
window.hitungHariKerja = hitungHariKerja;
|
|
window.showLoadingSwal = showLoadingSwal;
|
|
window.hideLoadingSwal = hideLoadingSwal;
|