|
|
|
@ -0,0 +1,214 @@ |
|
|
|
package mx.gob.jumapacelaya.ui; |
|
|
|
|
|
|
|
import com.vaadin.flow.component.button.Button; |
|
|
|
import com.vaadin.flow.component.button.ButtonVariant; |
|
|
|
import com.vaadin.flow.component.html.*; |
|
|
|
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.HorizontalLayout; |
|
|
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
|
|
|
import com.vaadin.flow.component.radiobutton.RadioButtonGroup; |
|
|
|
import com.vaadin.flow.component.textfield.TextField; |
|
|
|
import com.vaadin.flow.router.BeforeEnterEvent; |
|
|
|
import com.vaadin.flow.router.BeforeEnterObserver; |
|
|
|
import com.vaadin.flow.router.PageTitle; |
|
|
|
import com.vaadin.flow.router.Route; |
|
|
|
import com.vaadin.flow.server.auth.AnonymousAllowed; |
|
|
|
import mx.gob.jumapacelaya.models.encuestas.Pregunta; |
|
|
|
import mx.gob.jumapacelaya.models.encuestas.Respuesta; |
|
|
|
import mx.gob.jumapacelaya.services.encuestas.EncuestasDBService; |
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
import java.sql.Timestamp; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Timer; |
|
|
|
|
|
|
|
@Route("encuesta") |
|
|
|
@PageTitle("Encuesta de satisfacción") |
|
|
|
@AnonymousAllowed |
|
|
|
public class EncuestaView extends VerticalLayout implements BeforeEnterObserver { |
|
|
|
|
|
|
|
private EncuestasDBService encuestasDBService; |
|
|
|
private int mantenimientoId = -1; |
|
|
|
private final VerticalLayout mainLyt = new VerticalLayout(); |
|
|
|
private Span pregunta1Txt = new Span(); |
|
|
|
private RadioButtonGroup<String> pregunta1Rb = new RadioButtonGroup<>(); |
|
|
|
private Button btnEnviar = new Button("Enviar"); |
|
|
|
private TextField txtNumEmpl = new TextField("No. Empleado:"); |
|
|
|
|
|
|
|
|
|
|
|
private static class RespuestaComponente { |
|
|
|
Pregunta pregunta; |
|
|
|
RadioButtonGroup<String> radios; |
|
|
|
|
|
|
|
RespuestaComponente(Pregunta pregunta, RadioButtonGroup<String> radios) { |
|
|
|
this.pregunta = pregunta; |
|
|
|
this.radios = radios; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private final List<RespuestaComponente> respuestasUI = new ArrayList<>(); |
|
|
|
|
|
|
|
public EncuestaView(EncuestasDBService encuestasDBService) { |
|
|
|
this.encuestasDBService = encuestasDBService; |
|
|
|
|
|
|
|
setSpacing(true); |
|
|
|
setPadding(true); |
|
|
|
setSizeFull(); |
|
|
|
|
|
|
|
this.getStyle() |
|
|
|
.set("background-image", "url('/images/LOGO_1024X768.jpg')") |
|
|
|
.set("background-repeat", "no-repeat") |
|
|
|
.set("background-size", "cover") |
|
|
|
.set("background-position", "center"); |
|
|
|
|
|
|
|
|
|
|
|
mainLyt.setHeightFull(); |
|
|
|
mainLyt.setWidth("55%"); |
|
|
|
mainLyt.getStyle() |
|
|
|
.set("box-shadow", "0 4px 8px rgba(0,0,0,0.2)") |
|
|
|
.set("border-radius", "12px") |
|
|
|
.set("background-color", "white") |
|
|
|
.set("padding", "1rem") |
|
|
|
.set("margin", "1rem auto"); |
|
|
|
|
|
|
|
btnEnviar.addClickListener(e -> procesarRespuestas()); |
|
|
|
|
|
|
|
this.add(mainLyt); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void beforeEnter(BeforeEnterEvent beforeEnterEvent) { |
|
|
|
List<String> params = beforeEnterEvent.getLocation().getQueryParameters() |
|
|
|
.getParameters().get("mantenimientoId"); |
|
|
|
|
|
|
|
if (params != null && !params.isEmpty()) { |
|
|
|
try { |
|
|
|
mantenimientoId = Integer.parseInt(params.get(0)); |
|
|
|
mostrarMensaje(); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
add(new H2("Enlace inválido")); |
|
|
|
} |
|
|
|
} else { |
|
|
|
add(new H2("No se recibió ningún numero de mantenimiento")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void mostrarMensaje() { |
|
|
|
|
|
|
|
txtNumEmpl.setRequired(true); |
|
|
|
txtNumEmpl.setErrorMessage("Por favor, llena este campo"); |
|
|
|
|
|
|
|
VerticalLayout titulos = new VerticalLayout(); |
|
|
|
titulos.setSpacing(false); |
|
|
|
titulos.setPadding(false); |
|
|
|
titulos.add( |
|
|
|
new H2("Mantenimiento Preventivo a Equipo de Computo"), |
|
|
|
new Paragraph("La siguiente encuesta tiene como objetivo valorar el servicio que se brinda al proporcionar el mantenimiento preventivo del equipo de computo en el Organismo."), |
|
|
|
txtNumEmpl |
|
|
|
); |
|
|
|
|
|
|
|
VerticalLayout preguntasLyt = new VerticalLayout(); |
|
|
|
preguntasLyt.setWidthFull(); |
|
|
|
preguntasLyt.setPadding(false); |
|
|
|
preguntasLyt.setSpacing(false); |
|
|
|
|
|
|
|
List<Pregunta> preguntas = encuestasDBService.getPreguntas(); |
|
|
|
|
|
|
|
for (Pregunta p : preguntas) { |
|
|
|
HorizontalLayout fila = new HorizontalLayout(); |
|
|
|
fila.setWidthFull(); |
|
|
|
fila.setAlignItems(Alignment.CENTER); |
|
|
|
fila.getStyle().set("padding", "0.4rem"); |
|
|
|
fila.getStyle().set("border-bottom", "1px solid #e0e0e0"); |
|
|
|
|
|
|
|
Span texto = new Span(p.getPregunta()); |
|
|
|
texto.getStyle().set("font-weight", "600"); |
|
|
|
|
|
|
|
RadioButtonGroup<String> radios = new RadioButtonGroup<>(); |
|
|
|
radios.setItems("Si", "No"); |
|
|
|
|
|
|
|
fila.add(texto,radios); |
|
|
|
preguntasLyt.add(fila); |
|
|
|
|
|
|
|
respuestasUI.add(new RespuestaComponente(p,radios)); |
|
|
|
} |
|
|
|
|
|
|
|
HorizontalLayout gracias = new HorizontalLayout(new H3("¡Gracias!")); |
|
|
|
gracias.setWidthFull(); |
|
|
|
gracias.setJustifyContentMode(JustifyContentMode.CENTER); |
|
|
|
|
|
|
|
btnEnviar.setWidthFull(); |
|
|
|
btnEnviar.addThemeVariants(ButtonVariant.LUMO_PRIMARY); |
|
|
|
HorizontalLayout btnEnviarLyt = new HorizontalLayout(btnEnviar); |
|
|
|
btnEnviarLyt.setWidthFull(); |
|
|
|
btnEnviarLyt.setJustifyContentMode(JustifyContentMode.CENTER); |
|
|
|
btnEnviarLyt.setSpacing(false); |
|
|
|
btnEnviarLyt.setPadding(false); |
|
|
|
|
|
|
|
|
|
|
|
mainLyt.removeAll(); |
|
|
|
mainLyt.add(titulos,preguntasLyt,gracias, btnEnviarLyt); |
|
|
|
} |
|
|
|
|
|
|
|
private void procesarRespuestas() { |
|
|
|
|
|
|
|
if (txtNumEmpl.isEmpty()) { |
|
|
|
txtNumEmpl.setInvalid(true); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
int empleadoId = Integer.parseInt(txtNumEmpl.getValue()); |
|
|
|
Timestamp ahora = new Timestamp(System.currentTimeMillis()); |
|
|
|
|
|
|
|
for (RespuestaComponente rc : respuestasUI) { |
|
|
|
|
|
|
|
Pregunta pregunta = rc.pregunta; |
|
|
|
String respuestaTexto = rc.radios.getValue(); |
|
|
|
|
|
|
|
if (respuestaTexto == null) { |
|
|
|
System.out.println("Pregunta no respondida: " + pregunta.getPregunta()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
boolean respuestaBool = respuestaTexto.equals("Si"); |
|
|
|
|
|
|
|
encuestasDBService.insertRespuestas( |
|
|
|
mantenimientoId, |
|
|
|
pregunta.getPreguntaId(), |
|
|
|
ahora, |
|
|
|
respuestaBool, |
|
|
|
empleadoId |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
NotiEncuesta(); |
|
|
|
mainLyt.setVisible(false); |
|
|
|
|
|
|
|
this.setEnabled(false); |
|
|
|
} |
|
|
|
|
|
|
|
private void NotiEncuesta() { |
|
|
|
Notification ntf = new Notification(); |
|
|
|
ntf.setPosition(Notification.Position.MIDDLE); |
|
|
|
ntf.addThemeVariants(NotificationVariant.LUMO_SUCCESS); |
|
|
|
ntf.setDuration(0); |
|
|
|
|
|
|
|
H2 titulo = new H2("Encuesta enviada"); |
|
|
|
titulo.getStyle().set("color","white"); |
|
|
|
Span msj = new Span("Sus respuestas se han guardado correctamente."); |
|
|
|
Span msj2 = new Span("Gracias por participar en nuestra encuesta."); |
|
|
|
|
|
|
|
Icon succesIcon = new Icon(VaadinIcon.CHECK_CIRCLE); |
|
|
|
succesIcon.setSize("48px"); |
|
|
|
|
|
|
|
VerticalLayout layout = new VerticalLayout(succesIcon,titulo,msj,msj2); |
|
|
|
layout.setAlignItems(Alignment.CENTER); |
|
|
|
|
|
|
|
ntf.add(layout); |
|
|
|
ntf.open(); |
|
|
|
} |
|
|
|
} |