Sync files from main repo, new version.

This commit is contained in:
2025-09-09 17:51:42 +02:00
parent e22154f9ea
commit a1d81718e1
6 changed files with 212 additions and 36 deletions

View File

@@ -13,19 +13,24 @@ function populateSearchResults(results, selectedOption) {
div.innerHTML = `
<div>
<h3>${item.nome}</h3>
<p>Palina: ${item.palina}, Target ID: ${item.targetID}</p>
<p>Fermata: ${item.palina}, Target ID: ${item.targetID}</p>
</div>
`;
div.addEventListener('click', () => {
const url = `fermata.html?palina=${encodeURIComponent(item.palina)}&targetID=${encodeURIComponent(item.targetID)}&selectedOption=${encodeURIComponent(selectedOption)}`;
window.location.href = url;
window.open(url, "_blank");
});
searchResultsContainer.appendChild(div);
});
}
function getFermatadaBreve(codice){
const middle = String(codice).padStart(4, "0");
return `7${middle}0`;
}
function filterOptions(query, data) {
const q = query.toLowerCase();
return data.filter(item =>
@@ -35,6 +40,31 @@ function filterOptions(query, data) {
);
}
function filtraTesto(query, data){
const q = query.toLowerCase();
return data
.filter(item => (item.nome || '').toLowerCase().includes(q))
.sort((a, b) => (a.nome || '').localeCompare(b.nome || ''));
}
function filtraLungo(query, data){
const q = query.toLowerCase();
return data
.filter(item => (item.palina || '').toLowerCase().includes(q))
.sort((a, b) => (a.palina || '').localeCompare(b.palina || ''));
}
function filtraBreve(query, data){
const cod = getFermatadaBreve(query);
return filtraLungo(cod, data);
}
function filtraTID(query, data){
const q = query.toLowerCase();
return data
.filter(item => (item.targetID || '').toLowerCase().includes(q))
.sort((a, b) => (a.targetID || '').localeCompare(b.targetID || ''));
}
let allOptions = [];
let currentSelectedOption = '';
@@ -46,20 +76,67 @@ searchBar.addEventListener('input', function() {
populateSearchResults(filteredOptions, currentSelectedOption);
});
searchBar.addEventListener('input', function() {
const query = searchBar.value;
let filteredOptions;
if (currentSelectedOption !== "ra") {
filteredOptions = filterOptions(query, allOptions);
} else {
if (document.getElementById('text').checked){
filteredOptions = filtraTesto(query, allOptions);
}
else if (document.getElementById('lungo').checked){
filteredOptions = filtraLungo(query, allOptions);
}
else if (document.getElementById('breve').checked){
filteredOptions = filtraBreve(query, allOptions);
}
else if(document.getElementById('tid').checked){
filteredOptions = filtraTID(query, allOptions);
}
}
populateSearchResults(filteredOptions, currentSelectedOption);
});
const radios = document.querySelectorAll('#radios input[type="radio"]');
radios.forEach(radio => {
radio.addEventListener('change', () => {
searchBar.value = '';
document.getElementById('searchResults').innerHTML = '';
});
});
document.getElementById('bacino').addEventListener('change', function(event) {
const selectedOption = event.target.value;
currentSelectedOption = selectedOption;
if (!selectedOption) {
const urlFermate = `https://api.vichingo455.freeddns.org/fermateapi/bacino?selectedOption=${selectedOption}`;
const radiobuttons = document.getElementById('radios');
const ricerca = document.getElementById('ricerca');
ricerca.removeAttribute('style');
document.getElementById('searchBar').value = "";
if(selectedOption == "n"){
ricerca.setAttribute("style", "display: none;");
radiobuttons.setAttribute("style", "display: none;");
allOptions = [];
document.getElementById('searchResults').innerHTML = '';
return;
}
else if(selectedOption == "ra"){
radiobuttons.removeAttribute('style')
}
const resultsContainer = document.getElementById('searchResults');
resultsContainer.innerHTML = '<p>Caricamento lista fermate in corso...</p>';
fetch(`http://localhost:3005/bacino?selectedOption=${selectedOption}`)
if(selectedOption != "n"){
const resultsContainer = document.getElementById('searchResults');
resultsContainer.innerHTML = '<p>Caricamento lista fermate in corso...</p>';
if(selectedOption != "ra"){
radiobuttons.setAttribute("style", "display: none;");
}
fetch(urlFermate)
.then(res => res.json())
.then(data => {
allOptions = data;
@@ -69,4 +146,5 @@ document.getElementById('bacino').addEventListener('change', function(event) {
resultsContainer.innerHTML = '<p>Errore nel caricamento delle fermate.</p>';
console.error('Errore:', err);
});
}
});

View File

@@ -3,8 +3,7 @@ const palina = params.get('palina');
const targetID = params.get('targetID');
const selectedOption = params.get('selectedOption');
//const urlBackend = `https://api.vichingo455.freeddns.org/start-fermatebus.json/w?param=${targetID}&param2=${selectedOption}&palina=${palina}`;
const urlBackend = `http://localhost:3005/fermata?param=${targetID}&param2=${selectedOption}&palina=${palina}`;
const urlBackend = `https://api.vichingo455.freeddns.org/fermateapi/fermata?param=${targetID}&param2=${selectedOption}&palina=${palina}`;
function caricadati(){
fetch(urlBackend)
.then(res => res.json())
@@ -12,10 +11,15 @@ function caricadati(){
const fermata_span = document.getElementById('fermata-span');
if (data[0] && data[0].fermata !== undefined) {
fermata_span.innerHTML = `"${data[0].fermata}"`;
document.title = `Fermata ${data[0].fermata}`
}
const container = document.getElementById('tabella-container');
container.innerHTML = '';
fetch('https://api.vichingo455.freeddns.org/fermateapi/versione')
.then(res => res.text())
.then(versione => document.getElementById("ver").innerHTML = versione);
if (!data || data.length === 0) {
container.innerHTML = '<h3>Nessuna linea in arrivo.</h3>';
return;
@@ -33,7 +37,6 @@ function caricadati(){
<th>Orario</th>
<th>Stato attuale</th>
<th>Veicolo</th>
<th>Soppressa</th>
</tr>
`;
table.appendChild(thead);
@@ -51,7 +54,6 @@ function caricadati(){
<td>${item.orario}</td>
<td>${item.stato}</td>
<td>${item.mezzo}</td>
<td>${item.soppressa ? 'Sì' : 'No'}</td>
`;
tbody.appendChild(tr);
});
@@ -67,4 +69,5 @@ function caricadati(){
caricadati();
setInterval(caricadati, 60000);
setInterval(caricadati, 60000);