Rama-Ricardo #14
@ -1,15 +1,11 @@
|
||||
package com.primefactorsolutions.model;
|
||||
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@ -45,7 +41,7 @@
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(Status status) {
|
||||
public void setStatus(final Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,12 @@ import java.util.Collections;
|
||||
public class EmployeeService {
|
||||
private final EmployeeRepository employeeRepository;
|
||||
|
||||
public EmployeeService(EmployeeRepository employeeRepository) {
|
||||
public EmployeeService(final EmployeeRepository employeeRepository) {
|
||||
this.employeeRepository = employeeRepository;
|
||||
}
|
||||
|
||||
public List<Employee> findEmployees(int start, int pageSize, String sortProperty, boolean asc) {
|
||||
public List<Employee> findEmployees(
|
||||
final int start, final int pageSize, final String sortProperty, final boolean asc) {
|
||||
List<Employee> employees = employeeRepository.findAll();
|
||||
|
||||
alex
commented
no se puede guardar en un campo de la clase porque la clase es un singleton (si hay varios llamados van a haber problemas de concurrencia). solucion: no usar un campo en la clase y simplemente retornar toda la lista cada vez sin guardar en un campo. no se puede guardar en un campo de la clase porque la clase es un singleton (si hay varios llamados van a haber problemas de concurrencia). solucion: no usar un campo en la clase y simplemente retornar toda la lista cada vez sin guardar en un campo.
|
||||
int end = Math.min(start + pageSize, employees.size());
|
||||
@ -33,7 +34,7 @@ public class EmployeeService {
|
||||
return employees.subList(start, end);
|
||||
}
|
||||
|
||||
public List<Employee> findEmployees(int start, int pageSize) {
|
||||
public List<Employee> findEmployees(final int start, final int pageSize) {
|
||||
List<Employee> employees = employeeRepository.findAll();
|
||||
|
||||
int end = Math.min(start + pageSize, employees.size());
|
||||
|
@ -145,11 +145,11 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
|
||||
setSavedHandler((SavedHandler<Employee>) employee -> {
|
||||
if (validateForm()) {
|
||||
final Employee saved = employeeService.createOrUpdate(employee);
|
||||
Notification.show("Empleado guardado exitosamente.");
|
||||
Notification.show("Employee saved successfully.");
|
||||
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
|
||||
setEntityWithEnabledSave(saved);
|
||||
} else {
|
||||
Notification.show("Acción inválida. Por favor, complete todos los campos requeridos correctamente.", 3000, Notification.Position.MIDDLE);
|
||||
Notification.show("Please complete the required fields correctly.", 3000, Notification.Position.MIDDLE);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -27,7 +27,7 @@ public class EmployeesListView extends Main {
|
||||
private final EmployeeService employeeService;
|
||||
private final PagingGrid<Employee> table = new PagingGrid<>(Employee.class);
|
||||
|
||||
public EmployeesListView(EmployeeService employeeService) {
|
||||
public EmployeesListView(final EmployeeService employeeService) {
|
||||
this.employeeService = employeeService;
|
||||
setupView();
|
||||
refreshGrid();
|
||||
@ -46,17 +46,17 @@ public class EmployeesListView extends Main {
|
||||
setupPagingGrid();
|
||||
}
|
||||
|
||||
private void updateEmployeeStatus(Employee employee, boolean isActive) {
|
||||
private void updateEmployeeStatus(final Employee employee, final boolean isActive) {
|
||||
employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE);
|
||||
employeeService.createOrUpdate(employee);
|
||||
refreshGrid();
|
||||
}
|
||||
|
||||
private void addEditButtonColumn(String label, ButtonClickHandler handler) {
|
||||
private void addEditButtonColumn(final String label, final ButtonClickHandler handler) {
|
||||
table.addComponentColumn(employee -> createButton(label, () -> handler.handle(employee)));
|
||||
}
|
||||
|
||||
private Button createButton(String label, Runnable onClickAction) {
|
||||
private Button createButton(final String label, final Runnable onClickAction) {
|
||||
Button button = new Button(label);
|
||||
button.addClickListener(event -> onClickAction.run());
|
||||
return button;
|
||||
@ -66,7 +66,7 @@ public class EmployeesListView extends Main {
|
||||
return createButton("Add Employee", this::navigateToAddEmployeeView);
|
||||
}
|
||||
|
||||
private void navigateToEditView(Employee employee) {
|
||||
private void navigateToEditView(final Employee employee) {
|
||||
getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, employee.getId().toString()));
|
||||
alex
commented
podemos usar el componente PagingGrid de la llibreria Viritin (ya esta incluida). Ejemplo: https://addons.dokku1.parttio.org/paginggrid y codigo https://github.com/parttio/addon-demos/blob/main/src/main/java/org/example/views/PagingGridView.java asi ya no necesitamos crear los botones y navegacion manualmente. podemos usar el componente PagingGrid de la llibreria Viritin (ya esta incluida). Ejemplo: https://addons.dokku1.parttio.org/paginggrid y codigo https://github.com/parttio/addon-demos/blob/main/src/main/java/org/example/views/PagingGridView.java
asi ya no necesitamos crear los botones y navegacion manualmente.
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ public class EmployeesListView extends Main {
|
||||
table.setPagingDataProvider((page, pageSize) -> fetchEmployees((int) page, pageSize));
|
||||
}
|
||||
|
||||
private List<Employee> fetchEmployees(int page, int pageSize) {
|
||||
private List<Employee> fetchEmployees(final int page, final int pageSize) {
|
||||
int start = page * pageSize;
|
||||
if (hasSortOrder()) {
|
||||
return fetchSortedEmployees(start, pageSize);
|
||||
@ -95,9 +95,11 @@ public class EmployeesListView extends Main {
|
||||
return !table.getSortOrder().isEmpty();
|
||||
}
|
||||
|
||||
private List<Employee> fetchSortedEmployees(int start, int pageSize) {
|
||||
private List<Employee> fetchSortedEmployees(final int start, final int pageSize) {
|
||||
GridSortOrder<Employee> sortOrder = table.getSortOrder().getFirst();
|
||||
return employeeService.findEmployees(start, pageSize, sortOrder.getSorted().getKey(), sortOrder.getDirection() == SortDirection.ASCENDING);
|
||||
return employeeService.findEmployees(start, pageSize,
|
||||
sortOrder.getSorted().getKey(),
|
||||
sortOrder.getDirection() == SortDirection.ASCENDING);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
|
Loading…
Reference in New Issue
Block a user
quitar espacios blancos al inicio de cada linea