correccion atleta vista
This commit is contained in:
parent
b8513f370b
commit
8455ade1c6
|
@ -84,8 +84,8 @@ function logout() {
|
||||||
window.location.href = "../index.html";
|
window.location.href = "../index.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
function verSimulador(rutinaId, index) {
|
function verSimuladorCompleto(rutinaId) {
|
||||||
window.location.href = `simulador.html?routineId=${rutinaId}&formationIndex=${index}`;
|
window.location.href = `simulador.html?routineId=${rutinaId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cargarAsignaciones() {
|
async function cargarAsignaciones() {
|
||||||
|
@ -107,29 +107,48 @@ async function cargarAsignaciones() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
contenedor.innerHTML = '';
|
// Agrupar por rutinaId
|
||||||
|
const grupos = {};
|
||||||
formaciones.forEach(f => {
|
formaciones.forEach(f => {
|
||||||
|
if (!grupos[f.rutinaId]) {
|
||||||
|
grupos[f.rutinaId] = {
|
||||||
|
nombre: f.rutinaNombre,
|
||||||
|
formaciones: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
grupos[f.rutinaId].formaciones.push(f);
|
||||||
|
});
|
||||||
|
|
||||||
|
contenedor.innerHTML = '';
|
||||||
|
|
||||||
|
Object.entries(grupos).forEach(([rutinaId, grupo]) => {
|
||||||
const card = document.createElement("div");
|
const card = document.createElement("div");
|
||||||
card.className = "card text-start my-3 shadow-sm";
|
card.className = "card text-start my-3 shadow-sm";
|
||||||
|
|
||||||
|
const formacionesHTML = grupo.formaciones.map(f => `
|
||||||
|
<div class="mb-2">
|
||||||
|
<strong>${traducciones[langActual].formacion}:</strong> ${f.nombreColoquial || "—"}<br>
|
||||||
|
<strong>${traducciones[langActual].duracion}:</strong> ${f.duracion || "?"}s<br>
|
||||||
|
<strong>${traducciones[langActual].notas}:</strong> ${f.notasTacticas || "—"}<br>
|
||||||
|
<strong>${traducciones[langActual].rol}:</strong> ${f.atleta.rol || "—"} |
|
||||||
|
<strong>${traducciones[langActual].id}:</strong> ${f.atleta.idPersonalizado || "—"} |
|
||||||
|
<strong>${traducciones[langActual].figura}:</strong> ${f.atleta.figura || "—"}
|
||||||
|
</div>
|
||||||
|
`).join('');
|
||||||
|
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title text-primary fw-bold">${f.rutinaNombre || traducciones[langActual].rutinaSinNombre}</h5>
|
<h5 class="card-title text-primary fw-bold">${grupo.nombre || traducciones[langActual].rutinaSinNombre}</h5>
|
||||||
<h6 class="card-subtitle mb-2 text-muted">${traducciones[langActual].formacion}: ${f.nombreColoquial || "(sin nombre)"}</h6>
|
${formacionesHTML}
|
||||||
<p class="card-text small mb-1">
|
<button class="btn btn-sm btn-outline-success mt-2" onclick="verSimuladorCompleto('${rutinaId}')">
|
||||||
<strong>${traducciones[langActual].duracion}:</strong> ${f.duracion || "?"}s<br>
|
|
||||||
<strong>${traducciones[langActual].notas}:</strong> ${f.notasTacticas || "—"}<br>
|
|
||||||
<strong>${traducciones[langActual].rol}:</strong> ${f.atleta.rol || "N/A"} |
|
|
||||||
<strong>${traducciones[langActual].id}:</strong> ${f.atleta.idPersonalizado || "N/A"} |
|
|
||||||
<strong>${traducciones[langActual].figura}:</strong> ${f.atleta.figura || "—"}
|
|
||||||
</p>
|
|
||||||
<button class="btn btn-sm btn-outline-success" onclick="verSimulador('${f.rutinaId}', ${f.index})">
|
|
||||||
${traducciones[langActual].verSimulacion}
|
${traducciones[langActual].verSimulacion}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
contenedor.appendChild(card);
|
contenedor.appendChild(card);
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ Error al obtener formaciones:", err);
|
console.error("❌ Error al obtener formaciones:", err);
|
||||||
contenedor.innerHTML = `<p>${traducciones[langActual].errorCarga}</p>`;
|
contenedor.innerHTML = `<p>${traducciones[langActual].errorCarga}</p>`;
|
||||||
|
|
|
@ -610,26 +610,30 @@ function animarTransicion(nuevaFormacion) {
|
||||||
return a;
|
return a;
|
||||||
});
|
});
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
nombreColoquial: nombre,
|
nombreColoquial: nombre,
|
||||||
notasTacticas: notas,
|
notasTacticas: notas,
|
||||||
duracion: duracion || 0,
|
duracion: duracion || 0,
|
||||||
atletas: formacionActual.map(a => ({
|
atletas: formacionActual.map(a => ({
|
||||||
atletaId: a.atletaId,
|
atletaId: a.atletaId,
|
||||||
idPersonalizado: a.idPersonalizado,
|
idPersonalizado: a.idPersonalizado,
|
||||||
x: a.x,
|
x: a.x,
|
||||||
y: a.y,
|
y: a.y,
|
||||||
rol: a.rol,
|
rol: a.rol,
|
||||||
grupo: a.grupo,
|
grupo: a.grupo,
|
||||||
direccion: a.direccion,
|
direccion: a.direccion,
|
||||||
figura: a.figura,
|
figura: a.figura,
|
||||||
tipoElemento: a.tipoElemento,
|
tipoElemento: a.tipoElemento,
|
||||||
codigoElemento: a.codigoElemento,
|
codigoElemento: a.codigoElemento,
|
||||||
tipoPiscina: tipoPiscinaSelect.value,
|
tipoPiscina: tipoPiscinaSelect.value,
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
|
// Validación extra: asegura que se esté usando bien el ID de rutina
|
||||||
}))
|
if (!rutinaId) {
|
||||||
};
|
alert('No se puede guardar porque falta el ID de rutina.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const method = editIndex === null ? 'POST' : 'PUT';
|
const method = editIndex === null ? 'POST' : 'PUT';
|
||||||
const endpoint = editIndex === null
|
const endpoint = editIndex === null
|
||||||
|
|
|
@ -66,7 +66,8 @@ document.getElementById('langSelector')?.addEventListener('change', async (e) =>
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
const rutinaId = new URLSearchParams(window.location.search).get("routineId");
|
const rutinaId = new URLSearchParams(window.location.search).get("routineId");
|
||||||
const formationIndex = parseInt(new URLSearchParams(window.location.search).get("formationIndex"));
|
const formationIndexParam = new URLSearchParams(window.location.search).get("formationIndex");
|
||||||
|
const formationIndex = formationIndexParam !== null ? parseInt(formationIndexParam) : 0;
|
||||||
|
|
||||||
const userId = sessionStorage.getItem("userId");
|
const userId = sessionStorage.getItem("userId");
|
||||||
if (userId) {
|
if (userId) {
|
||||||
|
@ -87,8 +88,8 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
|
||||||
translateStatic();
|
translateStatic();
|
||||||
|
|
||||||
if (!rutinaId || isNaN(formationIndex)) {
|
if (!rutinaId) {
|
||||||
return alert("No se proporcionó ID de rutina o índice de formación.");
|
return alert("No se proporcionó ID de rutina.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const tituloRutina = document.getElementById("tituloRutina");
|
const tituloRutina = document.getElementById("tituloRutina");
|
||||||
|
@ -221,19 +222,36 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const formaciones = await fetch(`/api/rutinas/${rutinaId}/formations`).then(res => res.json());
|
const formaciones = await fetch(`/api/rutinas/${rutinaId}/formations`).then(res => res.json());
|
||||||
const formacion = formaciones[formationIndex];
|
|
||||||
|
|
||||||
if (!formacion) {
|
if (!Array.isArray(formaciones) || formaciones.length === 0) {
|
||||||
alert("La formación solicitada no existe.");
|
alert("La rutina no tiene formaciones.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
formacion.atletas.forEach(dibujarAtleta);
|
// Crear botones de la línea de tiempo
|
||||||
|
formaciones.forEach((f, i) => {
|
||||||
|
const block = document.createElement("button");
|
||||||
|
block.className = "btn btn-outline-primary btn-sm me-2 step";
|
||||||
|
block.textContent = `${f.nombreColoquial || `Formación ${i + 1}`} (${f.duracion || '?'}s)`;
|
||||||
|
block.dataset.index = i;
|
||||||
|
block.title = f.notasTacticas || '';
|
||||||
|
timeline.appendChild(block);
|
||||||
|
});
|
||||||
|
|
||||||
const block = document.createElement("button");
|
function renderFormacion(index) {
|
||||||
block.className = "btn btn-outline-primary btn-sm me-2 step";
|
const formacion = formaciones[index];
|
||||||
block.textContent = `${formacion.nombreColoquial || `Formación ${formationIndex + 1}`} (${formacion.duracion || '?'}s)`;
|
if (!formacion) return;
|
||||||
block.dataset.index = formationIndex;
|
|
||||||
block.title = formacion.notasTacticas || '';
|
layer.destroyChildren();
|
||||||
timeline.appendChild(block);
|
dibujarCuadricula(layer, piscinaWidth, piscinaHeight);
|
||||||
|
formacion.atletas.forEach(dibujarAtleta);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderFormacion(formationIndex);
|
||||||
|
|
||||||
|
timeline.addEventListener('click', (e) => {
|
||||||
|
if (!e.target.classList.contains('step')) return;
|
||||||
|
const index = parseInt(e.target.dataset.index);
|
||||||
|
renderFormacion(index);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue