Beta businserivizio seta

This commit is contained in:
Leocraft1
2025-08-19 17:36:33 +02:00
parent 53b0e7b58f
commit f643f7ce41
9 changed files with 598 additions and 10 deletions

View File

@@ -0,0 +1,132 @@
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.textContent=nome;
//Set corsie per stazione o autostazione
const corsie_nav = document.getElementById('corsie-nav');
if(nome.includes("STAZIONE FS")){
corsie_nav.innerHTML = `
<ul>
<li>
<a href="/seta_menu/cercaorario/altrecorsie.html?location=STAZIONE FS">Altre corsie</a>
</li>
</ul>`;
}
if(nome.includes("MODENA AUTOSTAZIONE")){
corsie_nav.innerHTML = `
<ul>
<li>
<a href="/seta_menu/cercaorario/altrecorsie.html?location=MODENA AUTOSTAZIONE">Altre corsie</a>
</li>
</ul>`;
}
if(nome.includes("GARIBALDI")){
corsie_nav.innerHTML = `
<ul>
<li>
<a href="/seta_menu/cercaorario/altrecorsie.html?location=GARIBALDI">Altre corsie</a>
</li>
</ul>`;
}
const urlBackend = `https://setaapi.serverissimo.freeddns.org/arrivals/${codice}`;
//const urlBackend = `http://localhost:5001/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 (element.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 class="linea">Linea</th>
<th class="direzione">Direzione</th>
<th class="orario">Orario (Rit/Ant)</th>
<th class="stato">Stato corsa</th>
<th class="veicolo">Veicolo</th>
<th class="location">Ora si trova a</th>
</tr>
`;
table.appendChild(thead);
// Corpo tabella
const tbody = document.createElement('tbody');
element.services.forEach(item => {
const tr = document.createElement('tr');
if(element.type=="planned"){
var stato="Prevista";
}else{
var stato="In tempo reale";
}if(element.next_stop==null){
var posizione="";
}else{
var posizione=element.next_stop;
}
if(element.delay==undefined){
tr.innerHTML = `
<td>${element.service}</td>
<td>${element.destination}</td>
<td>${element.arrival}</td>
<td>${stato}</td>
<td><a href="https://wimb.setaweb.it/qm/index.html?id=${element.busnum}" class="bianco">${element.busnum}</a></td>
<td>${posizione}</td>
`;
tbody.appendChild(tr);
}else{
if(element.delay>0){
tr.innerHTML = `
<td>${element.service}</td>
<td>${element.destination}</td>
<td>${element.arrival} (+${element.delay})</td>
<td>${stato}</td>
<td><a href="https://wimb.setaweb.it/qm/index.html?id=${element.busnum}" class="bianco">${element.busnum}</a></td>
<td>${posizione}</td>
`;
tbody.appendChild(tr);
}else{
tr.innerHTML = `
<td>${element.service}</td>
<td>${element.destination}</td>
<td>${element.arrival} (${element.delay})</td>
<td>${stato}</td>
<td><a href="https://wimb.setaweb.it/qm/index.html?id=${element.busnum}" class="bianco">${element.busnum}</a></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);

View File

@@ -0,0 +1,106 @@
const lineaSelect = document.getElementById('linea');
const modelloSelect = document.getElementById('modello');
let allresults = [];
//Reperire modelli e numeri linea
const urlRoutes = 'https://setaapi.serverissimo.freeddns.org/routenumberslist';
//const urlRoutes = 'http://localhost:5001/stoplist';
const urlModels = 'https://setaapi.serverissimo.freeddns.org/busmodels';
//const urlModels = 'http://localhost:5001/stoplist';
//Fetch routes and models and fill the select options
fetch(urlRoutes)
.then(response => {
if (!response.ok) throw new Error("Errore nel caricamento dei dati.");
return response.json();
})
.then(data => {
allresults = data;
console.log(allresults);
allresults.forEach(route => {
const option = document.createElement('option');
option.value = route;
option.textContent = route;
lineaSelect.appendChild(option);
});
})
.catch(error => console.error('Errore nel caricamento dei dati:', error));
fetch(urlModels)
.then(response => {
if (!response.ok) throw new Error("Errore nel caricamento dei dati.");
return response.json();
})
.then(data => {
allresults = data;
allresults.forEach(route => {
const option = document.createElement('option');
option.value = route;
option.textContent = route;
modelloSelect.appendChild(option);
});
})
.catch(error => console.error('Errore nel caricamento dei dati:', error));
const urlList="https://setaapi.serverissimo.freeddns.org/busesinservice";
caricadati();
function caricadati(){
fetch(urlList)
.then(response => {
if (!response.ok) throw new Error("Errore nel caricamento dei dati.");
return response.json();
})
.then(data => {
item = data.features;
})
.then(data => {
const container = document.getElementById('tabella-container');
container.innerHTML = '';
// Creo tabella
const table = document.createElement('table');
// Intestazione
const thead = document.createElement('thead');
thead.innerHTML = `
<tr>
<th class="orario">Veicolo</th>
<th class="stato">Modello veicolo</th>
<th class="linea">Linea</th>
<th class="direzione">Direzione</th>
<th class="veicolo">Ora si trova a</th>
</tr>
`;
table.appendChild(thead);
// Corpo tabella
const tbody = document.createElement('tbody');
item.forEach(item => {
const element = item.properties;
const tr = document.createElement('tr');
if(element.next_stop==null){
var posizione="";
}else{
var posizione=element.next_stop;
}
tr.innerHTML = `
<td><a href="https://wimb.setaweb.it/qm/index.html?id=${element.vehicle_code}" class="bianco">${element.vehicle_code}</a></td>
<td>${element.model}</td>
<td>${element.linea}</td>
<td>${element.route_desc}</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.';
});
}