ilerleme çubukları düzeltildi.

This commit is contained in:
2026-07-31 05:03:10 +02:00
parent 89bc3d14c3
commit 171e6a90be
+21 -39
View File
@@ -68,7 +68,7 @@ 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 DURUMU <span>📊</span> KAZA BORCU TAMAMLAMA TAMAMLANMA 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>
@@ -155,13 +155,12 @@ export function renderKaza(pb) {
} else { } else {
refreshKazaStats(container, pb); refreshKazaStats(container, pb);
// Hesapla ve PB'ye Ilk Borc Olarak Kaydet
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. Var olan borç verileriniz sıfırlanır. Onaylıyor musunuz?", "Doğum tarihinize göre kaza borcunuz hesaplanıp PocketBase veritabanına kaydedilecek. Onaylıyor musunuz?",
) )
) { ) {
const res = await initAndSaveInitialKaza(pb, birthDate, gender); const res = await initAndSaveInitialKaza(pb, birthDate, gender);
@@ -169,7 +168,7 @@ export function renderKaza(pb) {
await refreshKazaStats(container, pb); await refreshKazaStats(container, pb);
showKazaMsg( showKazaMsg(
container.querySelector("#kazaMsg"), container.querySelector("#kazaMsg"),
`✓ Borç hesaplandı (${res.days} gün) ve PocketBase'e başarıyla kaydedildi!`, `✓ Borç hesaplandı (${res.days} gün) ve PocketBase'e kaydedildi!`,
true, true,
); );
} else { } else {
@@ -182,14 +181,12 @@ export function renderKaza(pb) {
} }
}); });
// Kildim (Borctan Dus / Eksi Deger)
container container
.querySelector("#subtractKazaBtn") .querySelector("#subtractKazaBtn")
?.addEventListener("click", async () => { ?.addEventListener("click", async () => {
await updateKazaDebt(container, pb, -1); await updateKazaDebt(container, pb, -1);
}); });
// Yanlislikla dusulduyse borca geri ekle (Artir / Artı Deger)
container container
.querySelector("#addKazaBtn") .querySelector("#addKazaBtn")
?.addEventListener("click", async () => { ?.addEventListener("click", async () => {
@@ -200,29 +197,26 @@ export function renderKaza(pb) {
}; };
} }
// PB tarafina ilk borclari kaydetme (target_* alanlarina da ilk borcu yedekliyoruz)
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: error: "Doğum tarihiniz henüz mükellefiyet yaşından (12 Hicri yıl) küçük."
"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) {}
// Kaza borclarini sakliyoruz (fajr, dhuhr... doğrudan Kalan Borçtur)
const initialData = { const initialData = {
user: userId, user: userId,
fajr: calc.fajr, fajr: calc.fajr,
@@ -231,7 +225,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,
// Ilk borcu orantı hesabi icin sakliyoruz
target_fajr: calc.fajr, target_fajr: calc.fajr,
target_dhuhr: calc.dhuhr, target_dhuhr: calc.dhuhr,
target_asr: calc.asr, target_asr: calc.asr,
@@ -249,22 +242,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: error: err?.message || "PocketBase'e kaydedilemedi."
err?.message ||
"PocketBase'e kaydedilemedi. Collection alan izinlerini kontrol edin.",
}; };
} }
} }
// Kildikca Borctan Dusme Fonksiyonu (-1 ile çarparak eksiltir)
async function updateKazaDebt(container, pb, direction) { async function updateKazaDebt(container, pb, 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));
// direction -1 ise borctan duser, +1 ise borca ekler
const changeAmount = countValue * direction; const changeAmount = countValue * direction;
const msg = container.querySelector("#kazaMsg"); const msg = container.querySelector("#kazaMsg");
@@ -275,19 +264,13 @@ async function updateKazaDebt(container, pb, direction) {
.getFirstListItem(`user = "${userId}"`); .getFirstListItem(`user = "${userId}"`);
if (!userRecord) { if (!userRecord) {
showKazaMsg( showKazaMsg(msg, "Önce 'Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet' butonuna basmalısınız.", false);
msg,
"Önce 'Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet' butonuna basmalısınız.",
false,
);
return; return;
} }
const currentDebt = userRecord[prayerId] || 0; const currentDebt = userRecord[prayerId] || 0;
// Yeni kalan borcu hesapla (0'ın altına düşmesin)
const newDebt = Math.max(0, currentDebt + changeAmount); const newDebt = Math.max(0, currentDebt + changeAmount);
// PocketBase'e Guncel Borcu Kaydet (PATCH / UPDATE)
await pb.collection("kaza_logs").update(userRecord.id, { await pb.collection("kaza_logs").update(userRecord.id, {
[prayerId]: newDebt, [prayerId]: newDebt,
}); });
@@ -308,7 +291,6 @@ async function updateKazaDebt(container, pb, direction) {
} }
} }
// PB Verilerini ekrana yansıtma
async function refreshKazaStats(container, pb) { async function refreshKazaStats(container, pb) {
const userId = pb.authStore.model.id; const userId = pb.authStore.model.id;
let userRecord = null; let userRecord = null;
@@ -333,8 +315,9 @@ async function refreshKazaStats(container, pb) {
let grandCurrentDebtTotal = 0; let grandCurrentDebtTotal = 0;
PRAYERS.forEach((p) => { PRAYERS.forEach((p) => {
const initialDebt = userRecord[`target_${p.id}`] || userRecord[p.id] || 0; // Ilk borç verisi yoksa güncel borcu baz al
const currentDebt = userRecord[p.id] || 0; const initialDebt = userRecord[`target_${p.id}`] ?? userRecord[p.id] ?? 0;
const currentDebt = userRecord[p.id] ?? 0;
grandInitialTotal += initialDebt; grandInitialTotal += initialDebt;
grandCurrentDebtTotal += currentDebt; grandCurrentDebtTotal += currentDebt;
@@ -346,20 +329,19 @@ 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ç)
if (progressEl) { if (progressEl) {
const completed = Math.max(0, initialDebt - currentDebt); const completed = Math.max(0, initialDebt - currentDebt);
const pct = const pct = initialDebt > 0 ? Math.min(100, Math.max(0, Math.round((completed / initialDebt) * 100))) : 0;
initialDebt > 0
? Math.min(100, Math.round((completed / initialDebt) * 100))
: 100;
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.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");
@@ -378,4 +360,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");
} }