Merge pull request 'fix: se agrega como para seleccion de organizaciones para filtrar los procesos por organizacion y ejecutar los procesos por el filtro de organizacion establecido.' (#21) from T2026-01-032 into main
Reviewed-on: #21
This commit is contained in:
@@ -39,6 +39,7 @@ export async function fetchTasks(
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Params:', params.toString());
|
||||
const res = await fetchWithAuth(`${API_URL}/tasks/tasks/?${params.toString()}`);
|
||||
|
||||
if (!res.ok) {
|
||||
@@ -61,6 +62,7 @@ export interface ComandoResponse {
|
||||
// Interfaz para los parámetros de ejecución
|
||||
export interface EjecutarComandoParams {
|
||||
procesamiento?: string;
|
||||
organizacionid?: string;
|
||||
todos?: boolean;
|
||||
}
|
||||
|
||||
@@ -78,6 +80,10 @@ export async function ejecutarComando(
|
||||
if (params.procesamiento !== undefined) {
|
||||
requestData.procesamiento = params.procesamiento;
|
||||
}
|
||||
|
||||
if (params.organizacionid !== undefined) {
|
||||
requestData.organizacionid = params.organizacionid;
|
||||
}
|
||||
|
||||
if (params.todos !== undefined) {
|
||||
requestData.todos = params.todos;
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
|
||||
import { fetchTasks, ejecutarComando } from '../api/procesos.ts';
|
||||
import { fetchWithAuth } from '../fetchWithAuth';
|
||||
import { useNotification } from '../context/NotificationContext';
|
||||
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||
|
||||
// Modal para mostrar detalles del task
|
||||
const TaskDetailsModal = ({ task, onClose }) => {
|
||||
@@ -351,6 +352,10 @@ export default function Procesos() {
|
||||
const [pedimentoPedimentoFilter, setPedimentoPedimentoFilter] = useState('');
|
||||
const [servicioFilter, setServicioFilter] = useState('');
|
||||
const [statusFilter, setStatusFilter] = useState('');
|
||||
|
||||
const [organizacionFilter, setOrganizacionFilter] = useState('');
|
||||
const [organizaciones, setOrganizaciones] = useState([]);
|
||||
const [loadingOrganizaciones, setLoadingOrganizaciones] = useState(false);
|
||||
|
||||
// Sorting
|
||||
const [sortField, setSortField] = useState('');
|
||||
@@ -361,6 +366,7 @@ export default function Procesos() {
|
||||
pedimentoPedimentoFilter: '',
|
||||
statusFilter: '',
|
||||
servicioFilter: '',
|
||||
organizacionFilter: '', // Añadir esta línea
|
||||
sortField: '',
|
||||
sortOrder: 'asc'
|
||||
});
|
||||
@@ -374,6 +380,7 @@ export default function Procesos() {
|
||||
pedimentoPedimentoFilter,
|
||||
servicioFilter,
|
||||
statusFilter,
|
||||
organizacionFilter, // Añadir esta línea
|
||||
sortField,
|
||||
sortOrder
|
||||
};
|
||||
@@ -401,6 +408,7 @@ export default function Procesos() {
|
||||
if (pedimentoPedimentoFilter) filters['pedimento_app'] = pedimentoPedimentoFilter;
|
||||
if (servicioFilter) filters['servicio'] = servicioFilter;
|
||||
if (statusFilter) filters['status'] = statusFilter;
|
||||
if (organizacionFilter) filters['organizacion'] = organizacionFilter; // Añadir esta línea
|
||||
if (sortField) {
|
||||
// Mapear campos antiguos a nuevos si es necesario
|
||||
const fieldMapping = {
|
||||
@@ -426,17 +434,31 @@ export default function Procesos() {
|
||||
}
|
||||
}
|
||||
fetchData();
|
||||
}, [page, itemsPerPage, pedimentoPedimentoFilter, servicioFilter, statusFilter, sortField, sortOrder]);
|
||||
}, [page, itemsPerPage, pedimentoPedimentoFilter, servicioFilter, statusFilter, organizacionFilter, sortField, sortOrder]);
|
||||
|
||||
const [showProcesosDropdown, setShowProcesosDropdown] = useState(false);
|
||||
const [ejecutandoProceso, setEjecutandoProceso] = useState(false);
|
||||
|
||||
const handleEjecutarProcesamiento = async (params) => {
|
||||
// Verificar si se ha seleccionado una organización
|
||||
if (!organizacionFilter) {
|
||||
showMessage('Debes seleccionar una organización antes de ejecutar el proceso', 'warning');
|
||||
return; // Detener la ejecución
|
||||
}
|
||||
|
||||
try {
|
||||
setEjecutandoProceso(true);
|
||||
setShowProcesosDropdown(false);
|
||||
|
||||
const resultado = await ejecutarComando(params);
|
||||
|
||||
// Agregar el ID de la organización a los parámetros
|
||||
const paramsConOrganizacion = {
|
||||
...params,
|
||||
organizacionid: organizacionFilter // Solo necesitamos el ID
|
||||
};
|
||||
|
||||
console.log('Ejecutando proceso con parámetros:', paramsConOrganizacion);
|
||||
|
||||
const resultado = await ejecutarComando(paramsConOrganizacion);
|
||||
|
||||
if (resultado.message) {
|
||||
// Mostrar mensaje de éxito
|
||||
@@ -481,6 +503,27 @@ useEffect(() => {
|
||||
};
|
||||
}, [showProcesosDropdown]);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchOrganizaciones() {
|
||||
try {
|
||||
setLoadingOrganizaciones(true);
|
||||
const response = await fetchWithAuth(`${API_URL}/organization/organizaciones/`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setOrganizaciones(data.results || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error al cargar organizaciones:', error);
|
||||
} finally {
|
||||
setLoadingOrganizaciones(false);
|
||||
}
|
||||
}
|
||||
|
||||
fetchOrganizaciones();
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="min-h-screen p-4 bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-100 sm:p-6 lg:p-8">
|
||||
{/* Modal de detalles del task */}
|
||||
@@ -589,7 +632,7 @@ useEffect(() => {
|
||||
</svg>
|
||||
Filtros de búsqueda
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<div className="space-y-2">
|
||||
<label className="flex items-center gap-2 text-sm font-semibold text-gray-700">
|
||||
<div className="w-2 h-2 bg-blue-500 rounded-full"></div>
|
||||
@@ -653,6 +696,33 @@ useEffect(() => {
|
||||
<option value="9">Acuse Cove</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="flex items-center gap-2 text-sm font-semibold text-gray-700">
|
||||
<div className="w-2 h-2 bg-teal-500 rounded-full"></div>
|
||||
Organización
|
||||
</label>
|
||||
<select
|
||||
className="w-full px-4 py-3 text-sm transition-all duration-200 bg-white border border-gray-300 shadow-sm rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 hover:shadow-md"
|
||||
disabled={loadingOrganizaciones}
|
||||
value={organizacionFilter}
|
||||
onChange={e => {
|
||||
setOrganizacionFilter(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
>
|
||||
<option value="">Todas las organizaciones</option>
|
||||
{loadingOrganizaciones ? (
|
||||
<option value="" disabled>Cargando organizaciones...</option>
|
||||
) : (
|
||||
organizaciones.map((org) => (
|
||||
<option key={org.id} value={org.id}>
|
||||
{org.nombre}
|
||||
</option>
|
||||
))
|
||||
)}
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* BOTÓN PARA EJECUTAR PROCESAMIENTOS - AGREGAR AQUÍ */}
|
||||
|
||||
Reference in New Issue
Block a user