mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-29 20:05:51 +02:00
Add query link generation.
This commit is contained in:
parent
b93ebc1423
commit
4d7645efaf
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
|
@ -38,6 +38,13 @@
|
||||||
"url": "http://localhost:3001",
|
"url": "http://localhost:3001",
|
||||||
"webRoot": "${workspaceFolder}/site"
|
"webRoot": "${workspaceFolder}/site"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "pwa-chrome",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "client2",
|
||||||
|
"url": "http://localhost:3000",
|
||||||
|
"webRoot": "${workspaceFolder}/site"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "attach",
|
"request": "attach",
|
||||||
|
|
|
@ -18,6 +18,7 @@ function writeJSON(file, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sparToCanonical(rawItems, today) {
|
function sparToCanonical(rawItems, today) {
|
||||||
|
if (rawItems.hits) rawItems = rawItems.hits;
|
||||||
const canonicalItems = [];
|
const canonicalItems = [];
|
||||||
for (let i = 0; i < rawItems.length; i++) {
|
for (let i = 0; i < rawItems.length; i++) {
|
||||||
const item = rawItems[i];
|
const item = rawItems[i];
|
||||||
|
|
|
@ -3,9 +3,9 @@ const analysis = require("./analysis.js");
|
||||||
const dataDir = process?.argv?.[2] ?? "docker/data"
|
const dataDir = process?.argv?.[2] ?? "docker/data"
|
||||||
console.log("Restoring data from raw data.");
|
console.log("Restoring data from raw data.");
|
||||||
(async function () {
|
(async function () {
|
||||||
console.log("Items: " + JSON.parse(fs.readFileSync("docker/data/latest-canonical.json")).length);
|
/*console.log("Items: " + JSON.parse(fs.readFileSync("docker/data/latest-canonical.json")).length);
|
||||||
/*await analysis.updateData(dataDir);
|
await analysis.updateData(dataDir);
|
||||||
fs.copyFileSync(`${dataDir}/latest-canonical.json`, `${dataDir}/latest-canonical-old.json`);*/
|
fs.copyFileSync(`${dataDir}/latest-canonical.json`, `${dataDir}/latest-canonical-old.json`);*/
|
||||||
fs.writeFileSync(`${dataDir}/latest-canonical.json`, JSON.stringify(analysis.replay(dataDir), null, 2));
|
fs.writeFileSync(`${dataDir}/latest-canonical.json`, JSON.stringify(analysis.replay(dataDir), null, 2));
|
||||||
console.log("Items: " + JSON.parse(fs.readFileSync(`${dataDir}/latest-canonical.json`)).length);
|
console.log(`Wrote ${JSON.parse(fs.readFileSync(`${dataDir}/latest-canonical.json`)).length} to ${dataDir}/latest-canonical.json`);
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="column" style="max-width: 800px">
|
<div class="column" style="max-width: 1000px">
|
||||||
<div class="filters">
|
<div class="filters">
|
||||||
<a href="index.html"><strong>Produktsuche</strong></a>
|
<a href="index.html"><strong>Produktsuche</strong></a>
|
||||||
<a href="changes.html">Tagespreisänderungen</a>
|
<a href="changes.html">Tagespreisänderungen</a>
|
||||||
|
|
|
@ -39,6 +39,15 @@ async function load() {
|
||||||
|
|
||||||
return itemDom;
|
return itemDom;
|
||||||
});
|
});
|
||||||
|
const query = getQueryParameter("q");
|
||||||
|
if (query) {
|
||||||
|
document.querySelector("input").value = query;
|
||||||
|
const inputEvent = new Event('input', {
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
document.querySelector("input").dispatchEvent(inputEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
|
|
@ -43,6 +43,7 @@ async function loadItems() {
|
||||||
|
|
||||||
item.numPrices = item.priceHistory.length;
|
item.numPrices = item.priceHistory.length;
|
||||||
item.priceOldest = item.priceHistory[item.priceHistory.length - 1].price;
|
item.priceOldest = item.priceHistory[item.priceHistory.length - 1].price;
|
||||||
|
item.dateOldest = item.priceHistory[item.priceHistory.length - 1].date;
|
||||||
item.date = item.priceHistory[0].date;
|
item.date = item.priceHistory[0].date;
|
||||||
let lastPrice = item.price;
|
let lastPrice = item.price;
|
||||||
for (let i = 1; i < 10; i++) {
|
for (let i = 1; i < 10; i++) {
|
||||||
|
@ -231,6 +232,7 @@ function newSearchComponent(parentElement, items, searched, filter, headerModifi
|
||||||
parentElement.innerHTML = "";
|
parentElement.innerHTML = "";
|
||||||
parentElement.innerHTML = `
|
parentElement.innerHTML = `
|
||||||
<input id="search-${id}" class="search" type="text" placeholder="Produkte suchen...">
|
<input id="search-${id}" class="search" type="text" placeholder="Produkte suchen...">
|
||||||
|
<a id="querylink-${id}" class="hide">Query link</a>
|
||||||
<div class="filters">
|
<div class="filters">
|
||||||
<label><input id="billa-${id}" type="checkbox" checked="true"> Billa</label>
|
<label><input id="billa-${id}" type="checkbox" checked="true"> Billa</label>
|
||||||
<label><input id="spar-${id}" type="checkbox" checked="true"> Spar</label>
|
<label><input id="spar-${id}" type="checkbox" checked="true"> Spar</label>
|
||||||
|
@ -253,6 +255,7 @@ function newSearchComponent(parentElement, items, searched, filter, headerModifi
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const searchInput = parentElement.querySelector(`#search-${id}`);
|
const searchInput = parentElement.querySelector(`#search-${id}`);
|
||||||
|
const queryLink = parentElement.querySelector(`#querylink-${id}`);
|
||||||
const exact = parentElement.querySelector(`#exact-${id}`);
|
const exact = parentElement.querySelector(`#exact-${id}`);
|
||||||
const table = parentElement.querySelector(`#result-${id}`);
|
const table = parentElement.querySelector(`#result-${id}`);
|
||||||
const eigenmarken = parentElement.querySelector(`#eigenmarken-${id}`);
|
const eigenmarken = parentElement.querySelector(`#eigenmarken-${id}`);
|
||||||
|
@ -308,8 +311,11 @@ function newSearchComponent(parentElement, items, searched, filter, headerModifi
|
||||||
}
|
}
|
||||||
if (query.length > 0 && query.charAt(0) == "!") {
|
if (query.length > 0 && query.charAt(0) == "!") {
|
||||||
parentElement.querySelectorAll(".filters").forEach(f => f.style.display = "none");
|
parentElement.querySelectorAll(".filters").forEach(f => f.style.display = "none");
|
||||||
|
queryLink.classList.remove("hide");
|
||||||
|
queryLink.setAttribute("href", "/?q=" + encodeURIComponent(query));
|
||||||
} else {
|
} else {
|
||||||
parentElement.querySelectorAll(".filters").forEach(f => f.style.display = "block");
|
parentElement.querySelectorAll(".filters").forEach(f => f.style.display = "block");
|
||||||
|
queryLink.classList.add("hide");
|
||||||
}
|
}
|
||||||
search(searchInput.value);
|
search(searchInput.value);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user