ilerleme çubukları düzeltildi.
This commit is contained in:
+54
-52
@@ -24,7 +24,7 @@ export function renderKaza(pb) {
|
||||
<span class="text-3xl">📿</span>
|
||||
<div>
|
||||
<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>
|
||||
|
||||
@@ -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>
|
||||
<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>
|
||||
<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
|
||||
@@ -68,15 +68,15 @@ export function renderKaza(pb) {
|
||||
<div>
|
||||
<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>📊</span> KAZA BORCU TAMAMLAMA TAMAMLANMA ORANI
|
||||
<span>📊</span> KAZA BORCU TAMAMLAMA ORANI
|
||||
</span>
|
||||
<span id="overallPercentage" class="text-sm font-extrabold text-emerald-400">%0 Kılındı</span>
|
||||
</div>
|
||||
<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 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>
|
||||
</div>
|
||||
</div>
|
||||
@@ -88,10 +88,10 @@ export function renderKaza(pb) {
|
||||
(p) => `
|
||||
<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-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>
|
||||
<div class="w-full bg-slate-800 h-1.5 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 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 transition-all duration-500" style="width: 0%;"></div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
@@ -153,19 +153,19 @@ export function renderKaza(pb) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
refreshKazaStats(container, pb);
|
||||
refreshKazaStats(container, pb, birthDate, gender);
|
||||
|
||||
container
|
||||
.querySelector("#calcAndSaveBtn")
|
||||
?.addEventListener("click", async () => {
|
||||
if (
|
||||
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);
|
||||
if (res.success) {
|
||||
await refreshKazaStats(container, pb);
|
||||
await refreshKazaStats(container, pb, birthDate, gender);
|
||||
showKazaMsg(
|
||||
container.querySelector("#kazaMsg"),
|
||||
`✓ Borç hesaplandı (${res.days} gün) ve PocketBase'e kaydedildi!`,
|
||||
@@ -184,13 +184,13 @@ export function renderKaza(pb) {
|
||||
container
|
||||
.querySelector("#subtractKazaBtn")
|
||||
?.addEventListener("click", async () => {
|
||||
await updateKazaDebt(container, pb, -1);
|
||||
await updateKazaDebt(container, pb, birthDate, gender, -1);
|
||||
});
|
||||
|
||||
container
|
||||
.querySelector("#addKazaBtn")
|
||||
?.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) {
|
||||
try {
|
||||
const calc = calculateMissedPrayers(birthDate, gender, 12);
|
||||
|
||||
|
||||
if (!calc || calc.days <= 0) {
|
||||
return {
|
||||
success: false,
|
||||
error: "Doğum tarihiniz henüz mükellefiyet yaşından (12 Hicri yıl) küçük."
|
||||
return {
|
||||
success: false,
|
||||
error:
|
||||
"Doğum tarihiniz henüz mükellefiyet yaşından (12 Hicri yıl) küçük.",
|
||||
};
|
||||
}
|
||||
|
||||
const userId = pb.authStore.model.id;
|
||||
let userRecord = null;
|
||||
|
||||
|
||||
try {
|
||||
userRecord = await pb
|
||||
.collection("kaza_logs")
|
||||
.getFirstListItem(`user = "${userId}"`);
|
||||
} catch (e) {}
|
||||
|
||||
// PB tarafındaki varsayılan sütunlara (fajr, dhuhr vb.) borcu yazıyoruz
|
||||
const initialData = {
|
||||
user: userId,
|
||||
fajr: calc.fajr,
|
||||
@@ -225,12 +227,6 @@ async function initAndSaveInitialKaza(pb, birthDate, gender) {
|
||||
maghrib: calc.maghrib,
|
||||
isha: calc.isha,
|
||||
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) {
|
||||
@@ -242,18 +238,18 @@ async function initAndSaveInitialKaza(pb, birthDate, gender) {
|
||||
return { success: true, days: calc.days, fajr: calc.fajr };
|
||||
} catch (err) {
|
||||
console.error("PocketBase Kayıt Hatası:", err);
|
||||
return {
|
||||
success: false,
|
||||
error: err?.message || "PocketBase'e kaydedilemedi."
|
||||
return {
|
||||
success: false,
|
||||
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 countInput = container.querySelector("#kazaCount");
|
||||
const countValue = Math.max(1, parseInt(countInput?.value || "1", 10));
|
||||
|
||||
|
||||
const changeAmount = countValue * direction;
|
||||
const msg = container.querySelector("#kazaMsg");
|
||||
|
||||
@@ -264,7 +260,11 @@ async function updateKazaDebt(container, pb, direction) {
|
||||
.getFirstListItem(`user = "${userId}"`);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -279,45 +279,39 @@ async function updateKazaDebt(container, pb, direction) {
|
||||
msg,
|
||||
direction < 0
|
||||
? `✓ ${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,
|
||||
);
|
||||
|
||||
if (countInput) countInput.value = "1";
|
||||
await refreshKazaStats(container, pb);
|
||||
await refreshKazaStats(container, pb, birthDate, gender);
|
||||
} catch (err) {
|
||||
console.error("Güncelleme hatası:", err);
|
||||
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;
|
||||
let userRecord = null;
|
||||
|
||||
let userRecord = null;
|
||||
try {
|
||||
userRecord = await pb
|
||||
.collection("kaza_logs")
|
||||
.getFirstListItem(`user = "${userId}"`);
|
||||
} 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 grandCurrentDebtTotal = 0;
|
||||
|
||||
PRAYERS.forEach((p) => {
|
||||
// Ilk borç verisi yoksa güncel borcu baz al
|
||||
const initialDebt = userRecord[`target_${p.id}`] ?? userRecord[p.id] ?? 0;
|
||||
const currentDebt = userRecord[p.id] ?? 0;
|
||||
const initialDebt = initialCalc[p.id] || 0;
|
||||
// PB kaydı henüz yoksa kalan borç = ilk borçtur
|
||||
const currentDebt = userRecord
|
||||
? (userRecord[p.id] ?? initialDebt)
|
||||
: initialDebt;
|
||||
|
||||
grandInitialTotal += initialDebt;
|
||||
grandCurrentDebtTotal += currentDebt;
|
||||
@@ -329,19 +323,27 @@ async function refreshKazaStats(container, pb) {
|
||||
if (remainEl) remainEl.textContent = currentDebt;
|
||||
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) {
|
||||
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}%`;
|
||||
}
|
||||
});
|
||||
|
||||
// Genel Borç İlerleme Barı Hesabı
|
||||
const totalCompleted = Math.max(0, grandInitialTotal - grandCurrentDebtTotal);
|
||||
const overallPct =
|
||||
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;
|
||||
|
||||
const bar = container.querySelector("#overallProgressBar");
|
||||
@@ -360,4 +362,4 @@ function showKazaMsg(el, text, success) {
|
||||
el.textContent = text;
|
||||
el.className = `text-xs mt-3 ${success ? "text-emerald-400 font-medium" : "text-rose-400 font-medium"}`;
|
||||
el.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user