#4-Registro-de-Información-Personal #16
@ -21,38 +21,30 @@
|
||||
private String lastName;
|
||||
private LocalDate birthday;
|
||||
private String birthCity;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private MaritalStatus maritalStatus;
|
||||
|
||||
private String residenceAddress;
|
||||
private String phoneNumber;
|
||||
private String personalEmail;
|
||||
|
||||
private String emergencyCName;
|
||||
private String emergencyCAddress;
|
||||
private String emergencyCPhone;
|
||||
private String emergencyCEmail;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status status;
|
||||
|
||||
public enum Status {
|
||||
ACTIVE,
|
||||
INACTIVE
|
||||
}
|
||||
|
||||
public enum MaritalStatus {
|
||||
SINGLE,
|
||||
MARRIED,
|
||||
WIDOWED,
|
||||
DIVORCED
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
package com.primefactorsolutions.service;
|
||||
|
||||
import com.primefactorsolutions.model.Employee;
|
||||
import org.apache.commons.beanutils.BeanComparator;
|
||||
import com.primefactorsolutions.repositories.EmployeeRepository;
|
||||
@ -16,46 +15,33 @@ import java.util.Collections;
|
||||
@Data
|
||||
public class EmployeeService {
|
||||
private final EmployeeRepository employeeRepository;
|
||||
private List<Employee> pagedBase;
|
||||
|
||||
public EmployeeService(EmployeeRepository employeeRepository) {
|
||||
this.employeeRepository = employeeRepository;
|
||||
}
|
||||
|
||||
private void initializePagedBase() {
|
||||
if (pagedBase == null) {
|
||||
this.pagedBase = employeeRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Employee> findEmployees(int start, int pageSize, String sortProperty, boolean asc) {
|
||||
initializePagedBase(); // Asegurarse de que pagedBase esté inicializada
|
||||
System.err.println("findAll " + start + " " + pageSize + " sort " + sortProperty + " asc:" + asc );
|
||||
int end = (int) (start + pageSize);
|
||||
if (end > pagedBase.size()) {
|
||||
end = pagedBase.size();
|
||||
}
|
||||
Collections.sort(pagedBase, new BeanComparator<Employee>(sortProperty));
|
||||
List<Employee> employees = employeeRepository.findAll();
|
||||
|
||||
if(!asc) {
|
||||
Collections.reverse(pagedBase);
|
||||
int end = Math.min(start + pageSize, employees.size());
|
||||
employees.sort(new BeanComparator<>(sortProperty));
|
||||
|
||||
if (!asc) {
|
||||
Collections.reverse(employees);
|
||||
}
|
||||
return pagedBase.subList((int) start, end);
|
||||
|
||||
return employees.subList(start, end);
|
||||
}
|
||||
|
||||
public List<Employee> findEmployees(int start, int pageSize) {
|
||||
initializePagedBase(); // Asegurarse de que pagedBase esté inicializada
|
||||
System.err.println("findAll " + start + " " + pageSize);
|
||||
int end = (int) (start + pageSize);
|
||||
if (end > pagedBase.size()) {
|
||||
end = pagedBase.size();
|
||||
}
|
||||
return pagedBase.subList((int) start, end);
|
||||
List<Employee> employees = employeeRepository.findAll();
|
||||
|
||||
int end = Math.min(start + pageSize, employees.size());
|
||||
return employees.subList(start, end);
|
||||
}
|
||||
|
||||
public Employee createOrUpdate(final Employee employee) {
|
||||
final Employee saved = employeeRepository.save(employee);
|
||||
return saved;
|
||||
return employeeRepository.save(employee);
|
||||
}
|
||||
|
||||
public Employee getEmployee(final UUID id) {
|
||||
|
@ -43,22 +43,11 @@ public class EmployeesListView extends Main {
|
||||
|
||||
private void configureTable() {
|
||||
table.setColumns("firstName", "lastName", "status");
|
||||
addStatusColumn();
|
||||
addEditButtonColumn("Edit", this::navigateToEditView);
|
||||
addEditButtonColumn("Save", this::navigateToSaveChangeStatus);
|
||||
setupPagingGrid();
|
||||
alex marked this conversation as resolved
Outdated
|
||||
}
|
||||
|
||||
private void addStatusColumn() {
|
||||
table.addComponentColumn(this::createStatusCheckbox)
|
||||
.setHeader("Change Status");
|
||||
}
|
||||
|
||||
private Checkbox createStatusCheckbox(Employee employee) {
|
||||
Checkbox statusCheckbox = new Checkbox( employee.getStatus() == Employee.Status.ACTIVE);
|
||||
return statusCheckbox;
|
||||
}
|
||||
|
||||
private void updateEmployeeStatus(Employee employee, boolean isActive) {
|
||||
employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE);
|
||||
employeeService.createOrUpdate(employee);
|
||||
|
Loading…
Reference in New Issue
Block a user
no es necesario agregar esto porque ya existe el boton edit que navega a la vista edit.