From e78bc0bddab4f65a254bc4c14c55c704e5f6a285 Mon Sep 17 00:00:00 2001 From: Leocraft1 Date: Tue, 4 Nov 2025 18:14:49 +0100 Subject: [PATCH] Cercaorario con problemi linea --- seta_modena/servizi/cercaorario/css/style.css | 8 +- seta_modena/servizi/cercaorario/fermata.html | 3 +- .../cercaorario/js/fermata-problemi.js | 193 ++++++++++++++++++ .../servizi/cercaorario/js/notizielinea.js | 36 ++++ .../servizi/cercaorario/notizielinea.html | 32 +++ style.css | 8 + 6 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 seta_modena/servizi/cercaorario/js/fermata-problemi.js create mode 100644 seta_modena/servizi/cercaorario/js/notizielinea.js create mode 100644 seta_modena/servizi/cercaorario/notizielinea.html diff --git a/seta_modena/servizi/cercaorario/css/style.css b/seta_modena/servizi/cercaorario/css/style.css index c3bbc60..aaf8068 100644 --- a/seta_modena/servizi/cercaorario/css/style.css +++ b/seta_modena/servizi/cercaorario/css/style.css @@ -39,7 +39,13 @@ th,td { } .bus-card-red { - background-color: rgb(241, 120, 120) !important; + background-color: rgb(55, 14, 14) !important; +} +.bus-card-yellow { + background-color: rgb(65, 65, 0) !important; +} +.bus-card-green { + background-color: rgb(0, 55, 0) !important; } hr{ diff --git a/seta_modena/servizi/cercaorario/fermata.html b/seta_modena/servizi/cercaorario/fermata.html index 0dbc379..9ceaebe 100644 --- a/seta_modena/servizi/cercaorario/fermata.html +++ b/seta_modena/servizi/cercaorario/fermata.html @@ -26,11 +26,12 @@
Caricamento dati...

Il ritardo viene espresso rispetto all'orario previsto. Quello indicato, se disponibile, รจ l'orario di arrivo in tempo reale.

E' possibile cliccare sul numero del mezzo per vedere la sua posizione sulla mappa.

+

Se una corsa viene visualizzata in rosso, vuol dire che ci sono problemi sulla linea. Cliccare sul numero linea o sul

- + \ No newline at end of file diff --git a/seta_modena/servizi/cercaorario/js/fermata-problemi.js b/seta_modena/servizi/cercaorario/js/fermata-problemi.js new file mode 100644 index 0000000..6c62b4b --- /dev/null +++ b/seta_modena/servizi/cercaorario/js/fermata-problemi.js @@ -0,0 +1,193 @@ +const params = new URLSearchParams(window.location.search); +const nome = params.get('name'); +const codice = params.get('code'); + +//Ricerca per pulsante dall'altra parte +const url = 'https://setaapi.serverissimo.freeddns.org/stopcodesarchive'; +//const url='http://localhost:5001/stoplist'; +fetch(url) + .then(response => { + if (!response.ok) throw new Error("Errore nel caricamento dei dati."); + return response.json(); + }) + .then(data => { + allresults = data; + //Set corsie per stazione o autostazione + const corsie_nav = document.getElementById('corsie-nav'); + if(nome.includes("STAZIONE FS")){ + corsie_nav.innerHTML = ` + `; + } + if(nome.includes("MODENA AUTOSTAZIONE")){ + corsie_nav.innerHTML = ` + `; + } + if(nome.includes("GARIBALDI")){ + corsie_nav.innerHTML = ` + `; + } + if(nome.includes("POLO LEONARDO")){ + corsie_nav.innerHTML = ` + `; + } + //Pulsante dall'altra parte + console.log(altraParteSearch(nome)) + if(altraParteSearch(nome)!=undefined){ + const codes = altraParteSearch(nome); + const altrocodice = 0; + if(codice==codes[0]){ + altroCodice = codes[1]; + }else{ + altroCodice = codes[0]; + } + corsie_nav.innerHTML = ` + `; + } + }) + .catch(error => console.error('Errore nel caricamento dei dati:', error)); + +//Sets stop name +const fermata_span = document.getElementById('fermata-span'); +fermata_span.textContent=nome; + +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 (item.error=="no arrivals scheduled in next 90 minutes") { + container.innerHTML = '

Nessuna corsa programmata nei prossimi 90 minuti.

'; + return; + } + // Creo tabella + const table = document.createElement('table'); + + // Intestazione + const thead = document.createElement('thead'); + thead.innerHTML = ` + + Linea + Direzione + Orario (Rit/Ant) + Stato corsa + Veicolo + Ora si trova a + + `; + 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; + } + if(item.hasProblems==true){ + tr.setAttribute("class","bus-card-red"); + tr.innerHTML = ` + ${item.service} + ${item.destination} + `; + }else{ + tr.innerHTML = ` + ${item.service} + ${item.destination} + `; + } + if(item.delay==undefined){ + //le prime righe sono spostate sopra per link alle notizie se ci sono problemi + tr.innerHTML += ` + ${item.arrival} + ${stato} + ${item.busnum} + ${posizione} + `; + tbody.appendChild(tr); + }else{ + if(item.delay>0){ + tr.innerHTML += ` + ${item.arrival} (+${item.delay}) + ${stato} + ${item.busnum} + ${posizione} + `; + tbody.appendChild(tr); + }else{ + tr.innerHTML += ` + ${item.arrival} (${item.delay}) + ${stato} + ${item.busnum} + ${posizione} + `; + 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); + +function altraParteSearch(searchTerm){ + var dupedCodes = []; + var i = 0; + allresults.forEach(element => { + if(element.fermata.toLowerCase()==searchTerm.toLowerCase()){ + dupedCodes[i]=element.valore; + i++; + } + }); + if(dupedCodes.length==2){ + return dupedCodes; + }else if(dupedCodes.length==1){ + return undefined; + } +} \ No newline at end of file diff --git a/seta_modena/servizi/cercaorario/js/notizielinea.js b/seta_modena/servizi/cercaorario/js/notizielinea.js new file mode 100644 index 0000000..d628380 --- /dev/null +++ b/seta_modena/servizi/cercaorario/js/notizielinea.js @@ -0,0 +1,36 @@ +const params = new URLSearchParams(window.location.search); +const num = params.get('routenum'); +const newsContainer = document.getElementById('notizie-container'); +const lineaSpan = document.getElementById('linea-span'); + +//Urls +const url = "https://setaapi.serverissimo.freeddns.org/routeproblems/"+num; + +//Display numero linea +lineaSpan.textContent=num; + +//Spawn product card +fetch(url) + .then(response => { + if (!response.ok) throw new Error("Errore nel caricamento dei dati."); + return response.json(); + }) + .then(data => { + newsContainer.innerHTML=''; + data.problems.forEach(element => { + var div = document.createElement("div"); + div.setAttribute("class","news-card"); + var p = document.createElement('p'); + var h3 = document.createElement('h3'); + var a = document.createElement('a'); + const link = "/seta_modena/menu/notizia.html?link="+element.link; + a.setAttribute("href",link); + a.setAttribute("class","bianco"); + p.innerHTML=element.date; + h3.innerHTML=element.title; + a.appendChild(p); + a.appendChild(h3); + div.appendChild(a); + newsContainer.appendChild(div); + }); + }) \ No newline at end of file diff --git a/seta_modena/servizi/cercaorario/notizielinea.html b/seta_modena/servizi/cercaorario/notizielinea.html new file mode 100644 index 0000000..0f26e3a --- /dev/null +++ b/seta_modena/servizi/cercaorario/notizielinea.html @@ -0,0 +1,32 @@ + + + + + + SETA Modena - Orario fermate + + + + + + + + +
+ +
+

Notizie linea:

+ +
Caricamento dati...
+ + + + \ No newline at end of file diff --git a/style.css b/style.css index fcbb4b8..5d8e0ef 100644 --- a/style.css +++ b/style.css @@ -410,6 +410,14 @@ span.blu{ .lista-mezzi a{ text-decoration: underline; } + +/*Notizie cercaorario*/ + +#notizie-container{ + display: flex; + justify-content: center; +} + /* Zona ricerca */ .product-card { margin: 10px;