mirror of
https://github.com/Daniongithub/ER-TPL.git
synced 2025-10-02 22:30:48 +00:00
Beta cerca fermate seta + fix warning size
This commit is contained in:
52
seta_menu/cercaorario/js/cercafermata.js
Normal file
52
seta_menu/cercaorario/js/cercafermata.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const searchBar = document.getElementById('searchBar');
|
||||
const resultsContainer = document.getElementById('searchResults');
|
||||
|
||||
let allresults = [];
|
||||
window.onbeforeunload=searchBar.value="";
|
||||
|
||||
const url = 'http://setaapi.serverissimo.freeddns.org/stoplist';
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error("Errore nel caricamento dei dati.");
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
allresults = data;
|
||||
})
|
||||
.catch(error => console.error('Errore nel caricamento dei dati:', error));
|
||||
|
||||
searchBar.addEventListener('input', () => {
|
||||
const searchTerm = searchBar.value.toLowerCase();
|
||||
const filtered = allresults.filter(item =>
|
||||
item.fermata.toLowerCase().includes(searchTerm)
|
||||
);
|
||||
renderresults(filtered);
|
||||
});
|
||||
|
||||
function renderresults(results) {
|
||||
const searchResultsContainer = document.getElementById('searchResults');
|
||||
searchResultsContainer.innerHTML = '';
|
||||
|
||||
if (results.length === 0) {
|
||||
searchResultsContainer.innerHTML = '<p>Nessun risultato trovato</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
results.forEach(item => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'search-result';
|
||||
div.innerHTML = `
|
||||
<div>
|
||||
<h3>${item.fermata}</h3>
|
||||
<p>Codice fermata: ${item.valore}</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
div.addEventListener('click', () => {
|
||||
const url = `fermata.html?code=${encodeURIComponent(item.valore)}&name=${encodeURIComponent(item.fermata)}`;
|
||||
window.open(url, '_blank');
|
||||
});
|
||||
|
||||
searchResultsContainer.appendChild(div);
|
||||
});
|
||||
}
|
80
seta_menu/cercaorario/js/fermata.js
Normal file
80
seta_menu/cercaorario/js/fermata.js
Normal file
@@ -0,0 +1,80 @@
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const nome = params.get('name');
|
||||
const codice = params.get('code');
|
||||
|
||||
//Sets stop name
|
||||
const fermata_span = document.getElementById('fermata-span');
|
||||
fermata_span.innerHTML = `"${nome}"`;
|
||||
|
||||
const urlBackend = `http://setaapi.serverissimo.freeddns.org/arrivals/${codice}`;
|
||||
function caricadati(){
|
||||
fetch(urlBackend)
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error("Errore nel caricamento dei dati.");
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
item = data.arrival;
|
||||
})
|
||||
.then(data => {
|
||||
|
||||
const container = document.getElementById('tabella-container');
|
||||
container.innerHTML = '';
|
||||
|
||||
if (item.error=="no arrivals scheduled in next 90 minutes") {
|
||||
container.innerHTML = '<h3>Nessuna corsa programmata nei prossimi 90 minuti.</h3>';
|
||||
return;
|
||||
}
|
||||
// Creo tabella
|
||||
const table = document.createElement('table');
|
||||
|
||||
// Intestazione
|
||||
const thead = document.createElement('thead');
|
||||
thead.innerHTML = `
|
||||
<tr>
|
||||
<th>Linea</th>
|
||||
<th>Direzione</th>
|
||||
<th>Orario</th>
|
||||
<th>Stato corsa</th>
|
||||
<th>Veicolo</th>
|
||||
<th>Ora si trova a:</th>
|
||||
</tr>
|
||||
`;
|
||||
table.appendChild(thead);
|
||||
|
||||
// Corpo tabella
|
||||
const tbody = document.createElement('tbody');
|
||||
item.services.forEach(item => {
|
||||
const tr = document.createElement('tr');
|
||||
if(item.type=="planned"){
|
||||
var stato="Prevista";
|
||||
}else{
|
||||
var stato="In tempo reale";
|
||||
}if(item.next_stop==null){
|
||||
var posizione="";
|
||||
}else{
|
||||
var posizione=item.next_stop;
|
||||
}
|
||||
tr.innerHTML = `
|
||||
<td>${item.service}</td>
|
||||
<td>${item.destination}</td>
|
||||
<td>${item.arrival}</td>
|
||||
<td>${stato}</td>
|
||||
<td>${item.busnum}</td>
|
||||
<td>${posizione}</td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
table.appendChild(tbody);
|
||||
|
||||
container.appendChild(table);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Errore nel caricamento dati:', err);
|
||||
document.getElementById('tabella-container').textContent = 'Errore nel caricamento dati.';
|
||||
});
|
||||
}
|
||||
|
||||
caricadati();
|
||||
|
||||
setInterval(caricadati, 60000);
|
Reference in New Issue
Block a user