From 29ebc2e4e63a85fde90c853b4025ee631f9755e6 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 26 Aug 2024 10:52:00 -0400 Subject: [PATCH] =?UTF-8?q?#4=20Perfil=20de=20Empleado=20-=20Registro=20de?= =?UTF-8?q?=20Informaci=C3=B3n=20Personal=20con=20titulos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/EmployeeView.java | 174 ++++++++++++------ 1 file changed, 115 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 45331ef..5bb14d8 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -2,15 +2,17 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; -import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; -import com.vaadin.flow.component.ComponentEventListener; import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.html.H3; +import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.component.textfield.EmailField; import com.vaadin.flow.component.textfield.TextField; -import com.vaadin.flow.function.ValueProvider; +import com.vaadin.flow.data.value.ValueChangeMode; import com.vaadin.flow.router.BeforeEvent; import com.vaadin.flow.router.HasUrlParameter; import com.vaadin.flow.router.PageTitle; @@ -20,7 +22,6 @@ import jakarta.annotation.security.PermitAll; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.components.datepicker.VDatePicker; -import org.vaadin.firitin.components.grid.VGrid; import org.vaadin.firitin.form.BeanValidationForm; import java.util.List; @@ -31,7 +32,6 @@ import java.util.UUID; @Scope("prototype") @PageTitle("Employee") @Route(value = "/employees", layout = MainLayout.class) - public class EmployeeView extends BeanValidationForm implements HasUrlParameter { private final EmployeeService employeeService; @@ -39,98 +39,147 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private TextField lastName = null; private VDatePicker birthday = null; private TextField birthCity = null; - private TextField maritalStatus = null; + private ComboBox maritalStatus = null; private TextField residenceAddress = null; private TextField phoneNumber = null; - private TextField personalEmail = null; + private EmailField personalEmail = null; - private TextField emergencyCName; - private TextField emergencyCAddress; - private TextField emergencyCPhone; - private TextField emergencyCEmail; + private TextField emergencyCName = null; + private TextField emergencyCAddress = null; + private TextField emergencyCPhone = null; + private EmailField emergencyCEmail = null; + + private H2 mt = null; + private H3 fs = null; + private H3 ss = null; + + private final Button saveButton = new Button("Save"); + private final Button editButton = new Button("Edit"); public EmployeeView(final EmployeeService employeeService) { super(Employee.class); this.employeeService = employeeService; - final H2 title = new H2("INFORMACION GENERAL DEL EMPLEADO"); - final H3 subtitle = new H3("INFORMACION PERSONAL"); - final HorizontalLayout hl = new HorizontalLayout(); - final HorizontalLayout hf = new HorizontalLayout(); - name = new TextField(); + + configureButtons(); + + mt = new H2("Información General del Empleado"); + fs = new H3("Información Personal"); + ss = new H3("Datos de Contacto de Emergencia"); + + final HorizontalLayout mainLayout = new HorizontalLayout(); + final VerticalLayout sidebar = createSidebar(); + final VerticalLayout contentLayout = createContentLayout(); + final VerticalLayout contentLayout2 = createContentLayout(); + + name = new TextField("Nombres: "); name.setWidthFull(); - name.setLabel("Nombres: "); + name.setMaxLength(30); - lastName = new TextField(); + lastName = new TextField("Apellidos"); lastName.setWidthFull(); - lastName.setLabel("Apellidos: "); + lastName.setMaxLength(30); - birthday = new VDatePicker(); + birthday = new VDatePicker("Fecha de Nacimiento"); birthday.setWidthFull(); - birthday.setLabel("Fecha de Nacimiento:"); - birthCity = new TextField(); + birthCity = new TextField("Ciudad y País de Nacimiento"); birthCity.setWidthFull(); - birthCity.setLabel("Ciudad y pais de nacimiento: "); + birthCity.setMaxLength(20); - maritalStatus = new TextField(); + maritalStatus = new ComboBox<>("Estado Civil"); + maritalStatus.setItems(List.of("Soltero", "Casado", "Viudo", "Divorciado")); maritalStatus.setWidthFull(); - maritalStatus.setLabel("Estado Civil: "); - residenceAddress = new TextField(); + residenceAddress = new TextField("Dirección de Residencia"); residenceAddress.setWidthFull(); - residenceAddress.setLabel("Direccion de Residencia: "); + residenceAddress.setMaxLength(50); - phoneNumber = new TextField(); + phoneNumber = new TextField("Teléfono"); phoneNumber.setWidthFull(); - phoneNumber.setLabel("Telefono: "); + phoneNumber.setMaxLength(8); + phoneNumber.setValueChangeMode(ValueChangeMode.EAGER); + phoneNumber.addValueChangeListener(e -> { + if (!e.getValue().matches("\\d*")) { + phoneNumber.setErrorMessage("El teléfono debe contener solo números."); + } + }); - personalEmail = new TextField(); + personalEmail = new EmailField("E-mail"); personalEmail.setWidthFull(); - personalEmail.setLabel("E-mail: "); + personalEmail.setMaxLength(30); - final H3 secondsubtitle = new H3("DATOS DE CONTACTO DE EMERGENCIA"); - - emergencyCName = new TextField(); + emergencyCName = new TextField("Nombres y Apellidos de Contacto"); emergencyCName.setWidthFull(); - emergencyCName.setLabel("Nombres y Apellidos de contacto: "); + emergencyCName.setMaxLength(50); - emergencyCAddress = new TextField(); + emergencyCAddress = new TextField("Dirección de Contacto"); emergencyCAddress.setWidthFull(); - emergencyCAddress.setLabel("Direccion de contacto: "); + emergencyCAddress.setMaxLength(50); - emergencyCPhone = new TextField(); + emergencyCPhone = new TextField("Teléfono de Contacto"); emergencyCPhone.setWidthFull(); - emergencyCPhone.setLabel("Telefono de contacto: "); + emergencyCPhone.setMaxLength(8); + emergencyCPhone.setValueChangeMode(ValueChangeMode.EAGER); + emergencyCPhone.addValueChangeListener(e -> { + if (!e.getValue().matches("\\d*")) { + emergencyCPhone.setErrorMessage("El teléfono debe contener solo números."); + } + }); - emergencyCEmail = new TextField(); + emergencyCEmail = new EmailField("Email de Contacto"); emergencyCEmail.setWidthFull(); - emergencyCEmail.setLabel("Email de contacto: "); + emergencyCEmail.setMaxLength(30); - final VGrid grid = new VGrid<>(Employee.class); + contentLayout.add( + mt, fs, name, lastName, birthday, birthCity, maritalStatus, + residenceAddress, phoneNumber, personalEmail); - grid.addComponentColumn((ValueProvider) employee -> { - final Button edit = new Button("Edit"); - edit.addClickListener((ComponentEventListener>) buttonClickEvent -> { - // no-op - }); - return edit; - }); - - grid.addComponentColumn((ValueProvider) employee -> { - final Button save = new Button("Save"); - save.addClickListener((ComponentEventListener>) buttonClickEvent -> { - // no-op - }); - return save; - }); + contentLayout2.add( + ss, emergencyCName, emergencyCAddress, emergencyCPhone, emergencyCEmail); setSavedHandler((SavedHandler) employee -> { final Employee saved = employeeService.createOrUpdate(employee); setEntityWithEnabledSave(saved); - }); + mainLayout.add(sidebar, contentLayout, contentLayout2); + addClassName("main-layout"); + } + + private void configureButtons() { + editButton.setEnabled(false); // Desactivar el botón de editar inicialmente + + saveButton.addClickListener(e -> { + if (isValid()) { + saveButton.setEnabled(false); + } else { + Notification.show("Por favor, complete todos los campos obligatorios."); + } + }); + + editButton.addClickListener(e -> { + Notification.show("Modo de edición activado."); + setHasChanges(false); + }); + } + + private VerticalLayout createSidebar() { + VerticalLayout sidebar = new VerticalLayout(); + sidebar.setWidth("250px"); + sidebar.add(new Button("Información General", e -> navigateToSection("Información General"))); + sidebar.add(new Button("Detalles Profesionales", e -> navigateToSection("Detalles Profesionales"))); + return sidebar; + } + + private void navigateToSection(final String section) { + Notification.show("Navigating to " + section); + } + + private VerticalLayout createContentLayout() { + VerticalLayout contentLayout = new VerticalLayout(); + contentLayout.setWidth("100%"); + return contentLayout; } @Override @@ -138,14 +187,18 @@ public class EmployeeView extends BeanValidationForm implements HasUrl if (StringUtils.isNotBlank(s) && !"new".equals(s)) { var employee = employeeService.getEmployee(UUID.fromString(s)); setEntityWithEnabledSave(employee); + editButton.setEnabled(true); } else { setEntityWithEnabledSave(new Employee()); + editButton.setEnabled(false); } } @Override protected List getFormComponents() { return List.of( + mt, + fs, name, lastName, birthday, @@ -154,10 +207,13 @@ public class EmployeeView extends BeanValidationForm implements HasUrl residenceAddress, phoneNumber, personalEmail, + ss, emergencyCName, emergencyCAddress, emergencyCPhone, - emergencyCEmail + emergencyCEmail, + saveButton, + editButton ); }