ilerleme çubukları düzeltildi.

This commit is contained in:
2026-07-31 05:08:25 +02:00
parent 171e6a90be
commit f5d3fa46db
+54 -52
View File
@@ -24,7 +24,7 @@ export function renderKaza(pb) {
<span class="text-3xl">📿</span> <span class="text-3xl">📿</span>
<div> <div>
<h2 class="text-2xl font-bold text-white">Kaza Namazı Sayaç & Takip</h2> <h2 class="text-2xl font-bold text-white">Kaza Namazı Sayaç & Takip</h2>
<p class="text-slate-400 text-xs">Hicri takvime göre kaza borcunuzu PocketBase'e sabitleyin ve kıldıkça düşürün.</p> <p class="text-slate-400 text-xs">Hicri takvime göre kaza borcunuzu sabitleyin ve kıldıkça düşürün.</p>
</div> </div>
</div> </div>
@@ -58,7 +58,7 @@ export function renderKaza(pb) {
<div class="flex flex-wrap items-center justify-between gap-2 border-b border-white/10 pb-3"> <div class="flex flex-wrap items-center justify-between gap-2 border-b border-white/10 pb-3">
<div> <div>
<h3 class="text-xs font-bold text-indigo-300 uppercase tracking-wider">Kaza Borcu Tanımlama</h3> <h3 class="text-xs font-bold text-indigo-300 uppercase tracking-wider">Kaza Borcu Tanımlama</h3>
<p class="text-[11px] text-slate-400">Hicri takvime göre kaza borcunuzu hesaplar ve PocketBase'e ilk borç olarak kaydeder.</p> <p class="text-[11px] text-slate-400">Hicri takvime göre kaza borcunuzu hesaplar ve PocketBase'e kaydeder.</p>
</div> </div>
<button id="calcAndSaveBtn" class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-xl text-xs font-semibold transition-all shadow-md active:scale-95"> <button id="calcAndSaveBtn" class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-xl text-xs font-semibold transition-all shadow-md active:scale-95">
⚡ Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet ⚡ Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet
@@ -68,15 +68,15 @@ export function renderKaza(pb) {
<div> <div>
<div class="flex items-center justify-between mb-2"> <div class="flex items-center justify-between mb-2">
<span class="text-xs font-bold text-indigo-300 flex items-center gap-1.5"> <span class="text-xs font-bold text-indigo-300 flex items-center gap-1.5">
<span>📊</span> KAZA BORCU TAMAMLAMA TAMAMLANMA ORANI <span>📊</span> KAZA BORCU TAMAMLAMA ORANI
</span> </span>
<span id="overallPercentage" class="text-sm font-extrabold text-emerald-400">%0 Kılındı</span> <span id="overallPercentage" class="text-sm font-extrabold text-emerald-400">%0 Kılındı</span>
</div> </div>
<div class="w-full h-4 bg-slate-900 rounded-full overflow-hidden border border-white/5 p-0.5"> <div class="w-full h-4 bg-slate-900 rounded-full overflow-hidden border border-white/5 p-0.5">
<div id="overallProgressBar" class="h-full bg-linear-to-r from-indigo-500 via-purple-500 to-emerald-400 rounded-full transition-all duration-700 ease-out w-[0%]"></div> <div id="overallProgressBar" class="h-full bg-linear-to-r from-indigo-500 via-purple-500 to-emerald-400 rounded-full transition-all duration-700 ease-out" style="width: 0%;"></div>
</div> </div>
<div class="flex justify-between items-center text-[11px] text-slate-400 mt-2.5"> <div class="flex justify-between items-center text-[11px] text-slate-400 mt-2.5">
<span>İlk Toplam Borç: <b id="initialTotalText" class="text-slate-300">0</b> vakit</span> <span>Hesaplanan İlk Borç: <b id="initialTotalText" class="text-slate-300">0</b> vakit</span>
<span>Kalan Güncel Borç: <b id="totalRemainingText" class="text-amber-400">0</b> vakit</span> <span>Kalan Güncel Borç: <b id="totalRemainingText" class="text-amber-400">0</b> vakit</span>
</div> </div>
</div> </div>
@@ -88,10 +88,10 @@ export function renderKaza(pb) {
(p) => ` (p) => `
<div class="bg-slate-950/40 border border-white/10 p-3.5 rounded-2xl text-center relative overflow-hidden group"> <div class="bg-slate-950/40 border border-white/10 p-3.5 rounded-2xl text-center relative overflow-hidden group">
<p class="text-[11px] font-bold text-slate-300 mb-1">${p.name}</p> <p class="text-[11px] font-bold text-slate-300 mb-1">${p.name}</p>
<p class="text-xs text-slate-400">Kalan Borç: <span id="remaining-${p.id}" class="font-extrabold text-amber-300">-</span></p> <p class="text-xs text-slate-400">Kalan: <span id="remaining-${p.id}" class="font-extrabold text-amber-300">-</span></p>
<p class="text-[10px] text-slate-500 mt-0.5">İlk Borç: <span id="initial-${p.id}" class="text-slate-400">0</span></p> <p class="text-[10px] text-slate-500 mt-0.5">İlk Borç: <span id="initial-${p.id}" class="text-slate-400">0</span></p>
<div class="w-full bg-slate-800 h-1.5 rounded-full mt-2.5 overflow-hidden"> <div class="w-full bg-slate-800 h-2 rounded-full mt-2.5 overflow-hidden">
<div id="progress-${p.id}" class="bg-emerald-400 h-full w-[0%] transition-all duration-500"></div> <div id="progress-${p.id}" class="bg-emerald-400 h-full transition-all duration-500" style="width: 0%;"></div>
</div> </div>
</div> </div>
`, `,
@@ -153,19 +153,19 @@ export function renderKaza(pb) {
} }
}); });
} else { } else {
refreshKazaStats(container, pb); refreshKazaStats(container, pb, birthDate, gender);
container container
.querySelector("#calcAndSaveBtn") .querySelector("#calcAndSaveBtn")
?.addEventListener("click", async () => { ?.addEventListener("click", async () => {
if ( if (
confirm( confirm(
"Doğum tarihinize göre kaza borcunuz hesaplanıp PocketBase veritabanına kaydedilecek. Onaylıyor musunuz?", "Kaza borcunuz yeniden hesaplanıp PocketBase'e kaydedilecek. Onaylıyor musunuz?",
) )
) { ) {
const res = await initAndSaveInitialKaza(pb, birthDate, gender); const res = await initAndSaveInitialKaza(pb, birthDate, gender);
if (res.success) { if (res.success) {
await refreshKazaStats(container, pb); await refreshKazaStats(container, pb, birthDate, gender);
showKazaMsg( showKazaMsg(
container.querySelector("#kazaMsg"), container.querySelector("#kazaMsg"),
`✓ Borç hesaplandı (${res.days} gün) ve PocketBase'e kaydedildi!`, `✓ Borç hesaplandı (${res.days} gün) ve PocketBase'e kaydedildi!`,
@@ -184,13 +184,13 @@ export function renderKaza(pb) {
container container
.querySelector("#subtractKazaBtn") .querySelector("#subtractKazaBtn")
?.addEventListener("click", async () => { ?.addEventListener("click", async () => {
await updateKazaDebt(container, pb, -1); await updateKazaDebt(container, pb, birthDate, gender, -1);
}); });
container container
.querySelector("#addKazaBtn") .querySelector("#addKazaBtn")
?.addEventListener("click", async () => { ?.addEventListener("click", async () => {
await updateKazaDebt(container, pb, 1); await updateKazaDebt(container, pb, birthDate, gender, 1);
}); });
} }
}, },
@@ -200,23 +200,25 @@ export function renderKaza(pb) {
async function initAndSaveInitialKaza(pb, birthDate, gender) { async function initAndSaveInitialKaza(pb, birthDate, gender) {
try { try {
const calc = calculateMissedPrayers(birthDate, gender, 12); const calc = calculateMissedPrayers(birthDate, gender, 12);
if (!calc || calc.days <= 0) { if (!calc || calc.days <= 0) {
return { return {
success: false, success: false,
error: "Doğum tarihiniz henüz mükellefiyet yaşından (12 Hicri yıl) küçük." error:
"Doğum tarihiniz henüz mükellefiyet yaşından (12 Hicri yıl) küçük.",
}; };
} }
const userId = pb.authStore.model.id; const userId = pb.authStore.model.id;
let userRecord = null; let userRecord = null;
try { try {
userRecord = await pb userRecord = await pb
.collection("kaza_logs") .collection("kaza_logs")
.getFirstListItem(`user = "${userId}"`); .getFirstListItem(`user = "${userId}"`);
} catch (e) {} } catch (e) {}
// PB tarafındaki varsayılan sütunlara (fajr, dhuhr vb.) borcu yazıyoruz
const initialData = { const initialData = {
user: userId, user: userId,
fajr: calc.fajr, fajr: calc.fajr,
@@ -225,12 +227,6 @@ async function initAndSaveInitialKaza(pb, birthDate, gender) {
maghrib: calc.maghrib, maghrib: calc.maghrib,
isha: calc.isha, isha: calc.isha,
vitr: calc.vitr, vitr: calc.vitr,
target_fajr: calc.fajr,
target_dhuhr: calc.dhuhr,
target_asr: calc.asr,
target_maghrib: calc.maghrib,
target_isha: calc.isha,
target_vitr: calc.vitr,
}; };
if (userRecord) { if (userRecord) {
@@ -242,18 +238,18 @@ async function initAndSaveInitialKaza(pb, birthDate, gender) {
return { success: true, days: calc.days, fajr: calc.fajr }; return { success: true, days: calc.days, fajr: calc.fajr };
} catch (err) { } catch (err) {
console.error("PocketBase Kayıt Hatası:", err); console.error("PocketBase Kayıt Hatası:", err);
return { return {
success: false, success: false,
error: err?.message || "PocketBase'e kaydedilemedi." error: err?.message || "PocketBase'e kaydedilemedi.",
}; };
} }
} }
async function updateKazaDebt(container, pb, direction) { async function updateKazaDebt(container, pb, birthDate, gender, direction) {
const prayerId = container.querySelector("#kazaPrayerType").value; const prayerId = container.querySelector("#kazaPrayerType").value;
const countInput = container.querySelector("#kazaCount"); const countInput = container.querySelector("#kazaCount");
const countValue = Math.max(1, parseInt(countInput?.value || "1", 10)); const countValue = Math.max(1, parseInt(countInput?.value || "1", 10));
const changeAmount = countValue * direction; const changeAmount = countValue * direction;
const msg = container.querySelector("#kazaMsg"); const msg = container.querySelector("#kazaMsg");
@@ -264,7 +260,11 @@ async function updateKazaDebt(container, pb, direction) {
.getFirstListItem(`user = "${userId}"`); .getFirstListItem(`user = "${userId}"`);
if (!userRecord) { if (!userRecord) {
showKazaMsg(msg, "Önce 'Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet' butonuna basmalısınız.", false); showKazaMsg(
msg,
"Önce 'Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet' butonuna basmalısınız.",
false,
);
return; return;
} }
@@ -279,45 +279,39 @@ async function updateKazaDebt(container, pb, direction) {
msg, msg,
direction < 0 direction < 0
? `${countValue} vakit kılındı, borçtan düşüldü! Kalan: ${newDebt}` ? `${countValue} vakit kılındı, borçtan düşüldü! Kalan: ${newDebt}`
: `${countValue} vakit borca geri eklendi. Güncel: ${newDebt}`, : `${countValue} vakit borca eklendi. Kalan: ${newDebt}`,
true, true,
); );
if (countInput) countInput.value = "1"; if (countInput) countInput.value = "1";
await refreshKazaStats(container, pb); await refreshKazaStats(container, pb, birthDate, gender);
} catch (err) { } catch (err) {
console.error("Güncelleme hatası:", err); console.error("Güncelleme hatası:", err);
showKazaMsg(msg, "PocketBase güncellenirken hata oluştu.", false); showKazaMsg(msg, "PocketBase güncellenirken hata oluştu.", false);
} }
} }
async function refreshKazaStats(container, pb) { async function refreshKazaStats(container, pb, birthDate, gender) {
// İlk toplam borç verisini direkt doğum tarihinden dinamik alıyoruz (Hiç şaşmaz!)
const initialCalc = calculateMissedPrayers(birthDate, gender, 12);
const userId = pb.authStore.model.id; const userId = pb.authStore.model.id;
let userRecord = null;
let userRecord = null;
try { try {
userRecord = await pb userRecord = await pb
.collection("kaza_logs") .collection("kaza_logs")
.getFirstListItem(`user = "${userId}"`); .getFirstListItem(`user = "${userId}"`);
} catch (err) {} } catch (err) {}
if (!userRecord) {
PRAYERS.forEach((p) => {
const remainEl = container.querySelector(`#remaining-${p.id}`);
const initialEl = container.querySelector(`#initial-${p.id}`);
if (remainEl) remainEl.textContent = "Hesaplanmadı";
if (initialEl) initialEl.textContent = "0";
});
return;
}
let grandInitialTotal = 0; let grandInitialTotal = 0;
let grandCurrentDebtTotal = 0; let grandCurrentDebtTotal = 0;
PRAYERS.forEach((p) => { PRAYERS.forEach((p) => {
// Ilk borç verisi yoksa güncel borcu baz al const initialDebt = initialCalc[p.id] || 0;
const initialDebt = userRecord[`target_${p.id}`] ?? userRecord[p.id] ?? 0; // PB kaydı henüz yoksa kalan borç = ilk borçtur
const currentDebt = userRecord[p.id] ?? 0; const currentDebt = userRecord
? (userRecord[p.id] ?? initialDebt)
: initialDebt;
grandInitialTotal += initialDebt; grandInitialTotal += initialDebt;
grandCurrentDebtTotal += currentDebt; grandCurrentDebtTotal += currentDebt;
@@ -329,19 +323,27 @@ async function refreshKazaStats(container, pb) {
if (remainEl) remainEl.textContent = currentDebt; if (remainEl) remainEl.textContent = currentDebt;
if (initialEl) initialEl.textContent = initialDebt; if (initialEl) initialEl.textContent = initialDebt;
// Mini barların doluluk oranı hesabı (Kılınan Vakit / İlk Borç) // Yüzde Hesabı: (Kılınan Vakit / İlk Borç) * 100
if (progressEl) { if (progressEl) {
const completed = Math.max(0, initialDebt - currentDebt); const completed = Math.max(0, initialDebt - currentDebt);
const pct = initialDebt > 0 ? Math.min(100, Math.max(0, Math.round((completed / initialDebt) * 100))) : 0; const pct =
initialDebt > 0
? Math.min(
100,
Math.max(0, Math.round((completed / initialDebt) * 100)),
)
: 0;
progressEl.style.width = `${pct}%`; progressEl.style.width = `${pct}%`;
} }
}); });
// Genel Borç İlerleme Barı Hesabı
const totalCompleted = Math.max(0, grandInitialTotal - grandCurrentDebtTotal); const totalCompleted = Math.max(0, grandInitialTotal - grandCurrentDebtTotal);
const overallPct = const overallPct =
grandInitialTotal > 0 grandInitialTotal > 0
? Math.min(100, Math.max(0, Math.round((totalCompleted / grandInitialTotal) * 100))) ? Math.min(
100,
Math.max(0, Math.round((totalCompleted / grandInitialTotal) * 100)),
)
: 0; : 0;
const bar = container.querySelector("#overallProgressBar"); const bar = container.querySelector("#overallProgressBar");
@@ -360,4 +362,4 @@ function showKazaMsg(el, text, success) {
el.textContent = text; el.textContent = text;
el.className = `text-xs mt-3 ${success ? "text-emerald-400 font-medium" : "text-rose-400 font-medium"}`; el.className = `text-xs mt-3 ${success ? "text-emerald-400 font-medium" : "text-rose-400 font-medium"}`;
el.classList.remove("hidden"); el.classList.remove("hidden");
} }