-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-map.html
More file actions
368 lines (335 loc) · 17.6 KB
/
Copy pathadmin-map.html
File metadata and controls
368 lines (335 loc) · 17.6 KB
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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Admin - Corrector de farmacias</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: system-ui, sans-serif; background: #0d1117; color: #e6edf3; padding: 20px; }
.container { max-width: 1200px; margin: 0 auto; }
h1 { margin-bottom: 20px; color: #3fb950; font-size: 1.5rem; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { background: #161b22; border-radius: 16px; border: 1px solid #30363d; padding: 20px; }
.campo { margin-bottom: 15px; }
.campo label { display: block; font-size: 12px; color: #7d8590; margin-bottom: 4px; }
.campo input, .campo textarea { width: 100%; background: #0d1117; border: 1px solid #30363d; color: #e6edf3; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.coordenadas { background: #0d1117; padding: 12px; border-radius: 12px; margin: 15px 0; display: flex; gap: 10px; }
.coordenadas input { flex: 1; background: #0d1117; border: 1px solid #30363d; color: #e6edf3; padding: 6px 8px; border-radius: 8px; font-size: 12px; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
button { background: #3fb950; color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; }
button:hover { background: #2c974b; }
.btn-descargar { background: #1f6feb; }
.btn-gmaps { background: #ea4335; }
.estado { background: #0d1117; padding: 10px; border-radius: 8px; margin-top: 15px; text-align: center; font-size: 13px; }
#map { height: 500px; border-radius: 16px; border: 1px solid #30363d; }
#gmaps-frame { border-radius: 16px; }
.progress { background: #30363d; border-radius: 20px; height: 8px; width: 100%; margin: 20px 0; }
.progress-bar { background: #3fb950; border-radius: 20px; height: 8px; width: 0%; transition: width 0.3s; }
.badge { background: #3fb950; color: #0d1117; padding: 2px 8px; border-radius: 20px; font-size: 11px; margin-left: 10px; }
@media (max-width: 768px) { .grid { grid-template-columns: 1fr; } }
</style>
</head>
<body>
<script>
const PASSWORD = 'pasteldepapasconpasasdeuva';
const userInput = prompt('🔐 Contraseña de administrador:');
if (userInput !== PASSWORD) {
document.body.innerHTML = '<div style="display:flex; justify-content:center; align-items:center; height:100vh;"><div style="text-align:center;"><h1>⛔ Acceso denegado</h1><p>Contraseña incorrecta.</p></div></div>';
throw new Error('Acceso denegado');
}
</script>
<div class="container">
<h1>✏️ Editor completo de farmacias</h1>
<div class="progress"><div class="progress-bar" id="progress-bar"></div></div>
<div class="grid">
<div class="panel">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;">
<h2 id="farm-nombre" style="margin: 0;">Cargando... <span class="badge" id="contador">0/0</span></h2>
<button id="btn-lista" style="background: #30363d; color: #e6edf3; border: 1px solid #30363d; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12px;">📋 Ver lista</button>
</div>
<div id="panel-lista" style="display: none; max-height: 300px; overflow-y: auto; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; padding: 8px; margin-bottom: 12px;"></div>
<div class="campo"><label>🏷️ Nombre</label><input type="text" id="input-nombre"></div>
<div class="campo"><label>📍 Dirección</label><textarea id="input-direccion" rows="2"></textarea></div>
<div class="campo"><label>📞 Teléfono</label><input type="text" id="input-telefono"></div>
<div class="coordenadas"><input type="text" id="input-lat" placeholder="Latitud"><input type="text" id="input-lng" placeholder="Longitud"></div>
<div class="buttons">
<button id="btn-correcta">✅ Guardar y siguiente</button>
<button id="btn-anterior">⏪ Anterior</button>
<button id="btn-gmaps" class="btn-gmaps">📍 Buscar dirección</button>
<button id="btn-descargar" class="btn-descargar">💾 Descargar JSON</button>
</div>
<div id="estado" class="estado">📝 Editá los campos o arrastrá el pin</div>
</div>
<div class="panel" style="padding:0; display: flex; flex-direction: column;">
<div style="display: flex; gap: 4px; padding: 8px; background: #161b22; border-bottom: 1px solid #30363d;">
<button id="tab-leaflet" style="flex:1; padding: 6px; background: #3fb950; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 12px;">🗺️ Editar (Leaflet)</button>
<button id="tab-gmaps" style="flex:1; padding: 6px; background: #30363d; color: #e6edf3; border: none; border-radius: 6px; cursor: pointer; font-size: 12px;">📍 Google Maps</button>
</div>
<div style="flex:1; position: relative;">
<div id="map"></div>
<iframe id="gmaps-frame" style="display:none; width:100%; height:100%; border:none;"></iframe>
</div>
</div>
</div>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
let todasFarmacias = [];
let currentIndex = 0;
let currentMarker = null;
let map = null;
const pharmacyIcon = L.divIcon({
className: 'custom-pharmacy-icon',
html: '<svg width="34" height="34" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z" fill="#3fb950" stroke="white" stroke-width="1.5"/><path d="M12 7L12 13M9 10L15 10" stroke="white" stroke-width="1.5" stroke-linecap="round"/></svg>',
iconSize: [34, 34],
popupAnchor: [0, -17]
});
async function cargarFarmacias() {
const res = await fetch('db.json');
const ciclosData = await res.json();
const unicas = new Map();
for (const grupo in ciclosData) {
for (const f of ciclosData[grupo]) {
const key = `${f.nombre}|${f.direccion}`;
if (!unicas.has(key)) {
unicas.set(key, {
nombre: f.nombre,
direccion: f.direccion,
telefono: f.telefono,
lat: f.lat,
lng: f.lng,
keyOriginal: key
});
}
}
}
todasFarmacias = Array.from(unicas.values());
todasFarmacias.sort((a, b) => a.nombre.localeCompare(b.nombre));
actualizarProgreso();
mostrarFarmacia(0);
}
function mostrarFarmacia(index) {
const f = todasFarmacias[index];
if (!f) return;
document.getElementById('input-nombre').value = f.nombre || '';
document.getElementById('input-direccion').value = f.direccion || '';
document.getElementById('input-telefono').value = f.telefono || '';
document.getElementById('input-lat').value = f.lat != null ? f.lat.toFixed(6) : '';
document.getElementById('input-lng').value = f.lng != null ? f.lng.toFixed(6) : '';
document.getElementById('farm-nombre').innerHTML = `${f.nombre || '?'} <span class="badge">${index+1}/${todasFarmacias.length}</span>`;
actualizarMapa(f);
actualizarGoogleMaps();
}
function actualizarMapa(f) {
if (!map) {
map = L.map('map').setView([-38.0055, -57.5426], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap' }).addTo(map);
}
if (currentMarker) map.removeLayer(currentMarker);
if (window.markerGoogle) map.removeLayer(window.markerGoogle);
const lat = parseFloat(document.getElementById('input-lat').value);
const lng = parseFloat(document.getElementById('input-lng').value);
const pos = (!isNaN(lat) && !isNaN(lng)) ? [lat, lng] : [-38.0055, -57.5426];
currentMarker = L.marker(pos, { draggable: true, icon: pharmacyIcon }).addTo(map);
currentMarker.bindPopup(`<b>${f.nombre}</b><br>${f.direccion}<br><small>Arrastrá para corregir</small>`).openPopup();
currentMarker.on('dragend', () => {
const newPos = currentMarker.getLatLng();
document.getElementById('input-lat').value = newPos.lat.toFixed(6);
document.getElementById('input-lng').value = newPos.lng.toFixed(6);
actualizarFarmaciaDesdeCampos();
});
map.setView(pos, 16);
}
function actualizarGoogleMaps() {
const f = todasFarmacias[currentIndex];
if (f && f.direccion && document.getElementById('gmaps-frame').style.display !== 'none') {
const query = encodeURIComponent(f.direccion + ', Mar del Plata, Argentina');
document.getElementById('gmaps-frame').src = `https://www.google.com/maps?q=${query}&output=embed&z=16`;
}
}
async function buscarDireccionEnGoogle() {
const f = todasFarmacias[currentIndex];
if (!f || !f.direccion) return;
const queries = [
f.direccion + ', Mar del Plata, Argentina',
f.direccion.replace(/AV\.? ?/i, 'Avenida ') + ', Mar del Plata, Argentina',
f.direccion + ', Mar del Plata',
f.direccion
];
let data = null;
for (const query of queries) {
const url = `https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(query)}&limit=1&countrycodes=ar`;
try {
const response = await fetch(url);
data = await response.json();
if (data.length > 0) break;
} catch (e) { continue; }
}
if (data && data.length > 0) {
const googleLat = parseFloat(data[0].lat);
const googleLng = parseFloat(data[0].lon);
const iconoGoogle = L.divIcon({
className: 'custom-google-icon',
html: '<svg width="34" height="34" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z" fill="#4285F4" stroke="white" stroke-width="1.5"/><circle cx="12" cy="9" r="3" fill="white"/></svg>',
iconSize: [34, 34],
popupAnchor: [0, -17]
});
if (window.markerGoogle) map.removeLayer(window.markerGoogle);
window.markerGoogle = L.marker([googleLat, googleLng], { icon: iconoGoogle }).addTo(map);
window.markerGoogle.bindPopup(`<b>Resultado</b><br>${data[0].display_name}<br><small>¿Usar estas coordenadas?</small><br><button onclick="usarCoordenadasGoogle(${googleLat}, ${googleLng})" style="margin-top:4px; padding:4px 8px; background:#4285F4; color:white; border:none; border-radius:4px; cursor:pointer;">✅ Usar estas</button>`).openPopup();
document.getElementById('tab-leaflet').click();
map.setView([googleLat, googleLng], 16);
document.getElementById('estado').innerHTML = '📍 Resultado encontrado. Compará con el pin verde.';
document.getElementById('estado').style.color = '#4285F4';
} else {
document.getElementById('estado').innerHTML = '❌ No se encontró la dirección. Probá manualmente.';
document.getElementById('estado').style.color = '#f85149';
}
}
function usarCoordenadasGoogle(lat, lng) {
document.getElementById('input-lat').value = lat.toFixed(6);
document.getElementById('input-lng').value = lng.toFixed(6);
actualizarFarmaciaDesdeCampos();
const f = todasFarmacias[currentIndex];
actualizarMapa(f);
document.getElementById('estado').innerHTML = '✅ Coordenadas aplicadas';
document.getElementById('estado').style.color = '#3fb950';
}
window.usarCoordenadasGoogle = usarCoordenadasGoogle;
function actualizarFarmaciaDesdeCampos() {
const f = todasFarmacias[currentIndex];
f.nombre = document.getElementById('input-nombre').value.trim();
f.direccion = document.getElementById('input-direccion').value.trim();
f.telefono = document.getElementById('input-telefono').value.trim();
const lat = parseFloat(document.getElementById('input-lat').value);
const lng = parseFloat(document.getElementById('input-lng').value);
if (!isNaN(lat)) f.lat = lat;
if (!isNaN(lng)) f.lng = lng;
document.getElementById('estado').innerHTML = '✅ Cambios guardados localmente. Descargá el JSON al final.';
document.getElementById('estado').style.color = '#3fb950';
}
function siguiente() {
actualizarFarmaciaDesdeCampos();
if (currentIndex + 1 < todasFarmacias.length) {
currentIndex++;
mostrarFarmacia(currentIndex);
actualizarProgreso();
} else {
document.getElementById('estado').innerHTML = '🎉 Terminaste! Descargá el JSON.';
}
}
function anterior() {
actualizarFarmaciaDesdeCampos();
if (currentIndex - 1 >= 0) {
currentIndex--;
mostrarFarmacia(currentIndex);
actualizarProgreso();
}
}
async function descargarJSON() {
actualizarFarmaciaDesdeCampos();
const res = await fetch('db.json');
const dbOriginal = await res.json();
const ciclosData = {};
for (const grupo in dbOriginal) {
ciclosData[grupo] = [];
for (const farmacia of dbOriginal[grupo]) {
const key = `${farmacia.nombre}|${farmacia.direccion}`;
const encontrada = todasFarmacias.find(f => f.keyOriginal === key);
if (encontrada) {
ciclosData[grupo].push({
nombre: encontrada.nombre,
direccion: encontrada.direccion,
telefono: encontrada.telefono,
lat: encontrada.lat,
lng: encontrada.lng
});
} else {
ciclosData[grupo].push(farmacia);
}
}
}
let jsonStr = '{\n';
const grupos = Object.keys(ciclosData);
grupos.forEach((grupo, idxGrupo) => {
jsonStr += ` "${grupo}": [\n`;
ciclosData[grupo].forEach((f, i) => {
const lat = f.lat != null ? f.lat : null;
const lng = f.lng != null ? f.lng : null;
jsonStr += ` { "nombre": "${f.nombre.replace(/"/g, '\\"')}", "direccion": "${f.direccion.replace(/"/g, '\\"')}", "telefono": "${f.telefono}", "lat": ${lat}, "lng": ${lng} }`;
if (i < ciclosData[grupo].length - 1) jsonStr += ',';
jsonStr += '\n';
});
jsonStr += ' ]';
if (idxGrupo < grupos.length - 1) jsonStr += ',';
jsonStr += '\n';
});
jsonStr += '}';
const blob = new Blob([jsonStr], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'db.json';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
document.getElementById('estado').innerHTML = '✅ JSON descargado con coordenadas actualizadas.';
document.getElementById('estado').style.color = '#3fb950';
}
function actualizarProgreso() {
const porcentaje = (currentIndex / todasFarmacias.length) * 100;
document.getElementById('progress-bar').style.width = `${porcentaje}%`;
}
function bindEvents() {
document.getElementById('btn-correcta').addEventListener('click', siguiente);
document.getElementById('btn-anterior').addEventListener('click', anterior);
document.getElementById('btn-descargar').addEventListener('click', descargarJSON);
document.getElementById('btn-gmaps').addEventListener('click', buscarDireccionEnGoogle);
document.getElementById('tab-leaflet').addEventListener('click', () => {
document.getElementById('map').style.display = 'block';
document.getElementById('gmaps-frame').style.display = 'none';
document.getElementById('tab-leaflet').style.background = '#3fb950';
document.getElementById('tab-gmaps').style.background = '#30363d';
if (map) map.invalidateSize();
});
document.getElementById('tab-gmaps').addEventListener('click', () => {
const f = todasFarmacias[currentIndex];
if (f && f.direccion) {
const query = encodeURIComponent(f.direccion + ', Mar del Plata, Argentina');
document.getElementById('gmaps-frame').src = `https://www.google.com/maps?q=${query}&output=embed&z=16`;
document.getElementById('map').style.display = 'none';
document.getElementById('gmaps-frame').style.display = 'block';
document.getElementById('tab-leaflet').style.background = '#30363d';
document.getElementById('tab-gmaps').style.background = '#ea4335';
}
});
const campos = ['input-nombre', 'input-direccion', 'input-telefono', 'input-lat', 'input-lng'];
campos.forEach(id => {
document.getElementById(id).addEventListener('input', () => {
actualizarFarmaciaDesdeCampos();
const lat = parseFloat(document.getElementById('input-lat').value);
const lng = parseFloat(document.getElementById('input-lng').value);
if (!isNaN(lat) && !isNaN(lng) && currentMarker) currentMarker.setLatLng([lat, lng]);
});
});
}
cargarFarmacias();
document.getElementById('btn-lista').addEventListener('click', () => {
const panel = document.getElementById('panel-lista');
if (panel.style.display === 'none') {
panel.style.display = 'block';
panel.innerHTML = todasFarmacias.map((f, i) =>
`<div style="padding: 6px 8px; cursor: pointer; border-radius: 4px; color: #e6edf3; font-size: 13px; ${i === currentIndex ? 'background: #3fb950; color: #0d1117;' : ''}"
onclick="document.getElementById('panel-lista').style.display='none'; window.mostrarFarmacia(${i});">${i+1}. ${f.nombre} — ${f.direccion}</div>`
).join('');
} else {
panel.style.display = 'none';
}
});
window.mostrarFarmacia = mostrarFarmacia;
bindEvents();
</script>
</body>
</html>