@ -12,7 +12,9 @@ import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.html.Anchor ;
import com.vaadin.flow.component.html.Anchor ;
import com.vaadin.flow.server.StreamRegistration ;
import com.vaadin.flow.server.StreamRegistration ;
import com.vaadin.flow.server.StreamResource ;
import com.vaadin.flow.server.StreamResource ;
import mx.gob.jumapacelaya.services.EmailService ;
import mx.gob.jumapacelaya.services.ReportService ;
import mx.gob.jumapacelaya.services.ReportService ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.security.core.Authentication ;
import org.springframework.security.core.Authentication ;
import org.springframework.security.core.context.SecurityContextHolder ;
import org.springframework.security.core.context.SecurityContextHolder ;
import org.vaadin.lineawesome.LineAwesomeIcon ;
import org.vaadin.lineawesome.LineAwesomeIcon ;
@ -54,7 +56,11 @@ import mx.gob.jumapacelaya.services.SecurityService;
@CssImport ( "./themes/sistema-mantenimiento/styles.css" )
@CssImport ( "./themes/sistema-mantenimiento/styles.css" )
public class DetallesMantView extends VerticalLayout implements BeforeEnterObserver {
public class DetallesMantView extends VerticalLayout implements BeforeEnterObserver {
@Value ( "${app.base-url}" )
private String baseUrl ;
private final H3 id ;
private final H3 id ;
private final EmailService emailService ;
private HorizontalLayout fechasLayout ;
private HorizontalLayout fechasLayout ;
private TextField txtId ;
private TextField txtId ;
private final TextField txtEquipo ;
private final TextField txtEquipo ;
@ -68,9 +74,10 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
private final GridPro < ActualizacioneSeguridadModel > gridActualizaciones ;
private final GridPro < ActualizacioneSeguridadModel > gridActualizaciones ;
private final Button btnEditar ;
private final Button btnEditar ;
private final Button btnEditarFirmas ;
private final Button btnEditarFirmas ;
private final Button btnImprimirRepo ;
private final Button btnImprimirRepo = new Button ( "Imprimir Reporte" , new Icon ( VaadinIcon . PRINT ) ) ;
private final Button btnCancelar ;
private final Button btnCancelar ;
private final Button btnGuardar ;
private final Button btnGuardar ;
private final Button btnEnviarEncuesta = new Button ( "Enviar encuesta" , LineAwesomeIcon . ENVELOPE_SOLID . create ( ) ) ;
private int planAnualIdActual ;
private int planAnualIdActual ;
private int mantenimientoIdActual ;
private int mantenimientoIdActual ;
private Dialog confirmDialog ;
private Dialog confirmDialog ;
@ -88,7 +95,7 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
private final DatabaseService service ;
private final DatabaseService service ;
public DetallesMantView ( SecurityService securityService , DatabaseService service , ReportService reportService ) {
public DetallesMantView ( SecurityService securityService , DatabaseService service , ReportService reportService , EmailService emailService ) {
this . service = service ;
this . service = service ;
setPadding ( true ) ;
setPadding ( true ) ;
@ -192,15 +199,18 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
gridActualizaciones . addThemeVariants ( GridVariant . LUMO_ROW_STRIPES ) ;
gridActualizaciones . addThemeVariants ( GridVariant . LUMO_ROW_STRIPES ) ;
HorizontalLayout botonesHeaderLyt = new HorizontalLayout ( ) ;
botonesHeaderLyt . setWidthFull ( ) ;
botonesHeaderLyt . add ( btnImprimirRepo , btnEnviarEncuesta ) ;
HorizontalLayout botonesLayout = new HorizontalLayout ( ) ;
HorizontalLayout botonesLayout = new HorizontalLayout ( ) ;
botonesLayout . setWidthFull ( ) ;
botonesLayout . setWidthFull ( ) ;
botonesLayout . setJustifyContentMode ( JustifyContentMode . CENTER ) ;
botonesLayout . setJustifyContentMode ( JustifyContentMode . CENTER ) ;
btnEditar = new Button ( "Editar" , new Icon ( VaadinIcon . EDIT ) ) ;
btnEditar = new Button ( "Editar" , new Icon ( VaadinIcon . EDIT ) ) ;
btnImprimirRepo = new Button ( "Imprimir Reporte" , new Icon ( VaadinIcon . PRINT ) ) ;
btnEditarFirmas = new Button ( "Editar firmas" , LineAwesomeIcon . SIGNATURE_SOLID . create ( ) ) ;
btnEditarFirmas = new Button ( "Editar firmas" , LineAwesomeIcon . SIGNATURE_SOLID . create ( ) ) ;
btnGuardar = new Button ( "Guardar" , LineAwesomeIcon . SAVE_SOLID . create ( ) ) ;
btnGuardar = new Button ( "Guardar" , LineAwesomeIcon . SAVE_SOLID . create ( ) ) ;
btnCancelar = new Button ( "Cancelar" , new Icon ( VaadinIcon . CLOSE_CIRCLE_O ) ) ;
btnCancelar = new Button ( "Cancelar" , new Icon ( VaadinIcon . CLOSE_CIRCLE_O ) ) ;
botonesLayout . add ( btnEditar , btnEditarFirmas , btnImprimirRepo , btn Guardar , btnCancelar ) ;
botonesLayout . add ( btnEditar , btnEditarFirmas , btnGuardar , btnCancelar ) ;
btnGuardar . setVisible ( false ) ;
btnGuardar . setVisible ( false ) ;
btnGuardar . getStyle ( ) . set ( "background-color" , "#008000" ) ;
btnGuardar . getStyle ( ) . set ( "background-color" , "#008000" ) ;
@ -294,6 +304,9 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
} ) ;
} ) ;
btnEnviarEncuesta . addClickListener ( e - > enviarCorreo ( ) ) ;
/ / Se dispara el dialogo de confirmacion
/ / Se dispara el dialogo de confirmacion
btnGuardar . addClickListener ( e - > confirmDialog . open ( ) ) ;
btnGuardar . addClickListener ( e - > confirmDialog . open ( ) ) ;
@ -362,7 +375,9 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
addSignatureSection ( ) ;
addSignatureSection ( ) ;
mainLayout . add ( headerLayout , layout2 , fechasLayout , layout3 , gridHardware , gridActualizaciones , firmasLAyout , botonesLayout ) ;
mainLayout . add ( headerLayout , layout2 , fechasLayout , layout3 , gridHardware , gridActualizaciones , firmasLAyout , botonesLayout ) ;
add ( mainLayout ) ;
add ( botonesHeaderLyt , mainLayout ) ;
this . setSpacing ( false ) ;
this . emailService = emailService ;
}
}
@ -505,6 +520,27 @@ public class DetallesMantView extends VerticalLayout implements BeforeEnterObser
}
}
/ / METODO PARA ENVIAR LOS CORREOS ELECTRONICOS
private void enviarCorreo ( ) {
Usuario usuarioDestino = cbUsuario . getValue ( ) ;
if ( usuarioDestino ! = null & & usuarioDestino . getEmail ( ) ! = null ) {
String destinatario = usuarioDestino . getEmail ( ) ;
String asunto = "Encuesta de satisfacción -Mantenimiento #" + mantenimientoIdActual ;
String linkEncuesta = baseUrl + "/encuesta?mantenimientoId=" + mantenimientoIdActual ;
String cuerpo = linkEncuesta ;
String imagePath = "" ;
emailService . enviarCorreo ( destinatario , asunto , cuerpo , imagePath ) ;
Notification . show ( "Encuesta enviada correctamente para el mantenimiento No. " + mantenimientoIdActual , 3000 , Notification . Position . MIDDLE )
. addThemeVariants ( NotificationVariant . LUMO_SUCCESS ) ;
} else {
Notification . show ( "Por favor, seleccione un usuario destino" , 3000 , Notification . Position . MIDDLE ) ;
}
}
@Override
@Override
public void beforeEnter ( BeforeEnterEvent event ) {
public void beforeEnter ( BeforeEnterEvent event ) {
String idParam = event . getLocation ( ) . getQueryParameters ( ) . getParameters ( ) . get ( "id" ) ! = null
String idParam = event . getLocation ( ) . getQueryParameters ( ) . getParameters ( ) . get ( "id" ) ! = null