#4-Registro-de-Información-Personal #16

Merged
alex merged 15 commits from #4-Registro-de-Información-Personal into main 2024-09-08 13:08:42 +00:00
Showing only changes of commit a393c82649 - Show all commits

View File

@ -7,6 +7,7 @@ import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.html.Main; import com.vaadin.flow.component.html.Main;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; 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.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
@ -98,16 +99,28 @@ public class EmployeesListView extends Main {
private Button createNavigationButton(String label, int increment) { private Button createNavigationButton(String label, int increment) {
Button button = new Button(label); Button button = new Button(label);
button.addClickListener(event -> changePage(increment)); button.addClickListener(event -> handlePageChange(increment));
return button; return button;
} }
private void changePage(int increment) { private void handlePageChange(int increment) {
if (increment < 0 && currentPage > 1) { if (isPageChangeValid(increment)) {
currentPage--; currentPage += increment;
} else if (increment > 0 && employeeService.hasNextPage(currentPage, pageSize, sortField, ascending)) { updateGrid();
currentPage++; } 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() { private Button createAddEmployeeButton() {
return new Button("Add Employee", event -> return new Button("Add Employee", event ->
@ -117,7 +130,5 @@ public class EmployeesListView extends Main {
private void updateGrid() { private void updateGrid() {
Page<Employee> page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending); Page<Employee> page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending);
grid.setItems(page.getContent()); grid.setItems(page.getContent());
previous.setEnabled(currentPage > 1);
next.setEnabled(page.hasNext());
} }
} }