2023-06-01 17:40:11 +02:00
|
|
|
function updateCharts(canvasDom, items) {
|
2023-06-02 16:45:54 +02:00
|
|
|
const now = performance.now();
|
2023-06-01 17:40:11 +02:00
|
|
|
const sum = document.querySelector("#sum").checked;
|
|
|
|
const sumStores = document.querySelector("#sumstores").checked;
|
|
|
|
const todayOnly = document.querySelector("#todayonly").checked;
|
|
|
|
let startDate = document.querySelector("#start").value;
|
|
|
|
let endDate = document.querySelector("#end").value;
|
|
|
|
if (start > endDate) {
|
|
|
|
let tmp = start;
|
|
|
|
start = endDate;
|
|
|
|
endDate = tmp;
|
|
|
|
}
|
|
|
|
showCharts(canvasDom, items, sum, sumStores, todayOnly, startDate, endDate);
|
|
|
|
console.log("Updating charts took: " + (performance.now() - now) / 1000 + " seconds");
|
|
|
|
}
|
2023-05-15 13:53:34 +02:00
|
|
|
async function load() {
|
2023-05-23 11:21:48 +02:00
|
|
|
const items = await loadItems();
|
2023-05-23 20:07:26 +02:00
|
|
|
const chartDom = document.querySelector("#chart");
|
2023-06-01 17:40:11 +02:00
|
|
|
const canvasDom = chartDom.querySelector("canvas");
|
|
|
|
let lastHits = null;
|
|
|
|
document.querySelector("#sum").addEventListener("change", () => updateCharts(canvasDom, lastHits));
|
|
|
|
document.querySelector("#sumstores").addEventListener("change", () => updateCharts(canvasDom, lastHits));
|
|
|
|
document.querySelector("#todayonly").addEventListener("change", () => updateCharts(canvasDom, lastHits));
|
|
|
|
document.querySelector("#start").addEventListener("change", () => updateCharts(canvasDom, lastHits));
|
|
|
|
document.querySelector("#end").addEventListener("change", () => updateCharts(canvasDom, lastHits));
|
|
|
|
document.querySelector("#start").value = getOldestDate(items);
|
|
|
|
document.querySelector("#end").value = currentDate();
|
|
|
|
|
2023-06-02 16:45:54 +02:00
|
|
|
newSearchComponent(
|
|
|
|
document.querySelector("#search"),
|
|
|
|
items,
|
2023-05-23 20:07:26 +02:00
|
|
|
(hits) => {
|
2023-06-02 16:45:54 +02:00
|
|
|
items.forEach((item) => (item.chart = false));
|
2023-06-01 17:40:11 +02:00
|
|
|
if (hits.length > 0) {
|
|
|
|
chartDom.classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
chartDom.classList.add("hide");
|
|
|
|
}
|
|
|
|
updateCharts(canvasDom, hits);
|
|
|
|
lastHits = hits;
|
2023-05-23 20:07:26 +02:00
|
|
|
return hits;
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
(header) => {
|
2023-06-02 16:45:54 +02:00
|
|
|
header = dom("tr", `<th>Kette</th><th>Name</th><th>Menge</th><th>Preis 📈</th><th></th>`);
|
|
|
|
const showHideAll = header.querySelectorAll("th:nth-child(4)")[0];
|
2023-05-25 16:09:34 +02:00
|
|
|
showHideAll.style["cursor"] = "pointer";
|
|
|
|
showHideAll.showAll = true;
|
|
|
|
showHideAll.addEventListener("click", () => {
|
2023-06-02 16:45:54 +02:00
|
|
|
document
|
|
|
|
.querySelectorAll(".priceinfo")
|
|
|
|
.forEach((el) => (showHideAll.showAll ? el.classList.remove("hide") : el.classList.add("hide")));
|
2023-05-25 16:09:34 +02:00
|
|
|
showHideAll.showAll = !showHideAll.showAll;
|
2023-06-02 16:45:54 +02:00
|
|
|
});
|
2023-05-23 20:07:26 +02:00
|
|
|
return header;
|
2023-06-02 16:45:54 +02:00
|
|
|
},
|
|
|
|
(item, itemDom, items, setQuery) => {
|
|
|
|
const checked = (item.chart = (getQueryParameter("c") ?? []).includes(`${item.store}:${item.id}`));
|
2023-06-01 17:40:11 +02:00
|
|
|
const dataId = item.store + ":" + item.id;
|
|
|
|
const cell = dom("td", `<input type="checkbox" ${checked ? "checked" : ""} data-id="${dataId}">`);
|
2023-05-23 20:07:26 +02:00
|
|
|
itemDom.appendChild(cell);
|
2023-06-02 16:45:54 +02:00
|
|
|
const handleClick = (eventShouldSetQuery = false) => {
|
2023-06-01 17:40:11 +02:00
|
|
|
item.chart = cell.children[0].checked;
|
2023-06-02 16:45:54 +02:00
|
|
|
updateCharts(canvasDom, lastHits);
|
2023-05-30 11:52:35 +02:00
|
|
|
!!eventShouldSetQuery && setQuery();
|
2023-06-02 16:45:54 +02:00
|
|
|
};
|
2023-06-01 17:40:11 +02:00
|
|
|
cell.children[0].addEventListener("click", handleClick);
|
2023-05-30 11:52:35 +02:00
|
|
|
checked && handleClick();
|
2023-05-23 20:07:26 +02:00
|
|
|
return itemDom;
|
2023-06-02 16:45:54 +02:00
|
|
|
}
|
|
|
|
);
|
2023-05-26 11:28:40 +02:00
|
|
|
const query = getQueryParameter("q");
|
|
|
|
if (query) {
|
2023-06-01 19:10:14 +02:00
|
|
|
document.querySelector(".search").value = query;
|
2023-06-02 16:45:54 +02:00
|
|
|
const inputEvent = new Event("input", {
|
2023-05-26 11:28:40 +02:00
|
|
|
bubbles: true,
|
2023-06-02 16:45:54 +02:00
|
|
|
cancelable: false,
|
2023-05-26 11:28:40 +02:00
|
|
|
});
|
2023-06-01 19:10:14 +02:00
|
|
|
document.querySelector(".search").dispatchEvent(inputEvent);
|
2023-05-26 11:28:40 +02:00
|
|
|
}
|
2023-05-15 13:53:34 +02:00
|
|
|
}
|
|
|
|
|
2023-05-18 13:39:58 +02:00
|
|
|
load();
|