feat: eliminar scripts y vistas obsoletos relacionados con la gestión de items

This commit is contained in:
Shni
2025-10-15 22:44:20 -05:00
parent 9f5b0bbd7b
commit 929f93665c
6 changed files with 0 additions and 427 deletions

View File

@@ -1,59 +0,0 @@
(function(){
// Lightweight replacement for the legacy dashboard items script.
// Responsibilities kept minimal during migration to Item Lab:
// - Fetch and render items list
// - Wire Delete handlers
// - Redirect Edit actions to the Item Lab
const $ = id => document.getElementById(id);
const itemsRoot = $('itemsRoot');
const guildId = itemsRoot && itemsRoot.dataset ? itemsRoot.dataset.guildId : '';
const list = $('itemsList');
async function fetchItems(){
if(!list) return;
list.innerHTML = '<div class="text-white/60">Cargando...</div>';
try{
const res = await fetch('/api/dashboard/' + encodeURIComponent(guildId) + '/items');
if(!res.ok) throw new Error('fetch-failed');
const j = await res.json();
const items = (j && j.ok && Array.isArray(j.items)) ? j.items : [];
renderList(items);
}catch(e){ list.innerHTML = '<div class="text-red-400">Error cargando items</div>'; }
}
function escapeHtml(s){ return String(s||'').replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c])); }
function renderList(items){
if(!list) return;
list.innerHTML = '';
if(!items || items.length===0){ list.innerHTML = '<div class="text-white/60">No hay items</div>'; return; }
items.forEach(it=>{
const card = document.createElement('div');
card.className = 'p-3 bg-white/3 rounded mb-2 flex justify-between items-start';
const left = document.createElement('div'); left.style.flex = '1';
const titleDiv = document.createElement('div'); titleDiv.className='font-semibold text-white'; titleDiv.textContent = it.name || it.key || 'Sin nombre';
const descDiv = document.createElement('div'); descDiv.className = 'text-white/60 text-sm mt-1'; descDiv.textContent = it.description || '';
left.appendChild(titleDiv); left.appendChild(descDiv);
const right = document.createElement('div'); right.className = 'flex items-center gap-2';
const editBtn = document.createElement('button'); editBtn.className='editBtn px-2 py-1 bg-indigo-600 rounded text-white text-sm'; editBtn.textContent='Editar'; editBtn.dataset.id = it.id;
const delBtn = document.createElement('button'); delBtn.className='delBtn px-2 py-1 bg-red-600 rounded text-white text-sm'; delBtn.textContent='Eliminar'; delBtn.dataset.id = it.id;
right.appendChild(editBtn); right.appendChild(delBtn);
card.appendChild(left); card.appendChild(right); list.appendChild(card);
});
Array.from(list.querySelectorAll('.editBtn')).forEach(b=>b.addEventListener('click', onEdit));
Array.from(list.querySelectorAll('.delBtn')).forEach(b=>b.addEventListener('click', onDelete));
}
async function onDelete(e){ const id = e.currentTarget && e.currentTarget.dataset ? e.currentTarget.dataset.id : null; if(!id) return; if(!confirm('Eliminar item?')) return; try{ const res = await fetch('/api/dashboard/' + encodeURIComponent(guildId) + '/items/' + encodeURIComponent(id), { method:'DELETE' }); if(!res.ok) throw new Error('delete-failed'); await fetchItems(); alert('Item eliminado'); }catch(err){ alert('Error al eliminar'); } }
function onEdit(e){ const id = e.currentTarget && e.currentTarget.dataset ? e.currentTarget.dataset.id : null; if(!id) return; window.location.href = '/items/lab?guild=' + encodeURIComponent(guildId) + '&edit=' + encodeURIComponent(id); }
// wire create button (if present) to navigate to lab
const createBtn = $('createItemBtn'); if(createBtn) createBtn.addEventListener('click', (ev)=>{ ev.preventDefault(); window.location.href = '/items/lab?guild=' + encodeURIComponent(guildId); });
// initial load
fetchItems();
})();

View File

@@ -1,59 +0,0 @@
(function(){
// Lightweight replacement for the legacy dashboard items script.
// Responsibilities kept minimal during migration to Item Lab:
// - Fetch and render items list
// - Wire Delete handlers
// - Redirect Edit actions to the Item Lab
const $ = id => document.getElementById(id);
const itemsRoot = $('itemsRoot');
const guildId = itemsRoot && itemsRoot.dataset ? itemsRoot.dataset.guildId : '';
const list = $('itemsList');
async function fetchItems(){
if(!list) return;
list.innerHTML = '<div class="text-white/60">Cargando...</div>';
try{
const res = await fetch('/api/dashboard/' + encodeURIComponent(guildId) + '/items');
if(!res.ok) throw new Error('fetch-failed');
const j = await res.json();
const items = (j && j.ok && Array.isArray(j.items)) ? j.items : [];
renderList(items);
}catch(e){ list.innerHTML = '<div class="text-red-400">Error cargando items</div>'; }
}
function escapeHtml(s){ return String(s||'').replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c])); }
function renderList(items){
if(!list) return;
list.innerHTML = '';
if(!items || items.length===0){ list.innerHTML = '<div class="text-white/60">No hay items</div>'; return; }
items.forEach(it=>{
const card = document.createElement('div');
card.className = 'p-3 bg-white/3 rounded mb-2 flex justify-between items-start';
const left = document.createElement('div'); left.style.flex = '1';
const titleDiv = document.createElement('div'); titleDiv.className='font-semibold text-white'; titleDiv.textContent = it.name || it.key || 'Sin nombre';
const descDiv = document.createElement('div'); descDiv.className = 'text-white/60 text-sm mt-1'; descDiv.textContent = it.description || '';
left.appendChild(titleDiv); left.appendChild(descDiv);
const right = document.createElement('div'); right.className = 'flex items-center gap-2';
const editBtn = document.createElement('button'); editBtn.className='editBtn px-2 py-1 bg-indigo-600 rounded text-white text-sm'; editBtn.textContent='Editar'; editBtn.dataset.id = it.id;
const delBtn = document.createElement('button'); delBtn.className='delBtn px-2 py-1 bg-red-600 rounded text-white text-sm'; delBtn.textContent='Eliminar'; delBtn.dataset.id = it.id;
right.appendChild(editBtn); right.appendChild(delBtn);
card.appendChild(left); card.appendChild(right); list.appendChild(card);
});
Array.from(list.querySelectorAll('.editBtn')).forEach(b=>b.addEventListener('click', onEdit));
Array.from(list.querySelectorAll('.delBtn')).forEach(b=>b.addEventListener('click', onDelete));
}
async function onDelete(e){ const id = e.currentTarget && e.currentTarget.dataset ? e.currentTarget.dataset.id : null; if(!id) return; if(!confirm('Eliminar item?')) return; try{ const res = await fetch('/api/dashboard/' + encodeURIComponent(guildId) + '/items/' + encodeURIComponent(id), { method:'DELETE' }); if(!res.ok) throw new Error('delete-failed'); await fetchItems(); alert('Item eliminado'); }catch(err){ alert('Error al eliminar'); } }
function onEdit(e){ const id = e.currentTarget && e.currentTarget.dataset ? e.currentTarget.dataset.id : null; if(!id) return; window.location.href = '/dashboard/' + encodeURIComponent(guildId) + '/items/lab?edit=' + encodeURIComponent(id); }
// wire create button (if present) to navigate to lab
const createBtn = $('createItemBtn'); if(createBtn) createBtn.addEventListener('click', ()=>{ window.location.href = '/dashboard/' + encodeURIComponent(guildId) + '/items/lab'; });
// initial load
fetchItems();
})();

View File

@@ -1,121 +0,0 @@
(function(){
const $ = id => document.getElementById(id);
// Detect guildId from itemsRoot dataset when embedded, otherwise read ?guild= from query string when opened as standalone page
const guildId = (() => {
try{
const root = document.getElementById('itemsRoot');
if(root && root.dataset && root.dataset.guildId) return root.dataset.guildId;
const p = new URLSearchParams(location.search || '');
return p.get('guild') || '';
}catch(e){ return ''; }
})();
// form elements
const form = $('itemLabForm');
const labKey = $('labKey');
const labName = $('labName');
const labCategory = $('labCategory');
const labIcon = $('labIcon');
const labDescription = $('labDescription');
const labTags = $('labTags');
const labProps = $('labProps');
const labPreview = $('labPreview');
const labReset = $('labReset');
function resetForm(){ labKey.value=''; labName.value=''; labCategory.value=''; labIcon.value=''; labDescription.value=''; labTags.value=''; labProps.value='{}'; renderPreview(); }
function renderPreview(){
const payload = {
key: labKey.value.trim(),
name: labName.value.trim(),
category: labCategory.value.trim(),
icon: labIcon.value.trim(),
description: labDescription.value.trim(),
tags: labTags.value.split(',').map(s=>s.trim()).filter(Boolean),
props: (()=>{ try{ return JSON.parse(labProps.value||'{}'); }catch(e){ return labProps.value||"{}"; } })()
};
labPreview.textContent = JSON.stringify(payload, null, 2);
// update 3D preview (simple animate color based on key length)
if(window.lab3D && typeof window.lab3D.update === 'function') window.lab3D.update(payload);
}
if(form){
form.addEventListener('input', renderPreview);
form.addEventListener('submit', async (ev)=>{
ev.preventDefault();
const payload = {
key: labKey.value.trim(),
name: labName.value.trim(),
category: labCategory.value.trim(),
icon: labIcon.value.trim(),
description: labDescription.value.trim(),
tags: labTags.value.split(',').map(s=>s.trim()).filter(Boolean),
props: (()=>{ try{ return JSON.parse(labProps.value||'{}'); }catch(e){ alert('JSON inválido en Props'); throw e; } })()
};
try{
if(!guildId){ alert('No guildId disponible'); return; }
const res = await fetch('/api/dashboard/' + encodeURIComponent(guildId) + '/items', { method:'POST', headers:{ 'Content-Type':'application/json' }, body: JSON.stringify(payload) });
if(!res.ok){ alert('Error al guardar: HTTP ' + res.status); return; }
alert('Item guardado');
resetForm();
}catch(e){ alert('Error guardando: ' + (e && e.message)); }
});
labReset.addEventListener('click', resetForm);
}
// Prefill when editing: detect ?edit=<id>
(async function tryPrefill(){
try{
const params = new URLSearchParams(location.search || '');
const editId = params.get('edit');
if(!editId) return;
// show temporary loading state
const prev = labPreview.textContent;
labPreview.textContent = 'Cargando item...';
const res = await fetch('/api/dashboard/' + encodeURIComponent(guildId) + '/items/' + encodeURIComponent(editId));
if(!res.ok){ labPreview.textContent = 'Error cargando item: HTTP ' + res.status; return; }
const j = await res.json();
if(!j || !j.ok || !j.item){ labPreview.textContent = 'Item no encontrado'; return; }
const item = j.item;
// populate fields safely
if(labKey) labKey.value = item.key || '';
if(labName) labName.value = item.name || '';
if(labCategory) labCategory.value = item.category || '';
if(labIcon) labIcon.value = item.icon || '';
if(labDescription) labDescription.value = item.description || '';
if(labTags) labTags.value = Array.isArray(item.tags) ? item.tags.join(',') : (item.tags||'');
try{ labProps.value = item.props && typeof item.props === 'object' ? JSON.stringify(item.props, null, 2) : (item.props||'{}'); }catch(e){ labProps.value = '{}'; }
renderPreview();
// update browser history to remove query param (optional)
try{ const u = new URL(location.href); u.searchParams.delete('edit'); window.history.replaceState({}, '', u.toString()); }catch(e){}
}catch(e){ console.warn('prefill failed', e); }
})();
// minimal three.js preview
function init3D(){
try{
const container = $('lab3d');
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, container.clientWidth / container.clientHeight, 0.1, 1000);
camera.position.z = 5;
const renderer = new THREE.WebGLRenderer({ antialias:true });
renderer.setSize(container.clientWidth, container.clientHeight);
container.appendChild(renderer.domElement);
const geometry = new THREE.BoxGeometry(1.5,1.5,1.5);
const material = new THREE.MeshStandardMaterial({ color: 0x336699 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(5,5,5); scene.add(light);
function animate(){ requestAnimationFrame(animate); cube.rotation.x += 0.01; cube.rotation.y += 0.01; renderer.render(scene, camera); }
animate();
window.lab3D = {
update(payload){ try{ const k = (payload && payload.key) ? payload.key.length : 1; const c = Math.max(0.2, Math.min(1, (k%10)/10 + 0.2)); material.color.setRGB(c*0.2, c*0.5, c*0.8); }catch(e){} }
};
window.addEventListener('resize', ()=>{ renderer.setSize(container.clientWidth, container.clientHeight); camera.aspect = container.clientWidth / container.clientHeight; camera.updateProjectionMatrix(); });
}catch(e){ console.warn('3D init failed', e); }
}
resetForm(); renderPreview(); init3D();
})();

View File

@@ -1,72 +0,0 @@
<!DOCTYPE html>
<html lang="es" class="scroll-smooth">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Item Lab</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="/assets/css/styles.css?v=1" />
</head>
<body class="min-h-screen pixel-grid-bg pt-14">
<div id="item-lab-root" class="p-6 max-w-6xl mx-auto">
<h1 class="text-xl font-bold mb-4">Item Lab</h1>
<div class="grid grid-cols-2 gap-4">
<div>
<form id="itemLabForm" class="space-y-4 bg-[#071a2a] p-4 rounded">
<div class="flex gap-2">
<div class="flex-1">
<label>Key</label>
<input id="labKey" class="w-full" />
</div>
<div class="flex-1">
<label>Name</label>
<input id="labName" class="w-full" />
</div>
</div>
<div class="flex gap-2">
<div class="flex-1">
<label>Category</label>
<input id="labCategory" class="w-full" />
</div>
<div class="flex-1">
<label>Icon</label>
<input id="labIcon" class="w-full" />
</div>
</div>
<div>
<label>Description</label>
<textarea id="labDescription" class="w-full h-20"></textarea>
</div>
<div>
<label>Tags (comma)</label>
<input id="labTags" class="w-full" />
</div>
<div>
<label>Props (JSON)</label>
<textarea id="labProps" class="w-full h-32 font-mono"></textarea>
</div>
<div class="flex gap-2 justify-end">
<button type="button" id="labReset" class="btn">Reset</button>
<button type="submit" id="labSave" class="btn btn-primary">Guardar</button>
</div>
</form>
</div>
<div>
<div class="mb-4 bg-[#071a2a] p-4 rounded">
<h2 class="font-semibold mb-2">Preview 3D</h2>
<div id="lab3d" style="width:100%;height:300px;background:#001827;border-radius:6px;"></div>
</div>
<div class="bg-[#071a2a] p-4 rounded">
<h2 class="font-semibold mb-2">Preview JSON</h2>
<pre id="labPreview" class="text-sm max-h-60 overflow-auto p-2"></pre>
</div>
</div>
</div>
</div>
<script src="/assets/js/three.min.js"></script>
<script src="/assets/js/item_lab.js"></script>
</body>
</html>

View File

@@ -1,71 +0,0 @@
<!DOCTYPE html>
<html lang="es" class="scroll-smooth">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Item Lab</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="/assets/css/styles.css?v=1" />
</head>
<body class="min-h-screen pixel-grid-bg pt-14">
<div id="item-lab-root" class="p-6 max-w-6xl mx-auto">
<h1 class="text-xl font-bold mb-4">Item Lab</h1>
<div class="grid grid-cols-2 gap-4">
<div>
<form id="itemLabForm" class="space-y-4 bg-[#071a2a] p-4 rounded">
<div class="flex gap-2">
<div class="flex-1">
<label>Key</label>
<input id="labKey" class="w-full" />
</div>
<div class="flex-1">
<label>Name</label>
<input id="labName" class="w-full" />
</div>
</div>
<div class="flex gap-2">
<div class="flex-1">
<label>Category</label>
<input id="labCategory" class="w-full" />
</div>
<div class="flex-1">
<label>Icon</label>
<input id="labIcon" class="w-full" />
</div>
</div>
<div>
<label>Description</label>
<textarea id="labDescription" class="w-full h-20"></textarea>
</div>
<div>
<label>Tags (comma)</label>
<input id="labTags" class="w-full" />
</div>
<div>
<label>Props (JSON)</label>
<textarea id="labProps" class="w-full h-32 font-mono"></textarea>
</div>
<div class="flex gap-2 justify-end">
<button type="button" id="labReset" class="btn">Reset</button>
<button type="submit" id="labSave" class="btn btn-primary">Guardar</button>
</div>
</form>
</div>
<div>
<div class="mb-4 bg-[#071a2a] p-4 rounded">
<h2 class="font-semibold mb-2">Preview 3D</h2>
<div id="lab3d" style="width:100%;height:300px;background:#001827;border-radius:6px;"></div>
</div>
<div class="bg-[#071a2a] p-4 rounded">
<h2 class="font-semibold mb-2">Preview JSON</h2>
<pre id="labPreview" class="text-sm max-h-60 overflow-auto p-2"></pre>
</div>
</div>
</div>
</div>
<script src="/assets/js/three.min.js"></script>
<script src="/assets/js/item_lab.js"></script>
</body>
</html>

View File

@@ -1,45 +0,0 @@
<div id="itemsRoot" data-guild-id="<%= selectedGuildId ? selectedGuildId : '' %>" class="p-4 bg-gray-800/50 rounded">
<div class="flex items-center justify-between mb-4">
<h2 class="text-white text-lg font-semibold">Items</h2>
<div>
<a id="createItemBtn" href="/items/lab?guild=<%= selectedGuildId %>" class="inline-flex items-center gap-2 px-3 py-1 bg-indigo-600 rounded text-white">Crear item</a>
</div>
</div>
<div id="pageAlert" class="hidden mb-3"></div>
<div id="itemsList" class="space-y-3">
<!-- items will be rendered here by /assets/js/dashboard_items.js -->
</div>
<% if (!selectedGuildId) { %>
<div id="itemsHint" class="mt-3 text-yellow-300">Selecciona un servidor en la barra lateral o inicia sesión para administrar items.</div>
<% } %>
<!-- Modal / form skeleton (minimal) -->
<div id="itemModal" class="hidden fixed inset-0 items-center justify-center bg-black/60">
<div class="bg-[#061427] p-4 rounded w-11/12 max-w-3xl">
<div class="flex items-center justify-between mb-2">
<h3 id="modalTitle" class="text-white text-lg">Crear item</h3>
<button id="cancelItemBtn" class="text-white">✕</button>
</div>
<div id="modalError" class="hidden text-red-400 mb-2"></div>
<form id="itemForm">
<input id="itemId" type="hidden" />
<div class="grid grid-cols-2 gap-2">
<label class="text-white/80">Key <input id="fieldKey" class="w-full" /></label>
<label class="text-white/80">Name <input id="fieldName" class="w-full" /></label>
<label class="text-white/80">Category <input id="fieldCategory" class="w-full" /></label>
<label class="text-white/80">Icon <input id="fieldIcon" class="w-full" /></label>
<label class="text-white/80">Description <input id="fieldDescription" class="w-full" /></label>
<label class="text-white/80">Tags <input id="fieldTags" class="w-full" /></label>
</div>
<div class="mt-3 flex justify-end gap-2">
<button type="button" id="cancelItemBtnBottom" class="px-3 py-1 bg-gray-600 rounded text-white">Cancelar</button>
<button type="submit" class="px-3 py-1 bg-indigo-600 rounded text-white">Guardar</button>
</div>
</form>
</div>
</div>
<script src="/assets/js/dashboard_items.js" defer></script>
</div>