IMPLEMENTACION DE LOS VIDEOS EN EL CATALOGO PUBLICO
This commit is contained in:
@@ -186,6 +186,7 @@ async function cargarEstadisticas() {
|
||||
|
||||
document.getElementById('statProductos').textContent = productos.length;
|
||||
document.getElementById('statCategorias').textContent = categorias.length;
|
||||
cargarRedes(); // carga la sección de videos
|
||||
} catch (err) {
|
||||
console.error('Error cargando estadísticas:', err);
|
||||
}
|
||||
@@ -1858,12 +1859,15 @@ function setupProductosSearch() {
|
||||
// EXCEL/CSV — asignar nombre + precio por referencia
|
||||
// ════════════════════════════════
|
||||
function setupExcelUpload() {
|
||||
const input = document.getElementById('excelArchivo');
|
||||
const hint = document.getElementById('excelArchivoHint');
|
||||
const form = document.getElementById('formExcelUpload');
|
||||
const btn = document.getElementById('btnProcesarExcel');
|
||||
const input = document.getElementById('excelArchivo');
|
||||
const hint = document.getElementById('excelArchivoHint');
|
||||
const form = document.getElementById('formExcelUpload');
|
||||
const btn = document.getElementById('btnProcesarExcel');
|
||||
const selBtn = document.getElementById('btnSeleccionarExcel');
|
||||
if (!input || !form) return;
|
||||
|
||||
selBtn.addEventListener('click', () => input.click());
|
||||
|
||||
input.addEventListener('change', () => {
|
||||
const f = input.files && input.files[0];
|
||||
if (f) {
|
||||
@@ -2744,3 +2748,106 @@ function initGestores() {
|
||||
|
||||
// cargarDescargas() ahora usa los gestores
|
||||
// (definido arriba en la sección DESCARGAS)
|
||||
|
||||
// ════════════════════════════════
|
||||
// VIDEOS — gestión desde Dashboard
|
||||
// ════════════════════════════════
|
||||
async function cargarRedes() {
|
||||
await cargarListadoVideos();
|
||||
setupVideosForm();
|
||||
}
|
||||
|
||||
async function cargarListadoVideos() {
|
||||
const listEl = document.getElementById('videosList');
|
||||
const errEl = document.getElementById('videosError');
|
||||
errEl.classList.remove('show');
|
||||
try {
|
||||
const res = await fetch('/api/videos');
|
||||
const videos = await res.json();
|
||||
if (videos.length === 0) {
|
||||
listEl.innerHTML = '<p class="pedidos-empty" style="margin:0">No hay videos. Sube el primero.</p>';
|
||||
return;
|
||||
}
|
||||
listEl.innerHTML = videos.map(v => `
|
||||
<div class="video-item">
|
||||
<video src="${v.url}" controls preload="metadata" style="width:200px;border-radius:8px;max-height:120px;background:#000"></video>
|
||||
<span class="video-filename" title="${escapeHtml(v.filename)}">${escapeHtml(v.filename)}</span>
|
||||
<button type="button" class="video-delete" data-filename="${v.filename}" title="Eliminar">✕</button>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
listEl.querySelectorAll('.video-delete').forEach(btn => {
|
||||
btn.addEventListener('click', async () => {
|
||||
if (!confirm('¿Eliminar este video?')) return;
|
||||
try {
|
||||
const res = await fetch(`/api/videos/${btn.dataset.filename}`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include'
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || 'Error al eliminar');
|
||||
}
|
||||
await cargarListadoVideos();
|
||||
} catch (err) {
|
||||
errEl.textContent = err.message;
|
||||
errEl.classList.add('show');
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
listEl.innerHTML = `<p class="pedidos-empty" style="margin:0">Error: ${err.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
function setupVideosForm() {
|
||||
const btn = document.getElementById('btnSubirVideo');
|
||||
const input = document.getElementById('videoFileInput');
|
||||
const errEl = document.getElementById('videosError');
|
||||
const selBtn = document.getElementById('btnSeleccionarVideo');
|
||||
const nameEl = document.getElementById('videoFileName');
|
||||
if (!btn || btn.dataset.vidWired) return;
|
||||
btn.dataset.vidWired = '1';
|
||||
|
||||
selBtn.addEventListener('click', () => input.click());
|
||||
|
||||
input.addEventListener('change', () => {
|
||||
nameEl.textContent = input.files[0] ? input.files[0].name : 'Ningún archivo seleccionado';
|
||||
});
|
||||
|
||||
async function subir() {
|
||||
const file = input.files[0];
|
||||
if (!file) {
|
||||
errEl.textContent = 'Selecciona un archivo de video';
|
||||
errEl.classList.add('show');
|
||||
return;
|
||||
}
|
||||
errEl.classList.remove('show');
|
||||
btn.disabled = true;
|
||||
btn.textContent = '⏳ Subiendo…';
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append('video', file);
|
||||
const res = await fetch('/api/videos', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: fd
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || 'Error al subir');
|
||||
}
|
||||
input.value = '';
|
||||
nameEl.textContent = 'Ningún archivo seleccionado';
|
||||
await cargarListadoVideos();
|
||||
} catch (err) {
|
||||
errEl.textContent = err.message;
|
||||
errEl.classList.add('show');
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = '+ Subir video';
|
||||
}
|
||||
}
|
||||
|
||||
btn.addEventListener('click', subir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user