corregir que cuando selecciona un equipo este solo muestra los empleados de este equipo

This commit is contained in:
Melina Gutierrez 2024-11-28 08:00:37 -04:00 committed by alex
parent 3acc1426bf
commit f9e1d651ad

View File

@ -26,6 +26,7 @@ import java.time.temporal.IsoFields;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@SpringComponent @SpringComponent
@PermitAll @PermitAll
@ -142,14 +143,25 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
List<Team> teams = new ArrayList<>(teamService.findAllTeams()); List<Team> teams = new ArrayList<>(teamService.findAllTeams());
teamField.setItems(teamService.findAllTeams()); teamField.setItems(teamService.findAllTeams());
teamField.setItemLabelGenerator(Team::getName); teamField.setItemLabelGenerator(Team::getName);
teamField.setValue(teams.getFirst()); teamField.setValue(null);
teamField.addValueChangeListener(event -> { teamField.addValueChangeListener(event -> {
if (teams != null) { Team selectedTeam = event.getValue();
employeeField.getValue(); updateEmployeeField(selectedTeam);
event.getValue(); });
} }
}
); private void updateEmployeeField(Team selectedTeam) {
if (selectedTeam != null) {
List<Employee> employeesInTeam = employeeService.findAllEmployees().stream()
.filter(employee -> employee.getTeam() != null && employee.getTeam().equals(selectedTeam))
.collect(Collectors.toList());
employeeField.setItems(employeesInTeam);
if (!employeesInTeam.isEmpty()) {
employeeField.setValue(employeesInTeam.get(0));
} else {
employeeField.clear();
}
}
} }
private ComboBox<Employee> initializeEmployeeField() { private ComboBox<Employee> initializeEmployeeField() {
@ -157,7 +169,7 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
List<Employee> employees = new ArrayList<>(employeeService.findAllEmployees()); List<Employee> employees = new ArrayList<>(employeeService.findAllEmployees());
employeeField.setItems(employees); employeeField.setItems(employees);
employeeField.setItemLabelGenerator(this::getEmployeeFullName); employeeField.setItemLabelGenerator(this::getEmployeeFullName);
employeeField.setValue(employees.getFirst()); employeeField.setValue(null);
return employeeField; return employeeField;
} }
@ -168,11 +180,16 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
private void initializeDateField() { private void initializeDateField() {
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
LocalDate lastWeekMonday = today.minusWeeks(1).with(java.time.DayOfWeek.MONDAY); YearMonth currentMonth = YearMonth.of(today.getYear(), today.getMonth());
LocalDate startOfMonth = currentMonth.atDay(1);
LocalDate maxSelectableDate = today; LocalDate maxSelectableDate = today;
dateField.setMin(lastWeekMonday);
dateField.setMin(startOfMonth);
dateField.setMax(maxSelectableDate); dateField.setMax(maxSelectableDate);
dateField.setValue(today); dateField.setValue(today);
dateField.addValueChangeListener(event -> { dateField.addValueChangeListener(event -> {
LocalDate selectedDate = event.getValue(); LocalDate selectedDate = event.getValue();
if (selectedDate != null) { if (selectedDate != null) {
@ -186,7 +203,6 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
}); });
} }
private void saveHoursWorked() { private void saveHoursWorked() {
if (isFormValid()) { if (isFormValid()) {
HoursWorked hoursWorked = getEntity(); HoursWorked hoursWorked = getEntity();