From 93e42baa52b630dceaa3a0ab5952aebe6a04725c Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 28 Aug 2024 13:29:11 -0400 Subject: [PATCH 01/12] #7 Perfil de Personal Administrativo - Listado de empleados (Navegacion de paginas) --- .../service/EmployeeService.java | 15 +++- .../views/EmployeesListView.java | 77 +++++++------------ src/main/resources/data.sql | 13 +++- 3 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 716827d..97d2a07 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,10 +1,11 @@ package com.primefactorsolutions.service; -import com.primefactorsolutions.model.Candidate; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.repositories.EmployeeRepository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import lombok.Data; -import org.apache.commons.lang3.NotImplementedException; import org.springframework.stereotype.Service; import java.util.List; @@ -31,4 +32,14 @@ public class EmployeeService { public Employee getEmployee(final UUID id) { return null; } + + public Page getEmployeesPaginated(int pageNo, int pageSize) { + Pageable pageable = PageRequest.of(pageNo - 1, pageSize); + return employeeRepository.findAll(pageable); + } + + public boolean hasNextPage(int currentPage, int pageSize) { + Page page = getEmployeesPaginated(currentPage, pageSize); + return page.hasNext(); + } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 59fbb3f..9a403cb 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -10,19 +10,14 @@ import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.html.Main; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; -import com.vaadin.flow.data.provider.DataProvider; -import com.vaadin.flow.data.provider.DataProviderListener; -import com.vaadin.flow.data.provider.Query; import com.vaadin.flow.function.ValueProvider; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; -import com.vaadin.flow.shared.Registration; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.components.grid.VGrid; - -import java.util.stream.Stream; +import org.springframework.data.domain.Page; @SpringComponent @Scope("prototype") @@ -31,6 +26,10 @@ import java.util.stream.Stream; @PermitAll public class EmployeesListView extends Main { private final EmployeeService employeeService; + private int currentPage = 1; + private final int pageSize = 5; + private final Button previous; + private final Button next; public EmployeesListView(final EmployeeService employeeService) { this.employeeService = employeeService; @@ -69,58 +68,34 @@ public class EmployeesListView extends Main { }); return save; }); - - grid.setDataProvider(new DataProvider<>() { - @Override - public boolean isInMemory() { - return false; - } - - @Override - public int size(final Query query) { - return employeeService.getEmployees().size(); - } - - @Override - public Stream fetch(final Query query) { - int limit = query.getLimit(); - int pagerSize = query.getPageSize(); - int page = query.getPage(); - return employeeService.getEmployees().stream(); - } - - @Override - public void refreshItem(final Employee employee) { - // no-op - } - - @Override - public void refreshAll() { - // no-op - } - - @Override - public Registration addDataProviderListener(final DataProviderListener dataProviderListener) { - return null; + this.previous = new Button("Previous"); + this.previous.addClickListener((ComponentEventListener>) buttonClickEvent -> { + if (currentPage > 1) { + currentPage--; + updateGrid(grid); } }); - - final Button previous = new Button("Previous"); - previous.addClickListener((ComponentEventListener>) buttonClickEvent -> { - // no-op + hf.add(this.previous); + this.next = new Button("Next"); + this.next.addClickListener((ComponentEventListener>) buttonClickEvent -> { + if (employeeService.hasNextPage(currentPage, pageSize)) { + currentPage++; + updateGrid(grid); + } }); - hf.add(previous); - final Button next = new Button("Next"); - next.addClickListener((ComponentEventListener>) buttonClickEvent -> { - // no-op - }); - hf.add(next); + hf.add(this.next); final Button addEmployee = new Button("Add Employee"); addEmployee.addClickListener((ComponentEventListener>) buttonClickEvent -> { - this.getUI().get().navigate(EmployeeView.class, "new"); + this.getUI().flatMap(ui -> ui.navigate(EmployeeView.class, "new")); }); hf.add(addEmployee); - add(title, hl, grid, hf); + updateGrid(grid); + } + private void updateGrid(VGrid grid) { + Page page = employeeService.getEmployeesPaginated(currentPage, pageSize); + grid.setItems(page.getContent()); + this.previous.setEnabled(currentPage > 1); + this.next.setEnabled(page.hasNext()); } } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index f797344..0888a8a 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -13,4 +13,15 @@ insert into employee (id, version, first_name, last_name, status) values ('e99b7 insert into employee (id, version, first_name, last_name, status) values ('f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 1, 'Ana', 'Garcia Rojas', 'ACTIVE'); insert into employee (id, version, first_name, last_name, status) values ('2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 1, 'Carlos', 'Lopez Mendoza', 'INACTIVE'); insert into employee (id, version, first_name, last_name, status) values ('4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 1, 'Maria', 'Fernandez Villca', 'ACTIVE'); -insert into employee (id, version, first_name, last_name, status) values ('afc5c741-f70a-4394-853b-39d51b118927', 1, 'Luis', 'Gutierrez Mamani', 'ACTIVE'); \ No newline at end of file +insert into employee (id, version, first_name, last_name, status) values ('afc5c741-f70a-4394-853b-39d51b118927', 1, 'Luis', 'Gutierrez Mamani', 'ACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 1, 'Laura', 'Martinez Paredes', 'INACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('6e6a8a4e-9f6b-44eb-8c69-40acfdc86756', 1, 'Roberto', 'Santos Escobar', 'ACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('36b0d1c6-bdc0-4d98-94bb-08b9bce3f0d5', 1, 'Valeria', 'Morales Ochoa', 'INACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('5a1c6d80-58b3-43e3-a5a5-24b4a2d1d54a', 1, 'Jorge', 'Ramirez Tapia', 'ACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('9d6a5b2e-6d0b-4b89-8d6a-d3f3d1bfc047', 1, 'Sandra', 'Torres Huanca', 'ACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('f8b3e0c0-0d5a-4e5c-bf9d-207b9b5e8279', 1, 'Felipe', 'Quispe Huanca', 'INACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('cd80e1d0-9a08-44a6-bd63-2c63eaa003d4', 1, 'Gabriela', 'Rivas Arana', 'ACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('62d3c1b7-815e-4e96-8d7e-f8c4236bca55', 1, 'Oscar', 'Flores Quiroga', 'INACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('f20b7c5a-5a67-44f0-9ec1-4c1b8e80de05', 1, 'Marta', 'Vargas Soria', 'ACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('19b5a76e-d7b1-4b76-8b02-4d0748e85809', 1, 'Andres', 'Espinoza Chura', 'INACTIVE'); +insert into employee (id, version, first_name, last_name, status) values ('5c1a7b82-832d-4f24-8377-54b77b91b6a8', 1, 'Carla', 'Villanueva Arce', 'ACTIVE'); \ No newline at end of file -- 2.34.1 From aa041b33583d76c9854de16e0f451257e40699fe Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 28 Aug 2024 15:06:38 -0400 Subject: [PATCH 02/12] #7 Perfil de Personal Administrativo - Listado de empleados (Ordenar ascendente y descendente) --- .../service/EmployeeService.java | 11 +- .../views/EmployeesListView.java | 156 ++++++++++-------- 2 files changed, 95 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 97d2a07..6626fbc 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -6,6 +6,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import lombok.Data; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.util.List; @@ -33,13 +34,13 @@ public class EmployeeService { return null; } - public Page getEmployeesPaginated(int pageNo, int pageSize) { - Pageable pageable = PageRequest.of(pageNo - 1, pageSize); + public Page getEmployeesPaginated(int pageNo, int pageSize, String sortField, boolean ascending) { + Sort sort = ascending ? Sort.by(sortField).ascending() : Sort.by(sortField).descending(); + Pageable pageable = PageRequest.of(pageNo - 1, pageSize, sort); return employeeRepository.findAll(pageable); } - public boolean hasNextPage(int currentPage, int pageSize) { - Page page = getEmployeesPaginated(currentPage, pageSize); - return page.hasNext(); + public boolean hasNextPage(int currentPage, int pageSize, String sortField, boolean ascending) { + return getEmployeesPaginated(currentPage, pageSize, sortField, ascending).hasNext(); } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 9a403cb..bada406 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -2,15 +2,11 @@ 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.Main; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; -import com.vaadin.flow.function.ValueProvider; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; @@ -25,77 +21,103 @@ import org.springframework.data.domain.Page; @Route(value = "/employees", layout = MainLayout.class) @PermitAll public class EmployeesListView extends Main { - private final EmployeeService employeeService; - private int currentPage = 1; - private final int pageSize = 5; - private final Button previous; - private final Button next; - public EmployeesListView(final EmployeeService employeeService) { + private final EmployeeService employeeService; + private final int pageSize = 5; + private int currentPage = 1; + private String sortField = "firstName"; + private boolean ascending = true; + private VGrid grid; + private Button previous; + private Button next; + + public EmployeesListView(EmployeeService employeeService) { this.employeeService = employeeService; + addComponents(); + updateGrid(); + } + + private void addComponents() { + addTitle(); + addOrderButtons(); + configureGrid(); + addNavigationButtons(); + } + + private void addTitle() { final H2 title = new H2("Employees list"); + add(title); + } + + private void addOrderButtons() { final HorizontalLayout hl = new HorizontalLayout(); - final HorizontalLayout hf = new HorizontalLayout(); - final Button employeeListAscendingOrder = new Button("Employee List in Ascending Order"); - employeeListAscendingOrder.addClickListener((ComponentEventListener>) buttonClickEvent -> { - // no-op + hl.add(createOrderButton("Employee List in Ascending Order", true)); + hl.add(createOrderButton("Employee List in Descending Order", false)); + add(hl); + } + + private Button createOrderButton(String label, boolean isAscending) { + Button button = new Button(label); + button.addClickListener(event -> { + sortField = "firstName"; + ascending = isAscending; + updateGrid(); }); - hl.add(employeeListAscendingOrder); - final Button employeeListDescendingOrder = new Button("Employee List in Descending Order"); - employeeListDescendingOrder.addClickListener((ComponentEventListener>) buttonClickEvent -> { - // no-op - }); - hl.add(employeeListDescendingOrder); - final VGrid grid = new VGrid<>(Employee.class); + return button; + } + private void configureGrid() { + grid = new VGrid<>(Employee.class); grid.setColumns("firstName", "lastName", "status"); grid.setAllRowsVisible(true); - grid.addComponentColumn((ValueProvider) employee -> { - ComboBox statusComboBox = new ComboBox<>(); - statusComboBox.setItems("Active", "Inactive"); - return statusComboBox; - }).setHeader("Change Status"); - 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; - }); - this.previous = new Button("Previous"); - this.previous.addClickListener((ComponentEventListener>) buttonClickEvent -> { - if (currentPage > 1) { - currentPage--; - updateGrid(grid); - } - }); - hf.add(this.previous); - this.next = new Button("Next"); - this.next.addClickListener((ComponentEventListener>) buttonClickEvent -> { - if (employeeService.hasNextPage(currentPage, pageSize)) { - currentPage++; - updateGrid(grid); - } - }); - hf.add(this.next); - final Button addEmployee = new Button("Add Employee"); - addEmployee.addClickListener((ComponentEventListener>) buttonClickEvent -> { - this.getUI().flatMap(ui -> ui.navigate(EmployeeView.class, "new")); - }); - hf.add(addEmployee); - add(title, hl, grid, hf); - updateGrid(grid); + grid.addComponentColumn(employee -> createStatusComboBox()).setHeader("Change Status"); + grid.addComponentColumn(employee -> createEditButton()); + grid.addComponentColumn(employee -> createSaveButton()); + add(grid); } - private void updateGrid(VGrid grid) { - Page page = employeeService.getEmployeesPaginated(currentPage, pageSize); + + private ComboBox createStatusComboBox() { + ComboBox statusComboBox = new ComboBox<>(); + statusComboBox.setItems("Active", "Inactive"); + return statusComboBox; + } + + private Button createEditButton() { + return new Button("Edit"); + } + private Button createSaveButton() { + return new Button("Save"); + } + + private void addNavigationButtons() { + final HorizontalLayout hf = new HorizontalLayout(); + previous = createNavigationButton("Previous", -1); + next = createNavigationButton("Next", 1); + hf.add(previous, next, createAddEmployeeButton()); + add(hf); + } + + private Button createNavigationButton(String label, int increment) { + Button button = new Button(label); + button.addClickListener(event -> changePage(increment)); + return button; + } + private void changePage(int increment) { + if (increment < 0 && currentPage > 1) { + currentPage--; + } else if (increment > 0 && employeeService.hasNextPage(currentPage, pageSize, sortField, ascending)) { + currentPage++; + } + updateGrid(); + } + private Button createAddEmployeeButton() { + return new Button("Add Employee", event -> + getUI().flatMap(ui -> ui.navigate(EmployeeView.class, "new")) + ); + } + private void updateGrid() { + Page page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending); grid.setItems(page.getContent()); - this.previous.setEnabled(currentPage > 1); - this.next.setEnabled(page.hasNext()); + previous.setEnabled(currentPage > 1); + next.setEnabled(page.hasNext()); } } -- 2.34.1 From a393c82649423e1f0b2a60c3cf8d2160e81cc233 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 28 Aug 2024 15:37:09 -0400 Subject: [PATCH 03/12] =?UTF-8?q?#7=20Perfil=20de=20Personal=20Administrat?= =?UTF-8?q?ivo=20-=20Listado=20de=20empleados=20(Mostrar=20mensaje:=20No?= =?UTF-8?q?=20existen=20m=C3=A1s=20datos=20en=20la=20lista)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/EmployeesListView.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index bada406..4dc9706 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -7,6 +7,7 @@ import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.html.Main; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; @@ -98,16 +99,28 @@ public class EmployeesListView extends Main { private Button createNavigationButton(String label, int increment) { Button button = new Button(label); - button.addClickListener(event -> changePage(increment)); + button.addClickListener(event -> handlePageChange(increment)); return button; } - private void changePage(int increment) { - if (increment < 0 && currentPage > 1) { - currentPage--; - } else if (increment > 0 && employeeService.hasNextPage(currentPage, pageSize, sortField, ascending)) { - currentPage++; + private void handlePageChange(int increment) { + if (isPageChangeValid(increment)) { + currentPage += increment; + updateGrid(); + } else { + showNotification("No existen más datos en lista."); } - updateGrid(); + } + private boolean isPageChangeValid(int increment) { + if (increment < 0) { + return currentPage > 1; + } else if (increment > 0) { + return employeeService.hasNextPage(currentPage, pageSize, sortField, ascending); + } + return false; + } + private void showNotification(String message) { + Notification notification = new Notification(message, 3000, Notification.Position.BOTTOM_END); + notification.open(); } private Button createAddEmployeeButton() { return new Button("Add Employee", event -> @@ -117,7 +130,5 @@ public class EmployeesListView extends Main { private void updateGrid() { Page page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending); grid.setItems(page.getContent()); - previous.setEnabled(currentPage > 1); - next.setEnabled(page.hasNext()); } } -- 2.34.1 From 59c7b2af859e16de7e84eef7cb8325d7b0d5704d Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Fri, 30 Aug 2024 14:54:36 -0400 Subject: [PATCH 04/12] Integracioin modulos employeeView y employeeListView --- .../primefactorsolutions/model/Employee.java | 22 +++ .../service/EmployeeService.java | 5 +- .../views/EmployeeView.java | 169 +++++++++++++++++- 3 files changed, 188 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 6e883f0..3d0d863 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -19,6 +19,21 @@ import java.util.List; public class Employee extends BaseEntity { private String firstName; private String lastName; + private LocalDate birthday; + private String birthCity; + + @Enumerated(EnumType.STRING) + private MaritalStatus maritalStatus; + + private String residenceAddress; + private String phoneNumber; + private String personalEmail; + + private String emergencyCName; + private String emergencyCAddress; + private String emergencyCPhone; + private String emergencyCEmail; + @Enumerated(EnumType.STRING) private Status status; @@ -26,4 +41,11 @@ public class Employee extends BaseEntity { ACTIVE, INACTIVE } + + public enum MaritalStatus { + SINGLE, + MARRIED, + WIDOWED, + DIVORCED + } } diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 6626fbc..5e5a94f 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -11,6 +11,8 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.UUID; +import java.util.Optional; + @Service @Data @@ -31,7 +33,8 @@ public class EmployeeService { } public Employee getEmployee(final UUID id) { - return null; + Optional employee = employeeRepository.findById(id); + return employee.orElse(null); } public Page getEmployeesPaginated(int pageNo, int pageSize, String sortField, boolean ascending) { diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 6003b76..d2a570e 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -3,8 +3,16 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.vaadin.flow.component.Component; +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.data.value.ValueChangeMode; import com.vaadin.flow.router.BeforeEvent; import com.vaadin.flow.router.HasUrlParameter; import com.vaadin.flow.router.PageTitle; @@ -13,6 +21,7 @@ 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.form.BeanValidationForm; import java.util.List; @@ -24,21 +33,150 @@ import java.util.UUID; @PageTitle("Employee") @Route(value = "/employees", layout = MainLayout.class) public class EmployeeView extends BeanValidationForm implements HasUrlParameter { + private final EmployeeService employeeService; - private TextField name = null; + private final TextField firstName; + private final TextField lastName; + private final ComboBox status; + private final VDatePicker birthday; + private final TextField birthCity; + private final ComboBox maritalStatus; + private final TextField residenceAddress; + private final TextField phoneNumber; + private final EmailField personalEmail; + + private final TextField emergencyCName; + private final TextField emergencyCAddress; + private final TextField emergencyCPhone; + private final EmailField emergencyCEmail; + + private final H2 mt; + private final H3 fs; + private final H3 ss; public EmployeeView(final EmployeeService employeeService) { super(Employee.class); this.employeeService = employeeService; - name = new TextField(); - name.setWidthFull(); - name.setLabel("Name"); + + 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(); + + firstName = new TextField("Nombres: "); + firstName.setWidthFull(); + firstName.setMaxLength(30); + firstName.setRequired(true); + + lastName = new TextField("Apellidos"); + lastName.setWidthFull(); + lastName.setMaxLength(30); + lastName.setRequired(true); + + status = new ComboBox<>("Estado"); + status.setItems(List.of("ACTIVE", "INACTIVE")); + lastName.setWidthFull(); + lastName.setMaxLength(30); + status.setRequired(true); + + birthday = new VDatePicker("Fecha de Nacimiento"); + birthday.setWidthFull(); + + birthCity = new TextField("Ciudad y País de Nacimiento"); + birthCity.setWidthFull(); + birthCity.setMaxLength(20); + + maritalStatus = new ComboBox<>("Estado Civil"); + maritalStatus.setItems(List.of("Soltero", "Casado", "Viudo", "Divorciado")); + maritalStatus.setWidthFull(); + + residenceAddress = new TextField("Dirección de Residencia"); + residenceAddress.setWidthFull(); + residenceAddress.setMaxLength(50); + + phoneNumber = new TextField("Teléfono"); + phoneNumber.setWidthFull(); + 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 EmailField("E-mail"); + personalEmail.setWidthFull(); + personalEmail.setMaxLength(30); + + emergencyCName = new TextField("Nombres y Apellidos de Contacto"); + emergencyCName.setWidthFull(); + emergencyCName.setMaxLength(50); + + emergencyCAddress = new TextField("Dirección de Contacto"); + emergencyCAddress.setWidthFull(); + emergencyCAddress.setMaxLength(50); + + emergencyCPhone = new TextField("Teléfono de Contacto"); + emergencyCPhone.setWidthFull(); + 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 EmailField("Email de Contacto"); + emergencyCEmail.setWidthFull(); + emergencyCEmail.setMaxLength(30); + + contentLayout.add( + mt, fs, firstName, lastName, status, birthday, birthCity, maritalStatus, + residenceAddress, phoneNumber, personalEmail); + + contentLayout2.add( + ss, emergencyCName, emergencyCAddress, emergencyCPhone, emergencyCEmail); setSavedHandler((SavedHandler) employee -> { - final Employee saved = employeeService.createOrUpdate(employee); - setEntityWithEnabledSave(saved); + if (validateForm()) { + final Employee saved = employeeService.createOrUpdate(employee); + Notification.show("Empleado guardado exitosamente."); + getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class)); + setEntityWithEnabledSave(saved); + } else { + Notification.show("Acción inválida. Por favor, complete todos los campos requeridos correctamente.", 3000, Notification.Position.MIDDLE); + } }); + + mainLayout.add(sidebar, contentLayout, contentLayout2); + addClassName("main-layout"); + } + + private boolean validateForm() { + return !firstName.isEmpty() && !lastName.isEmpty() && status.getValue() != null; + } + + 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 @@ -53,7 +191,24 @@ public class EmployeeView extends BeanValidationForm implements HasUrl @Override protected List getFormComponents() { - return List.of(name); + return List.of( + mt, + fs, + firstName, + lastName, + status, + birthday, + birthCity, + maritalStatus, + residenceAddress, + phoneNumber, + personalEmail, + ss, + emergencyCName, + emergencyCAddress, + emergencyCPhone, + emergencyCEmail + ); } } -- 2.34.1 From 4eebdf6f0113f5242d1c1457e809d24778c52a3a Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 3 Sep 2024 11:42:20 -0400 Subject: [PATCH 05/12] #7 Perfil de Personal Administrativo - Listado de empleados (Implementar PagingGrid) --- pom.xml | 5 + .../primefactorsolutions/model/Employee.java | 108 ++++++----- .../service/EmployeeService.java | 52 +++-- .../views/EmployeesListView.java | 180 +++++++++--------- 4 files changed, 182 insertions(+), 163 deletions(-) diff --git a/pom.xml b/pom.xml index e192968..cdd0c6d 100644 --- a/pom.xml +++ b/pom.xml @@ -110,6 +110,11 @@ spring-boot-starter-test test + + commons-beanutils + commons-beanutils + 1.9.4 + org.mockito mockito-core diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 3d0d863..0a8e09d 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -1,51 +1,59 @@ -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 -@AllArgsConstructor -@NoArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class Employee extends BaseEntity { - private String firstName; - private String lastName; - private LocalDate birthday; - private String birthCity; - - @Enumerated(EnumType.STRING) - private MaritalStatus maritalStatus; - - private String residenceAddress; - private String phoneNumber; - private String personalEmail; - - private String emergencyCName; - private String emergencyCAddress; - private String emergencyCPhone; - private String emergencyCEmail; - - @Enumerated(EnumType.STRING) - private Status status; - - public enum Status { - ACTIVE, - INACTIVE + 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 + @AllArgsConstructor + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public class Employee extends BaseEntity { + private String firstName; + private String lastName; + private LocalDate birthday; + private String birthCity; + + @Enumerated(EnumType.STRING) + private MaritalStatus maritalStatus; + + private String residenceAddress; + private String phoneNumber; + private String personalEmail; + + private String emergencyCName; + private String emergencyCAddress; + private String emergencyCPhone; + private String emergencyCEmail; + + @Enumerated(EnumType.STRING) + private Status status; + + public enum Status { + ACTIVE, + INACTIVE + } + + public enum MaritalStatus { + SINGLE, + MARRIED, + WIDOWED, + DIVORCED + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } } - - public enum MaritalStatus { - SINGLE, - MARRIED, - WIDOWED, - DIVORCED - } -} diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 5e5a94f..55c2218 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,49 +1,65 @@ package com.primefactorsolutions.service; import com.primefactorsolutions.model.Employee; +import org.apache.commons.beanutils.BeanComparator; import com.primefactorsolutions.repositories.EmployeeRepository; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; import lombok.Data; -import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.util.List; import java.util.UUID; import java.util.Optional; +import java.util.Collections; @Service @Data public class EmployeeService { private final EmployeeRepository employeeRepository; + private List pagedBase; public EmployeeService(EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } + private void initializePagedBase() { + if (pagedBase == null) { + this.pagedBase = employeeRepository.findAll(); + } + } + + public List findEmployees(int start, int pageSize, String sortProperty, boolean asc) { + initializePagedBase(); // Asegurarse de que pagedBase esté inicializada + System.err.println("findAll " + start + " " + pageSize + " sort " + sortProperty + " asc:" + asc ); + int end = (int) (start + pageSize); + if (end > pagedBase.size()) { + end = pagedBase.size(); + } + Collections.sort(pagedBase, new BeanComparator(sortProperty)); + + if(!asc) { + Collections.reverse(pagedBase); + } + return pagedBase.subList((int) start, end); + } + + public List findEmployees(int start, int pageSize) { + initializePagedBase(); // Asegurarse de que pagedBase esté inicializada + System.err.println("findAll " + start + " " + pageSize); + int end = (int) (start + pageSize); + if (end > pagedBase.size()) { + end = pagedBase.size(); + } + return pagedBase.subList((int) start, end); + } + public Employee createOrUpdate(final Employee employee) { final Employee saved = employeeRepository.save(employee); return saved; } - public List getEmployees() { - return employeeRepository.findAll(); - } - public Employee getEmployee(final UUID id) { Optional employee = employeeRepository.findById(id); return employee.orElse(null); } - - public Page getEmployeesPaginated(int pageNo, int pageSize, String sortField, boolean ascending) { - Sort sort = ascending ? Sort.by(sortField).ascending() : Sort.by(sortField).descending(); - Pageable pageable = PageRequest.of(pageNo - 1, pageSize, sort); - return employeeRepository.findAll(pageable); - } - - public boolean hasNextPage(int currentPage, int pageSize, String sortField, boolean ascending) { - return getEmployeesPaginated(currentPage, pageSize, sortField, ascending).hasNext(); - } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 4dc9706..3b0e664 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -3,18 +3,20 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.combobox.ComboBox; +import com.vaadin.flow.component.checkbox.Checkbox; import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.html.Main; -import com.vaadin.flow.component.orderedlayout.HorizontalLayout; -import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; +import org.vaadin.firitin.components.grid.PagingGrid; +import com.vaadin.flow.component.grid.GridSortOrder; +import com.vaadin.flow.data.provider.SortDirection; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; -import org.vaadin.firitin.components.grid.VGrid; -import org.springframework.data.domain.Page; + +import java.util.List; + @SpringComponent @Scope("prototype") @@ -24,111 +26,99 @@ import org.springframework.data.domain.Page; public class EmployeesListView extends Main { private final EmployeeService employeeService; - private final int pageSize = 5; - private int currentPage = 1; - private String sortField = "firstName"; - private boolean ascending = true; - private VGrid grid; - private Button previous; - private Button next; + private final PagingGrid table = new PagingGrid<>(Employee.class); public EmployeesListView(EmployeeService employeeService) { this.employeeService = employeeService; - addComponents(); - updateGrid(); + setupView(); + refreshGrid(); } - private void addComponents() { - addTitle(); - addOrderButtons(); - configureGrid(); - addNavigationButtons(); + private void setupView() { + add(new H2("Employee List")); + configureTable(); + add(createAddEmployeeButton()); + add(table); } - private void addTitle() { - final H2 title = new H2("Employees list"); - add(title); + private void configureTable() { + table.setColumns("firstName", "lastName", "status"); + addStatusColumn(); + addEditButtonColumn("Edit", this::navigateToEditView); + addEditButtonColumn("Save", this::navigateToSaveChangeStatus); + setupPagingGrid(); } - private void addOrderButtons() { - final HorizontalLayout hl = new HorizontalLayout(); - hl.add(createOrderButton("Employee List in Ascending Order", true)); - hl.add(createOrderButton("Employee List in Descending Order", false)); - add(hl); + private void addStatusColumn() { + table.addComponentColumn(this::createStatusCheckbox) + .setHeader("Change Status"); } - private Button createOrderButton(String label, boolean isAscending) { + private Checkbox createStatusCheckbox(Employee employee) { + Checkbox statusCheckbox = new Checkbox( employee.getStatus() == Employee.Status.ACTIVE); + return statusCheckbox; + } + + private void updateEmployeeStatus(Employee employee, boolean isActive) { + employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE); + employeeService.createOrUpdate(employee); + refreshGrid(); + } + + private void addEditButtonColumn(String label, ButtonClickHandler handler) { + table.addComponentColumn(employee -> createButton(label, () -> handler.handle(employee))); + } + + private Button createButton(String label, Runnable onClickAction) { Button button = new Button(label); - button.addClickListener(event -> { - sortField = "firstName"; - ascending = isAscending; - updateGrid(); - }); + button.addClickListener(event -> onClickAction.run()); return button; } - private void configureGrid() { - grid = new VGrid<>(Employee.class); - grid.setColumns("firstName", "lastName", "status"); - grid.setAllRowsVisible(true); - grid.addComponentColumn(employee -> createStatusComboBox()).setHeader("Change Status"); - grid.addComponentColumn(employee -> createEditButton()); - grid.addComponentColumn(employee -> createSaveButton()); - add(grid); - } - private ComboBox createStatusComboBox() { - ComboBox statusComboBox = new ComboBox<>(); - statusComboBox.setItems("Active", "Inactive"); - return statusComboBox; - } - - private Button createEditButton() { - return new Button("Edit"); - } - private Button createSaveButton() { - return new Button("Save"); - } - - private void addNavigationButtons() { - final HorizontalLayout hf = new HorizontalLayout(); - previous = createNavigationButton("Previous", -1); - next = createNavigationButton("Next", 1); - hf.add(previous, next, createAddEmployeeButton()); - add(hf); - } - - private Button createNavigationButton(String label, int increment) { - Button button = new Button(label); - button.addClickListener(event -> handlePageChange(increment)); - return button; - } - private void handlePageChange(int increment) { - if (isPageChangeValid(increment)) { - currentPage += increment; - updateGrid(); - } else { - showNotification("No existen más datos en lista."); - } - } - private boolean isPageChangeValid(int increment) { - if (increment < 0) { - return currentPage > 1; - } else if (increment > 0) { - return employeeService.hasNextPage(currentPage, pageSize, sortField, ascending); - } - return false; - } - private void showNotification(String message) { - Notification notification = new Notification(message, 3000, Notification.Position.BOTTOM_END); - notification.open(); - } private Button createAddEmployeeButton() { - return new Button("Add Employee", event -> - getUI().flatMap(ui -> ui.navigate(EmployeeView.class, "new")) - ); + return createButton("Add Employee", this::navigateToAddEmployeeView); } - private void updateGrid() { - Page page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending); - grid.setItems(page.getContent()); + + private void navigateToEditView(Employee employee) { + getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, employee.getId().toString())); } -} + + private void navigateToAddEmployeeView() { + getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, "new")); + } + + private void navigateToSaveChangeStatus(Employee employee) { + // no-op + } + + private void setupPagingGrid() { + table.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); + table.setPageSize(5); + } + + private void refreshGrid() { + table.setPagingDataProvider((page, pageSize) -> fetchEmployees((int) page, pageSize)); + } + + private List fetchEmployees(int page, int pageSize) { + int start = page * pageSize; + if (hasSortOrder()) { + return fetchSortedEmployees(start, pageSize); + } + return employeeService.findEmployees(start, pageSize); + } + + private boolean hasSortOrder() { + return !table.getSortOrder().isEmpty(); + } + + private List fetchSortedEmployees(int start, int pageSize) { + GridSortOrder sortOrder = table.getSortOrder().getFirst(); + return employeeService.findEmployees(start, pageSize, sortOrder.getSorted().getKey(), sortOrder.getDirection() == SortDirection.ASCENDING); + } + + @FunctionalInterface + private interface ButtonClickHandler { + void handle(Employee employee); + } +} \ No newline at end of file -- 2.34.1 From 7d6955a5c355b532ae787b6721662a22a9ef049f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 3 Sep 2024 20:00:09 -0400 Subject: [PATCH 06/12] #7 Perfil de Personal Administrativo - Listado de empleados (correcciones) --- .../primefactorsolutions/model/Employee.java | 8 ---- .../service/EmployeeService.java | 42 +++++++------------ .../views/EmployeesListView.java | 11 ----- 3 files changed, 14 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 0a8e09d..94fce40 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -21,38 +21,30 @@ private String lastName; private LocalDate birthday; private String birthCity; - @Enumerated(EnumType.STRING) private MaritalStatus maritalStatus; - private String residenceAddress; private String phoneNumber; private String personalEmail; - private String emergencyCName; private String emergencyCAddress; private String emergencyCPhone; private String emergencyCEmail; - @Enumerated(EnumType.STRING) private Status status; - public enum Status { ACTIVE, INACTIVE } - public enum MaritalStatus { SINGLE, MARRIED, WIDOWED, DIVORCED } - public Status getStatus() { return status; } - public void setStatus(Status status) { this.status = status; } diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 55c2218..da815d9 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,5 +1,4 @@ package com.primefactorsolutions.service; - import com.primefactorsolutions.model.Employee; import org.apache.commons.beanutils.BeanComparator; import com.primefactorsolutions.repositories.EmployeeRepository; @@ -16,50 +15,37 @@ import java.util.Collections; @Data public class EmployeeService { private final EmployeeRepository employeeRepository; - private List pagedBase; public EmployeeService(EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } - private void initializePagedBase() { - if (pagedBase == null) { - this.pagedBase = employeeRepository.findAll(); - } - } - public List findEmployees(int start, int pageSize, String sortProperty, boolean asc) { - initializePagedBase(); // Asegurarse de que pagedBase esté inicializada - System.err.println("findAll " + start + " " + pageSize + " sort " + sortProperty + " asc:" + asc ); - int end = (int) (start + pageSize); - if (end > pagedBase.size()) { - end = pagedBase.size(); - } - Collections.sort(pagedBase, new BeanComparator(sortProperty)); + List employees = employeeRepository.findAll(); - if(!asc) { - Collections.reverse(pagedBase); + int end = Math.min(start + pageSize, employees.size()); + employees.sort(new BeanComparator<>(sortProperty)); + + if (!asc) { + Collections.reverse(employees); } - return pagedBase.subList((int) start, end); + + return employees.subList(start, end); } public List findEmployees(int start, int pageSize) { - initializePagedBase(); // Asegurarse de que pagedBase esté inicializada - System.err.println("findAll " + start + " " + pageSize); - int end = (int) (start + pageSize); - if (end > pagedBase.size()) { - end = pagedBase.size(); - } - return pagedBase.subList((int) start, end); + List employees = employeeRepository.findAll(); + + int end = Math.min(start + pageSize, employees.size()); + return employees.subList(start, end); } public Employee createOrUpdate(final Employee employee) { - final Employee saved = employeeRepository.save(employee); - return saved; + return employeeRepository.save(employee); } public Employee getEmployee(final UUID id) { Optional employee = employeeRepository.findById(id); return employee.orElse(null); } -} +} \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 3b0e664..e8adeb4 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -43,22 +43,11 @@ public class EmployeesListView extends Main { private void configureTable() { table.setColumns("firstName", "lastName", "status"); - addStatusColumn(); addEditButtonColumn("Edit", this::navigateToEditView); addEditButtonColumn("Save", this::navigateToSaveChangeStatus); setupPagingGrid(); } - private void addStatusColumn() { - table.addComponentColumn(this::createStatusCheckbox) - .setHeader("Change Status"); - } - - private Checkbox createStatusCheckbox(Employee employee) { - Checkbox statusCheckbox = new Checkbox( employee.getStatus() == Employee.Status.ACTIVE); - return statusCheckbox; - } - private void updateEmployeeStatus(Employee employee, boolean isActive) { employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE); employeeService.createOrUpdate(employee); -- 2.34.1 From dd95b70c66d042a79b17b79b8433b9da85e8fddc Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 3 Sep 2024 20:11:44 -0400 Subject: [PATCH 07/12] #7 Perfil de Personal Administrativo - Listado de empleados (correcciones v2) --- .../com/primefactorsolutions/views/EmployeesListView.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index e8adeb4..b91c03c 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -3,7 +3,6 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.checkbox.Checkbox; import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.html.Main; import com.vaadin.flow.router.PageTitle; @@ -44,7 +43,6 @@ public class EmployeesListView extends Main { private void configureTable() { table.setColumns("firstName", "lastName", "status"); addEditButtonColumn("Edit", this::navigateToEditView); - addEditButtonColumn("Save", this::navigateToSaveChangeStatus); setupPagingGrid(); } @@ -76,10 +74,6 @@ public class EmployeesListView extends Main { getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, "new")); } - private void navigateToSaveChangeStatus(Employee employee) { - // no-op - } - private void setupPagingGrid() { table.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); table.setPageSize(5); -- 2.34.1 From 49dc6421f52a43c451f1977577fc79673e201b99 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 4 Sep 2024 12:44:47 -0400 Subject: [PATCH 08/12] Correccion de estilo de codigo --- .../primefactorsolutions/model/Employee.java | 10 +++------- .../service/EmployeeService.java | 7 ++++--- .../views/EmployeeView.java | 4 ++-- .../views/EmployeesListView.java | 18 ++++++++++-------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 94fce40..c6d918b 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -1,16 +1,12 @@ 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 @AllArgsConstructor @@ -45,7 +41,7 @@ public Status getStatus() { return status; } - public void setStatus(Status status) { + public void setStatus(final Status status) { this.status = status; } } diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index da815d9..993eecd 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -16,11 +16,12 @@ import java.util.Collections; public class EmployeeService { private final EmployeeRepository employeeRepository; - public EmployeeService(EmployeeRepository employeeRepository) { + public EmployeeService(final EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } - public List findEmployees(int start, int pageSize, String sortProperty, boolean asc) { + public List findEmployees( + final int start, final int pageSize, final String sortProperty, final boolean asc) { List employees = employeeRepository.findAll(); int end = Math.min(start + pageSize, employees.size()); @@ -33,7 +34,7 @@ public class EmployeeService { return employees.subList(start, end); } - public List findEmployees(int start, int pageSize) { + public List findEmployees(final int start, final int pageSize) { List employees = employeeRepository.findAll(); int end = Math.min(start + pageSize, employees.size()); diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index d2a570e..9e49fe4 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -145,11 +145,11 @@ public class EmployeeView extends BeanValidationForm implements HasUrl setSavedHandler((SavedHandler) employee -> { if (validateForm()) { final Employee saved = employeeService.createOrUpdate(employee); - Notification.show("Empleado guardado exitosamente."); + Notification.show("Employee saved successfully."); getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class)); setEntityWithEnabledSave(saved); } else { - Notification.show("Acción inválida. Por favor, complete todos los campos requeridos correctamente.", 3000, Notification.Position.MIDDLE); + Notification.show("Please complete the required fields correctly.", 3000, Notification.Position.MIDDLE); } }); diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index b91c03c..489ded8 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -27,7 +27,7 @@ public class EmployeesListView extends Main { private final EmployeeService employeeService; private final PagingGrid table = new PagingGrid<>(Employee.class); - public EmployeesListView(EmployeeService employeeService) { + public EmployeesListView(final EmployeeService employeeService) { this.employeeService = employeeService; setupView(); refreshGrid(); @@ -46,17 +46,17 @@ public class EmployeesListView extends Main { setupPagingGrid(); } - private void updateEmployeeStatus(Employee employee, boolean isActive) { + private void updateEmployeeStatus(final Employee employee, final boolean isActive) { employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE); employeeService.createOrUpdate(employee); refreshGrid(); } - private void addEditButtonColumn(String label, ButtonClickHandler handler) { + private void addEditButtonColumn(final String label, final ButtonClickHandler handler) { table.addComponentColumn(employee -> createButton(label, () -> handler.handle(employee))); } - private Button createButton(String label, Runnable onClickAction) { + private Button createButton(final String label, final Runnable onClickAction) { Button button = new Button(label); button.addClickListener(event -> onClickAction.run()); return button; @@ -66,7 +66,7 @@ public class EmployeesListView extends Main { return createButton("Add Employee", this::navigateToAddEmployeeView); } - private void navigateToEditView(Employee employee) { + private void navigateToEditView(final Employee employee) { getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, employee.getId().toString())); } @@ -83,7 +83,7 @@ public class EmployeesListView extends Main { table.setPagingDataProvider((page, pageSize) -> fetchEmployees((int) page, pageSize)); } - private List fetchEmployees(int page, int pageSize) { + private List fetchEmployees(final int page, final int pageSize) { int start = page * pageSize; if (hasSortOrder()) { return fetchSortedEmployees(start, pageSize); @@ -95,9 +95,11 @@ public class EmployeesListView extends Main { return !table.getSortOrder().isEmpty(); } - private List fetchSortedEmployees(int start, int pageSize) { + private List fetchSortedEmployees(final int start, final int pageSize) { GridSortOrder sortOrder = table.getSortOrder().getFirst(); - return employeeService.findEmployees(start, pageSize, sortOrder.getSorted().getKey(), sortOrder.getDirection() == SortDirection.ASCENDING); + return employeeService.findEmployees(start, pageSize, + sortOrder.getSorted().getKey(), + sortOrder.getDirection() == SortDirection.ASCENDING); } @FunctionalInterface -- 2.34.1 From 5c4d2cdc74926d2c661fb7806175cc0d3cacf296 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Fri, 6 Sep 2024 10:31:35 -0400 Subject: [PATCH 09/12] #4 , 5 , 6 Perfil de Empleado - Registro, Guardado y Modificacion de Informacion Personal --- .../primefactorsolutions/model/Employee.java | 5 ++ .../views/EmployeeView.java | 86 ++++++++++++++++++- .../views/EmployeesListView.java | 7 ++ 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index c6d918b..c130d86 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -22,10 +22,15 @@ private String residenceAddress; private String phoneNumber; private String personalEmail; + private String position; + private String team; private String emergencyCName; private String emergencyCAddress; private String emergencyCPhone; private String emergencyCEmail; + @Lob + private byte[] profilePicture; + @Enumerated(EnumType.STRING) private Status status; public enum Status { diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 9e49fe4..e367113 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -7,11 +7,14 @@ 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.html.Image; 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.component.upload.Upload; +import com.vaadin.flow.component.upload.receivers.MemoryBuffer; import com.vaadin.flow.data.value.ValueChangeMode; import com.vaadin.flow.router.BeforeEvent; import com.vaadin.flow.router.HasUrlParameter; @@ -24,6 +27,8 @@ import org.springframework.context.annotation.Scope; import org.vaadin.firitin.components.datepicker.VDatePicker; import org.vaadin.firitin.form.BeanValidationForm; +import java.io.InputStream; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -45,6 +50,8 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final TextField residenceAddress; private final TextField phoneNumber; private final EmailField personalEmail; + private final TextField position; + private final TextField team; private final TextField emergencyCName; private final TextField emergencyCAddress; @@ -55,6 +62,14 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final H3 fs; private final H3 ss; + private final Upload imageUpload; + private final Image employeeImage; + private byte[] imageBytes; + + private final Button saveButton; + private final Button editButton; + private final List formFields = new ArrayList<>(); + public EmployeeView(final EmployeeService employeeService) { super(Employee.class); this.employeeService = employeeService; @@ -113,6 +128,14 @@ public class EmployeeView extends BeanValidationForm implements HasUrl personalEmail.setWidthFull(); personalEmail.setMaxLength(30); + position = new TextField("Cargo"); + position.setWidthFull(); + position.setMaxLength(30); + + team = new TextField("Equipo"); + team.setWidthFull(); + team.setMaxLength(30); + emergencyCName = new TextField("Nombres y Apellidos de Contacto"); emergencyCName.setWidthFull(); emergencyCName.setMaxLength(50); @@ -135,19 +158,53 @@ public class EmployeeView extends BeanValidationForm implements HasUrl emergencyCEmail.setWidthFull(); emergencyCEmail.setMaxLength(30); + MemoryBuffer buffer = new MemoryBuffer(); + imageUpload = new Upload(buffer); + imageUpload.setAcceptedFileTypes("image/jpeg", "image/png", "image/gif"); + imageUpload.setMaxFileSize(1024 * 1024); + + employeeImage = new Image(); + employeeImage.setMaxHeight("150px"); + employeeImage.setMaxWidth("150px"); + + + imageUpload.addSucceededListener(event -> { + try { + InputStream inputStream = buffer.getInputStream(); + imageBytes = inputStream.readAllBytes(); + employeeImage.setSrc( + "data:image/png;base64," + java.util.Base64.getEncoder().encodeToString(imageBytes)); + Notification.show("Imagen subida correctamente."); + } catch (Exception ex) { + Notification.show( + "Error al subir la imagen: " + ex.getMessage(), 3000, Notification.Position.MIDDLE); + } + }); + + editButton = new Button("Editar"); + saveButton = new Button("Guardar"); + + setFormFieldsEnabled(false); + + editButton.addClickListener(event -> setFormFieldsEnabled(true)); + + contentLayout.add( mt, fs, firstName, lastName, status, birthday, birthCity, maritalStatus, - residenceAddress, phoneNumber, personalEmail); + residenceAddress, phoneNumber, personalEmail, position, team, imageUpload, employeeImage); contentLayout2.add( ss, emergencyCName, emergencyCAddress, emergencyCPhone, emergencyCEmail); setSavedHandler((SavedHandler) employee -> { if (validateForm()) { + employee.setProfilePicture(imageBytes); + employee.setStatus(Employee.Status.valueOf(status.getValue())); final Employee saved = employeeService.createOrUpdate(employee); Notification.show("Employee saved successfully."); getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class)); setEntityWithEnabledSave(saved); + setFormFieldsEnabled(false); } else { Notification.show("Please complete the required fields correctly.", 3000, Notification.Position.MIDDLE); } @@ -157,6 +214,24 @@ public class EmployeeView extends BeanValidationForm implements HasUrl addClassName("main-layout"); } + private void setFormFieldsEnabled(final boolean enabled) { + firstName.setEnabled(enabled); + lastName.setEnabled(enabled); + status.setEnabled(enabled); + birthday.setEnabled(enabled); + birthCity.setEnabled(enabled); + maritalStatus.setEnabled(enabled); + residenceAddress.setEnabled(enabled); + phoneNumber.setEnabled(enabled); + personalEmail.setEnabled(enabled); + position.setEnabled(enabled); + team.setEnabled(enabled); + emergencyCName.setEnabled(enabled); + emergencyCAddress.setEnabled(enabled); + emergencyCPhone.setEnabled(enabled); + emergencyCEmail.setEnabled(enabled); + } + private boolean validateForm() { return !firstName.isEmpty() && !lastName.isEmpty() && status.getValue() != null; } @@ -184,8 +259,10 @@ public class EmployeeView extends BeanValidationForm implements HasUrl if (StringUtils.isNotBlank(s) && !"new".equals(s)) { var employee = employeeService.getEmployee(UUID.fromString(s)); setEntityWithEnabledSave(employee); + setFormFieldsEnabled(true); } else { setEntityWithEnabledSave(new Employee()); + setFormFieldsEnabled(true); } } @@ -203,11 +280,16 @@ public class EmployeeView extends BeanValidationForm implements HasUrl residenceAddress, phoneNumber, personalEmail, + position, + team, + imageUpload, + employeeImage, ss, emergencyCName, emergencyCAddress, emergencyCPhone, - emergencyCEmail + emergencyCEmail, + editButton ); } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 489ded8..3227a3c 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -44,6 +44,11 @@ public class EmployeesListView extends Main { table.setColumns("firstName", "lastName", "status"); addEditButtonColumn("Edit", this::navigateToEditView); setupPagingGrid(); + + table.addItemDoubleClickListener(event -> { + Employee employee = event.getItem(); + navigateToEditView(employee); + }); } private void updateEmployeeStatus(final Employee employee, final boolean isActive) { @@ -80,6 +85,8 @@ public class EmployeesListView extends Main { } private void refreshGrid() { + List employees = employeeService.getEmployeeRepository().findAll(); + table.setItems(employees); table.setPagingDataProvider((page, pageSize) -> fetchEmployees((int) page, pageSize)); } -- 2.34.1 From 9b3fed87a9c3ec26c23056c96eccf3a5ca1f1dcd Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Sat, 7 Sep 2024 17:33:54 -0400 Subject: [PATCH 10/12] #4 Perfil de Empleado-Registro, Guardado y Modificacion de Informacion Personal con las mejoras implementadas --- .../primefactorsolutions/model/Employee.java | 5 +- .../views/EmployeeView.java | 105 +++++++++++++++++- 2 files changed, 102 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index c130d86..0e4d33a 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -28,9 +28,8 @@ private String emergencyCAddress; private String emergencyCPhone; private String emergencyCEmail; - @Lob - private byte[] profilePicture; - + @Column(columnDefinition = "TEXT") + private String profileImage; @Enumerated(EnumType.STRING) private Status status; public enum Status { diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 15b272d..0011715 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -7,11 +7,14 @@ 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.html.Image; 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.component.upload.Upload; +import com.vaadin.flow.component.upload.receivers.MemoryBuffer; import com.vaadin.flow.data.value.ValueChangeMode; import com.vaadin.flow.router.*; import com.vaadin.flow.spring.annotation.SpringComponent; @@ -20,6 +23,9 @@ import org.springframework.context.annotation.Scope; import org.vaadin.firitin.components.datepicker.VDatePicker; import org.vaadin.firitin.form.BeanValidationForm; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Base64; import java.util.List; import java.util.UUID; @@ -31,6 +37,7 @@ import java.util.UUID; public class EmployeeView extends BeanValidationForm implements HasUrlParameter { private static final String SAVE_BUTTON_TEXT = "Save"; + private static final String EDIT_BUTTON_TEXT = "Edit"; private static final String NOTIFICATION_SAVE_SUCCESS = "Employee saved successfully."; private static final String NOTIFICATION_VALIDATE_ERROR = "Please complete the required fields correctly."; private static final String PHONE_NUMBER_ERROR_MESSAGE = "El teléfono debe contener solo números."; @@ -46,11 +53,19 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final TextField residenceAddress = createTextField("Dirección de Residencia", 50, false); private final TextField phoneNumber = createTextField("Teléfono", 8, false); private final EmailField personalEmail = createEmailField("E-mail"); + private final TextField position = createTextField("Cargo", 30, false); + private final TextField team = createTextField("Equipo", 30, false); private final TextField emergencyCName = createTextField("Nombres y Apellidos de Contacto", 50, false); private final TextField emergencyCAddress = createTextField("Dirección de Contacto", 50, false); private final TextField emergencyCPhone = createTextField("Teléfono de Contacto", 8, false); private final EmailField emergencyCEmail = createEmailField("Email de Contacto"); + + private final MemoryBuffer buffer = new MemoryBuffer(); + private final Upload upload = new Upload(buffer); + private final Image profileImagePreview = new Image(); + private final Button saveButton = new Button(SAVE_BUTTON_TEXT, e -> saveEmployee()); + private final Button editButton = new Button(EDIT_BUTTON_TEXT, e -> enableEditMode()); private final H2 mt = new H2("Información General del Empleado"); private final H3 fs = new H3("Información Personal"); @@ -69,8 +84,29 @@ public class EmployeeView extends BeanValidationForm implements HasUrl phoneNumber.addValueChangeListener(e -> validatePhoneNumber(phoneNumber, e.getValue())); emergencyCPhone.setValueChangeMode(ValueChangeMode.EAGER); emergencyCPhone.addValueChangeListener(e -> validatePhoneNumber(emergencyCPhone, e.getValue())); - + configureUpload(); saveButton.setVisible(true); + editButton.setVisible(true); + } + + private void configureUpload() { + upload.setAcceptedFileTypes("image/jpeg", "image/png"); + upload.setMaxFileSize(1024 * 1024); + upload.addSucceededListener(event -> { + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + buffer.getInputStream().transferTo(outputStream); + byte[] imageBytes = outputStream.toByteArray(); + String base64Image = Base64.getEncoder().encodeToString(imageBytes); + + getEntity().setProfileImage(base64Image); + + profileImagePreview.setSrc("data:image/jpeg;base64," + base64Image); + profileImagePreview.setMaxWidth("150px"); + profileImagePreview.setMaxHeight("150px"); + } catch (IOException e) { + Notification.show("Error al subir la imagen."); + } + }); } private void validatePhoneNumber(final TextField textField, final String value) { @@ -95,8 +131,13 @@ public class EmployeeView extends BeanValidationForm implements HasUrl maritalStatus, residenceAddress, phoneNumber, - personalEmail); - contentLayout2.add(ss, emergencyCName, emergencyCAddress, emergencyCPhone, emergencyCEmail, saveButton); + personalEmail, + position, + team); + contentLayout2.add( + ss, emergencyCName, emergencyCAddress, + emergencyCPhone, emergencyCEmail, upload, + profileImagePreview, saveButton, editButton); mainLayout.add(contentLayout1, contentLayout2); addClassName("main-layout"); @@ -162,6 +203,13 @@ public class EmployeeView extends BeanValidationForm implements HasUrl } } + private void enableEditMode() { + setFieldsEditable(); + saveButton.setVisible(true); + editButton.setVisible(false); + } + + @Override public void setParameter(final BeforeEvent beforeEvent, final String action) { RouteParameters params = beforeEvent.getRouteParameters(); @@ -169,19 +217,42 @@ public class EmployeeView extends BeanValidationForm implements HasUrl if ("new".equals(action)) { setEntityWithEnabledSave(new Employee()); + saveButton.setVisible(true); + editButton.setVisible(false); + setFieldsEditable(); } else { UUID employeeId = UUID.fromString(s); var employee = employeeService.getEmployee(employeeId); setEntityWithEnabledSave(employee); if ("edit".equals(action) && !s.isEmpty()) { + saveButton.setVisible(true); + editButton.setVisible(false); status.setValue(employee.getStatus()); + setFieldsEditable(); } else if ("view".equals(action) && !s.isEmpty()) { setFieldsReadOnly(); saveButton.setVisible(false); + editButton.setVisible(true); + setFieldsReadOnly(); + displayProfileImage(employee); } } } + private void displayProfileImage(final Employee employee) { + if (employee.getProfileImage() != null && !employee.getProfileImage().isEmpty()) { + profileImagePreview.setSrc("data:image/jpeg;base64," + employee.getProfileImage()); + profileImagePreview.setVisible(true); + profileImagePreview.setMaxWidth("150px"); + profileImagePreview.setMaxHeight("150px"); + + upload.setVisible(false); + } else { + profileImagePreview.setVisible(false); + upload.setVisible(true); + } + } + private void setFieldsReadOnly() { firstName.setReadOnly(true); lastName.setReadOnly(true); @@ -192,18 +263,42 @@ public class EmployeeView extends BeanValidationForm implements HasUrl residenceAddress.setReadOnly(true); phoneNumber.setReadOnly(true); personalEmail.setReadOnly(true); + position.setReadOnly(true); + team.setReadOnly(true); emergencyCName.setReadOnly(true); emergencyCAddress.setReadOnly(true); emergencyCPhone.setReadOnly(true); emergencyCEmail.setReadOnly(true); + upload.setVisible(true); + profileImagePreview.setVisible(true); } + private void setFieldsEditable() { + firstName.setReadOnly(false); + lastName.setReadOnly(false); + status.setReadOnly(false); + birthday.setReadOnly(false); + birthCity.setReadOnly(false); + maritalStatus.setReadOnly(false); + residenceAddress.setReadOnly(false); + phoneNumber.setReadOnly(false); + personalEmail.setReadOnly(false); + position.setReadOnly(false); + team.setReadOnly(false); + emergencyCName.setReadOnly(false); + emergencyCAddress.setReadOnly(false); + emergencyCPhone.setReadOnly(false); + emergencyCEmail.setReadOnly(false); + upload.setVisible(true); + } + + @Override protected List getFormComponents() { return List.of( mt, fs, firstName, lastName, status, birthday, birthCity, maritalStatus, - residenceAddress, phoneNumber, personalEmail, ss, emergencyCName, - emergencyCAddress, emergencyCPhone, emergencyCEmail, saveButton + residenceAddress, phoneNumber, personalEmail, position, team, ss, emergencyCName, + emergencyCAddress, emergencyCPhone, emergencyCEmail, upload, profileImagePreview, saveButton, editButton ); } } -- 2.34.1 From 926b32a8cc6bb0955445a8c422a5b944794920c2 Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Sun, 8 Sep 2024 08:06:01 -0400 Subject: [PATCH 11/12] #4 Perfil de Empleado-Registro, Guardado y Modificacion de Informacion Personal con las mejoras implementadas --- .../java/com/primefactorsolutions/views/EmployeeView.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 0011715..ad1f23d 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -70,6 +70,8 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final H2 mt = new H2("Información General del Empleado"); private final H3 fs = new H3("Información Personal"); private final H3 ss = new H3("Datos de Contacto de Emergencia"); + private final H3 si = new H3("Foto del Empleado"); + public EmployeeView(final EmployeeService employeeService) { super(Employee.class); @@ -136,7 +138,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl team); contentLayout2.add( ss, emergencyCName, emergencyCAddress, - emergencyCPhone, emergencyCEmail, upload, + emergencyCPhone, emergencyCEmail, si, upload, profileImagePreview, saveButton, editButton); mainLayout.add(contentLayout1, contentLayout2); @@ -298,7 +300,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl return List.of( mt, fs, firstName, lastName, status, birthday, birthCity, maritalStatus, residenceAddress, phoneNumber, personalEmail, position, team, ss, emergencyCName, - emergencyCAddress, emergencyCPhone, emergencyCEmail, upload, profileImagePreview, saveButton, editButton + emergencyCAddress, emergencyCPhone, emergencyCEmail, si, upload, profileImagePreview, saveButton, editButton ); } } -- 2.34.1 From 9799e23ac8a1d46980444c729c3e65f49d8f50ca Mon Sep 17 00:00:00 2001 From: Melina Gutierrez Date: Sun, 8 Sep 2024 08:26:03 -0400 Subject: [PATCH 12/12] #4 Perfil de Empleado-Quitar el addItemDoubleClickListener para editar porque ya existe el boton de edit --- .../java/com/primefactorsolutions/views/EmployeeView.java | 3 ++- .../com/primefactorsolutions/views/EmployeesListView.java | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index ad1f23d..6709e6f 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -300,7 +300,8 @@ public class EmployeeView extends BeanValidationForm implements HasUrl return List.of( mt, fs, firstName, lastName, status, birthday, birthCity, maritalStatus, residenceAddress, phoneNumber, personalEmail, position, team, ss, emergencyCName, - emergencyCAddress, emergencyCPhone, emergencyCEmail, si, upload, profileImagePreview, saveButton, editButton + emergencyCAddress, emergencyCPhone, emergencyCEmail, si, upload, profileImagePreview, + saveButton, editButton ); } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 369d2ce..e9f3726 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -45,11 +45,6 @@ public class EmployeesListView extends Main { addEditButtonColumn("View", this::navigateToEmployeeView); addEditButtonColumn("Edit", this::navigateToEditView); setupPagingGrid(); - - table.addItemDoubleClickListener(event -> { - Employee employee = event.getItem(); - navigateToEditView(employee); - }); } private void updateEmployeeStatus(final Employee employee, final boolean isActive) { -- 2.34.1