From d53792f3802b3e1fee0368ed949b9f31813ccdc6 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 27 Nov 2024 21:03:39 -0400 Subject: [PATCH] #37 Perfil de Personal Administrativo - Listado General de Vacaciones(Agregar filtro de categoria) --- .../views/DocumentView.java | 1 - .../views/RequestsListView.java | 43 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/DocumentView.java b/src/main/java/com/primefactorsolutions/views/DocumentView.java index 5033966..3e738fd 100644 --- a/src/main/java/com/primefactorsolutions/views/DocumentView.java +++ b/src/main/java/com/primefactorsolutions/views/DocumentView.java @@ -53,7 +53,6 @@ public class DocumentView extends BeanValidationForm implements HasUrl private Button saveButton; private Button viewDocumentButton; - public DocumentView(final DocumentService documentService, final EmployeeService employeeService, final AuthenticationContext authContext) { diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 1c9c1d3..24bd3e0 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -55,6 +55,7 @@ public class RequestsListView extends BaseView { private ComboBox employeeFilter; private ComboBox teamFilter; + private ComboBox categoryFilter; private ComboBox stateFilter; public RequestsListView(final TimeOffRequestService requestService, @@ -66,7 +67,7 @@ public class RequestsListView extends BaseView { this.teamService = teamService; this.vacationService = vacationService; initializeView(); - refreshGeneralRequestGrid(null, null, null); + refreshGeneralRequestGrid(null, null, null, null); } private void initializeView() { @@ -82,6 +83,7 @@ public class RequestsListView extends BaseView { final HorizontalLayout hl = new HorizontalLayout(); hl.add(createEmployeeFilter()); hl.add(createTeamFilter()); + hl.add(createCategoryFilter()); hl.add(createStateFilter()); getCurrentPageLayout().add(hl); } @@ -90,6 +92,7 @@ public class RequestsListView extends BaseView { requestGrid.addColumn(this::getEmployeeFullName).setHeader("Empleado"); requestGrid.addColumn(this::getTeamName).setHeader("Equipo"); requestGrid.addColumn(this::getEmployeeStatus).setHeader("Estado del empleado"); + requestGrid.addColumn(this::getCategory).setHeader("Categoria"); requestGrid.addColumn(this::getGeneralTotal).setHeader("Total general"); requestGrid.addComponentColumn((ValueProvider) employee -> { final MenuBar menuBar = new MenuBar(); @@ -107,10 +110,11 @@ public class RequestsListView extends BaseView { private void refreshGeneralRequestGrid(final Employee employee, final Team team, + final TimeOffRequestType category, final Status state) { requestGrid.setPagingDataProvider((page, pageSize) -> { int start = (int) (page * requestGrid.getPageSize()); - return fetchFilteredEmployees(start, pageSize, employee, team, state); + return fetchFilteredEmployees(start, pageSize, employee, team, category, state); }); requestGrid.getDataProvider().refreshAll(); } @@ -119,6 +123,7 @@ public class RequestsListView extends BaseView { final int pageSize, final Employee employee, final Team team, + final TimeOffRequestType category, final Status state) { List filteredEmployees = employeeService.findAllEmployees(); @@ -134,6 +139,16 @@ public class RequestsListView extends BaseView { .collect(Collectors.toList()); } + if (category != null && category != TimeOffRequestType.values()[0]) { + filteredEmployees = filteredEmployees.stream() + .filter(emp -> { + Optional request = requestService + .findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.EN_USO); + return request.isPresent() && request.get().getCategory() == category; + }) + .collect(Collectors.toList()); + } + if (state != null && state != Status.TODOS) { filteredEmployees = filteredEmployees.stream() .filter(emp -> { @@ -168,6 +183,12 @@ public class RequestsListView extends BaseView { return activeRequest.isPresent() ? "EN_DESCANSO" : "EN_FUNCIONES"; } + private String getCategory(final Employee employee) { + Optional activeRequest = requestService + .findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.EN_USO); + return activeRequest.map(request -> request.getCategory().toString()).orElse(""); + } + private String getGeneralTotal(final Employee employee) { List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); List vacations = vacationService.findVacations(); @@ -363,6 +384,7 @@ public class RequestsListView extends BaseView { refreshGeneralRequestGrid( event.getValue(), teamFilter.getValue(), + categoryFilter.getValue(), stateFilter.getValue() ) ); @@ -380,12 +402,28 @@ public class RequestsListView extends BaseView { refreshGeneralRequestGrid( employeeFilter.getValue(), event.getValue(), + categoryFilter.getValue(), stateFilter.getValue() ) ); return teamFilter; } + private ComboBox createCategoryFilter() { + categoryFilter = new ComboBox<>("Category"); + categoryFilter.setItems(TimeOffRequestType.values()); + categoryFilter.setValue(TimeOffRequestType.values()[0]); + categoryFilter.addValueChangeListener(event -> + refreshGeneralRequestGrid( + employeeFilter.getValue(), + teamFilter.getValue(), + event.getValue(), + stateFilter.getValue() + ) + ); + return categoryFilter; + } + private ComboBox createStateFilter() { stateFilter = new ComboBox<>("Estado del empleado"); stateFilter.setItems(Status.values()); @@ -394,6 +432,7 @@ public class RequestsListView extends BaseView { refreshGeneralRequestGrid( employeeFilter.getValue(), teamFilter.getValue(), + categoryFilter.getValue(), event.getValue() ) );