mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-04 17:04:53 +02:00
fix imports js
This commit is contained in:
parent
ada9fa4029
commit
f785e67f49
6 changed files with 163 additions and 42 deletions
|
@ -23,7 +23,16 @@ import './dashboard-charts.js';
|
|||
import Chart from 'chart.js/auto';
|
||||
import ChartDataLabels from 'chartjs-plugin-datalabels';
|
||||
import maplibregl from 'maplibre-gl';
|
||||
import { genererCouleurPastel, setupCitySearch, handleAddCityFormSubmit, enableLabourageForm, getLabourerUrl, adjustListGroupFontSize, toggleCompletionInfo } from './utils.js';
|
||||
import {
|
||||
genererCouleurPastel,
|
||||
setupCitySearch,
|
||||
handleAddCityFormSubmit,
|
||||
enableLabourageForm,
|
||||
getLabourerUrl,
|
||||
adjustListGroupFontSize,
|
||||
toggleCompletionInfo,
|
||||
updateMapHeightForLargeScreens
|
||||
} from './utils.js';
|
||||
import Tablesort from 'tablesort';
|
||||
|
||||
window.Chart = Chart;
|
||||
|
@ -34,6 +43,7 @@ window.getLabourerUrl = getLabourerUrl;
|
|||
window.ChartDataLabels = ChartDataLabels;
|
||||
window.maplibregl = maplibregl;
|
||||
window.toggleCompletionInfo = toggleCompletionInfo;
|
||||
window.updateMapHeightForLargeScreens = updateMapHeightForLargeScreens;
|
||||
|
||||
Chart.register(ChartDataLabels);
|
||||
|
||||
|
@ -41,6 +51,11 @@ Chart.register(ChartDataLabels);
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
console.log('DOMContentLoaded');
|
||||
|
||||
if(updateMapHeightForLargeScreens){
|
||||
|
||||
updateMapHeightForLargeScreens();
|
||||
window.addEventListener('resize', updateMapHeightForLargeScreens);
|
||||
}
|
||||
|
||||
const randombg = genererCouleurPastel();
|
||||
// Appliquer la couleur au body
|
||||
|
@ -184,7 +199,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
});
|
||||
}
|
||||
|
||||
enableLabourageForm();
|
||||
enableLabourageForm();
|
||||
adjustListGroupFontSize('.list-group-item');
|
||||
});
|
||||
|
|
@ -97,7 +97,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
align: 'center',
|
||||
color: '#000',
|
||||
display: true,
|
||||
font: { weight: 'bold' },
|
||||
font: { weight: '400', size : "1rem" },
|
||||
formatter: (value, context) => {
|
||||
return context.dataset.data[context.dataIndex].label;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
label: 'Régression linéaire',
|
||||
type: 'line',
|
||||
data: regressionLine,
|
||||
borderColor: 'rgba(0, 0, 0, 0.7)',
|
||||
borderColor: 'rgba(162, 255, 40, 0.7)',
|
||||
borderWidth: 2,
|
||||
pointRadius: 0,
|
||||
fill: false,
|
||||
|
@ -135,7 +135,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
return [
|
||||
`${d.label}`,
|
||||
`Population: ${d.x.toLocaleString()}`,
|
||||
`Lieux / 1000 hab: ${d.y.toFixed(2)}`,
|
||||
`Lieux / hab: ${d.y.toFixed(2)}`,
|
||||
`Total lieux: ${Math.round(Math.pow(d.r / 2, 2))}`,
|
||||
`Complétion: ${d.completion}%`
|
||||
];
|
||||
|
|
|
@ -97,7 +97,7 @@ async function searchInseeCode(query) {
|
|||
}
|
||||
}
|
||||
|
||||
function updateMapHeightForLargeScreens() {
|
||||
export function updateMapHeightForLargeScreens() {
|
||||
const mapFound = document.querySelector('#map');
|
||||
if (mapFound && window.innerHeight > 800 && window.innerWidth > 800) {
|
||||
mapFound.style.height = window.innerWidth * 0.8 + 'px';
|
||||
|
@ -171,13 +171,24 @@ export function enableLabourageForm() {
|
|||
const form = citySearchInput.closest('form');
|
||||
setupCitySearch('citySearch', 'citySuggestions', function (result_search) {
|
||||
if (form) {
|
||||
const labourageBtn = form.querySelector('.btn-labourer');
|
||||
const labourageBtn = form.querySelector('button[type="submit"]');
|
||||
if (labourageBtn) {
|
||||
labourageBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Chargement...';
|
||||
labourageBtn.disabled = true;
|
||||
// Remplir le champ caché avec le code INSEE
|
||||
const inseeInput = form.querySelector('#selectedZipCode');
|
||||
if (inseeInput) {
|
||||
inseeInput.value = result_search.insee;
|
||||
}
|
||||
// Changer l'action du formulaire pour pointer vers la bonne URL
|
||||
form.action = getLabourerUrl(result_search);
|
||||
|
||||
// Changer le texte du bouton et le désactiver
|
||||
labourageBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Labourage de ' + result_search.name + '...';
|
||||
labourageBtn.disabled = true;
|
||||
|
||||
// Soumettre le formulaire
|
||||
form.submit();
|
||||
}
|
||||
}
|
||||
window.location.href = getLabourerUrl(result_search);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +202,7 @@ export function setupCitySearch(inputId, suggestionListId, onSelect) {
|
|||
let timeoutId = null;
|
||||
let searchOngoing = false;
|
||||
|
||||
searchInput.addEventListener('input', function () {
|
||||
searchInput.addEventListener('keyup', function () {
|
||||
clearTimeout(timeoutId);
|
||||
const query = this.value.trim();
|
||||
if (query.length < 3) {
|
||||
|
@ -329,7 +340,6 @@ export function calculateCompletion(properties) {
|
|||
if (properties.website || properties['contact:website']) completed++;
|
||||
if (properties.phone || properties['contact:phone']) completed++;
|
||||
if (properties.wheelchair) completed++;
|
||||
if (properties.note) completed++;
|
||||
|
||||
return {
|
||||
percentage: total > 0 ? (completed / total) * 100 : 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue