hoursworked #75
@ -5,6 +5,7 @@ import com.primefactorsolutions.model.HoursWorked;
|
|||||||
import com.primefactorsolutions.service.EmployeeService;
|
import com.primefactorsolutions.service.EmployeeService;
|
||||||
import com.primefactorsolutions.service.HoursWorkedService;
|
import com.primefactorsolutions.service.HoursWorkedService;
|
||||||
import com.vaadin.flow.component.grid.Grid;
|
import com.vaadin.flow.component.grid.Grid;
|
||||||
|
import com.vaadin.flow.component.html.H2;
|
||||||
import com.vaadin.flow.component.notification.Notification;
|
import com.vaadin.flow.component.notification.Notification;
|
||||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
import com.vaadin.flow.component.textfield.TextField;
|
import com.vaadin.flow.component.textfield.TextField;
|
||||||
@ -15,13 +16,9 @@ import com.vaadin.flow.router.PageTitle;
|
|||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
import jakarta.persistence.ManyToOne;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import com.vaadin.flow.component.html.Label;
|
import com.vaadin.flow.component.html.Label;
|
||||||
import org.springframework.web.servlet.HandlerMapping;
|
|
||||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
||||||
import org.vaadin.firitin.components.datepicker.VDatePicker;
|
import org.vaadin.firitin.components.datepicker.VDatePicker;
|
||||||
|
|
||||||
|
|
||||||
@ -36,19 +33,18 @@ import java.util.Locale;
|
|||||||
@SpringComponent
|
@SpringComponent
|
||||||
@PermitAll
|
@PermitAll
|
||||||
@Scope("prototype")
|
@Scope("prototype")
|
||||||
@PageTitle("Hours Worked")
|
@PageTitle("Horas Trabajadas")
|
||||||
@Route(value = "/hours-worked/me", layout = MainLayout.class)
|
@Route(value = "/hours-worked/me", layout = MainLayout.class)
|
||||||
public class HoursWorkedView extends VerticalLayout {
|
public class HoursWorkedView extends VerticalLayout {
|
||||||
@ManyToOne
|
|
||||||
private Actividad actividad;
|
|
||||||
|
|
||||||
private final List<Actividad> actividades = new ArrayList<>();
|
private final List<Actividad> actividades = new ArrayList<>();
|
||||||
private final List<Actividad> actividadesEspecificas = new ArrayList<>(); // Nueva lista para tareas específicas
|
private final List<Actividad> actividadesEspecificas = new ArrayList<>(); // Nueva lista para tareas específicas
|
||||||
private final Grid<Actividad> grid = new Grid<>(Actividad.class);
|
private final Grid<Actividad> grid = new Grid<>(Actividad.class);
|
||||||
private final Grid<Actividad> gridActividadesEspecificas = new Grid<>(Actividad.class);
|
private final Grid<Actividad> gridActividadesEspecificas = new Grid<>(Actividad.class);
|
||||||
|
|
||||||
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Empleado");
|
||||||
private final ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
|
private final ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
|
||||||
|
private VDatePicker fechaPicker = new VDatePicker("Selecciona una fecha");
|
||||||
|
|
||||||
|
|
||||||
private final ComboBox<String> tareasEspecificasDropdown = new ComboBox<>("Tareas Específicas");
|
private final ComboBox<String> tareasEspecificasDropdown = new ComboBox<>("Tareas Específicas");
|
||||||
private final TextField tareaEspecificaInput = new TextField("Especificar Tarea");
|
private final TextField tareaEspecificaInput = new TextField("Especificar Tarea");
|
||||||
@ -62,15 +58,11 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private final HoursWorkedService hoursWorkedService;
|
private final HoursWorkedService hoursWorkedService;
|
||||||
|
|
||||||
private final Label fechasLabel = new Label("Selecciona una semana para ver las fechas.");
|
private final H2 equipoLabel = new H2("Tareas del Cliente/Equipo");
|
||||||
|
private final H2 empresaLabel = new H2("Tareas de la Empresa");
|
||||||
private final Label totalCompletadoLabel = new Label();
|
private final Label totalCompletadoLabel = new Label();
|
||||||
private final Label horasPendientesLabel = new Label();
|
private final Label horasPendientesLabel = new Label();
|
||||||
|
|
||||||
private final Label numeroSemanaLabel = new Label("Número de la Semana: ");
|
|
||||||
|
|
||||||
private VDatePicker fechaPicker = new VDatePicker("Selecciona una fecha");
|
|
||||||
|
|
||||||
|
|
||||||
public HoursWorkedView(final EmployeeService employeeService, final HoursWorkedService hoursWorkedService) {
|
public HoursWorkedView(final EmployeeService employeeService, final HoursWorkedService hoursWorkedService) {
|
||||||
this.employeeService = employeeService;
|
this.employeeService = employeeService;
|
||||||
this.hoursWorkedService = hoursWorkedService;
|
this.hoursWorkedService = hoursWorkedService;
|
||||||
@ -149,10 +141,7 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
LocalDate selectedDate = event.getValue();
|
LocalDate selectedDate = event.getValue();
|
||||||
if (selectedDate != null) {
|
if (selectedDate != null) {
|
||||||
selectedStartOfWeek = getStartOfWeek(selectedDate);
|
selectedStartOfWeek = getStartOfWeek(selectedDate);
|
||||||
LocalDate endOfWeek = selectedStartOfWeek.plusDays(6);
|
|
||||||
weekNumber = getWeekOfYear(selectedDate);
|
weekNumber = getWeekOfYear(selectedDate);
|
||||||
fechasLabel.setText("Semana del " + selectedStartOfWeek + " al " + endOfWeek);
|
|
||||||
numeroSemanaLabel.setText("Número de la Semana: " + weekNumber);
|
|
||||||
cargarDatos();
|
cargarDatos();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -189,12 +178,14 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton,
|
HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton,
|
||||||
cerrarButton, verMesButton);
|
cerrarButton, verMesButton);
|
||||||
|
|
||||||
VerticalLayout totalesLayout = new VerticalLayout(totalCompletadoLabel, horasPendientesLabel);
|
VerticalLayout totalesLayout = new VerticalLayout(totalCompletadoLabel,
|
||||||
|
horasPendientesLabel);
|
||||||
totalesLayout.setSpacing(true);
|
totalesLayout.setSpacing(true);
|
||||||
totalesLayout.setPadding(true);
|
totalesLayout.setPadding(true);
|
||||||
|
|
||||||
add(fechaPicker, fechasLabel, numeroSemanaLabel, filtersLayout, actividadFormLayout,
|
add(fechaPicker, filtersLayout, actividadFormLayout,
|
||||||
tareasEspecificasLayout, grid, gridActividadesEspecificas, buttonsLayout, totalesLayout);
|
equipoLabel, grid, empresaLabel, tareasEspecificasLayout,
|
||||||
|
gridActividadesEspecificas, buttonsLayout, totalesLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configurarGrid() {
|
private void configurarGrid() {
|
||||||
@ -209,6 +200,7 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
grid.addColumn(Actividad::getSabado).setHeader("Sábado");
|
grid.addColumn(Actividad::getSabado).setHeader("Sábado");
|
||||||
grid.addColumn(Actividad::getDomingo).setHeader("Domingo");
|
grid.addColumn(Actividad::getDomingo).setHeader("Domingo");
|
||||||
grid.addColumn(this::calcularTotalPorDia).setHeader("Total Día").setKey("totalDia");
|
grid.addColumn(this::calcularTotalPorDia).setHeader("Total Día").setKey("totalDia");
|
||||||
|
grid.setItems(actividades);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configurarGridActividadesEspecificas() {
|
private void configurarGridActividadesEspecificas() {
|
||||||
@ -294,7 +286,7 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
return new HorizontalLayout(actividadNombre, horasInput, agregarActividadButton);
|
return new HorizontalLayout(actividadNombre, horasInput, agregarActividadButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void agregarOActualizarActividad(Actividad nuevaActividad, DayOfWeek dia, double horas) {
|
private void agregarOActualizarActividad(final Actividad nuevaActividad, final DayOfWeek dia, final double horas) {
|
||||||
Actividad actividadExistente = actividades.stream()
|
Actividad actividadExistente = actividades.stream()
|
||||||
.filter(a -> a.getNombre().equals(nuevaActividad.getNombre()))
|
.filter(a -> a.getNombre().equals(nuevaActividad.getNombre()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
@ -414,7 +406,7 @@ public class HoursWorkedView extends VerticalLayout {
|
|||||||
|
|
||||||
private LocalDate getStartOfWeek(final LocalDate date) {
|
private LocalDate getStartOfWeek(final LocalDate date) {
|
||||||
WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
||||||
return date.with(weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
|
return date.with(weekFields.dayOfWeek(), DayOfWeek.FRIDAY.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double calcularTotalPorDia(final Actividad actividad) {
|
private double calcularTotalPorDia(final Actividad actividad) {
|
||||||
|
Loading…
Reference in New Issue
Block a user