From 7e415ae8375558fc8557e5ed04a4713399e9b67d Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 5 Nov 2024 10:47:16 -0400 Subject: [PATCH 1/2] cambiar team string a un team class --- .../views/EmployeeView.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index bdf5a82..a8c4f51 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -1,8 +1,10 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; +import com.primefactorsolutions.model.Team; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.ReportService; +import com.primefactorsolutions.service.TeamService; import com.vaadin.componentfactory.pdfviewer.PdfViewer; import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; @@ -27,6 +29,7 @@ import com.vaadin.flow.router.*; import com.vaadin.flow.server.StreamResource; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.components.datepicker.VDatePicker; import org.vaadin.firitin.form.BeanValidationForm; @@ -47,6 +50,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final EmployeeService employeeService; private final ReportService reportService; + private final TeamService teamService; // TODO: campo usado para registrar al empleado en LDAP. Este campo podria estar en otro form eventualmente. private final TextField username = createTextField("Username: ", 30, true); @@ -67,7 +71,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final EmailField personalEmail = createEmailField("E-mail"); private final TextField cod = createTextField("Codigo de Empleado", 30, false); private final TextField position = createTextField("Cargo", 30, false); - private final TextField team = createTextField("Equipo", 30, false); + private final ComboBox team = new ComboBox<>("Equipo"); private final TextField leadManager = createTextField("Lead/Manager", 30, false); private final TextField project = createTextField("Proyecto", 30, false); private final TextField emergencyCName = createTextField("Nombres y Apellidos de Contacto", 50, false); @@ -135,10 +139,13 @@ public class EmployeeView extends BeanValidationForm implements HasUrl private final H3 datBanc = new H3("Datos Bancados"); private final H3 datGest = new H3("Datos Gestora Pública y Seguro Social"); - public EmployeeView(final EmployeeService employeeService, final ReportService reportService) { + public EmployeeView(final EmployeeService employeeService, + final ReportService reportService, + final TeamService teamService) { super(Employee.class); this.employeeService = employeeService; this.reportService = reportService; + this.teamService = teamService; saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY); configureComponents(); @@ -155,6 +162,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl editButton.setVisible(true); reportButton.setVisible(true); birthday.addValueChangeListener(event -> calculateAge()); + createTeamComboBox(); reportButton.addClickListener((ComponentEventListener>) buttonClickEvent -> { var employee = getEntity(); @@ -262,12 +270,11 @@ public class EmployeeView extends BeanValidationForm implements HasUrl return emailField; } - private ComboBox createComboBox(final String label, final T[] items) { - ComboBox comboBox = new ComboBox<>(label); - comboBox.setItems(items); - comboBox.setItemLabelGenerator(Object::toString); - comboBox.setWidthFull(); - return comboBox; + private void createTeamComboBox() { + List teams = teamService.findAllTeams(); + team.setItems(teams); + team.setItemLabelGenerator(Team::getName); + team.setWidthFull(); } private ComboBox createGenderComboBox() { @@ -317,6 +324,7 @@ public class EmployeeView extends BeanValidationForm implements HasUrl UUID employeeId = UUID.fromString(s); var employee = employeeService.getEmployee(employeeId); setEntityWithEnabledSave(employee); + team.setValue(employee.getTeam()); if ("edit".equals(action) && !s.isEmpty()) { saveButton.setVisible(true); -- 2.34.1 From 88e80a7dcc5635775197291d7a8a2e1279028291 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 5 Nov 2024 13:33:00 -0400 Subject: [PATCH 2/2] =?UTF-8?q?traducir=20a=20espa=C3=B1ol=20y=20cambiar?= =?UTF-8?q?=20uso=20de=20grid=20a=20paging=20grid=20de=20RequestEmploye?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestEmployeeView.java | 90 ++++++++++--------- .../views/RequestView.java | 24 ++--- .../views/RequestsListView.java | 2 +- 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index f2e0088..db19a41 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -6,7 +6,6 @@ import com.primefactorsolutions.service.TimeOffRequestService; import com.primefactorsolutions.service.VacationService; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.combobox.ComboBox; -import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.H3; import com.vaadin.flow.component.html.Span; @@ -20,6 +19,7 @@ import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; +import org.vaadin.firitin.components.grid.PagingGrid; import java.util.Collections; import java.util.List; @@ -36,7 +36,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter private final TimeOffRequestService requestService; private final EmployeeService employeeService; private final VacationService vacationService; - private final Grid requestGrid = new Grid<>(TimeOffRequest.class); + private final PagingGrid requestGrid = new PagingGrid<>(TimeOffRequest.class); private List requests = Collections.emptyList(); private ComboBox categoryFilter; private ComboBox stateFilter; @@ -65,7 +65,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private ComboBox createCategoryFilter() { - categoryFilter = new ComboBox<>("Category"); + categoryFilter = new ComboBox<>("Categoría"); categoryFilter.setItems(TimeOffRequestType.values()); categoryFilter.setValue(TimeOffRequestType.values()[0]); categoryFilter.addValueChangeListener(event -> refreshRequestGrid(event.getValue(), stateFilter.getValue())); @@ -73,7 +73,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private ComboBox createStateFilter() { - stateFilter = new ComboBox<>("State"); + stateFilter = new ComboBox<>("Estado de la solicitud"); stateFilter.setItems(TimeOffRequestStatus.values()); stateFilter.setValue(TimeOffRequestStatus.values()[0]); stateFilter.addValueChangeListener(event -> refreshRequestGrid(categoryFilter.getValue(), event.getValue())); @@ -87,7 +87,15 @@ public class RequestEmployeeView extends Div implements HasUrlParameter "startDate", "endDate", "daysToBeTake"); - requestGrid.setAllRowsVisible(true); + + requestGrid.getColumnByKey("category").setHeader("Categoría"); + requestGrid.getColumnByKey("state").setHeader("Estado"); + requestGrid.getColumnByKey("startDate").setHeader("Fecha de Inicio"); + requestGrid.getColumnByKey("endDate").setHeader("Fecha de Fin"); + requestGrid.getColumnByKey("daysToBeTake").setHeader("Días a Tomar"); + + requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); + requestGrid.setPageSize(5); requestGrid.asSingleSelect().addValueChangeListener(event -> { TimeOffRequest selectedRequest = event.getValue(); if (selectedRequest != null) { @@ -102,22 +110,22 @@ public class RequestEmployeeView extends Div implements HasUrlParameter .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); double totalVacations = requests.stream() - .filter(req -> req.getCategory().toString().startsWith("VACATION")) + .filter(req -> req.getCategory().toString().startsWith("VACACION")) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); double totalPersonalDays = requests.stream() .filter(req -> !verificationIsHoliday(req)) - .filter(req -> !req.getCategory().name().startsWith("VACATION")) + .filter(req -> !req.getCategory().name().startsWith("VACACION")) .mapToDouble(TimeOffRequest::getAvailableDays) .sum(); double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays; return new VerticalLayout( - new Span("TOTAL HOLIDAYS: " + totalHoliday), - new Span("TOTAL VACATIONS: " + totalVacations), - new Span("TOTAL PERSONAL DAYS: " + totalPersonalDays), - new Span("TOTAL GENERAL: " + totalAvailableDays) + new Span("Total días libres: " + totalHoliday), + new Span("Total vacaciones: " + totalVacations), + new Span("Total días personales: " + totalPersonalDays), + new Span("Total general: " + totalAvailableDays) ); } @@ -127,24 +135,23 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private HorizontalLayout createActionButtons() { - Button viewButton = new Button("View", event -> { - if (request != null) { - navigateToViewRequest(request); - } else { - Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE); - } - }); - Button editButton = new Button("Edit", event -> { - if (request != null) { - navigateToEditRequest(request); - } else { - Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE); - } - }); - Button closeButton = new Button("Close", event -> navigateToRequestsListView()); + Button viewButton = createButton("Ver", () -> navigateToViewRequest(request)); + Button editButton = createButton("Editar", () -> navigateToEditRequest(request)); + Button closeButton = new Button("Salir", event -> navigateToRequestsListView()); + return new HorizontalLayout(viewButton, editButton, closeButton); } + private Button createButton(String caption, Runnable action) { + return new Button(caption, event -> { + if (request != null) { + action.run(); + } else { + Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE); + } + }); + } + private void navigateToRequestsListView() { getUI().ifPresent(ui -> ui.navigate(RequestsListView.class)); } @@ -162,33 +169,30 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private void refreshRequestGrid(final TimeOffRequestType category, final TimeOffRequestStatus state) { - List filteredRequests = allFiltersAreNull(category, state) - ? requestService.findRequestsByEmployeeId(employeeId) - : fetchFilteredTimeOffRequests(category, state); - for (TimeOffRequest request : filteredRequests) { - requestService.saveTimeOffRequest(request); - } - requestGrid.setItems(filteredRequests); + requestGrid.setPagingDataProvider((page, pageSize) -> { + int start = (int) (page * requestGrid.getPageSize()); + return fetchFilteredTimeOffRequests(start, pageSize, category, state); + }); + requestGrid.getDataProvider().refreshAll(); } - private boolean allFiltersAreNull(final TimeOffRequestType category, final TimeOffRequestStatus state) { - return category == null && state == null; - } - - private List fetchFilteredTimeOffRequests(final TimeOffRequestType category, + private List fetchFilteredTimeOffRequests(final int start, + final int pageSize, + final TimeOffRequestType category, final TimeOffRequestStatus state) { requests = requestService.findRequestsByEmployeeId(employeeId); - if (category != null && !"ALL".equals(category.name())) { + if (category != null && !"TODOS".equals(category.name())) { requests = requests.stream() .filter(req -> req.getCategory().equals(category)) .collect(Collectors.toList()); } - if (state != null && !"ALL".equals(state.name())) { + if (state != null && !"TODOS".equals(state.name())) { requests = requests.stream() .filter(req -> req.getState().equals(state)) .collect(Collectors.toList()); } - return requests; + int end = Math.min(start + pageSize, requests.size()); + return requests.subList(start, end); } @Override @@ -202,7 +206,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private void setViewTitle(final String employeeName, final String employeeTeam) { - addComponentAsFirst(new H3("Name: " + employeeName)); - addComponentAtIndex(1, new H3("Team: " + employeeTeam)); + addComponentAsFirst(new H3("Nombre del empleado: " + employeeName)); + addComponentAtIndex(1, new H3("Equipo: " + employeeTeam)); } } diff --git a/src/main/java/com/primefactorsolutions/views/RequestView.java b/src/main/java/com/primefactorsolutions/views/RequestView.java index 1fae708..47b5ae2 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestView.java @@ -27,12 +27,12 @@ import java.util.UUID; @Route(value = "/requests/:requestId?/:action?", layout = MainLayout.class) public class RequestView extends BeanValidationForm implements HasUrlParameter { - private final ComboBox state = new ComboBox<>("State"); - private final DatePicker expiration = new DatePicker("Expiration"); - private final DatePicker startDate = new DatePicker("Start Date"); - private final DatePicker endDate = new DatePicker("End Date"); - private final NumberField availableDays = new NumberField("Available Days"); - private final NumberField daysToBeTake = new NumberField("Days To Be Take"); + private final ComboBox state = new ComboBox<>("Estado de la solicitud"); + private final DatePicker expiration = new DatePicker("Vencimiento"); + private final DatePicker startDate = new DatePicker("Fecha de inicio"); + private final DatePicker endDate = new DatePicker("Fecha de fin"); + private final NumberField availableDays = new NumberField("Días disponibles"); + private final NumberField daysToBeTake = new NumberField("Días a tomar"); private final TimeOffRequestService requestService; private final EmployeeService employeeService; @@ -85,13 +85,13 @@ public class RequestView extends BeanValidationForm implements H } protected Button createSaveButton() { - saveButton = new Button("Save"); + saveButton = new Button("Guardar"); saveButton.addClickListener(event -> saveRequest()); return saveButton; } protected Button createCloseButton() { - Button closeButton = new Button("Close"); + Button closeButton = new Button("Salir"); closeButton.addClickListener(event -> closeForm()); return closeButton; } @@ -110,7 +110,7 @@ public class RequestView extends BeanValidationForm implements H TimeOffRequest request = getEntity(); setRequestFieldValues(request); requestService.saveTimeOffRequest(request); - Notification.show("Request saved successfully."); + Notification.show("Solicitud guardada correctamente."); closeForm(); } } @@ -147,14 +147,14 @@ public class RequestView extends BeanValidationForm implements H } private H3 createEmployeeHeader() { - return new H3("Employee: " + employee.getFirstName() + " " + employee.getLastName()); + return new H3("Empleado: " + employee.getFirstName() + " " + employee.getLastName()); } private H3 createTeamHeader() { - return new H3("Team: " + employee.getTeam().getName()); + return new H3("Equipo: " + employee.getTeam().getName()); } private H3 createCategoryHeader() { - return new H3("Category: " + request.getCategory()); + return new H3("Categoría: " + request.getCategory()); } } diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 8b6465c..2551fee 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -90,7 +90,7 @@ public class RequestsListView extends Main { if (selectedEmployeeId != null) { navigateToTimeOffRequestView(selectedEmployeeId); } else { - Notification.show("Seleccione una solicitud para verla.", 3000, Notification.Position.MIDDLE); + Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE); } }); Button closeButton = new Button("Salir", event -> navigateToMainView()); -- 2.34.1