podzial dzienny
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
let expensesChart = null;
|
||||
let categorySplit = true;
|
||||
|
||||
const rangeLabel = document.getElementById("chartRangeLabel");
|
||||
|
||||
if (typeof window.selectedCategoryId === "undefined") {
|
||||
@@ -11,6 +13,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
let url = '/expenses_data?range=' + range;
|
||||
|
||||
const showAllCheckbox = document.getElementById("showAllLists");
|
||||
|
||||
if (showAllCheckbox) {
|
||||
url += showAllCheckbox.checked ? '&show_all=true' : '&show_all=false';
|
||||
} else {
|
||||
@@ -20,9 +23,11 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
if (startDate && endDate) {
|
||||
url += `&start_date=${startDate}&end_date=${endDate}`;
|
||||
}
|
||||
|
||||
if (window.selectedCategoryId) {
|
||||
url += `&category_id=${window.selectedCategoryId}`;
|
||||
}
|
||||
|
||||
if (categorySplit) {
|
||||
url += '&by_category=true';
|
||||
}
|
||||
@@ -106,11 +111,13 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
window.loadExpenses = loadExpenses;
|
||||
|
||||
const toggleBtn = document.getElementById("toggleCategorySplit");
|
||||
|
||||
toggleBtn.addEventListener("click", function () {
|
||||
categorySplit = !categorySplit;
|
||||
|
||||
// Znajdź aktualnie aktywny przycisk podziału czasu
|
||||
let activeRange = 'currentmonth'; // domyślna wartość
|
||||
|
||||
if (document.getElementById('toggleDailySplit').classList.contains('btn-primary')) {
|
||||
activeRange = 'daily';
|
||||
} else if (document.getElementById('toggleMonthlySplit').classList.contains('btn-primary')) {
|
||||
@@ -126,10 +133,21 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
this.classList.remove("btn-outline-info");
|
||||
this.classList.add("btn-outline-warning");
|
||||
}
|
||||
loadExpenses(activeRange);
|
||||
|
||||
// Pobierz wybrane daty
|
||||
const startDateInput = document.getElementById("startDate");
|
||||
const endDateInput = document.getElementById("endDate");
|
||||
const startDate = startDateInput ? startDateInput.value : null;
|
||||
const endDate = endDateInput ? endDateInput.value : null;
|
||||
|
||||
// Wywołaj loadExpenses z przekazaniem zakresu dat, jeśli jest ustawiony
|
||||
if (startDate && endDate) {
|
||||
loadExpenses(activeRange, startDate, endDate);
|
||||
} else {
|
||||
loadExpenses(activeRange);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
toggleBtn.textContent = "🔵 Pokaż całościowo";
|
||||
toggleBtn.classList.remove("btn-outline-warning");
|
||||
toggleBtn.classList.add("btn-outline-info");
|
||||
@@ -141,6 +159,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
const lastWeek = new Date(today);
|
||||
lastWeek.setDate(today.getDate() - 7);
|
||||
const formatDate = (d) => d.toISOString().split('T')[0];
|
||||
|
||||
startDateInput.value = formatDate(lastWeek);
|
||||
endDateInput.value = formatDate(today);
|
||||
|
||||
@@ -160,11 +179,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
document.querySelectorAll('.range-btn').forEach(b => b.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
const range = this.getAttribute('data-range');
|
||||
|
||||
if (range === "currentmonth") {
|
||||
const today = new Date();
|
||||
const firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
|
||||
const formatDate = (d) => d.toISOString().split('T')[0];
|
||||
loadExpenses('custom', formatDate(firstDay), formatDate(today));
|
||||
} else {
|
||||
loadExpenses(range);
|
||||
@@ -176,7 +193,14 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
document.getElementById('chart-tab').addEventListener('shown.bs.tab', function () {
|
||||
// Sprawdź jaki tryb jest aktywny (domyślnie dzienny lub miesięczny)
|
||||
if (document.getElementById('toggleDailySplit').classList.contains('btn-primary')) {
|
||||
loadExpenses('daily');
|
||||
const startDate = startDateInput.value || null;
|
||||
const endDate = endDateInput.value || null;
|
||||
|
||||
if (startDate && endDate) {
|
||||
loadExpenses('daily', startDate, endDate);
|
||||
} else {
|
||||
loadExpenses('daily');
|
||||
}
|
||||
} else if (document.getElementById('toggleMonthlySplit').classList.contains('btn-primary')) {
|
||||
loadExpenses('monthly');
|
||||
} else {
|
||||
@@ -184,10 +208,8 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Jeśli jesteśmy od razu na zakładce Wykres
|
||||
//if (document.getElementById('chart-tab').classList.contains('active')) {
|
||||
// loadExpenses("currentmonth");
|
||||
// }
|
||||
|
||||
//if (document.getElementById('chart-tab').classList.contains('active')) {
|
||||
// loadExpenses("currentmonth");
|
||||
//}
|
||||
});
|
||||
|
Reference in New Issue
Block a user