#46 Perfil de Empleado - Registro Semanal de Horas trabajadas con el numero de semanas

This commit is contained in:
Melina Gutierrez 2024-10-15 10:11:14 -04:00
parent 3e57c50378
commit b5396ae373

View File

@ -18,15 +18,16 @@ import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import com.vaadin.flow.component.html.Label;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.IntStream;
@SpringComponent
@PermitAll
@ -42,21 +43,28 @@ public class HoursWorkedView extends VerticalLayout {
@Autowired
private EmployeeService employeeService;
private final Label fechasLabel = new Label("Selecciona una semana para ver las fechas.");
public HoursWorkedView() {
actividades = new ArrayList<>();
grid = new Grid<>(Actividad.class, false);
totalsGrid = new Grid<>(Actividad.class, false);
DatePicker datePicker = new DatePicker("Selecciona una fecha");
datePicker.setValue(LocalDate.now());
datePicker.addValueChangeListener(event -> {
LocalDate selectedDate = event.getValue();
if (selectedDate != null) {
selectedStartOfWeek = selectedDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
ComboBox<String> semanaComboBox = new ComboBox<>("Selecciona una semana");
semanaComboBox.setItems(getWeeksOfYear());
semanaComboBox.addValueChangeListener(event -> {
String selectedWeek = event.getValue();
if (selectedWeek != null) {
int weekNumber = Integer.parseInt(selectedWeek.split(" ")[1]);
selectedStartOfWeek = getStartOfWeek(weekNumber);
LocalDate endOfWeek = selectedStartOfWeek.plusDays(6);
fechasLabel.setText(("Semana del " + selectedStartOfWeek + " al " + endOfWeek));
mostrarActividadesDeLaSemana();
}
});
datePicker.setWidth("250px");
semanaComboBox.setWidth("250px");
ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
equipoDropdown.setItems("Equipo 1", "Equipo 2", "Equipo 3");
@ -130,15 +138,29 @@ public class HoursWorkedView extends VerticalLayout {
HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton, cerrarButton);
add(datePicker, filtersLayout, grid, actividadFormLayout, buttonsLayout);
add(semanaComboBox, fechasLabel, filtersLayout, grid, actividadFormLayout, buttonsLayout);
add(totalsGrid);
configurarTablaTotales();
}
private List<String> getWeeksOfYear() {
return IntStream.rangeClosed(1, 52)
.mapToObj(week -> "Semana " + week)
.toList();
}
private LocalDate getStartOfWeek(int weekNumber) {
WeekFields weekFields = WeekFields.of(Locale.getDefault());
return LocalDate.now()
.with(weekFields.weekOfYear(), weekNumber)
.with(weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
}
private void mostrarActividadesDeLaSemana() {
if (selectedStartOfWeek != null) {
Notification.show("Mostrando actividades de la semana del " + selectedStartOfWeek + " al " + selectedStartOfWeek.plusDays(6));
Notification.show("Mostrando actividades de la semana del " +
selectedStartOfWeek + " al " + selectedStartOfWeek.plusDays(6));
}
}