up historique

This commit is contained in:
Tykayn 2025-06-21 11:28:31 +02:00 committed by tykayn
parent ad4170db14
commit c274fd6a63
12 changed files with 448 additions and 616 deletions

View file

@ -71,7 +71,7 @@ function check_validity(e) {
}
}
const genererCouleurPastel = () => {
export const genererCouleurPastel = () => {
const r = Math.floor(Math.random() * 75 + 180);
const g = Math.floor(Math.random() * 75 + 180);
const b = Math.floor(Math.random() * 75 + 180);
@ -163,23 +163,26 @@ function openInPanoramax() {
window.open(panoramaxUrl);
}
function enableLabourageForm() {
export function enableLabourageForm() {
const citySearchInput = document.getElementById('citySearch');
const citySuggestionsList = document.getElementById('citySuggestions');
if (citySearchInput && citySuggestionsList) {
const form = citySearchInput.closest('form');
setupCitySearch('citySearch', 'citySuggestions', function (result_search) {
const labourageBtn = document.querySelector('.btn-labourer');
if (labourageBtn) {
labourageBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Chargement...';
labourageBtn.disabled = true;
if (form) {
const labourageBtn = form.querySelector('.btn-labourer');
if (labourageBtn) {
labourageBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Chargement...';
labourageBtn.disabled = true;
}
}
window.location.href = getLabourerUrl(result_search);
});
}
}
function setupCitySearch(inputId, suggestionListId, onSelect) {
export function setupCitySearch(inputId, suggestionListId, onSelect) {
const searchInput = document.getElementById(inputId);
const suggestionList = document.getElementById(suggestionListId);
@ -251,14 +254,14 @@ function setupCitySearch(inputId, suggestionListId, onSelect) {
});
}
function getLabourerUrl(obj) {
export function getLabourerUrl(obj) {
if (obj && obj.insee) {
return `/admin/labourer_insee/${obj.insee}`;
return `/admin/labourer/${obj.insee}`;
}
return '#';
}
function handleAddCityFormSubmit(event) {
export function handleAddCityFormSubmit(event) {
event.preventDefault();
const zipCode = document.getElementById('selectedZipCode').value;
if (zipCode && zipCode.match(/^\d{5}$/)) {
@ -268,9 +271,9 @@ function handleAddCityFormSubmit(event) {
}
}
function colorizePercentageCells(selector, color = '154, 205, 50') {
export function colorizePercentageCells(selector, color = '154, 205, 50') {
document.querySelectorAll(selector).forEach(cell => {
const percentage = parseInt(cell.textContent);
const percentage = parseInt(cell.textContent.replace('%', ''), 10);
if (!isNaN(percentage)) {
const alpha = percentage / 100;
cell.style.backgroundColor = `rgba(${color}, ${alpha})`;
@ -278,45 +281,66 @@ function colorizePercentageCells(selector, color = '154, 205, 50') {
});
}
function colorizePercentageCellsRelative(selector, color = '154, 205, 50') {
export function colorizePercentageCellsRelative(selector, color = '154, 205, 50') {
let min = Infinity;
let max = -Infinity;
const cells = document.querySelectorAll(selector);
let maxValue = 0;
cells.forEach(cell => {
const value = parseInt(cell.textContent);
if (!isNaN(value) && value > maxValue) {
maxValue = value;
const value = parseInt(cell.textContent.replace('%', ''), 10);
if (!isNaN(value)) {
min = Math.min(min, value);
max = Math.max(max, value);
}
});
cells.forEach(cell => {
const value = parseInt(cell.textContent);
if (!isNaN(value)) {
const alpha = value / maxValue;
cell.style.backgroundColor = `rgba(${color}, ${alpha})`;
}
});
if (max > min) {
cells.forEach(cell => {
const value = parseInt(cell.textContent.replace('%', ''), 10);
if (!isNaN(value)) {
const ratio = (value - min) / (max - min);
cell.style.backgroundColor = `rgba(${color}, ${ratio.toFixed(2)})`;
}
});
}
}
function adjustListGroupFontSize(selector, minFont = 0.8, maxFont = 1.2) {
const items = document.querySelectorAll(selector);
const count = items.length;
export function adjustListGroupFontSize(selector, minFont = 0.8, maxFont = 1.2) {
const listItems = document.querySelectorAll(selector);
if (listItems.length === 0) return;
let fontSize = maxFont;
const count = listItems.length;
if (count > 0) {
fontSize = Math.max(minFont, maxFont - (count - 5) * 0.05);
}
items.forEach(item => {
listItems.forEach(item => {
item.style.fontSize = fontSize + 'rem';
});
}
window.setupCitySearch = setupCitySearch;
window.handleAddCityFormSubmit = handleAddCityFormSubmit;
window.colorizePercentageCells = colorizePercentageCells;
window.colorizePercentageCellsRelative = colorizePercentageCellsRelative;
export function calculateCompletion(properties) {
let completed = 0;
const total = 7; // Nombre de critères
if (properties.name) completed++;
if (properties['addr:housenumber'] && properties['addr:street']) completed++;
if (properties.opening_hours) completed++;
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,
completed: completed,
total: total
};
}
window.check_validity = check_validity;
window.colorHeadingTable = colorHeadingTable;
window.openInPanoramax = openInPanoramax;
window.listChangesets = listChangesets;
window.colorHeadingTable = colorHeadingTable;
window.adjustListGroupFontSize = adjustListGroupFontSize;
window.genererCouleurPastel = genererCouleurPastel;
window.adjustListGroupFontSize = adjustListGroupFontSize;
window.calculateCompletion = calculateCompletion;