From 2a561a925cf9368d1d99097ebf74af3ffe617e16 Mon Sep 17 00:00:00 2001 From: Alex Prudencio Date: Sun, 17 Nov 2024 16:37:57 -0500 Subject: [PATCH] change list page size --- .../views/AssessmentsListView.java | 5 +++-- .../views/CandidatesListView.java | 7 +++---- .../com/primefactorsolutions/views/Constants.java | 5 +++++ .../views/DocumentsListView.java | 4 +++- .../views/EmployeesListView.java | 2 +- .../views/HoursWorkedListView.java | 14 +++++++------- .../views/PendingRequestsListView.java | 6 +++--- .../views/QuestionsListView.java | 10 ++++------ .../views/RequestEmployeeView.java | 9 +++------ .../views/RequestsListView.java | 13 +++++-------- 10 files changed, 37 insertions(+), 38 deletions(-) create mode 100644 src/main/java/com/primefactorsolutions/views/Constants.java diff --git a/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java b/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java index cf755c3..88160c6 100644 --- a/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java +++ b/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java @@ -37,7 +37,7 @@ public class AssessmentsListView extends Main { final HorizontalLayout hl = new HorizontalLayout(); final Button addAssessment = new Button("Add Assessment"); addAssessment.addClickListener((ComponentEventListener>) buttonClickEvent -> { - this.getUI().get().navigate(AssessmentView.class, "new"); + this.getUI().flatMap(ui -> ui.navigate(AssessmentView.class, "new")); }); hl.add(addAssessment); @@ -51,7 +51,7 @@ public class AssessmentsListView extends Main { grid.addComponentColumn((ValueProvider) assessment -> { var result = new Button("Result", event -> - this.getUI().get().navigate(SubmissionView.class, assessment.getId().toString()) + this.getUI().flatMap(ui -> ui.navigate(SubmissionView.class, assessment.getId().toString())) ); result.setEnabled(assessment.isCompleted()); @@ -95,6 +95,7 @@ public class AssessmentsListView extends Main { return assessmentService.getAssessments().size(); } + @SuppressWarnings("unused") @Override public Stream fetch(final Query query) { int limit = query.getLimit(); diff --git a/src/main/java/com/primefactorsolutions/views/CandidatesListView.java b/src/main/java/com/primefactorsolutions/views/CandidatesListView.java index 599bb57..c887c37 100644 --- a/src/main/java/com/primefactorsolutions/views/CandidatesListView.java +++ b/src/main/java/com/primefactorsolutions/views/CandidatesListView.java @@ -28,15 +28,13 @@ import java.util.stream.Stream; @Route(value = "/candidates", layout = MainLayout.class) @PermitAll public class CandidatesListView extends Main { - private final CandidateService candidateService; public CandidatesListView(final CandidateService candidateService) { - this.candidateService = candidateService; final HorizontalLayout hl = new HorizontalLayout(); final Button addCandidate = new Button("Add Candidate"); addCandidate.addClickListener((ComponentEventListener>) buttonClickEvent -> { - this.getUI().get().navigate(CandidateView.class, "new"); + this.getUI().flatMap(ui -> ui.navigate(CandidateView.class, "new")); }); hl.add(addCandidate); @@ -46,7 +44,7 @@ public class CandidatesListView extends Main { grid.addComponentColumn((ValueProvider) candidate -> { final Button edit = new Button("Edit"); edit.addClickListener((ComponentEventListener>) buttonClickEvent -> - this.getUI().get().navigate(CandidateView.class, candidate.getId().toString())); + this.getUI().flatMap(ui -> ui.navigate(CandidateView.class, candidate.getId().toString()))); return edit; }); @@ -61,6 +59,7 @@ public class CandidatesListView extends Main { return candidateService.getCandidates().size(); } + @SuppressWarnings("unused") @Override public Stream fetch(final Query query) { int limit = query.getLimit(); diff --git a/src/main/java/com/primefactorsolutions/views/Constants.java b/src/main/java/com/primefactorsolutions/views/Constants.java new file mode 100644 index 0000000..92d0410 --- /dev/null +++ b/src/main/java/com/primefactorsolutions/views/Constants.java @@ -0,0 +1,5 @@ +package com.primefactorsolutions.views; + +public class Constants { + public static final int PAGE_SIZE = 10; +} diff --git a/src/main/java/com/primefactorsolutions/views/DocumentsListView.java b/src/main/java/com/primefactorsolutions/views/DocumentsListView.java index c95e917..e733495 100644 --- a/src/main/java/com/primefactorsolutions/views/DocumentsListView.java +++ b/src/main/java/com/primefactorsolutions/views/DocumentsListView.java @@ -24,6 +24,8 @@ import org.vaadin.firitin.components.grid.PagingGrid; import java.io.ByteArrayInputStream; import java.util.List; +import static com.primefactorsolutions.views.Constants.PAGE_SIZE; + @SpringComponent @Scope("prototype") @@ -133,7 +135,7 @@ public class DocumentsListView extends Main { private void configurePagination() { documentGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); - documentGrid.setPageSize(5); + documentGrid.setPageSize(PAGE_SIZE); } private void updateDocumentGrid(final DocumentType documentType, final Employee employee) { diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 15fc02a..cb91785 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -75,7 +75,7 @@ public class EmployeesListView extends Main { private void setupPagingGrid() { table.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); - table.setPageSize(5); + table.setPageSize(Constants.PAGE_SIZE); } private void refreshGrid() { diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java index 4be4a2a..e50ef43 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java @@ -23,6 +23,8 @@ import java.time.temporal.IsoFields; import java.util.*; import java.util.stream.Collectors; +import static com.primefactorsolutions.views.Constants.PAGE_SIZE; + @SpringComponent @PermitAll @Scope("prototype") @@ -34,7 +36,6 @@ public class HoursWorkedListView extends Main { private final EmployeeService employeeService; private final TeamService teamService; private final PagingGrid hoursWorkedGrid = new PagingGrid<>(); - private List employees = Collections.emptyList(); private ComboBox employeeFilter; private ComboBox teamFilter; private UUID selectedEmployeeId; @@ -46,7 +47,6 @@ public class HoursWorkedListView extends Main { this.hoursWorkedService = hoursWorkedService; this.employeeService = employeeService; this.teamService = teamService; - this.employees = employeeService.findAllEmployees(); initializeView(); refreshGridListHoursWorked(null, null); @@ -127,7 +127,7 @@ public class HoursWorkedListView extends Main { hoursWorkedGrid.addColumn(hw -> hw.getDate() != null ? hw.getDate().toString() : "") .setHeader("Fecha") .setSortable(true); - hoursWorkedGrid.addColumn(hw -> hw.getWeekNumber()) + hoursWorkedGrid.addColumn(HoursWorked::getWeekNumber) .setHeader("Semana") .setSortable(true); hoursWorkedGrid.addColumn(hw -> hw.getEmployee().getFirstName() + " " + hw.getEmployee().getLastName()) @@ -136,12 +136,12 @@ public class HoursWorkedListView extends Main { .getName() : "Sin asignar") .setHeader("Equipo"); hoursWorkedGrid.addColumn(HoursWorked::getActividad).setHeader("Actividad"); - hoursWorkedGrid.addColumn(hw -> hw.getHours()).setHeader("Total Horas").setSortable(true); + hoursWorkedGrid.addColumn(HoursWorked::getHours).setHeader("Total Horas").setSortable(true); hoursWorkedGrid.addColumn(hw -> hw.getHoraspendientes() - calcularTotal(hw)).setHeader("Horas Pendientes") .setSortable(true); hoursWorkedGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); - hoursWorkedGrid.setPageSize(5); + hoursWorkedGrid.setPageSize(PAGE_SIZE); hoursWorkedGrid.asSingleSelect().addValueChangeListener(event -> { HoursWorked selectedHoursWorked = event.getValue(); if (selectedHoursWorked != null) { @@ -159,7 +159,7 @@ public class HoursWorkedListView extends Main { private double calculateTotalUtilized(final List employeeRequests) { return employeeRequests.stream() .filter(Objects::nonNull) - .mapToDouble(hoursworked -> hoursworked.getHours()) + .mapToDouble(HoursWorked::getHours) .sum(); } @@ -223,7 +223,7 @@ public class HoursWorkedListView extends Main { List teams = new ArrayList<>(teamService.findAllTeams()); teams.addFirst(createAllTeamsOption()); teamFilter.setItems(teams); - teamFilter.setItemLabelGenerator(team -> getTeamLabel(team)); + teamFilter.setItemLabelGenerator(this::getTeamLabel); teamFilter.setValue(teams.getFirst()); teamFilter.addValueChangeListener(event -> refreshGridListHoursWorked( diff --git a/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java b/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java index db9b783..8ab68da 100644 --- a/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/PendingRequestsListView.java @@ -19,6 +19,8 @@ import org.vaadin.firitin.components.grid.PagingGrid; import java.util.*; import java.util.stream.Collectors; +import static com.primefactorsolutions.views.Constants.PAGE_SIZE; + @SpringComponent @Scope("prototype") @PageTitle("PendingRequests") @@ -31,7 +33,6 @@ public class PendingRequestsListView extends Main { private final TeamService teamService; private final PagingGrid pendingRequestsGrid = new PagingGrid<>(); - private List employees = Collections.emptyList(); private ComboBox employeeFilter; private ComboBox teamFilter; private ComboBox categoryFilter; @@ -44,7 +45,6 @@ public class PendingRequestsListView extends Main { this.requestService = requestService; this.employeeService = employeeService; this.teamService = teamService; - this.employees = employeeService.findAllEmployees(); initializeView(); refreshGeneralPendingRequestsGrid(null, null, null); } @@ -68,7 +68,7 @@ public class PendingRequestsListView extends Main { pendingRequestsGrid.addColumn(this::getCategory).setHeader("Categoría"); pendingRequestsGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); - pendingRequestsGrid.setPageSize(5); + pendingRequestsGrid.setPageSize(PAGE_SIZE); pendingRequestsGrid.asSingleSelect().addValueChangeListener(event -> { TimeOffRequest selectedRequest = event.getValue(); if (selectedRequest != null) { diff --git a/src/main/java/com/primefactorsolutions/views/QuestionsListView.java b/src/main/java/com/primefactorsolutions/views/QuestionsListView.java index 23deca7..ffd0c15 100644 --- a/src/main/java/com/primefactorsolutions/views/QuestionsListView.java +++ b/src/main/java/com/primefactorsolutions/views/QuestionsListView.java @@ -28,16 +28,13 @@ import java.util.stream.Stream; @Route(value = "/questions", layout = MainLayout.class) @PermitAll public class QuestionsListView extends Main { - private final QuestionService questionService; public QuestionsListView(final QuestionService questionService) { - this.questionService = questionService; final HorizontalLayout hl = new HorizontalLayout(); final Button addQuestion = new Button("Add Question"); - addQuestion.addClickListener((ComponentEventListener>) buttonClickEvent -> { - this.getUI().get().navigate(QuestionView.class, "new"); - }); + addQuestion.addClickListener((ComponentEventListener>) buttonClickEvent -> + this.getUI().flatMap(ui -> ui.navigate(QuestionView.class, "new"))); hl.add(addQuestion); final VGrid grid = new VGrid<>(Question.class); @@ -45,7 +42,7 @@ public class QuestionsListView extends Main { grid.addComponentColumn((ValueProvider) question -> { final Button edit = new Button("Edit"); edit.addClickListener((ComponentEventListener>) buttonClickEvent -> - this.getUI().get().navigate(QuestionView.class, question.getId().toString())); + this.getUI().flatMap(ui -> ui.navigate(QuestionView.class, question.getId().toString()))); return edit; }); grid.setDataProvider(new DataProvider<>() { @@ -59,6 +56,7 @@ public class QuestionsListView extends Main { return questionService.getQuestions().size(); } + @SuppressWarnings("unused") @Override public Stream fetch(final Query query) { int limit = query.getLimit(); diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 58b4ab6..5e8c437 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -26,6 +26,8 @@ import java.time.Period; import java.util.*; import java.util.stream.Collectors; +import static com.primefactorsolutions.views.Constants.PAGE_SIZE; + @SpringComponent @PermitAll @Scope("prototype") @@ -96,7 +98,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter requestGrid.getColumnByKey("daysToBeTake").setHeader("Días a Tomar"); requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); - requestGrid.setPageSize(5); + requestGrid.setPageSize(PAGE_SIZE); requestGrid.asSingleSelect().addValueChangeListener(event -> { TimeOffRequest selectedRequest = event.getValue(); if (selectedRequest != null) { @@ -244,9 +246,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter private double calculateHolidayUtilizedDays(final int year) { return requests.stream() .filter(this::verificationIsHoliday) - .filter(this::verificationIsHoliday) - .filter(req -> req.getState() == TimeOffRequestStatus.APROBADO) - .filter(req -> req.getState() == TimeOffRequestStatus.EN_USO) .filter(req -> req.getState() == TimeOffRequestStatus.TOMADO) .filter(req -> getStartDateYear(req) == year) .mapToDouble(TimeOffRequest::getDaysToBeTake) @@ -256,8 +255,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter private double calculatePersonalDaysUtilized(final boolean isMale, final int year) { return requests.stream() .filter(req -> !verificationIsHoliday(req)) - .filter(req -> req.getState() == TimeOffRequestStatus.APROBADO) - .filter(req -> req.getState() == TimeOffRequestStatus.EN_USO) .filter(req -> req.getState() == TimeOffRequestStatus.TOMADO) .filter(req -> !getStandardExclusions().contains(req.getCategory())) .filter(req -> !(isMale && getMaleSpecificExclusions().contains(req.getCategory()))) diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index 4b770e1..029a66b 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -22,6 +22,8 @@ import java.time.Period; import java.util.*; import java.util.stream.Collectors; +import static com.primefactorsolutions.views.Constants.PAGE_SIZE; + @SpringComponent @Scope("prototype") @PageTitle("Requests") @@ -35,10 +37,8 @@ public class RequestsListView extends Main { private final VacationService vacationService; private final PagingGrid requestGrid = new PagingGrid<>(); - private List employees = Collections.emptyList(); private ComboBox employeeFilter; private ComboBox teamFilter; - private ComboBox categoryFilter; private ComboBox stateFilter; private UUID selectedEmployeeId; @@ -51,7 +51,6 @@ public class RequestsListView extends Main { this.employeeService = employeeService; this.teamService = teamService; this.vacationService = vacationService; - this.employees = employeeService.findAllEmployees(); initializeView(); refreshGeneralRequestGrid(null, null, null); } @@ -77,7 +76,7 @@ public class RequestsListView extends Main { requestGrid.addColumn(this::getGeneralTotal).setHeader("Total general"); requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); - requestGrid.setPageSize(5); + requestGrid.setPageSize(PAGE_SIZE); requestGrid.asSingleSelect().addValueChangeListener(event -> { Employee selectedRequest = event.getValue(); if (selectedRequest != null) { @@ -328,10 +327,8 @@ public class RequestsListView extends Main { && !employeeRequestCategories.contains(vacation.getCategory())) { return false; } - if (!isFemale(employee) && genderSpecificExclusions.contains(vacation.getCategory())) { - return false; - } - return true; + + return isFemale(employee) || !genderSpecificExclusions.contains(vacation.getCategory()); } private boolean isFemale(final Employee employee) {