diff --git a/src/components/Perifericos/Pregunta7EP.tsx b/src/components/Perifericos/Pregunta7EP.tsx
index 5901232..406a6e3 100644
--- a/src/components/Perifericos/Pregunta7EP.tsx
+++ b/src/components/Perifericos/Pregunta7EP.tsx
@@ -1,6 +1,8 @@
"use client";
import React, { useState, useEffect } from "react";
+import axios from "axios";
+import Cookies from "js-cookie";
import "../../app/styles/layout/pregunta7.scss";
interface Dato {
@@ -8,29 +10,6 @@ interface Dato {
cantidad: number;
}
-const datosSimulados: Dato[] = [
- { nombre: "AULA DE ROBÓTICA 101", cantidad: 18 },
- { nombre: "LAB DE QUÍMICA 201", cantidad: 25 },
- { nombre: "LAB DE FÍSICA 202", cantidad: 30 },
- { nombre: "LAB DE PROGRAMACIÓN 301", cantidad: 40 },
- { nombre: "AULA DE DISEÑO 102", cantidad: 22 },
- { nombre: "LAB ELECTRÓNICA 204", cantidad: 35 },
- { nombre: "LAB COMPUTACIÓN 305", cantidad: 28 },
- { nombre: "AULA INTERACTIVA 106", cantidad: 15 },
- { nombre: "LAB DE INNOVACIÓN 307", cantidad: 33 },
- { nombre: "SALA DE CONFERENCIAS A", cantidad: 12 },
- { nombre: "LAB DE MECATRÓNICA 308", cantidad: 45 },
- { nombre: "LAB DE INTELIGENCIA ARTIFICIAL 309", cantidad: 38 },
- { nombre: "LAB DE REDES 310", cantidad: 27 },
- { nombre: "SALA MULTIMEDIA B", cantidad: 20 },
- { nombre: "LAB DE BIOLOGÍA 205", cantidad: 26 },
- { nombre: "LAB DE MECÁNICA 210", cantidad: 32 },
- { nombre: "AULA DE INGLÉS 110", cantidad: 19 },
- { nombre: "SALA DE DOCENTES", cantidad: 14 },
- { nombre: "LAB DE BIG DATA 311", cantidad: 36 },
- { nombre: "LAB DE CIBERSEGURIDAD 312", cantidad: 29 },
-];
-
export default function Pregunta7EP() {
const [data, setData] = useState
([]);
const [currentPage, setCurrentPage] = useState(1);
@@ -38,8 +17,25 @@ export default function Pregunta7EP() {
const [sortColumn, setSortColumn] = useState(null);
const [sortAsc, setSortAsc] = useState(true);
+ const api_url = process.env.NEXT_PUBLIC_API_URL;
+
useEffect(() => {
- setData(datosSimulados);
+ const token = Cookies.get("token");
+ const headers = { Authorization: `Bearer ${token}` };
+
+ axios
+ .get(`${api_url}/equipos/reporte/contar_laboratorio`, { headers })
+ .then((res) => {
+ const formato: Dato[] = res.data.map((item: any) => ({
+ nombre: item.laboratorio || "SIN NOMBRE",
+ cantidad: item.total || 0,
+ }));
+
+ setData(formato);
+ })
+ .catch((err) => {
+ console.error("Error cargando datos:", err);
+ });
}, []);
const sortedData = React.useMemo(() => {
@@ -80,6 +76,10 @@ export default function Pregunta7EP() {
return (
+
+ Numero de laboratorios.
+
+
Mostrar
@@ -99,7 +99,10 @@ export default function Pregunta7EP() {
- handleSort("nombre")}>
+ handleSort("nombre")}
+ style={{ textAlign: "center" }}
+ >
Nombre del laboratorio o aula
{sortColumn === "nombre" && (
- handleSort("cantidad")}>
+ handleSort("cantidad")}
+ style={{ textAlign: "center" }}
+ >
Cantidad
{sortColumn === "cantidad" && (
([]);
+ const [currentPage, setCurrentPage] = useState(1);
+ const [recordsPerPage, setRecordsPerPage] = useState(10);
+ const [sortColumn, setSortColumn] = useState(null);
+ const [sortAsc, setSortAsc] = useState(true);
+
+ const api_url = process.env.NEXT_PUBLIC_API_URL;
+
+ useEffect(() => {
+ const token = Cookies.get("token");
+ const headers = { Authorization: `Bearer ${token}` };
+
+ axios
+ .get(`${api_url}/equipos/reporte/contar_proyecto`, { headers })
+ .then((res) => {
+ const formato: Dato[] = res.data.map((item: any) => ({
+ nombre: item.proyecto || "SIN PROYECTO",
+ cantidad: Number(item.total) || 0,
+ }));
+
+ setData(formato);
+ })
+ .catch((err) => {
+ console.error("Error cargando datos:", err);
+ });
+ }, []);
+
+ const sortedData = React.useMemo(() => {
+ if (!sortColumn) return data;
+ return [...data].sort((a, b) => {
+ if (a[sortColumn] < b[sortColumn]) return sortAsc ? -1 : 1;
+ if (a[sortColumn] > b[sortColumn]) return sortAsc ? 1 : -1;
+ return 0;
+ });
+ }, [data, sortColumn, sortAsc]);
+
+ const paginatedData = React.useMemo(() => {
+ const start = (currentPage - 1) * recordsPerPage;
+ return sortedData.slice(start, start + recordsPerPage);
+ }, [sortedData, currentPage, recordsPerPage]);
+
+ const totalPages = Math.ceil(sortedData.length / recordsPerPage);
+
+ const handleSort = (column: keyof Dato) => {
+ if (sortColumn === column) {
+ setSortAsc(!sortAsc);
+ } else {
+ setSortColumn(column);
+ setSortAsc(true);
+ }
+ setCurrentPage(1);
+ };
+
+ const handleRecordsPerPageChange = (
+ e: React.ChangeEvent
+ ) => {
+ setRecordsPerPage(Number(e.target.value));
+ setCurrentPage(1);
+ };
+
+ const startItem = (currentPage - 1) * recordsPerPage + 1;
+ const endItem = Math.min(startItem + recordsPerPage - 1, sortedData.length);
+
+ return (
+
+
Numero de proyectos.
+
+
+ Mostrar
+
+ 5
+ 10
+ 25
+
+ registros
+
+
+ Mostrando {startItem} al {endItem} de {sortedData.length} resultados
+
+
+
+
+
+
+
+ handleSort("nombre")}
+ style={{ textAlign: "center" }}
+ >
+ Proyecto
+ {sortColumn === "nombre" && (
+
+ )}
+
+
+ handleSort("cantidad")}
+ style={{ textAlign: "center" }}
+ >
+ Cantidad
+ {sortColumn === "cantidad" && (
+
+ )}
+
+
+
+
+
+ {paginatedData.map((item, index) => (
+
+ {item.nombre}
+ {item.cantidad}
+
+ ))}
+
+
+
+
+
+ setCurrentPage((prev) => Math.max(prev - 1, 1))}
+ disabled={currentPage === 1}
+ >
+ {"<"}
+
+
+ {Array.from({ length: totalPages }, (_, i) => i + 1).map((page) => (
+ setCurrentPage(page)}
+ className={page === currentPage ? "active" : ""}
+ >
+ {page}
+
+ ))}
+
+
+ setCurrentPage((prev) => Math.min(prev + 1, totalPages))
+ }
+ disabled={currentPage === totalPages}
+ >
+ {">"}
+
+
+
+ );
+}