2025-05-26 11:32:53 +02:00
|
|
|
{% extends 'base.html.twig' %}
|
|
|
|
|
2025-06-03 10:52:15 +02:00
|
|
|
{% block title %}Tableau de bord{% endblock %}
|
2025-05-26 11:32:53 +02:00
|
|
|
|
|
|
|
{% block stylesheets %}
|
|
|
|
{{ parent() }}
|
2025-06-03 14:58:23 +02:00
|
|
|
<link href='{{ asset('js/maplibre/maplibre-gl.css') }}' rel='stylesheet' />
|
2025-05-26 11:32:53 +02:00
|
|
|
<style>
|
|
|
|
.hidden {
|
|
|
|
display: none;
|
|
|
|
}
|
2025-06-01 19:52:56 +02:00
|
|
|
#mapDashboard {
|
|
|
|
height: 400px;
|
|
|
|
width: 100%;
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
}
|
2025-06-17 13:23:47 +02:00
|
|
|
.suggestion-list {
|
2025-06-03 12:51:20 +02:00
|
|
|
position: absolute;
|
|
|
|
background: white;
|
2025-06-17 13:23:47 +02:00
|
|
|
border: 1px solid #ddd;
|
|
|
|
border-radius: 4px;
|
|
|
|
max-height: 200px;
|
|
|
|
overflow-y: auto;
|
2025-06-03 12:51:20 +02:00
|
|
|
width: 100%;
|
|
|
|
z-index: 1000;
|
2025-06-21 10:26:55 +02:00
|
|
|
display: none;
|
2025-05-28 17:05:34 +02:00
|
|
|
}
|
2025-06-17 13:23:47 +02:00
|
|
|
.suggestion-item {
|
|
|
|
padding: 8px 12px;
|
|
|
|
cursor: pointer;
|
|
|
|
border-bottom: 1px solid #eee;
|
2025-06-01 20:08:57 +02:00
|
|
|
}
|
2025-06-17 13:23:47 +02:00
|
|
|
.suggestion-item:hover {
|
|
|
|
background-color: #f5f5f5;
|
|
|
|
}
|
|
|
|
.suggestion-name {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
.suggestion-details {
|
|
|
|
font-size: 0.9em;
|
|
|
|
color: #666;
|
|
|
|
}
|
|
|
|
.suggestion-type {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
.search-container {
|
|
|
|
position: relative;
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
{% endblock %}
|
2025-06-01 20:08:57 +02:00
|
|
|
|
2025-05-28 17:05:34 +02:00
|
|
|
|
2025-05-26 11:32:53 +02:00
|
|
|
{% block body %}
|
2025-06-17 13:23:47 +02:00
|
|
|
<div class="container">
|
2025-05-26 11:32:53 +02:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-12">
|
2025-06-17 13:23:47 +02:00
|
|
|
<h1 class="mb-4">Tableau de bord</h1>
|
2025-05-26 11:32:53 +02:00
|
|
|
</div>
|
2025-06-17 13:23:47 +02:00
|
|
|
</div>
|
2025-06-21 10:26:55 +02:00
|
|
|
|
|
|
|
<div class="row mb-4">
|
|
|
|
<div class="col-12">
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-header">
|
|
|
|
Statistiques des villes (nombre de commerces)
|
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
<canvas id="statsBubbleChart" style="min-height: 400px; width: 100%;"></canvas>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-06-05 15:43:11 +02:00
|
|
|
|
2025-06-17 13:23:47 +02:00
|
|
|
<div class="row">
|
2025-06-21 10:26:55 +02:00
|
|
|
<div class="col-12">
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-body">
|
|
|
|
<h3 class="card-title">Labourer une ville</h3>
|
|
|
|
<form id="labourerForm">
|
|
|
|
<div class="search-container">
|
|
|
|
<input type="text"
|
|
|
|
id="citySearch"
|
|
|
|
class="form-control"
|
|
|
|
placeholder="Rechercher une ville..."
|
|
|
|
autocomplete="off">
|
|
|
|
<div id="citySuggestions" class="suggestion-list"></div>
|
|
|
|
</div>
|
|
|
|
<input type="hidden" name="zip_code" id="selectedZipCode">
|
|
|
|
<button type="submit" class="btn btn-primary mt-3">Labourer cette ville</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row mt-4">
|
2025-06-17 13:23:47 +02:00
|
|
|
<div class="col-12">
|
|
|
|
<h2>Statistiques par ville</h2>
|
|
|
|
<div class="table-responsive">
|
|
|
|
<table class="table table-striped">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Ville</th>
|
|
|
|
<th>Code postal</th>
|
|
|
|
<th>Complétion</th>
|
|
|
|
<th>Nombre de commerces</th>
|
2025-06-21 10:26:55 +02:00
|
|
|
<th>Lieux par habitants</th>
|
2025-06-17 13:23:47 +02:00
|
|
|
<th>Actions</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{% for stat in stats %}
|
|
|
|
<tr>
|
2025-06-17 18:27:19 +02:00
|
|
|
<td><a href="{{ path('app_admin_stats', {'insee_code': stat.zone}) }}" title="Voir les statistiques de cette ville">
|
2025-06-17 16:23:29 +02:00
|
|
|
{{ stat.name }}
|
2025-06-17 18:27:19 +02:00
|
|
|
{% if not stat.name and stat.zone starts with '751' %}
|
|
|
|
Paris {{ stat.zone|slice(-2) }}e.
|
|
|
|
|
|
|
|
{% endif %}
|
2025-06-17 16:23:29 +02:00
|
|
|
</a></td>
|
2025-06-17 13:23:47 +02:00
|
|
|
<td>{{ stat.zone }}</td>
|
|
|
|
<td>{{ stat.completionPercent }}%</td>
|
2025-06-21 10:26:55 +02:00
|
|
|
<td>{{ stat.placesCount }}</td>
|
|
|
|
<td>{{ (stat.placesCount / (stat.population or 1 ))|round(2) }}</td>
|
2025-06-17 13:23:47 +02:00
|
|
|
<td>
|
2025-06-17 16:23:29 +02:00
|
|
|
<div class="btn-group" role="group">
|
2025-06-17 18:27:19 +02:00
|
|
|
<a href="{{ path('app_admin_stats', {'insee_code': stat.zone}) }}" class="btn btn-sm btn-primary" title="Voir les statistiques de cette ville">
|
2025-06-17 16:23:29 +02:00
|
|
|
<i class="bi bi-eye"></i>
|
|
|
|
</a>
|
2025-06-17 18:27:19 +02:00
|
|
|
<a href="{{ path('app_admin_labourer', {'insee_code': stat.zone}) }}"
|
2025-06-17 16:23:29 +02:00
|
|
|
class="btn btn-sm btn-success btn-labourer"
|
|
|
|
data-zip-code="{{ stat.zone }}"
|
|
|
|
title="Labourer cette ville"
|
|
|
|
>
|
|
|
|
<i class="bi bi-recycle"></i>
|
|
|
|
</a>
|
2025-06-19 10:20:40 +02:00
|
|
|
|
2025-06-17 18:27:19 +02:00
|
|
|
<a href="{{ path('app_admin_delete_by_zone', {'insee_code': stat.zone}) }}"
|
2025-06-17 16:23:29 +02:00
|
|
|
class="btn btn-sm btn-danger"
|
|
|
|
onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette zone ?')"
|
|
|
|
title="Supprimer cette ville"
|
|
|
|
>
|
|
|
|
<i class="bi bi-trash"></i>
|
|
|
|
</a>
|
|
|
|
</div>
|
2025-06-17 13:23:47 +02:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{% endfor %}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-05-26 11:32:53 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{% endblock %}
|
2025-06-18 00:41:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
{% block javascripts %}
|
|
|
|
{{ parent() }}
|
2025-06-21 10:26:55 +02:00
|
|
|
{# Les scripts sont maintenant gérés par Webpack Encore via app.js #}
|
2025-06-18 00:41:24 +02:00
|
|
|
<script>
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
2025-06-21 10:26:55 +02:00
|
|
|
const statsDataRaw = [
|
|
|
|
{% for stat in stats %}
|
|
|
|
{% if stat.placesCount > 0 and stat.name is not null and stat.population > 0 %}
|
|
|
|
{
|
|
|
|
label: '{{ (stat.name ~ " (" ~ stat.zone ~ ")")|e('js') }}',
|
|
|
|
placesCount: {{ stat.placesCount }},
|
|
|
|
completion: {{ stat.completionPercent|default(0) }},
|
|
|
|
x: {{ stat.population }},
|
|
|
|
y: {{ (stat.placesCount / stat.population * 1000)|round(2) }}
|
|
|
|
},
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
];
|
|
|
|
|
|
|
|
const ctx = document.getElementById('statsBubbleChart');
|
|
|
|
if (ctx && statsDataRaw.length > 0) {
|
|
|
|
const statsData = statsDataRaw.map(d => ({
|
|
|
|
...d,
|
|
|
|
r: Math.sqrt(d.placesCount) * 2.5 // Utilise la racine carrée pour la taille, avec un facteur d'échelle
|
|
|
|
}));
|
|
|
|
|
|
|
|
new Chart(ctx.getContext('2d'), {
|
|
|
|
type: 'bubble',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
label: 'Commerces par ville',
|
|
|
|
data: statsData,
|
|
|
|
backgroundColor: statsData.map(d => `hsla(120, 60%, 70%, ${d.completion / 120 + 0.2})`),
|
|
|
|
borderColor: 'hsl(120, 60%, 40%)',
|
|
|
|
borderWidth: 1,
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
callbacks: {
|
|
|
|
label: function(context) {
|
|
|
|
const data = context.dataset.data[context.dataIndex];
|
|
|
|
let label = data.label || '';
|
|
|
|
if (label) {
|
|
|
|
label += ': ';
|
|
|
|
}
|
|
|
|
label += `${data.placesCount} commerces, ${data.y} pour 1000 hab., ${data.completion}% complétion`;
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
type: 'logarithmic',
|
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: 'Population (échelle log)'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: 'Commerces pour 1000 habitants'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// La fonction est maintenant globale grâce à l'import dans app.js
|
|
|
|
if (typeof colorizePercentageCells === 'function') {
|
|
|
|
colorizePercentageCells('td:nth-child(3)');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gérer le formulaire de labourage
|
|
|
|
const labourageForm = document.getElementById('labourerForm');
|
|
|
|
const citySearchInput = document.getElementById('citySearch');
|
|
|
|
const selectedZipCodeInput = document.getElementById('selectedZipCode');
|
|
|
|
const labourageBtn = labourageForm.querySelector('button[type="submit"]');
|
|
|
|
const originalBtnHtml = labourageBtn.innerHTML;
|
|
|
|
|
|
|
|
if (labourageForm && citySearchInput && typeof setupCitySearch === 'function') {
|
|
|
|
setupCitySearch('citySearch', 'citySuggestions', function (suggestion) {
|
|
|
|
// Afficher le spinner et désactiver le bouton
|
|
|
|
labourageBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Chargement...';
|
|
|
|
labourageBtn.disabled = true;
|
|
|
|
citySearchInput.disabled = true;
|
|
|
|
|
|
|
|
if (suggestion.insee) {
|
|
|
|
window.location.href = `/admin/labourer/${suggestion.insee}`;
|
|
|
|
} else if (suggestion.postcode) {
|
|
|
|
// Moins probable, mais en solution de repli
|
|
|
|
window.location.href = `/admin/labourer/${suggestion.postcode}`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
labourageForm.addEventListener('submit', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
alert("Veuillez rechercher et sélectionner une ville directement dans la liste de suggestions.");
|
|
|
|
});
|
|
|
|
}
|
2025-06-18 00:41:24 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
{% endblock %}
|