|
|
@ -0,0 +1,200 @@ |
|
|
|
|
|
package mx.gob.jumapacelaya.ui; |
|
|
|
|
|
|
|
|
|
|
|
import com.vaadin.flow.component.button.Button; |
|
|
|
|
|
import com.vaadin.flow.component.button.ButtonVariant; |
|
|
|
|
|
import com.vaadin.flow.component.dashboard.Dashboard; |
|
|
|
|
|
import com.vaadin.flow.component.dashboard.DashboardSection; |
|
|
|
|
|
import com.vaadin.flow.component.dashboard.DashboardWidget; |
|
|
|
|
|
import com.vaadin.flow.component.grid.Grid; |
|
|
|
|
|
import com.vaadin.flow.component.html.Div; |
|
|
|
|
|
import com.vaadin.flow.component.html.Span; |
|
|
|
|
|
import com.vaadin.flow.component.icon.Icon; |
|
|
|
|
|
import com.vaadin.flow.component.icon.SvgIcon; |
|
|
|
|
|
import com.vaadin.flow.component.icon.VaadinIcon; |
|
|
|
|
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; |
|
|
|
|
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
|
|
|
|
|
import com.vaadin.flow.router.PageTitle; |
|
|
|
|
|
import com.vaadin.flow.router.Route; |
|
|
|
|
|
import jakarta.annotation.security.PermitAll; |
|
|
|
|
|
import mx.gob.jumapacelaya.models.encuestas.ConteoEncuestas; |
|
|
|
|
|
import mx.gob.jumapacelaya.models.encuestas.ConteoRespuestas; |
|
|
|
|
|
import mx.gob.jumapacelaya.services.DatabaseService; |
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
import org.vaadin.lineawesome.LineAwesomeIcon; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@PermitAll |
|
|
|
|
|
@PageTitle("Resultados de Encuestas") |
|
|
|
|
|
@Route(value = "resultados-encuestas", layout = MainLayout.class) |
|
|
|
|
|
public class ResultEncuestasView extends VerticalLayout { |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ResultEncuestasView.class); |
|
|
|
|
|
private final DatabaseService databaseService; |
|
|
|
|
|
private DashboardWidget totalEncu; |
|
|
|
|
|
private DashboardWidget totalResp; |
|
|
|
|
|
private DashboardWidget porcentajeResp; |
|
|
|
|
|
private DashboardWidget pregunta1; |
|
|
|
|
|
private DashboardWidget pregunta2; |
|
|
|
|
|
private DashboardWidget pregunta3; |
|
|
|
|
|
private DashboardWidget pregunta4; |
|
|
|
|
|
private DashboardWidget pregunta5; |
|
|
|
|
|
private DashboardWidget pregunta6; |
|
|
|
|
|
|
|
|
|
|
|
public ResultEncuestasView(DatabaseService databaseService) { |
|
|
|
|
|
this.databaseService = databaseService; |
|
|
|
|
|
createToolbar(); |
|
|
|
|
|
createDashboard(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public HorizontalLayout createToolbar() { |
|
|
|
|
|
Button btnExport = new Button("Exportar a PDF", LineAwesomeIcon.FILE_PDF.create()); |
|
|
|
|
|
btnExport.addThemeVariants(ButtonVariant.LUMO_SMALL); |
|
|
|
|
|
|
|
|
|
|
|
HorizontalLayout toolbar = new HorizontalLayout(btnExport); |
|
|
|
|
|
toolbar.setAlignItems(Alignment.BASELINE); |
|
|
|
|
|
toolbar.setWidthFull(); |
|
|
|
|
|
|
|
|
|
|
|
add(toolbar); |
|
|
|
|
|
return toolbar; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Dashboard createDashboard() { |
|
|
|
|
|
Dashboard dashboard = new Dashboard(); |
|
|
|
|
|
dashboard.setMinimumColumnWidth("150px"); |
|
|
|
|
|
dashboard.setMaximumColumnCount(3); |
|
|
|
|
|
|
|
|
|
|
|
// Secciónes del dashboard |
|
|
|
|
|
DashboardSection generalSection = dashboard.addSection("General"); |
|
|
|
|
|
DashboardSection preguntasSection = dashboard.addSection("Preguntas"); |
|
|
|
|
|
|
|
|
|
|
|
// Widgets para la sección General |
|
|
|
|
|
totalEncu = new DashboardWidget("Total Encuestas"); |
|
|
|
|
|
totalResp = new DashboardWidget("Total Respuestas"); |
|
|
|
|
|
porcentajeResp = new DashboardWidget("Porcentaje de Respuestas"); |
|
|
|
|
|
|
|
|
|
|
|
generalSection.add(totalEncu); |
|
|
|
|
|
generalSection.add(totalResp); |
|
|
|
|
|
generalSection.add(porcentajeResp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Widget para la sección Preguntas |
|
|
|
|
|
pregunta1 = new DashboardWidget("Pregunta 1"); |
|
|
|
|
|
pregunta2 = new DashboardWidget("Pregunta 2"); |
|
|
|
|
|
pregunta3 = new DashboardWidget("Pregunta 3"); |
|
|
|
|
|
pregunta4 = new DashboardWidget("Pregunta 4"); |
|
|
|
|
|
pregunta5 = new DashboardWidget("Pregunta 5"); |
|
|
|
|
|
pregunta6 = new DashboardWidget("Pregunta 6"); |
|
|
|
|
|
|
|
|
|
|
|
preguntasSection.add(pregunta1); |
|
|
|
|
|
preguntasSection.add(pregunta2); |
|
|
|
|
|
preguntasSection.add(pregunta3); |
|
|
|
|
|
preguntasSection.add(pregunta4); |
|
|
|
|
|
preguntasSection.add(pregunta5); |
|
|
|
|
|
preguntasSection.add(pregunta6); |
|
|
|
|
|
|
|
|
|
|
|
mostrarTotales(); |
|
|
|
|
|
mostrarPreguntas(); |
|
|
|
|
|
add(dashboard); |
|
|
|
|
|
return dashboard; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Div createDiv(String valor, LineAwesomeIcon icon, String color) { |
|
|
|
|
|
Div content = new Div(); |
|
|
|
|
|
content.setClassName("dashboard-widget-content"); |
|
|
|
|
|
content.getStyle() |
|
|
|
|
|
.set("display", "flex") |
|
|
|
|
|
.set("align-items", "center") |
|
|
|
|
|
.set("justify-content", "center") |
|
|
|
|
|
.set("gap", "15px"); |
|
|
|
|
|
|
|
|
|
|
|
SvgIcon vIcon = icon.create(); |
|
|
|
|
|
vIcon.getStyle().set("color", color); |
|
|
|
|
|
vIcon.setSize("40px"); |
|
|
|
|
|
|
|
|
|
|
|
Span text = new Span(valor); |
|
|
|
|
|
text.getStyle().set("font-size", "2.2rem"); |
|
|
|
|
|
text.getStyle().set("font-weight", "800"); |
|
|
|
|
|
|
|
|
|
|
|
content.add(vIcon, text); |
|
|
|
|
|
return content; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Div createPreguntaContent(ConteoRespuestas data) { |
|
|
|
|
|
Div container = new Div(); |
|
|
|
|
|
container.setClassName("pregunta-widget-container"); |
|
|
|
|
|
container.getStyle().set("padding", "10px"); |
|
|
|
|
|
|
|
|
|
|
|
Span txtPregunta = new Span(data.getPregunta()); |
|
|
|
|
|
txtPregunta.getStyle().set("font-size", "0.9em") |
|
|
|
|
|
.set("display", "block") |
|
|
|
|
|
.set("margin-bottom", "15px") |
|
|
|
|
|
.set("height", "45px") |
|
|
|
|
|
.set("overflow", "hidden"); |
|
|
|
|
|
|
|
|
|
|
|
HorizontalLayout metrics = new HorizontalLayout(); |
|
|
|
|
|
metrics.setJustifyContentMode(JustifyContentMode.BETWEEN); |
|
|
|
|
|
metrics.setWidthFull(); |
|
|
|
|
|
|
|
|
|
|
|
metrics.add( |
|
|
|
|
|
createStat("Si", String.valueOf(data.getTotalSi()), "#27ae60"), |
|
|
|
|
|
createStat("No", String.valueOf(data.getTotalNo()), "#e74c3c"), |
|
|
|
|
|
createStat("%", String.format("%.0f", data.getPorcentaje()), "#BC955B") |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
container.add(txtPregunta, metrics); |
|
|
|
|
|
return container; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private VerticalLayout createStat(String label, String value, String color) { |
|
|
|
|
|
Span l = new Span(label); |
|
|
|
|
|
l.getStyle().set("font-size", "0.7em").set("color", "gray"); |
|
|
|
|
|
Span v = new Span(value); |
|
|
|
|
|
v.getStyle().set("font-weight", "bold").set("color", color); |
|
|
|
|
|
|
|
|
|
|
|
VerticalLayout vl = new VerticalLayout(l,v); |
|
|
|
|
|
vl.setAlignItems(Alignment.CENTER); |
|
|
|
|
|
vl.setSpacing(false); |
|
|
|
|
|
vl.setPadding(false); |
|
|
|
|
|
return vl; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void mostrarTotales() { |
|
|
|
|
|
List<ConteoEncuestas> datos = databaseService.getTotalEncuestas(); |
|
|
|
|
|
|
|
|
|
|
|
if (!datos.isEmpty()) { |
|
|
|
|
|
ConteoEncuestas totales = datos.get(0); |
|
|
|
|
|
|
|
|
|
|
|
totalEncu.setContent(createDiv( |
|
|
|
|
|
String.valueOf(totales.getTotalEnviadas()), |
|
|
|
|
|
LineAwesomeIcon.CLIPBOARD_LIST_SOLID, "#BC955B" |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
totalResp.setContent(createDiv( |
|
|
|
|
|
String.valueOf(totales.getTotalRespondidas()), |
|
|
|
|
|
LineAwesomeIcon.CHECK_CIRCLE, "#BC955B" |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
porcentajeResp.setContent(createDiv( |
|
|
|
|
|
String.valueOf(totales.getPorcentajeRespondidas()), |
|
|
|
|
|
LineAwesomeIcon.PERCENT_SOLID, "#BC955B" |
|
|
|
|
|
)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void mostrarPreguntas() { |
|
|
|
|
|
List<ConteoRespuestas> lista = databaseService.getTotalRespuestas(); |
|
|
|
|
|
|
|
|
|
|
|
DashboardWidget[] widgets = {pregunta1,pregunta2,pregunta3,pregunta4,pregunta5,pregunta6}; |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < lista.size() && i < widgets.length; i++) { |
|
|
|
|
|
ConteoRespuestas data = lista.get(i); |
|
|
|
|
|
DashboardWidget widget = widgets[i]; |
|
|
|
|
|
|
|
|
|
|
|
widget.setTitle("Pregunta #" + data.getPreguntaId()); |
|
|
|
|
|
|
|
|
|
|
|
widget.setContent(createPreguntaContent(data)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |