#7 Perfil de Personal Administrativo - Listado de empleados (Mostrar mensaje: No existen más datos en la lista)

This commit is contained in:
jesus.pelaez 2024-08-28 15:37:09 -04:00
parent aa041b3358
commit a393c82649

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.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.");
}
}
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<Employee> page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending);
grid.setItems(page.getContent());
previous.setEnabled(currentPage > 1);
next.setEnabled(page.hasNext());
}
}