From 70b57708c6c09cef1a44be9a2996e76dea99c2e0 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Sat, 24 Aug 2024 11:39:48 -0400 Subject: [PATCH 1/3] =?UTF-8?q?#4=20Perfil=20de=20Empleado=20-=20Campos=20?= =?UTF-8?q?de=20Informaci=C3=B3n=20Personal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primefactorsolutions/model/Employee.java | 4 - .../service/EmployeeService.java | 4 +- .../views/EmployeeView.java | 112 +++++++++++++++++- 3 files changed, 110 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 7610a4f..a819555 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -1,15 +1,11 @@ package com.primefactorsolutions.model; -import io.hypersistence.utils.hibernate.type.json.JsonType; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import org.hibernate.annotations.Type; -import java.time.LocalDate; -import java.util.List; @Data @Entity diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 716827d..ddd9a0f 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,10 +1,8 @@ package com.primefactorsolutions.service; -import com.primefactorsolutions.model.Candidate; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.repositories.EmployeeRepository; import lombok.Data; -import org.apache.commons.lang3.NotImplementedException; import org.springframework.stereotype.Service; import java.util.List; @@ -15,7 +13,7 @@ import java.util.UUID; public class EmployeeService { private final EmployeeRepository employeeRepository; - public EmployeeService(EmployeeRepository employeeRepository) { + public EmployeeService(final EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 6003b76..45331ef 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -2,9 +2,15 @@ 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.textfield.EmailField; +import com.vaadin.flow.component.ComponentEventListener; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.html.H2; +import com.vaadin.flow.component.html.H3; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.textfield.TextField; +import com.vaadin.flow.function.ValueProvider; import com.vaadin.flow.router.BeforeEvent; import com.vaadin.flow.router.HasUrlParameter; import com.vaadin.flow.router.PageTitle; @@ -13,6 +19,8 @@ import com.vaadin.flow.spring.annotation.SpringComponent; 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; @@ -23,22 +31,106 @@ 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; private TextField name = null; + private TextField lastName = null; + private VDatePicker birthday = null; + private TextField birthCity = null; + private TextField maritalStatus = null; + private TextField residenceAddress = null; + private TextField phoneNumber = null; + private TextField personalEmail = null; + + private TextField emergencyCName; + private TextField emergencyCAddress; + private TextField emergencyCPhone; + private TextField emergencyCEmail; 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(); name.setWidthFull(); - name.setLabel("Name"); + name.setLabel("Nombres: "); + + lastName = new TextField(); + lastName.setWidthFull(); + lastName.setLabel("Apellidos: "); + + birthday = new VDatePicker(); + birthday.setWidthFull(); + birthday.setLabel("Fecha de Nacimiento:"); + + birthCity = new TextField(); + birthCity.setWidthFull(); + birthCity.setLabel("Ciudad y pais de nacimiento: "); + + maritalStatus = new TextField(); + maritalStatus.setWidthFull(); + maritalStatus.setLabel("Estado Civil: "); + + residenceAddress = new TextField(); + residenceAddress.setWidthFull(); + residenceAddress.setLabel("Direccion de Residencia: "); + + phoneNumber = new TextField(); + phoneNumber.setWidthFull(); + phoneNumber.setLabel("Telefono: "); + + personalEmail = new TextField(); + personalEmail.setWidthFull(); + personalEmail.setLabel("E-mail: "); + + final H3 secondsubtitle = new H3("DATOS DE CONTACTO DE EMERGENCIA"); + + emergencyCName = new TextField(); + emergencyCName.setWidthFull(); + emergencyCName.setLabel("Nombres y Apellidos de contacto: "); + + emergencyCAddress = new TextField(); + emergencyCAddress.setWidthFull(); + emergencyCAddress.setLabel("Direccion de contacto: "); + + emergencyCPhone = new TextField(); + emergencyCPhone.setWidthFull(); + emergencyCPhone.setLabel("Telefono de contacto: "); + + emergencyCEmail = new TextField(); + emergencyCEmail.setWidthFull(); + emergencyCEmail.setLabel("Email de contacto: "); + + final VGrid grid = new VGrid<>(Employee.class); + + 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; + }); setSavedHandler((SavedHandler) employee -> { final Employee saved = employeeService.createOrUpdate(employee); setEntityWithEnabledSave(saved); + }); + + } @Override @@ -53,7 +145,21 @@ public class EmployeeView extends BeanValidationForm implements HasUrl @Override protected List getFormComponents() { - return List.of(name); + return List.of( + name, + lastName, + birthday, + birthCity, + maritalStatus, + residenceAddress, + phoneNumber, + personalEmail, + emergencyCName, + emergencyCAddress, + emergencyCPhone, + emergencyCEmail + ); } + } -- 2.34.1 From 29ebc2e4e63a85fde90c853b4025ee631f9755e6 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Mon, 26 Aug 2024 10:52:00 -0400 Subject: [PATCH 2/3] =?UTF-8?q?#4=20Perfil=20de=20Empleado=20-=20Registro?= =?UTF-8?q?=20de=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 ); } -- 2.34.1 From 3825d79479ae192bcbcb89a24ac43048c855545b Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Tue, 27 Aug 2024 20:39:40 -0400 Subject: [PATCH 3/3] =?UTF-8?q?#5=20Perfil=20de=20Empleado=20-=20A=C3=B1ad?= =?UTF-8?q?ir=20la=20funcion=20de=20guardado=20de=20Informaci=C3=B3n=20Per?= =?UTF-8?q?sonal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/EmployeeView.java | 32 +++---------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 5bb14d8..6dab5d1 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -53,14 +53,12 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private H3 fs = null; private H3 ss = null; - private final Button saveButton = new Button("Save"); - private final Button editButton = new Button("Edit"); + //private final Button editButton = new Button("Edit"); public EmployeeView(final EmployeeService employeeService) { super(Employee.class); this.employeeService = employeeService; - configureButtons(); mt = new H2("Información General del Empleado"); fs = new H3("Información Personal"); @@ -139,6 +137,8 @@ public class EmployeeView extends BeanValidationForm implements HasUrl setSavedHandler((SavedHandler) employee -> { final Employee saved = employeeService.createOrUpdate(employee); + Notification.show("Empleado guardado exitosamente."); + getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class)); setEntityWithEnabledSave(saved); }); @@ -147,23 +147,6 @@ public class EmployeeView extends BeanValidationForm implements HasUrl } - 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"); @@ -187,10 +170,8 @@ 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); } } @@ -211,11 +192,8 @@ public class EmployeeView extends BeanValidationForm implements HasUrl emergencyCName, emergencyCAddress, emergencyCPhone, - emergencyCEmail, - saveButton, - editButton + emergencyCEmail ); } -} - +} \ No newline at end of file -- 2.34.1