mirror of
https://github.com/Daniongithub/ER-TPL.git
synced 2025-10-02 14:50:47 +00:00
New service
This commit is contained in:
75
start_menu/servizi/start-fermatebus/js/cercafermata.js
Normal file
75
start_menu/servizi/start-fermatebus/js/cercafermata.js
Normal file
@@ -0,0 +1,75 @@
|
||||
function loadJSON(file, callback) {
|
||||
fetch(file)
|
||||
.then(response => response.json())
|
||||
.then(data => callback(data))
|
||||
.catch(error => console.error('Errore nel caricare il file JSON:', error));
|
||||
}
|
||||
|
||||
function populateSearchResults(results, selectedOption) {
|
||||
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.nome}</h3>
|
||||
<p>Palina: ${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;
|
||||
});
|
||||
|
||||
searchResultsContainer.appendChild(div);
|
||||
});
|
||||
}
|
||||
|
||||
function filterOptions(query, data) {
|
||||
return data.filter(item => item.nome.toLowerCase().includes(query.toLowerCase()));
|
||||
}
|
||||
|
||||
let allOptions = [];
|
||||
let currentSelectedOption = '';
|
||||
|
||||
const searchBar = document.getElementById('searchBar');
|
||||
searchBar.addEventListener('input', function() {
|
||||
const query = searchBar.value;
|
||||
const filteredOptions = filterOptions(query, allOptions);
|
||||
populateSearchResults(filteredOptions, currentSelectedOption);
|
||||
});
|
||||
|
||||
document.getElementById('bacino').addEventListener('change', function(event) {
|
||||
const selectedOption = event.target.value;
|
||||
currentSelectedOption = selectedOption;
|
||||
|
||||
let file = '';
|
||||
switch (selectedOption) {
|
||||
case 'ra':
|
||||
file = 'js/fermate-ra.json';
|
||||
break;
|
||||
case 'rn':
|
||||
file = 'js/fermate-rn.json';
|
||||
break;
|
||||
case 'fc':
|
||||
file = 'js/fermate-fc.json';
|
||||
break;
|
||||
default:
|
||||
allOptions = [];
|
||||
document.getElementById('searchResults').innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
loadJSON(file, (data) => {
|
||||
allOptions = data;
|
||||
populateSearchResults(allOptions, currentSelectedOption);
|
||||
});
|
||||
});
|
58
start_menu/servizi/start-fermatebus/js/fermata.js
Normal file
58
start_menu/servizi/start-fermatebus/js/fermata.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const palina = params.get('palina');
|
||||
const targetID = params.get('targetID');
|
||||
const selectedOption = params.get('selectedOption');
|
||||
console.log(palina, targetID, selectedOption);
|
||||
|
||||
// Esempio URL backend che ritorna JSON { linea, destinazione, veicolo, soppressa }
|
||||
const urlBackend = `https://api.vichingo455.freeddns.org/start-fermatebus.json/?param=${targetID}¶m2=${selectedOption}&palina=${palina}`;
|
||||
|
||||
fetch(urlBackend)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
const container = document.getElementById('tabella-container');
|
||||
container.innerHTML = '';
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
container.textContent = 'Nessun dato trovato.';
|
||||
return;
|
||||
}
|
||||
|
||||
// Creo tabella
|
||||
const table = document.createElement('table');
|
||||
|
||||
// Intestazione
|
||||
const thead = document.createElement('thead');
|
||||
thead.innerHTML = `
|
||||
<tr>
|
||||
<th>Linea</th>
|
||||
<th>Destinazione</th>
|
||||
<th>Veicolo</th>
|
||||
<th>Soppressa</th>
|
||||
</tr>
|
||||
`;
|
||||
table.appendChild(thead);
|
||||
|
||||
// Corpo tabella
|
||||
const tbody = document.createElement('tbody');
|
||||
data.forEach(item => {
|
||||
const tr = document.createElement('tr');
|
||||
if (item.soppressa) {
|
||||
tr.classList.add('bus-card-red');
|
||||
}
|
||||
tr.innerHTML = `
|
||||
<td>${item.linea}</td>
|
||||
<td>${item.destinazione}</td>
|
||||
<td>${item.mezzo}</td>
|
||||
<td>${item.soppressa ? 'Sì' : 'No'}</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.';
|
||||
});
|
17192
start_menu/servizi/start-fermatebus/js/fermate-fc.json
Normal file
17192
start_menu/servizi/start-fermatebus/js/fermate-fc.json
Normal file
File diff suppressed because it is too large
Load Diff
13737
start_menu/servizi/start-fermatebus/js/fermate-ra.json
Normal file
13737
start_menu/servizi/start-fermatebus/js/fermate-ra.json
Normal file
File diff suppressed because it is too large
Load Diff
17887
start_menu/servizi/start-fermatebus/js/fermate-rn.json
Normal file
17887
start_menu/servizi/start-fermatebus/js/fermate-rn.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user