@ -13,6 +13,7 @@ import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.Icon ;
import com.vaadin.flow.component.icon.VaadinIcon ;
import com.vaadin.flow.component.notification.Notification ;
import com.vaadin.flow.component.notification.NotificationVariant ;
import com.vaadin.flow.component.orderedlayout.FlexComponent ;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout ;
import com.vaadin.flow.component.orderedlayout.VerticalLayout ;
@ -28,12 +29,14 @@ import com.vaadin.flow.router.Route;
import de.f0rce.signaturepad.SignaturePad ;
import jakarta.annotation.security.PermitAll ;
import mx.gob.jumapacelaya.models.DepartamentosModel ;
import mx.gob.jumapacelaya.models.TiposHardware ;
import mx.gob.jumapacelaya.models.TiposMantenimiento ;
import mx.gob.jumapacelaya.models.Usuario ;
import mx.gob.jumapacelaya.services.DatabaseService ;
import java.time.LocalDate ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.List ;
@ -111,7 +114,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
} else if ( "2" . equals ( tipoSeleccionado . getTipomantId ( ) ) ) { / / 2 es para CORRECTIVO
this . fecha . clear ( ) ;
etiquetaLayout . setVisible ( true ) ;
correctivoLayout ( ) ; / / Asegúrate de que este método se llame
correctivoLayout ( ) ;
} else {
/ / Para otros tipos de mantenimiento
this . fecha . clear ( ) ;
@ -199,10 +202,10 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
/ / Metodo para agregar un nuevo ComboBox de tipo de hardware y campos de texto
private List < HorizontalLayout > hardwareLayouts = new ArrayList < > ( ) ;
private void addNuevoTipo ( ) {
ComboBox < String > tipoHardware = new ComboBox < > ( ) ;
List < String > tiposHardware = databaseService . getTiposHardware ( ) ;
tipoHardware . setItems ( tiposHardware ) ;
ComboBox < TiposHardware > tipoHardware = new ComboBox < > ( ) ;
tipoHardware . setPlaceholder ( "Tipo de hardware" ) ;
tipoHardware . setItemLabelGenerator ( TiposHardware : : getNombreHardware ) ;
tipoHardware . setItems ( databaseService . getTiposHardware ( ) ) ;
tipoHardware . setSizeFull ( ) ;
NumberField noSerie = new NumberField ( ) ;
@ -224,11 +227,15 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
placa . setSizeFull ( ) ;
tipoHardware . addValueChangeListener ( event - > {
String tipoSeleccionado = event . getValue ( ) ;
TiposHardware tipoSeleccionado = event . getValue ( ) ;
if ( tipoSeleccionado ! = null ) {
int tipoId = Integer . parseInt ( tipoSeleccionado ) ;
if ( tipoId = = 6 | | tipoId = = 7 ) {
String nombreTipo = tipoSeleccionado . getNombreHardware ( ) ;
if ( "TECLADO" . equals ( nombreTipo ) ) {
noSerie . setEnabled ( false ) ;
modelo . setEnabled ( false ) ;
placa . setEnabled ( false ) ;
} else if ( "MOUSE" . equals ( nombreTipo ) ) {
noSerie . setEnabled ( false ) ;
modelo . setEnabled ( false ) ;
placa . setEnabled ( false ) ;
@ -454,44 +461,72 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
int mantenimientoId = databaseService . getUltimoMantenimientoId ( ) ;
for ( HorizontalLayout layout : hardwareLayouts ) {
ComboBox < String > tipoHardware = ( ComboBox < String > ) layout . getComponentAt ( 0 ) ;
ComboBox < TiposHardware > tipoHardware = ( ComboBox < TiposHardware > ) layout . getComponentAt ( 0 ) ; / / Ahora es ComboBox < TiposHardware >
NumberField noSerie = ( NumberField ) layout . getComponentAt ( 1 ) ;
TextField modelo = ( TextField ) layout . getComponentAt ( 2 ) ;
NumberField placa = ( NumberField ) layout . getComponentAt ( 3 ) ;
TiposHardware tipoSeleccionado = tipoHardware . getValue ( ) ;
/ / Definir tipos de hardware opcionales ( sin necesidad de modelo , número de serie y placa )
List < String > tiposOpcionales = Arrays . asList ( "TECLADO" , "MOUSE" ) ;
/ / Verificar si el tipo de hardware es opcional
boolean esOpcional = tipoSeleccionado ! = null & & tiposOpcionales . contains ( tipoSeleccionado . getNombreHardware ( ) ) ;
/ / Validar campos solo si el tipo de hardware no es opcional
int numSerieInt = noSerie . getValue ( ) ! = null ? noSerie . getValue ( ) . intValue ( ) : 0 ;
int placaInt = placa . getValue ( ) ! = null ? placa . getValue ( ) . intValue ( ) : 0 ;
/ / Validaciones antes de insertar detalles del hardware
if ( tipoHardware . getValue ( ) = = null | | modelo . getValue ( ) = = null | | numSerieInt < = 0 | | placaInt < = 0 ) {
Notification . show ( "Por favor, completa todos los campos de hardware" , 4000 , Notification . Position . MIDDLE ) ;
return ;
if ( ! esOpcional ) {
if ( tipoHardware . getValue ( ) = = null | | modelo . getValue ( ) = = null | | numSerieInt < = 0 | | placaInt < = 0 ) {
Notification . show ( "Por favor, completa todos los campos de hardware" , 4000 , Notification . Position . MIDDLE )
. addThemeVariants ( NotificationVariant . LUMO_WARNING ) ;
return ;
}
} else {
if ( tipoSeleccionado = = null ) {
Notification . show ( "Por favor, selecciona un tipo de hardware" , 4000 , Notification . Position . MIDDLE )
. addThemeVariants ( NotificationVariant . LUMO_WARNING ) ;
return ;
}
}
/ / Obtener el ID de tipo de hardware seleccionado
String tipoHardwareId = tipoSeleccionado . getTipoHardwareId ( ) ;
boolean isHardwareInserted = databaseService . insertarHardware (
tipoHardware . getValue ( ) ,
tipoHardwareId , / / Ahora usamos el ID del tipo de hardware
numSerieInt ,
modelo . getValue ( ) ,
placaInt ,
mantenimientoId
) ;
/ / Limpiar los campos después de la inserción
tipoHardware . clear ( ) ;
modelo . clear ( ) ;
placa . clear ( ) ;
noSerie . clear ( ) ;
if ( ! isHardwareInserted ) {
Notification . show ( "Error al insertar detalles del hardware" , 4000 , Notification . Position . MIDDLE ) ;
Notification . show ( "Error al insertar detalles del hardware" , 4000 , Notification . Position . MIDDLE )
. addThemeVariants ( NotificationVariant . LUMO_ERROR ) ;
return ;
}
}
/ / AQUI MANEJO LA INSERCION DE LOS DATOS DE LOS CHECKBOXES DE ACTUALIZACIONES DE SEGURIDAD ! ! !
for ( String actualizacionSelecionada : actualizaciones . getSelectedItems ( ) ) {
boolean isActualizacionInserted = databaseService . insertActualizacionSeg ( actualizacionSelecionada , null , mantenimientoId ) ;
if ( ! isActualizacionInserted ) {
Notification . show ( "Error al insertar actualizacion de seguridad" , 4000 , Notification . Position . MIDDLE ) ;
Notification . show ( "Error al insertar actualizacion de seguridad" , 4000 , Notification . Position . MIDDLE )
. addThemeVariants ( NotificationVariant . LUMO_ERROR ) ;
return ;
}
}
@ -503,14 +538,17 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
boolean isOtrasActualizaciones = databaseService . insertActualizacionSeg ( actualizacion , otrasActu , mantenimientoId ) ;
if ( ! isOtrasActualizaciones ) {
Notification . show ( "Error al insertar otras actualizaciones de seguridad" , 4000 , Notification . Position . MIDDLE ) ;
Notification . show ( "Error al insertar otras actualizaciones" , 4000 , Notification . Position . MIDDLE )
. addThemeVariants ( NotificationVariant . LUMO_ERROR ) ;
return ;
}
}
}
/ / NOTIFICACION DE GUARDADO EXITOSO Y LIMPIEZA DE LOS CAMPOS ! ! !
Notification . show ( "!!Mantenimiento guardado exitosamente!!" , 4000 , Notification . Position . MIDDLE ) ;
Notification . show ( "!!Mantenimiento guardado exitosamente!!" , 4000 , Notification . Position . MIDDLE )
. addThemeVariants ( NotificationVariant . LUMO_SUCCESS ) ;
fecha . clear ( ) ;
tipoMantt . clear ( ) ;
area . clear ( ) ;
@ -552,12 +590,29 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
}
/ / Cambiamos el valor por el ID
/ * if ( "1" . equals ( tipoParam ) ) { / / 1 es para PREVENTIVO
tipoMantt . setValue ( "1" ) ; / / Establecemos el ID en el ComboBox
tipoMantt . setReadOnly ( true ) ;
} else if ( "2" . equals ( tipoParam ) ) { / / 2 es para CORRECTIVO
tipoMantt . setValue ( "2" ) ;
tipoMantt . setReadOnly ( true ) ;
} * /
if ( "1" . equals ( tipoParam ) ) { / / 1 es para PREVENTIVO
TiposMantenimiento preventivo = tipoMantt . getDataProvider ( )
. fetch ( new com . vaadin . flow . data . provider . Query < > ( ) )
. filter ( tipo - > "1" . equals ( tipo . getTipomantId ( ) ) )
. findFirst ( )
. orElse ( null ) ;
if ( preventivo ! = null ) {
tipoMantt . setValue ( preventivo ) ;
tipoMantt . setReadOnly ( true ) ;
}
} else if ( "2" . equals ( tipoParam ) ) { / / 2 es para CORRECTIVO
TiposMantenimiento correctivo = tipoMantt . getDataProvider ( )
. fetch ( new com . vaadin . flow . data . provider . Query < > ( ) )
. filter ( tipo - > "2" . equals ( tipo . getTipomantId ( ) ) )
. findFirst ( )
. orElse ( null ) ;
if ( correctivo ! = null ) {
tipoMantt . setValue ( correctivo ) ;
tipoMantt . setReadOnly ( true ) ;
}
}
}
}