gestor_models/list_tables.php
2025-06-25 08:47:02 -04:00

99 lines
3.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Listar Tablas</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container py-5">
<div class="card shadow-sm">
<div class="card-header bg-secondary text-white d-flex justify-content-between align-items-center">
<h3 class="mb-0">Modelos en la Base de Datos</h3>
<a href="register_model.php" class="btn btn-success"> Agregar Modelo</a>
</div>
<div class="card-body">
<table id="tables" class="table table-striped" style="width:100%">
<thead class="table-dark">
<tr>
<th>Nombre</th>
<th>Versión</th>
<th>Tamaño/Peso</th>
<th>Capas</th>
<th class="text-center">Acción</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
<script>
$(function() {
$('#tables').DataTable({
serverSide: true,
processing: true,
ajax: 'ajax/get_tables.php',
columns: [{
data: 'name',
title: 'Nombre'
},
{
data: 'version',
title: 'Versión'
},
{
data: 'model_size',
title: 'Tamaño/Peso'
},
{
data: 'layers',
title: 'Capas'
},
{
data: null,
orderable: false,
className: 'text-center',
title: 'Acción',
render: d => `
<button class="btn btn-info btn-sm me-1" onclick="editarModelo(${d.id})">Editar</button>
<button class="btn btn-danger btn-sm mx-1" onclick="eliminarModelo(${d.id}, this)">Eliminar</button>
`
}
],
language: {
url: '//cdn.datatables.net/plug-ins/1.13.4/i18n/es-ES.json'
}
});
});
function eliminarModelo(id, btn) {
if (confirm('¿Seguro que deseas eliminar este modelo?')) {
$.post('ajax/delete_model.php', {
id: id
}, function(resp) {
if (resp.success) {
// Elimina la fila de la tabla sin recargar
$('#tables').DataTable().row($(btn).parents('tr')).remove().draw();
} else {
alert('No se pudo eliminar el modelo');
}
}, 'json');
}
}
function editarModelo(id) {
// Redirige al formulario de edición con el ID del modelo
window.location.href = 'editar_modelo.php?id=' + id;
}
</script>
</body>
</html>