2023-06-11 23:49:18 +02:00
|
|
|
const { getQueryParameter } = require("./misc");
|
|
|
|
const model = require("./model");
|
|
|
|
require("./views");
|
2023-06-06 23:56:57 +02:00
|
|
|
|
2023-06-11 23:49:18 +02:00
|
|
|
(async () => {
|
|
|
|
await model.load();
|
|
|
|
const itemsFilter = document.querySelector("items-filter");
|
|
|
|
const itemsList = document.querySelector("items-list");
|
|
|
|
const itemsChart = document.querySelector("items-chart");
|
|
|
|
itemsFilter.model = itemsList.model = model.items;
|
2023-06-06 23:56:57 +02:00
|
|
|
|
2023-06-11 23:49:18 +02:00
|
|
|
const stateToUrl = (event) => {
|
|
|
|
const filterState = JSON.stringify(itemsFilter.state);
|
|
|
|
const listState = JSON.stringify(itemsList.state);
|
|
|
|
const chartState = JSON.stringify(itemsChart.state);
|
2023-06-12 00:32:48 +02:00
|
|
|
const chartedItems = model.items.filteredItems
|
|
|
|
.filter((item) => item.chart)
|
|
|
|
.map((item) => item.store + item.id)
|
|
|
|
.join(";");
|
|
|
|
history.pushState({}, null, location.pathname + "?f=" + filterState + "&l=" + listState + "&c=" + chartState + "&d=" + chartedItems);
|
2023-06-11 23:49:18 +02:00
|
|
|
};
|
2023-06-06 23:56:57 +02:00
|
|
|
|
2023-06-11 23:49:18 +02:00
|
|
|
itemsFilter.addEventListener("x-change", stateToUrl);
|
|
|
|
itemsList.addEventListener("x-change", stateToUrl);
|
2023-06-01 17:40:11 +02:00
|
|
|
|
2023-06-11 23:49:18 +02:00
|
|
|
const f = getQueryParameter("f");
|
|
|
|
const l = getQueryParameter("l");
|
|
|
|
const c = getQueryParameter("c");
|
2023-06-12 00:32:48 +02:00
|
|
|
const d = getQueryParameter("d");
|
2023-06-11 23:49:18 +02:00
|
|
|
if (f) itemsFilter.state = JSON.parse(f);
|
|
|
|
if (l) itemsList.state = JSON.parse(l);
|
|
|
|
if (c) itemsChart.state = JSON.parse(c);
|
2023-06-12 00:32:48 +02:00
|
|
|
if (d) {
|
|
|
|
for (const id of d.split(";")) {
|
|
|
|
model.items.lookup[id].chart = true;
|
|
|
|
}
|
2023-06-12 00:54:11 +02:00
|
|
|
itemsFilter.fireChangeEvent();
|
2023-06-12 00:32:48 +02:00
|
|
|
}
|
2023-06-11 23:49:18 +02:00
|
|
|
itemsFilter.filter();
|
|
|
|
})();
|