ilerleme çubukları düzeltildi.
This commit is contained in:
+13
-31
@@ -68,7 +68,7 @@ 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 DURUMU
|
||||
<span>📊</span> KAZA BORCU TAMAMLAMA TAMAMLANMA ORANI
|
||||
</span>
|
||||
<span id="overallPercentage" class="text-sm font-extrabold text-emerald-400">%0 Kılındı</span>
|
||||
</div>
|
||||
@@ -155,13 +155,12 @@ export function renderKaza(pb) {
|
||||
} else {
|
||||
refreshKazaStats(container, pb);
|
||||
|
||||
// Hesapla ve PB'ye Ilk Borc Olarak Kaydet
|
||||
container
|
||||
.querySelector("#calcAndSaveBtn")
|
||||
?.addEventListener("click", async () => {
|
||||
if (
|
||||
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);
|
||||
@@ -169,7 +168,7 @@ export function renderKaza(pb) {
|
||||
await refreshKazaStats(container, pb);
|
||||
showKazaMsg(
|
||||
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,
|
||||
);
|
||||
} else {
|
||||
@@ -182,14 +181,12 @@ export function renderKaza(pb) {
|
||||
}
|
||||
});
|
||||
|
||||
// Kildim (Borctan Dus / Eksi Deger)
|
||||
container
|
||||
.querySelector("#subtractKazaBtn")
|
||||
?.addEventListener("click", async () => {
|
||||
await updateKazaDebt(container, pb, -1);
|
||||
});
|
||||
|
||||
// Yanlislikla dusulduyse borca geri ekle (Artir / Artı Deger)
|
||||
container
|
||||
.querySelector("#addKazaBtn")
|
||||
?.addEventListener("click", async () => {
|
||||
@@ -200,7 +197,6 @@ export function renderKaza(pb) {
|
||||
};
|
||||
}
|
||||
|
||||
// PB tarafina ilk borclari kaydetme (target_* alanlarina da ilk borcu yedekliyoruz)
|
||||
async function initAndSaveInitialKaza(pb, birthDate, gender) {
|
||||
try {
|
||||
const calc = calculateMissedPrayers(birthDate, gender, 12);
|
||||
@@ -208,8 +204,7 @@ async function initAndSaveInitialKaza(pb, birthDate, gender) {
|
||||
if (!calc || calc.days <= 0) {
|
||||
return {
|
||||
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."
|
||||
};
|
||||
}
|
||||
|
||||
@@ -222,7 +217,6 @@ async function initAndSaveInitialKaza(pb, birthDate, gender) {
|
||||
.getFirstListItem(`user = "${userId}"`);
|
||||
} catch (e) {}
|
||||
|
||||
// Kaza borclarini sakliyoruz (fajr, dhuhr... doğrudan Kalan Borçtur)
|
||||
const initialData = {
|
||||
user: userId,
|
||||
fajr: calc.fajr,
|
||||
@@ -231,7 +225,6 @@ async function initAndSaveInitialKaza(pb, birthDate, gender) {
|
||||
maghrib: calc.maghrib,
|
||||
isha: calc.isha,
|
||||
vitr: calc.vitr,
|
||||
// Ilk borcu orantı hesabi icin sakliyoruz
|
||||
target_fajr: calc.fajr,
|
||||
target_dhuhr: calc.dhuhr,
|
||||
target_asr: calc.asr,
|
||||
@@ -251,20 +244,16 @@ async function initAndSaveInitialKaza(pb, birthDate, gender) {
|
||||
console.error("PocketBase Kayıt Hatası:", err);
|
||||
return {
|
||||
success: false,
|
||||
error:
|
||||
err?.message ||
|
||||
"PocketBase'e kaydedilemedi. Collection alan izinlerini kontrol edin.",
|
||||
error: err?.message || "PocketBase'e kaydedilemedi."
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Kildikca Borctan Dusme Fonksiyonu (-1 ile çarparak eksiltir)
|
||||
async function updateKazaDebt(container, pb, direction) {
|
||||
const prayerId = container.querySelector("#kazaPrayerType").value;
|
||||
const countInput = container.querySelector("#kazaCount");
|
||||
const countValue = Math.max(1, parseInt(countInput?.value || "1", 10));
|
||||
|
||||
// direction -1 ise borctan duser, +1 ise borca ekler
|
||||
const changeAmount = countValue * direction;
|
||||
const msg = container.querySelector("#kazaMsg");
|
||||
|
||||
@@ -275,19 +264,13 @@ 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;
|
||||
}
|
||||
|
||||
const currentDebt = userRecord[prayerId] || 0;
|
||||
// Yeni kalan borcu hesapla (0'ın altına düşmesin)
|
||||
const newDebt = Math.max(0, currentDebt + changeAmount);
|
||||
|
||||
// PocketBase'e Guncel Borcu Kaydet (PATCH / UPDATE)
|
||||
await pb.collection("kaza_logs").update(userRecord.id, {
|
||||
[prayerId]: newDebt,
|
||||
});
|
||||
@@ -308,7 +291,6 @@ async function updateKazaDebt(container, pb, direction) {
|
||||
}
|
||||
}
|
||||
|
||||
// PB Verilerini ekrana yansıtma
|
||||
async function refreshKazaStats(container, pb) {
|
||||
const userId = pb.authStore.model.id;
|
||||
let userRecord = null;
|
||||
@@ -333,8 +315,9 @@ async function refreshKazaStats(container, pb) {
|
||||
let grandCurrentDebtTotal = 0;
|
||||
|
||||
PRAYERS.forEach((p) => {
|
||||
const initialDebt = userRecord[`target_${p.id}`] || userRecord[p.id] || 0;
|
||||
const currentDebt = userRecord[p.id] || 0;
|
||||
// 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;
|
||||
|
||||
grandInitialTotal += initialDebt;
|
||||
grandCurrentDebtTotal += currentDebt;
|
||||
@@ -346,20 +329,19 @@ 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ç)
|
||||
if (progressEl) {
|
||||
const completed = Math.max(0, initialDebt - currentDebt);
|
||||
const pct =
|
||||
initialDebt > 0
|
||||
? Math.min(100, Math.round((completed / initialDebt) * 100))
|
||||
: 100;
|
||||
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.round((totalCompleted / grandInitialTotal) * 100))
|
||||
? Math.min(100, Math.max(0, Math.round((totalCompleted / grandInitialTotal) * 100)))
|
||||
: 0;
|
||||
|
||||
const bar = container.querySelector("#overallProgressBar");
|
||||
|
||||
Reference in New Issue
Block a user