mirror of
https://github.com/Daniongithub/startfermate.git
synced 2025-10-02 14:10:48 +00:00
Sync files from main repo, new version.
This commit is contained in:
@@ -13,19 +13,24 @@ function populateSearchResults(results, selectedOption) {
|
||||
div.innerHTML = `
|
||||
<div>
|
||||
<h3>${item.nome}</h3>
|
||||
<p>Palina: ${item.palina}, Target ID: ${item.targetID}</p>
|
||||
<p>Fermata: ${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;
|
||||
window.open(url, "_blank");
|
||||
});
|
||||
|
||||
searchResultsContainer.appendChild(div);
|
||||
});
|
||||
}
|
||||
|
||||
function getFermatadaBreve(codice){
|
||||
const middle = String(codice).padStart(4, "0");
|
||||
return `7${middle}0`;
|
||||
}
|
||||
|
||||
function filterOptions(query, data) {
|
||||
const q = query.toLowerCase();
|
||||
return data.filter(item =>
|
||||
@@ -35,6 +40,31 @@ function filterOptions(query, data) {
|
||||
);
|
||||
}
|
||||
|
||||
function filtraTesto(query, data){
|
||||
const q = query.toLowerCase();
|
||||
return data
|
||||
.filter(item => (item.nome || '').toLowerCase().includes(q))
|
||||
.sort((a, b) => (a.nome || '').localeCompare(b.nome || ''));
|
||||
}
|
||||
|
||||
function filtraLungo(query, data){
|
||||
const q = query.toLowerCase();
|
||||
return data
|
||||
.filter(item => (item.palina || '').toLowerCase().includes(q))
|
||||
.sort((a, b) => (a.palina || '').localeCompare(b.palina || ''));
|
||||
}
|
||||
|
||||
function filtraBreve(query, data){
|
||||
const cod = getFermatadaBreve(query);
|
||||
return filtraLungo(cod, data);
|
||||
}
|
||||
|
||||
function filtraTID(query, data){
|
||||
const q = query.toLowerCase();
|
||||
return data
|
||||
.filter(item => (item.targetID || '').toLowerCase().includes(q))
|
||||
.sort((a, b) => (a.targetID || '').localeCompare(b.targetID || ''));
|
||||
}
|
||||
|
||||
let allOptions = [];
|
||||
let currentSelectedOption = '';
|
||||
@@ -46,20 +76,67 @@ searchBar.addEventListener('input', function() {
|
||||
populateSearchResults(filteredOptions, currentSelectedOption);
|
||||
});
|
||||
|
||||
searchBar.addEventListener('input', function() {
|
||||
const query = searchBar.value;
|
||||
let filteredOptions;
|
||||
|
||||
if (currentSelectedOption !== "ra") {
|
||||
filteredOptions = filterOptions(query, allOptions);
|
||||
} else {
|
||||
if (document.getElementById('text').checked){
|
||||
filteredOptions = filtraTesto(query, allOptions);
|
||||
}
|
||||
else if (document.getElementById('lungo').checked){
|
||||
filteredOptions = filtraLungo(query, allOptions);
|
||||
}
|
||||
else if (document.getElementById('breve').checked){
|
||||
filteredOptions = filtraBreve(query, allOptions);
|
||||
}
|
||||
else if(document.getElementById('tid').checked){
|
||||
filteredOptions = filtraTID(query, allOptions);
|
||||
}
|
||||
}
|
||||
populateSearchResults(filteredOptions, currentSelectedOption);
|
||||
});
|
||||
|
||||
const radios = document.querySelectorAll('#radios input[type="radio"]');
|
||||
radios.forEach(radio => {
|
||||
radio.addEventListener('change', () => {
|
||||
searchBar.value = '';
|
||||
document.getElementById('searchResults').innerHTML = '';
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('bacino').addEventListener('change', function(event) {
|
||||
const selectedOption = event.target.value;
|
||||
currentSelectedOption = selectedOption;
|
||||
|
||||
if (!selectedOption) {
|
||||
const urlFermate = `https://api.vichingo455.freeddns.org/fermateapi/bacino?selectedOption=${selectedOption}`;
|
||||
|
||||
const radiobuttons = document.getElementById('radios');
|
||||
const ricerca = document.getElementById('ricerca');
|
||||
ricerca.removeAttribute('style');
|
||||
|
||||
document.getElementById('searchBar').value = "";
|
||||
|
||||
if(selectedOption == "n"){
|
||||
ricerca.setAttribute("style", "display: none;");
|
||||
radiobuttons.setAttribute("style", "display: none;");
|
||||
allOptions = [];
|
||||
document.getElementById('searchResults').innerHTML = '';
|
||||
return;
|
||||
}
|
||||
else if(selectedOption == "ra"){
|
||||
radiobuttons.removeAttribute('style')
|
||||
}
|
||||
|
||||
const resultsContainer = document.getElementById('searchResults');
|
||||
resultsContainer.innerHTML = '<p>Caricamento lista fermate in corso...</p>';
|
||||
|
||||
fetch(`http://localhost:3005/bacino?selectedOption=${selectedOption}`)
|
||||
if(selectedOption != "n"){
|
||||
const resultsContainer = document.getElementById('searchResults');
|
||||
resultsContainer.innerHTML = '<p>Caricamento lista fermate in corso...</p>';
|
||||
if(selectedOption != "ra"){
|
||||
radiobuttons.setAttribute("style", "display: none;");
|
||||
}
|
||||
fetch(urlFermate)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
allOptions = data;
|
||||
@@ -69,4 +146,5 @@ document.getElementById('bacino').addEventListener('change', function(event) {
|
||||
resultsContainer.innerHTML = '<p>Errore nel caricamento delle fermate.</p>';
|
||||
console.error('Errore:', err);
|
||||
});
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user