mirror of
https://github.com/Daniongithub/ER-TPL.git
synced 2025-12-06 13:32:02 +00:00
Spostamento di file seta
This commit is contained in:
76
seta_modena/menu/percorsi/js/linea.js
Normal file
76
seta_modena/menu/percorsi/js/linea.js
Normal file
@@ -0,0 +1,76 @@
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const id = params.get('routecode');
|
||||
const num = params.get('routenum');
|
||||
const codiceSpan = document.getElementById('codice-span');
|
||||
const destSpan = document.getElementById('destinazione-span');
|
||||
const pNav = document.getElementById('percorso-nav');
|
||||
|
||||
//Displays route code
|
||||
codiceSpan.textContent = id;
|
||||
//Nav per tornare indietro
|
||||
pNav.innerHTML = `
|
||||
<ul>
|
||||
<li><a href="/index.html"><h1 style="font-size: 100%;font-weight: 500;">Home</h1></a></li>
|
||||
<li><a href="/seta_menu/percorsi/index.html"><h1 style="font-size: 100%;font-weight: 500;">Selettore linea</h1></a></li>
|
||||
<li><a href="/seta_menu/percorsi/rcodes.html?routenum=${num}"><h1 style="font-size: 100%;font-weight: 500;">Selettore percorso</h1></a></li>
|
||||
</ul>
|
||||
`;
|
||||
|
||||
const urlBackend = `https://setaapi.serverissimo.freeddns.org/routestops/${id}`;
|
||||
//const urlBackend = `http://localhost:5001/arrivals/${codice}`;
|
||||
function caricadati(){
|
||||
var item=[];
|
||||
fetch(urlBackend)
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error("Errore di risposta nel caricamento dei dati, probabilmente il server API è offline.");
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
item = data;
|
||||
})
|
||||
.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="linea" style="text-align:center;">Nome:</th>
|
||||
<th class="linea" style="text-align:center;">Codice:</th>
|
||||
</tr>
|
||||
`;
|
||||
table.appendChild(thead);
|
||||
|
||||
// Corpo tabella
|
||||
const tbody = document.createElement('tbody');
|
||||
item.forEach(item => {
|
||||
const element = item;
|
||||
var tr = document.createElement('tr');
|
||||
tr.innerHTML = `
|
||||
<tr>
|
||||
<td class="uguale"><a href="/seta_menu/cercaorario/fermata.html?code=${item.code}&name=${item.desc}" class="bianco">${item.desc}</a></td>
|
||||
<td class="uguale"><a href="/seta_menu/cercaorario/fermata.html?code=${item.code}&name=${item.desc}" class="bianco">${item.code}</a></td>
|
||||
</tr>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
if(element.islast==true){
|
||||
destSpan.innerHTML=element.desc.toUpperCase();
|
||||
}
|
||||
});
|
||||
table.appendChild(tbody);
|
||||
container.appendChild(table);
|
||||
})
|
||||
.catch(err => {
|
||||
if(item.error=="Percorso non trovato"){
|
||||
document.getElementById('tabella-container').textContent = "Percorso non trovato.";
|
||||
}else{
|
||||
console.error('Errore nel caricamento dati:', err);
|
||||
document.getElementById('tabella-container').textContent = "Errore nella sintassi dei dati ricevuti.";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
caricadati();
|
||||
Reference in New Issue
Block a user