mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-06-20 01:44:42 +02:00
up stats page
This commit is contained in:
parent
a412cb977a
commit
e4bf3753b0
9 changed files with 357 additions and 124 deletions
|
@ -23,6 +23,112 @@
|
|||
<script src='https://cdn.jsdelivr.net/npm/maplibre-gl@3.6.2/dist/maplibre-gl.js'></script>
|
||||
<script >
|
||||
|
||||
|
||||
// Fonction pour rechercher avec Addok
|
||||
async function searchPostalCode(query) {
|
||||
try {
|
||||
const response = await fetch(`https://api-adresse.data.gouv.fr/search/?q=${query}&type=municipality&autocomplete=1`);
|
||||
const data = await response.json();
|
||||
return data.features.map(feature => ({
|
||||
label: `${feature.properties.city} (${feature.properties.postcode})`,
|
||||
postcode: feature.properties.postcode,
|
||||
city: feature.properties.city
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la recherche:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Créer et configurer la liste de suggestions
|
||||
const suggestionList = document.createElement('ul');
|
||||
suggestionList.style.cssText = `
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: 1px solid #ccc;
|
||||
border-top: none;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
background: white;
|
||||
width: 100%;
|
||||
z-index: 1000;
|
||||
`;
|
||||
|
||||
// Configurer l'input de recherche
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const searchInput = document.getElementById('app_admin_labourer');
|
||||
const inputContainer = searchInput.parentElement;
|
||||
|
||||
// Ajouter un conteneur relatif pour le positionnement
|
||||
const searchWrapper = document.createElement('div');
|
||||
searchWrapper.style.position = 'relative';
|
||||
inputContainer.appendChild(searchWrapper);
|
||||
searchWrapper.appendChild(searchInput);
|
||||
searchWrapper.appendChild(suggestionList);
|
||||
|
||||
let debounceTimer;
|
||||
|
||||
searchInput.addEventListener('input', async (e) => {
|
||||
clearTimeout(debounceTimer);
|
||||
debounceTimer = setTimeout(async () => {
|
||||
const query = e.target.value;
|
||||
if (query.length < 2) {
|
||||
suggestionList.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
const suggestions = await searchPostalCode(query);
|
||||
suggestionList.innerHTML = '';
|
||||
|
||||
if (suggestions.length === 0) {
|
||||
const li = document.createElement('li');
|
||||
li.style.cssText = `
|
||||
padding: 8px 12px;
|
||||
color: #666;
|
||||
font-style: italic;
|
||||
`;
|
||||
li.textContent = 'Aucun résultat trouvé';
|
||||
suggestionList.appendChild(li);
|
||||
return;
|
||||
}
|
||||
|
||||
suggestions.forEach(suggestion => {
|
||||
const li = document.createElement('li');
|
||||
li.style.cssText = `
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid #eee;
|
||||
`;
|
||||
li.textContent = suggestion.label;
|
||||
|
||||
li.addEventListener('mouseenter', () => {
|
||||
li.style.backgroundColor = '#f0f0f0';
|
||||
});
|
||||
|
||||
li.addEventListener('mouseleave', () => {
|
||||
li.style.backgroundColor = 'white';
|
||||
});
|
||||
|
||||
li.addEventListener('click', () => {
|
||||
searchInput.value = suggestion.postcode;
|
||||
suggestionList.innerHTML = '';
|
||||
labourer();
|
||||
});
|
||||
|
||||
suggestionList.appendChild(li);
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// Cacher la liste quand on clique ailleurs
|
||||
document.addEventListener('click', (e) => {
|
||||
if (!inputContainer.contains(e.target)) {
|
||||
suggestionList.innerHTML = '';
|
||||
}
|
||||
});
|
||||
});
|
||||
// Définir la fonction labourer dans le scope global
|
||||
function labourer() {
|
||||
window.location.href = '/admin/labourer/' + document.getElementById('app_admin_labourer').value;
|
||||
|
@ -60,35 +166,25 @@
|
|||
}
|
||||
|
||||
const postalCodes = [{% for stat in stats %}'{{ stat.zone }}'{% if not loop.last %}, {% endif %}{% endfor %}];
|
||||
{% verbatim %}
|
||||
|
||||
// exemple de recherche de villes par leur code postal:
|
||||
// [out:json][timeout:25];
|
||||
// (
|
||||
// {{geocodeArea:76200}}->.searchArea_1;
|
||||
// nwr["boundary"="administrative"]["admin_level"="8"]
|
||||
// ["name"](area.searchArea_1);
|
||||
// {{geocodeArea:76000}}->.searchArea_2;
|
||||
// nwr["boundary"="administrative"]["admin_level"="8"]["name"](area.searchArea_2);
|
||||
// ) ;
|
||||
// out center;
|
||||
{% endverbatim %}
|
||||
|
||||
{% verbatim %}
|
||||
console.log(postalCodes);
|
||||
let postalLines = ``;
|
||||
postalCodes.forEach(code => {
|
||||
if (/^\d+$/.test(code)) {
|
||||
|
||||
{% verbatim %}
|
||||
postalLines += `\n{{geocodeArea:${code}}}->.searchArea_${code};\nnwr[admin_level=8]["name"](area.searchArea_${code});`
|
||||
{% endverbatim %}
|
||||
postalLines += `
|
||||
area["postal_code"="${code}"]->.searchArea_${code};
|
||||
nwr["admin_level"="8"]["name"](area.searchArea_${code});`;
|
||||
}
|
||||
});
|
||||
const query = `[out:json][timeout:25];
|
||||
(
|
||||
${postalLines}
|
||||
);
|
||||
out center;` ;
|
||||
(
|
||||
${postalLines}
|
||||
);
|
||||
out body;
|
||||
>;
|
||||
out skel qt;`;
|
||||
{% endverbatim %}
|
||||
|
||||
console.log(query);
|
||||
console.log('https://overpass-api.de/api/interpreter');
|
||||
const response = await fetch('https://overpass-api.de/api/interpreter', {
|
||||
|
@ -141,9 +237,7 @@
|
|||
<h2>Statistiques : {{ stats|length }} codes postaux</h2>
|
||||
|
||||
<div id="mapDashboard"></div>
|
||||
<input class="form-control" type="text" id="app_admin_labourer" value="75013">
|
||||
<button class="btn btn-primary" id="labourer">Labourer les mises à jour</button>
|
||||
|
||||
|
||||
|
||||
<table class="table table-hover table-striped table-responsive">
|
||||
<thead>
|
||||
|
@ -158,7 +252,7 @@
|
|||
{% for stat in stats %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ path('app_admin_stats', {'zip_code': stat.zone}) }}">{{ stat.zone }}</a>
|
||||
<a href="{{ path('app_admin_stats', {'zip_code': stat.zone}) }}">{{ stat.zone }} {{ stat.name }}</a>
|
||||
</td>
|
||||
<td>{{ stat.placesCount }}</td>
|
||||
<td style="background : rgba(0 , 255, 0, {{stat.completionPercent / 100 }} )">{{ stat.completionPercent }}</td>
|
||||
|
@ -173,7 +267,11 @@
|
|||
</table>
|
||||
|
||||
<h2>{{ places|length }} Lieux</h2>
|
||||
<h2><button class="btn btn-primary" id="labourer">Labourer les mises à jour</button></h2>
|
||||
<label for="app_admin_labourer">Rechercher une ville </label>
|
||||
<input class="form-control" type="text" id="app_admin_labourer" value="75013">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue