History in widget
This commit is contained in:
parent
3a2b78fcce
commit
84fe2d5946
1 changed files with 56 additions and 6 deletions
|
@ -47,6 +47,13 @@
|
||||||
return `${year}-${month}-${day}`;
|
return `${year}-${month}-${day}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHistoryDays() {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const history = parseInt(urlParams.get('history')) || 14;
|
||||||
|
// Limit history to maximum 365 days
|
||||||
|
return Math.min(Math.max(1, history), 365);
|
||||||
|
}
|
||||||
|
|
||||||
function getHourFromTimeString(timeStr) {
|
function getHourFromTimeString(timeStr) {
|
||||||
return parseInt(timeStr.split(':')[0]);
|
return parseInt(timeStr.split(':')[0]);
|
||||||
}
|
}
|
||||||
|
@ -74,6 +81,7 @@
|
||||||
const tomorrow = new Date(today);
|
const tomorrow = new Date(today);
|
||||||
tomorrow.setDate(today.getDate() + 1);
|
tomorrow.setDate(today.getDate() + 1);
|
||||||
const tomorrowString = formatDate(tomorrow);
|
const tomorrowString = formatDate(tomorrow);
|
||||||
|
const historyDays = getHistoryDays();
|
||||||
|
|
||||||
// Check if tomorrow's data is available
|
// Check if tomorrow's data is available
|
||||||
let tomorrowAvailable = false;
|
let tomorrowAvailable = false;
|
||||||
|
@ -85,18 +93,36 @@
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
let rowCount = tomorrowAvailable ? 15 : 14;
|
// Calculate total rows: history days + today + tomorrow (if available)
|
||||||
|
let rowCount = historyDays + 1; // history days + today
|
||||||
|
if (tomorrowAvailable) {
|
||||||
|
rowCount += 1; // + tomorrow
|
||||||
|
}
|
||||||
|
|
||||||
for (let offset = 0; offset < rowCount; offset++) {
|
for (let offset = 0; offset < rowCount; offset++) {
|
||||||
let date;
|
let date;
|
||||||
let label;
|
let label;
|
||||||
if (tomorrowAvailable && offset === 0) {
|
if (tomorrowAvailable && offset === 0) {
|
||||||
|
// Tomorrow is first row if available
|
||||||
date = tomorrow;
|
date = tomorrow;
|
||||||
label = `Zítra (${tomorrowString})`;
|
label = `Zítra (${tomorrowString})`;
|
||||||
|
} else if (tomorrowAvailable && offset === 1) {
|
||||||
|
// Today is second row if tomorrow is available
|
||||||
|
date = today;
|
||||||
|
const todayString = formatDate(today);
|
||||||
|
label = `Dnes (${todayString})`;
|
||||||
|
} else if (!tomorrowAvailable && offset === 0) {
|
||||||
|
// Today is first row if tomorrow is not available
|
||||||
|
date = today;
|
||||||
|
const todayString = formatDate(today);
|
||||||
|
label = `Dnes (${todayString})`;
|
||||||
} else {
|
} else {
|
||||||
|
// Historical days
|
||||||
date = new Date(today);
|
date = new Date(today);
|
||||||
date.setDate(today.getDate() - (tomorrowAvailable ? offset - 1 : offset));
|
const daysBack = tomorrowAvailable ? offset - 1 : offset;
|
||||||
|
date.setDate(today.getDate() - daysBack);
|
||||||
const dateString = formatDate(date);
|
const dateString = formatDate(date);
|
||||||
label = offset === (tomorrowAvailable ? 1 : 0) ? `Dnes (${dateString})` : dateString;
|
label = dateString;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateString = formatDate(date);
|
const dateString = formatDate(date);
|
||||||
|
@ -287,18 +313,42 @@
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
let rowCount = tomorrowAvailable ? 15 : 14;
|
const historyDays = getHistoryDays();
|
||||||
|
|
||||||
|
// Calculate total rows: history days + today + tomorrow (if available)
|
||||||
|
let rowCount = historyDays + 1; // history days + today
|
||||||
|
if (tomorrowAvailable) {
|
||||||
|
rowCount += 1; // + tomorrow
|
||||||
|
}
|
||||||
|
|
||||||
for (let offset = 0; offset < rowCount; offset++) {
|
for (let offset = 0; offset < rowCount; offset++) {
|
||||||
let date;
|
let date;
|
||||||
|
let isToday = false;
|
||||||
|
|
||||||
if (tomorrowAvailable && offset === 0) {
|
if (tomorrowAvailable && offset === 0) {
|
||||||
|
// Tomorrow is first row if available
|
||||||
date = tomorrow;
|
date = tomorrow;
|
||||||
|
} else if (tomorrowAvailable && offset === 1) {
|
||||||
|
// Today is second row if tomorrow is available
|
||||||
|
date = today;
|
||||||
|
isToday = true;
|
||||||
|
} else if (!tomorrowAvailable && offset === 0) {
|
||||||
|
// Today is first row if tomorrow is not available
|
||||||
|
date = today;
|
||||||
|
isToday = true;
|
||||||
} else {
|
} else {
|
||||||
|
// Historical days
|
||||||
date = new Date(today);
|
date = new Date(today);
|
||||||
date.setDate(today.getDate() - (tomorrowAvailable ? offset - 1 : offset));
|
const daysBack = tomorrowAvailable ? offset - 1 : offset;
|
||||||
|
date.setDate(today.getDate() - daysBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateString = formatDate(date);
|
const dateString = formatDate(date);
|
||||||
loadData(dateString, (tomorrowAvailable ? offset === 1 : offset === 0));
|
loadData(dateString, isToday);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the chart after loading table data
|
||||||
|
await updateChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
|
|
Loading…
Reference in a new issue