Feat Workers Prioridades y Nivel Serilog
This commit is contained in:
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -7,6 +7,7 @@ import { ConfiguracionGeneral } from './ConfiguracionGeneral';
|
||||
import { BancasManager } from './BancasManager';
|
||||
import { LogoOverridesManager } from './LogoOverridesManager';
|
||||
import { CandidatoOverridesManager } from './CandidatoOverridesManager';
|
||||
import { WorkerManager } from './WorkerManager';
|
||||
|
||||
export const DashboardPage = () => {
|
||||
const { logout } = useAuth();
|
||||
@@ -35,6 +36,8 @@ export const DashboardPage = () => {
|
||||
</div>
|
||||
<ConfiguracionGeneral />
|
||||
<BancasManager />
|
||||
<hr style={{ margin: '2rem 0' }}/>
|
||||
<WorkerManager />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
|
||||
140
Elecciones-Web/frontend-admin/src/components/WorkerManager.tsx
Normal file
140
Elecciones-Web/frontend-admin/src/components/WorkerManager.tsx
Normal file
@@ -0,0 +1,140 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { getConfiguracion, updateConfiguracion, updateLoggingLevel } from '../services/apiService';
|
||||
import type { ConfiguracionResponse } from '../services/apiService';
|
||||
|
||||
// --- Componente de Switch reutilizable para la UI ---
|
||||
const Switch = ({ label, isChecked, onChange }: { label: string, isChecked: boolean, onChange: (checked: boolean) => void }) => (
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: '0.5rem', cursor: 'pointer' }}>
|
||||
<input type="checkbox" checked={isChecked} onChange={e => onChange(e.target.checked)} />
|
||||
{label}
|
||||
</label>
|
||||
);
|
||||
|
||||
export const WorkerManager = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// Estados locales para manejar los valores de la UI
|
||||
const [resultadosActivado, setResultadosActivado] = useState(true);
|
||||
const [bajasActivado, setBajasActivado] = useState(true);
|
||||
const [prioridad, setPrioridad] = useState('Resultados');
|
||||
const [loggingLevel, setLoggingLevel] = useState('Information');
|
||||
|
||||
// Query para obtener la configuración actual desde la API
|
||||
const { data: configData, isLoading } = useQuery<ConfiguracionResponse>({
|
||||
queryKey: ['configuracion'],
|
||||
queryFn: getConfiguracion,
|
||||
});
|
||||
|
||||
// useEffect para sincronizar el estado local con los datos de la API una vez cargados
|
||||
useEffect(() => {
|
||||
if (configData) {
|
||||
setResultadosActivado(configData.Worker_Resultados_Activado === 'true');
|
||||
setBajasActivado(configData.Worker_Bajas_Activado === 'true');
|
||||
setPrioridad(configData.Worker_Prioridad || 'Resultados');
|
||||
setLoggingLevel(configData.Logging_Level || 'Information');
|
||||
}
|
||||
}, [configData]);
|
||||
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
// Creamos dos promesas separadas, una para la config general y otra para el logging
|
||||
const configPromise = updateConfiguracion({
|
||||
...configData,
|
||||
'Worker_Resultados_Activado': resultadosActivado.toString(),
|
||||
'Worker_Bajas_Activado': bajasActivado.toString(),
|
||||
'Worker_Prioridad': prioridad,
|
||||
'Logging_Level': loggingLevel,
|
||||
});
|
||||
|
||||
// La llamada al endpoint de logging-level es la que cambia el nivel EN VIVO.
|
||||
const loggingPromise = updateLoggingLevel({ level: loggingLevel });
|
||||
|
||||
// Ejecutamos ambas en paralelo
|
||||
await Promise.all([configPromise, loggingPromise]);
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: ['configuracion'] });
|
||||
alert('Configuración de Workers y Logging guardada.');
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error al guardar la configuración:", error);
|
||||
alert('Error al guardar la configuración.');
|
||||
}
|
||||
};
|
||||
|
||||
const isPrioridadDisabled = !resultadosActivado || !bajasActivado;
|
||||
|
||||
if (isLoading) {
|
||||
return <div className="admin-module"><h3>Gestión de Workers</h3><p>Cargando configuración...</p></div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="admin-module">
|
||||
<h3>Gestión de Workers</h3>
|
||||
<p>Controla el comportamiento de los procesos de captura de datos.</p>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem', borderTop: '1px solid #eee', paddingTop: '1rem' }}>
|
||||
|
||||
{/* --- Switches On/Off --- */}
|
||||
<div style={{ display: 'flex', alignSelf: 'center', gap: '2rem' }}>
|
||||
<Switch
|
||||
label="Activar Worker de Resultados"
|
||||
isChecked={resultadosActivado}
|
||||
onChange={setResultadosActivado}
|
||||
/>
|
||||
<Switch
|
||||
label="Activar Worker de Bancas/Telegramas"
|
||||
isChecked={bajasActivado}
|
||||
onChange={setBajasActivado}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* --- Contenedor para Selectores --- */}
|
||||
<div style={{ display: 'flex', gap: '2rem', alignSelf:'center', alignItems: 'flex-start' }}>
|
||||
{/* --- Selector de Prioridad --- */}
|
||||
<div>
|
||||
<label htmlFor="prioridad-select" style={{ display: 'block', marginBottom: '0.5rem', fontWeight: 500 }}>
|
||||
Prioridad (si ambos están activos)
|
||||
</label>
|
||||
<select
|
||||
id="prioridad-select"
|
||||
value={prioridad}
|
||||
onChange={e => setPrioridad(e.target.value)}
|
||||
disabled={isPrioridadDisabled}
|
||||
style={{ padding: '0.5rem', minWidth: '200px' }}
|
||||
>
|
||||
<option value="Resultados">Resultados (Noche Electoral)</option>
|
||||
<option value="Telegramas">Telegramas (Post-Escrutinio)</option>
|
||||
</select>
|
||||
{isPrioridadDisabled && <small style={{ display: 'block', marginTop: '0.5rem', color: '#666' }}>Activar ambos workers para elegir prioridad.</small>}
|
||||
</div>
|
||||
|
||||
{/* --- NUEVO: Selector de Nivel de Logging --- */}
|
||||
<div>
|
||||
<label htmlFor="logging-select" style={{ display: 'block', marginBottom: '0.5rem', fontWeight: 500 }}>
|
||||
Nivel de Logging (En vivo)
|
||||
</label>
|
||||
<select
|
||||
id="logging-select"
|
||||
value={loggingLevel}
|
||||
onChange={e => setLoggingLevel(e.target.value)}
|
||||
style={{ padding: '0.5rem', minWidth: '200px' }}
|
||||
>
|
||||
<option value="Verbose">Verbose (Máximo detalle)</option>
|
||||
<option value="Debug">Debug</option>
|
||||
<option value="Information">Information (Normal)</option>
|
||||
<option value="Warning">Warning (Advertencias)</option>
|
||||
<option value="Error">Error</option>
|
||||
<option value="Fatal">Fatal (Críticos)</option>
|
||||
</select>
|
||||
<small style={{ display: 'block', marginTop: '0.5rem', color: '#666' }}>Cambia el nivel de log en tiempo real.</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* --- Botón de Guardar --- */}
|
||||
<div style={{ marginTop: '1rem' }}>
|
||||
<button onClick={handleSave}>Guardar Toda la Configuración</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -121,10 +121,10 @@ export const updateLogos = async (data: LogoAgrupacionCategoria[]): Promise<void
|
||||
};
|
||||
|
||||
export const getMunicipiosForAdmin = async (): Promise<MunicipioSimple[]> => {
|
||||
// Ahora usa adminApiClient, que apunta a /api/admin/
|
||||
// La URL final será /api/admin/catalogos/municipios
|
||||
const response = await adminApiClient.get('/catalogos/municipios');
|
||||
return response.data;
|
||||
// Ahora usa adminApiClient, que apunta a /api/admin/
|
||||
// La URL final será /api/admin/catalogos/municipios
|
||||
const response = await adminApiClient.get('/catalogos/municipios');
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// 6. Overrides de Candidatos
|
||||
@@ -135,4 +135,14 @@ export const getCandidatos = async (): Promise<CandidatoOverride[]> => {
|
||||
|
||||
export const updateCandidatos = async (data: CandidatoOverride[]): Promise<void> => {
|
||||
await adminApiClient.put('/candidatos', data);
|
||||
};
|
||||
|
||||
// 7. Gestión de Logging
|
||||
export interface UpdateLoggingLevelData {
|
||||
level: string;
|
||||
}
|
||||
|
||||
export const updateLoggingLevel = async (data: UpdateLoggingLevelData): Promise<void> => {
|
||||
// Este endpoint es específico, no es parte de la configuración general
|
||||
await adminApiClient.put(`/logging-level`, data);
|
||||
};
|
||||
Reference in New Issue
Block a user