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
@@ -39,6 +39,7 @@ export async function fetchTasks(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('Params:', params.toString());
|
||||||
const res = await fetchWithAuth(`${API_URL}/tasks/tasks/?${params.toString()}`);
|
const res = await fetchWithAuth(`${API_URL}/tasks/tasks/?${params.toString()}`);
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
@@ -61,6 +62,7 @@ export interface ComandoResponse {
|
|||||||
// Interfaz para los parámetros de ejecución
|
// Interfaz para los parámetros de ejecución
|
||||||
export interface EjecutarComandoParams {
|
export interface EjecutarComandoParams {
|
||||||
procesamiento?: string;
|
procesamiento?: string;
|
||||||
|
organizacionid?: string;
|
||||||
todos?: boolean;
|
todos?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +80,10 @@ export async function ejecutarComando(
|
|||||||
if (params.procesamiento !== undefined) {
|
if (params.procesamiento !== undefined) {
|
||||||
requestData.procesamiento = params.procesamiento;
|
requestData.procesamiento = params.procesamiento;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.organizacionid !== undefined) {
|
||||||
|
requestData.organizacionid = params.organizacionid;
|
||||||
|
}
|
||||||
|
|
||||||
if (params.todos !== undefined) {
|
if (params.todos !== undefined) {
|
||||||
requestData.todos = params.todos;
|
requestData.todos = params.todos;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
|
|||||||
import { fetchTasks, ejecutarComando } from '../api/procesos.ts';
|
import { fetchTasks, ejecutarComando } from '../api/procesos.ts';
|
||||||
import { fetchWithAuth } from '../fetchWithAuth';
|
import { fetchWithAuth } from '../fetchWithAuth';
|
||||||
import { useNotification } from '../context/NotificationContext';
|
import { useNotification } from '../context/NotificationContext';
|
||||||
|
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||||
|
|
||||||
// Modal para mostrar detalles del task
|
// Modal para mostrar detalles del task
|
||||||
const TaskDetailsModal = ({ task, onClose }) => {
|
const TaskDetailsModal = ({ task, onClose }) => {
|
||||||
@@ -351,6 +352,10 @@ export default function Procesos() {
|
|||||||
const [pedimentoPedimentoFilter, setPedimentoPedimentoFilter] = useState('');
|
const [pedimentoPedimentoFilter, setPedimentoPedimentoFilter] = useState('');
|
||||||
const [servicioFilter, setServicioFilter] = useState('');
|
const [servicioFilter, setServicioFilter] = useState('');
|
||||||
const [statusFilter, setStatusFilter] = useState('');
|
const [statusFilter, setStatusFilter] = useState('');
|
||||||
|
|
||||||
|
const [organizacionFilter, setOrganizacionFilter] = useState('');
|
||||||
|
const [organizaciones, setOrganizaciones] = useState([]);
|
||||||
|
const [loadingOrganizaciones, setLoadingOrganizaciones] = useState(false);
|
||||||
|
|
||||||
// Sorting
|
// Sorting
|
||||||
const [sortField, setSortField] = useState('');
|
const [sortField, setSortField] = useState('');
|
||||||
@@ -361,6 +366,7 @@ export default function Procesos() {
|
|||||||
pedimentoPedimentoFilter: '',
|
pedimentoPedimentoFilter: '',
|
||||||
statusFilter: '',
|
statusFilter: '',
|
||||||
servicioFilter: '',
|
servicioFilter: '',
|
||||||
|
organizacionFilter: '', // Añadir esta línea
|
||||||
sortField: '',
|
sortField: '',
|
||||||
sortOrder: 'asc'
|
sortOrder: 'asc'
|
||||||
});
|
});
|
||||||
@@ -374,6 +380,7 @@ export default function Procesos() {
|
|||||||
pedimentoPedimentoFilter,
|
pedimentoPedimentoFilter,
|
||||||
servicioFilter,
|
servicioFilter,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
organizacionFilter, // Añadir esta línea
|
||||||
sortField,
|
sortField,
|
||||||
sortOrder
|
sortOrder
|
||||||
};
|
};
|
||||||
@@ -401,6 +408,7 @@ export default function Procesos() {
|
|||||||
if (pedimentoPedimentoFilter) filters['pedimento_app'] = pedimentoPedimentoFilter;
|
if (pedimentoPedimentoFilter) filters['pedimento_app'] = pedimentoPedimentoFilter;
|
||||||
if (servicioFilter) filters['servicio'] = servicioFilter;
|
if (servicioFilter) filters['servicio'] = servicioFilter;
|
||||||
if (statusFilter) filters['status'] = statusFilter;
|
if (statusFilter) filters['status'] = statusFilter;
|
||||||
|
if (organizacionFilter) filters['organizacion'] = organizacionFilter; // Añadir esta línea
|
||||||
if (sortField) {
|
if (sortField) {
|
||||||
// Mapear campos antiguos a nuevos si es necesario
|
// Mapear campos antiguos a nuevos si es necesario
|
||||||
const fieldMapping = {
|
const fieldMapping = {
|
||||||
@@ -426,17 +434,31 @@ export default function Procesos() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetchData();
|
fetchData();
|
||||||
}, [page, itemsPerPage, pedimentoPedimentoFilter, servicioFilter, statusFilter, sortField, sortOrder]);
|
}, [page, itemsPerPage, pedimentoPedimentoFilter, servicioFilter, statusFilter, organizacionFilter, sortField, sortOrder]);
|
||||||
|
|
||||||
const [showProcesosDropdown, setShowProcesosDropdown] = useState(false);
|
const [showProcesosDropdown, setShowProcesosDropdown] = useState(false);
|
||||||
const [ejecutandoProceso, setEjecutandoProceso] = useState(false);
|
const [ejecutandoProceso, setEjecutandoProceso] = useState(false);
|
||||||
|
|
||||||
const handleEjecutarProcesamiento = async (params) => {
|
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 {
|
try {
|
||||||
setEjecutandoProceso(true);
|
setEjecutandoProceso(true);
|
||||||
setShowProcesosDropdown(false);
|
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) {
|
if (resultado.message) {
|
||||||
// Mostrar mensaje de éxito
|
// Mostrar mensaje de éxito
|
||||||
@@ -481,6 +503,27 @@ useEffect(() => {
|
|||||||
};
|
};
|
||||||
}, [showProcesosDropdown]);
|
}, [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 (
|
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">
|
<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 */}
|
{/* Modal de detalles del task */}
|
||||||
@@ -589,7 +632,7 @@ useEffect(() => {
|
|||||||
</svg>
|
</svg>
|
||||||
Filtros de búsqueda
|
Filtros de búsqueda
|
||||||
</h3>
|
</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">
|
<div className="space-y-2">
|
||||||
<label className="flex items-center gap-2 text-sm font-semibold text-gray-700">
|
<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>
|
<div className="w-2 h-2 bg-blue-500 rounded-full"></div>
|
||||||
@@ -653,6 +696,33 @@ useEffect(() => {
|
|||||||
<option value="9">Acuse Cove</option>
|
<option value="9">Acuse Cove</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
{/* BOTÓN PARA EJECUTAR PROCESAMIENTOS - AGREGAR AQUÍ */}
|
{/* BOTÓN PARA EJECUTAR PROCESAMIENTOS - AGREGAR AQUÍ */}
|
||||||
|
|||||||
Reference in New Issue
Block a user