-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarquesdata.html
529 lines (445 loc) · 24.3 KB
/
marquesdata.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Formulaire d'ajout de données</title>
<meta name="title" content="France Fabrique - Découvrez le Made in France">
<meta name="description" content="France Fabrique vous permet de visualiser tout le Made in France : usines, boutiques, marques et bien plus encore. Explorez la richesse de la production française.">
<meta name="keywords" content="Made in France, usines, boutiques, marques, production française, fabriqué en France, industrie française, artisanat français, produits français">
<meta name="robots" content="index, follow">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/flowbite.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@supabase/[email protected]/dist/umd/supabase.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster/dist/MarkerCluster.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster/dist/MarkerCluster.Default.css" />
<style>
body {
font-family: Arial, sans-serif;
}
input, textarea, select {
width: 100%;
padding: 8px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
width: 100%;
padding: 10px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
}
.hidden {
display: none;
}
#openModal, #AddMarker {
display: none; /* Le bouton est caché par défaut */
}
#map {
height: 400px;
width: 100%;
}
</style>
</head>
<body>
<nav class="bg-white border-gray-200 dark:bg-gray-900">
<div class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4">
<a href="/" class="flex items-center space-x-3 rtl:space-x-reverse">
<img src="fav.png" class="h-8" alt="FranceFabrique.fr Logo" />
<span class="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">FranceFabrique.fr</span>
</a>
<button data-collapse-toggle="navbar-default" type="button" class="inline-flex items-center p-2 w-10 h-10 justify-center text-sm text-gray-500 rounded-lg md:hidden hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600" aria-controls="navbar-default" aria-expanded="false">
<span class="sr-only">Open main menu</span>
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 17 14">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h15M1 7h15M1 13h15"/>
</svg>
</button>
<div class="hidden w-full md:block md:w-auto" id="navbar-default">
<ul class="font-medium flex flex-col p-4 md:p-0 mt-4 border border-gray-100 rounded-lg bg-gray-50 md:flex-row md:space-x-8 rtl:space-x-reverse md:mt-0 md:border-0 md:bg-white dark:bg-gray-800 md:dark:bg-gray-900 dark:border-gray-700">
<li>
<a href="marquelisting.html" class="block py-2 px-3 text-white bg-white-700 rounded md:bg-transparent md:text-white-700 md:p-0 dark:text-white md:dark:text-white-500" aria-current="page">Listing des marques</a>
</li>
<li>
<a href="form.html" class="block py-2 px-3 text-white bg-white-700 rounded md:bg-transparent md:text-white-700 md:p-0 dark:text-white md:dark:text-white-500" aria-current="page">Ajout de marker</a>
</li>
<li>
<a href="marque.html" class="block py-2 px-3 text-white bg-white-700 rounded md:bg-transparent md:text-white-700 md:p-0 dark:text-white md:dark:text-white-500" aria-current="page">Ajout d'une marque</a>
</li>
</ul>
</div>
</div>
</nav>
<button id="openModal" class="py-2 px-4 bg-indigo-600 text-white rounded-md shadow-md hover:bg-indigo-700">
Modifier la Marque
</button>
<div id="data-container"></div>
<!-- La Modal -->
<div id="modal" class="hidden fixed inset-0 bg-gray-800 bg-opacity-50 flex justify-center items-center z-50">
<div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-lg">
<button id="closeModal" class="absolute top-2 right-2 text-gray-600 hover:text-gray-900">
×
</button>
<h1 class="text-center text-3xl font-semibold mb-8">Modifier la Marque</h1>
<form id="editForm" class="space-y-4">
<div>
<label for="password" class="block text-sm font-medium text-gray-700">Mot de passe :</label>
<input type="password" id="password" name="password" required class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="nom" class="block text-sm font-medium text-gray-700">Nom :</label>
<input type="text" id="nom" name="nom" required class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="description" class="block text-sm font-medium text-gray-700">Description :</label>
<textarea id="description" name="description" required class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"></textarea>
</div>
<div>
<label for="image" class="block text-sm font-medium text-gray-700">URL de l'image :</label>
<input type="url" id="image" name="image" required class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="logo" class="block text-sm font-medium text-gray-700">Logo :</label>
<input type="url" id="logo" name="logo" required class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="link" class="block text-sm font-medium text-gray-700">Lien :</label>
<input type="url" id="link" name="link" required class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<button type="submit" class="w-full py-2 bg-indigo-600 text-white rounded-md shadow-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500">
Mettre a jour
</button>
</div>
</form>
</div>
</div>
<div id="modaladdmarker" class="hidden fixed inset-0 bg-gray-800 bg-opacity-50 flex justify-center items-center z-50">
<div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-lg">
<button id="closeModaladdmarker" class="absolute top-2 right-2 text-gray-600 hover:text-gray-900">
×
</button>
<h1 class="text-center text-3xl font-semibold mb-8">Ajouter un marker</h1>
<form id="markerForm">
<label for="markerSelect" class="block text-sm font-medium text-gray-700">Markers</label>
<select id="markerSelect" name="marker" class="block w-full mt-2 p-2 border border-gray-300 rounded-lg">
<!-- Les options seront insérées ici dynamiquement -->
</select>
<div class="mt-4 flex justify-end">
<button type="button" id="validateButtonAddMarker" class="bg-blue-600 text-white px-4 py-2 rounded-lg">Valider</button>
</div>
</form>
</div>
</div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet.markercluster/dist/leaflet.markercluster.js"></script>
<script type="module">
const urlParams = new URLSearchParams(window.location.search);
// Vérifier si 'edit=true' est présent
if (urlParams.get('edit') === 'true') {
// Afficher le bouton si la condition est remplie
document.getElementById('openModal').style.display = 'block';
// document.getElementById('AddMarker').style.display = 'block';
}
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm';
import { SUPABASE_URL, SUPABASE_KEY } from './config.js';
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
// Fonction pour récupérer l'ID depuis l'URL http://localhost:8000/marquesdata.html?id=3
function getIdFromUrl() {
const params = new URLSearchParams(window.location.search);
return params.get("id"); // Récupère ?id=xxx dans l'URL
}
// Fonction principale pour afficher les données
async function displayData(id) {
const dataContainer = document.getElementById("data-container");
// Récupère les données
const data = await fetchDataById(id);
dataContainer.innerHTML = `
<div class="bg-white">
<div class="mx-auto grid max-w-2xl grid-cols-1 items-center gap-x-8 gap-y-16 px-4 py-24 sm:px-6 sm:py-32 lg:max-w-7xl lg:grid-cols-2 lg:px-8">
<div id="map"></div>
<div>
<h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">${data.Name}</h2>
<p class="mt-4 text-gray-500">${data.Description}</p>
<br>
<a href="${data.link}" target="_blank" class="inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">
Visiter
<svg class="rtl:rotate-180 w-3.5 h-3.5 ms-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 10">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5h12m0 0L9 1m4 4L9 9"/>
</svg>
</a>
<a id="AddMarker" class="inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">
Ajouter un Marker
</a>
</div>
<div class="grid grid-cols-2 grid-rows-2 gap-4 sm:gap-6 lg:gap-8">
<!-- Images statiques, ou dynamisées en fonction des données -->
<img src="${data.Logo}" alt="${data.Name} - Image 1" class="rounded-lg bg-gray-100">
<img src="${data.image}" alt="${data.Name} - Image 2" class="rounded-lg bg-gray-100">
</div>
</div>
</div>
`;
if (urlParams.get('edit') === 'true') {
document.getElementById('AddMarker').style.display = 'block';
}
}
// Fonction pour simuler une base de données ou un appel API
async function fetchDataById(id) {
const { data, error } = await supabase
.from("Marques") // Remplacez par le nom de votre table
.select("*") // Sélectionner toutes les colonnes
.eq("id", id) // Condition : id = celui passé en paramètre
.single(); // Récupérer une seule ligne (si l'ID est unique)
if (error) {
console.error("Erreur lors de la récupération :", error);
return null;
}
return data;
}
// Fonction pour se connecter
async function signIn(password) {
const datauser = await supabase.auth.signInWithPassword({
email: '[email protected]', // Remplacez par votre email
password: password, // Remplacez par votre mot de passe
});
return datauser.data.session.access_token
}
// Appelle la fonction une fois la page chargée
const id = getIdFromUrl(); // Récupère l'ID depuis l'URL
const itemIdElement = document.getElementById("item-id");
displayData(id);
// Sélection des éléments
const openModalBtn = document.getElementById('openModal');
const closeModalBtn = document.getElementById('closeModal');
const modal = document.getElementById('modal');
const form = document.getElementById('editForm');
// Ouvrir la modal
openModalBtn.addEventListener('click', () => {
map.classList.add('hidden');
modal.classList.remove('hidden');
const form = document.getElementById('editForm');
const fetchData = async () => {
try {
// Exemples de données récupérées
const data = await fetchDataById(id);
console.log(data)
// Préremplir les champs du formulaire
form.elements['password'].value = data.password || ''; // Par sécurité, ne jamais afficher de mot de passe !
form.elements['nom'].value = data.Name || '';
form.elements['description'].value = data.Description || '';
form.elements['image'].value = data.image || '';
form.elements['logo'].value = data.Logo || '';
form.elements['link'].value = data.link || '';
} catch (error) {
console.error('Erreur lors de la récupération des données :', error);
alert('Impossible de charger les données.');
}
};
fetchData();
});
setTimeout(() => {
const AddMarkerBtn = document.getElementById('AddMarker');
const modaladdmarker = document.getElementById('modaladdmarker');
const map = document.getElementById('map');
AddMarkerBtn.addEventListener('click', () => {
map.classList.add('hidden');
modaladdmarker.classList.remove('hidden');
showMarkers();
});
modaladdmarker.addEventListener('click', (event) => {
console.log(event)
if (event.target === modaladdmarker) {
modaladdmarker.classList.add('hidden');
map.classList.remove('hidden');
}
});
},3000);
document.getElementById("validateButtonAddMarker").addEventListener("click", () => {
const select = document.getElementById("markerSelect");
const selectedMarkerId = select.value; // Récupérer l'ID du marker sélectionné
if (!selectedMarkerId) {
alert("Veuillez sélectionner un marker avant de valider.");
return;
}
// Appelez la fonction que vous souhaitez exécuter avec l'ID sélectionné
console.log(selectedMarkerId)
insertMarqueUsine(selectedMarkerId);
// executeFunction(selectedMarkerId);
// closeModal(); // Ferme la modal après validation
});
async function insertMarqueUsine(usineId) {
try {
const id = getIdFromUrl();
// Insérer dans la table Marques_usines
const { data, error } = await supabase
.from("Marques_usines")
.insert([
{
marque_id: id, // ID fixe pour la marque
usines_id: usineId, // ID sélectionné dans la modal
},
]);
if (error) {
console.error("Erreur lors de l'insertion :", error);
alert("Une erreur s'est produite lors de l'ajout. Veuillez réessayer.");
} else {
console.log("Insertion réussie :", data);
alert("Usine ajoutée avec succès !");
}
} catch (err) {
console.error("Erreur inattendue :", err);
alert("Une erreur inattendue s'est produite.");
}
}
async function showMarkers() {
const markerList = await fetchAllMarker(); // Attendez que la promesse soit résolue
console.log(markerList); // Affiche les données une fois qu'elles sont récupérées
const select = document.getElementById("markerSelect");
// Vider les options existantes
select.innerHTML = "";
// Ajouter une option par défaut
select.innerHTML = '<option value="" disabled selected>Choisissez un marker</option>';
// Ajouter les options dynamiquement
markerList.forEach(marker => {
const option = document.createElement("option");
option.value = marker.id; // Supposez que chaque marker a un ID
option.textContent = marker.name || `${marker.title}`; // Ajustez en fonction de vos données
select.appendChild(option);
});
}
async function fetchAllMarker() {
const { data, error } = await supabase
.from('Marker') // Remplacez par le nom de votre table
.select('*'); // Sélectionner toutes les colonnes
if (error) {
console.error('Erreur lors de la récupération des données :', error);
return;
} else {
return data;
}
}
// Fermer la modal
closeModalBtn.addEventListener('click', () => {
modal.classList.add('hidden');
});
// Fermer la modal en cliquant en dehors
modal.addEventListener('click', (event) => {
if (event.target === modal) {
modal.classList.add('hidden');
map.classList.remove('hidden');
}
});
// Soumission du formulaire
form.addEventListener('submit', async (event) => {
event.preventDefault();
const formData = new FormData(form);
const data = Object.fromEntries(formData);
const user = await signIn(data.password);
console.log(user)
if (user) {
const id = getIdFromUrl();
const { data2, error } = await supabase
.from('Marques') // Nom de la table Supabase
.update({
Name: data.nom, // Utilise le nom des colonnes de la table pour les clés
Description: data.description,
image: data.image,
link: data.link,
Logo: data.logo
})
.eq('id', id); // Condition pour mettre à jour (ici, `id` = markerId)
console.log(id);
if (error) {
console.error('Erreur lors de la mise à jour des données :', error);
alert('Erreur lors de la mise à jour du marqueur.');
} else {
// alert('Marqueur mis à jour avec succès !');
// form.reset(); // Réinitialiser le formulaire si nécessaire
}
modal.classList.add('hidden');
} else {
alert('Échec de la connexion. Veuillez vérifier vos informations de connexion.');
}
});
setTimeout(() => {
const map = L.map('map').setView([46.603354, 1.888334], 6);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 18,
}).addTo(map);
const markers = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
// Récupérer le nombre de marqueurs dans le cluster
const markersCount = cluster.getChildCount();
// Choisir une image selon le nombre de marqueurs
let imageUrl = 'cluster.jpg'; // Par défaut, une petite image
// Retourner un DivIcon personnalisé avec l'image
return new L.DivIcon({
html: `<div style="width: 40px; height: 40px; background-image: url(${imageUrl}); background-size: cover; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold;">${markersCount}</div>`,
className: 'marker-cluster',
iconSize: new L.Point(40, 40) // Taille de l'icône
});
}
});
// Définir des icônes pour chaque type
const iconMap = {
usi: L.icon({
iconUrl: 'usi.png',
iconSize: [20, 32],
iconAnchor: [16, 32],
popupAnchor: [0, -32],
className: 'marker-icon'
}),
mag: L.icon({
iconUrl: 'mif.png',
iconSize: [32, 32],
iconAnchor: [16, 32],
popupAnchor: [0, -32],
className: 'marker-icon'
})
};
async function fetchDataMarkerById(id) {
// Récupérer les données depuis Supabase
const { data, error } = await supabase
.from("Marques_usines") // Remplacez par le nom de votre table
.select('Marker(*)') // Sélectionner toutes les colonnes
.eq("marque_id", id);
if (error) {
console.error('Erreur lors de la récupération des données :', error);
return;
}
// Ajouter les marqueurs à la carte
// console.log(data)
data.forEach(point => {
// console.log(point)
const markerIcon = iconMap[point.Marker.type] || L.icon({
iconUrl: 'marker.png',
iconSize: [32, 32],
iconAnchor: [16, 32],
popupAnchor: [0, -32],
className: 'marker-icon'
});
const marker = L.marker([point.Marker.lat, point.Marker.lng], { icon: markerIcon });
const popupContent = `
<div class="popup-content">
<img src="${point.Marker.image}" alt="${point.Marker.title}" />
<h3>${point.Marker.title}</h3>
<p>${point.Marker.description}</p>
<a href="${point.Marker.link}" target="_blank">En savoir plus</a>
</div>
`;
marker.bindPopup(popupContent);
markers.addLayer(marker);
});
map.addLayer(markers);
}
fetchDataMarkerById(id);
}, 1000);
</script>
</body>
</html>