Vacaciones #66

Merged
jesus.pelaez merged 2 commits from Vacaciones into En-desarrollo 2024-11-05 18:32:43 +00:00
Showing only changes of commit 7e415ae837 - Show all commits

View File

@ -1,8 +1,10 @@
package com.primefactorsolutions.views; package com.primefactorsolutions.views;
import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.model.Team;
import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.EmployeeService;
import com.primefactorsolutions.service.ReportService; import com.primefactorsolutions.service.ReportService;
import com.primefactorsolutions.service.TeamService;
import com.vaadin.componentfactory.pdfviewer.PdfViewer; import com.vaadin.componentfactory.pdfviewer.PdfViewer;
import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.Component; import com.vaadin.flow.component.Component;
@ -27,6 +29,7 @@ import com.vaadin.flow.router.*;
import com.vaadin.flow.server.StreamResource; import com.vaadin.flow.server.StreamResource;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.components.datepicker.VDatePicker; import org.vaadin.firitin.components.datepicker.VDatePicker;
import org.vaadin.firitin.form.BeanValidationForm; import org.vaadin.firitin.form.BeanValidationForm;
@ -47,6 +50,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
private final EmployeeService employeeService; private final EmployeeService employeeService;
private final ReportService reportService; private final ReportService reportService;
private final TeamService teamService;
// TODO: campo usado para registrar al empleado en LDAP. Este campo podria estar en otro form eventualmente. // TODO: campo usado para registrar al empleado en LDAP. Este campo podria estar en otro form eventualmente.
private final TextField username = createTextField("Username: ", 30, true); private final TextField username = createTextField("Username: ", 30, true);
@ -67,7 +71,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
private final EmailField personalEmail = createEmailField("E-mail"); private final EmailField personalEmail = createEmailField("E-mail");
private final TextField cod = createTextField("Codigo de Empleado", 30, false); private final TextField cod = createTextField("Codigo de Empleado", 30, false);
private final TextField position = createTextField("Cargo", 30, false); private final TextField position = createTextField("Cargo", 30, false);
private final TextField team = createTextField("Equipo", 30, false); private final ComboBox<Team> team = new ComboBox<>("Equipo");
private final TextField leadManager = createTextField("Lead/Manager", 30, false); private final TextField leadManager = createTextField("Lead/Manager", 30, false);
private final TextField project = createTextField("Proyecto", 30, false); private final TextField project = createTextField("Proyecto", 30, false);
private final TextField emergencyCName = createTextField("Nombres y Apellidos de Contacto", 50, false); private final TextField emergencyCName = createTextField("Nombres y Apellidos de Contacto", 50, false);
@ -135,10 +139,13 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
private final H3 datBanc = new H3("Datos Bancados"); private final H3 datBanc = new H3("Datos Bancados");
private final H3 datGest = new H3("Datos Gestora Pública y Seguro Social"); private final H3 datGest = new H3("Datos Gestora Pública y Seguro Social");
public EmployeeView(final EmployeeService employeeService, final ReportService reportService) { public EmployeeView(final EmployeeService employeeService,
final ReportService reportService,
final TeamService teamService) {
super(Employee.class); super(Employee.class);
this.employeeService = employeeService; this.employeeService = employeeService;
this.reportService = reportService; this.reportService = reportService;
this.teamService = teamService;
saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY); saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
configureComponents(); configureComponents();
@ -155,6 +162,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
editButton.setVisible(true); editButton.setVisible(true);
reportButton.setVisible(true); reportButton.setVisible(true);
birthday.addValueChangeListener(event -> calculateAge()); birthday.addValueChangeListener(event -> calculateAge());
createTeamComboBox();
reportButton.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> { reportButton.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
var employee = getEntity(); var employee = getEntity();
@ -262,12 +270,11 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
return emailField; return emailField;
} }
private <T> ComboBox<T> createComboBox(final String label, final T[] items) { private void createTeamComboBox() {
ComboBox<T> comboBox = new ComboBox<>(label); List<Team> teams = teamService.findAllTeams();
comboBox.setItems(items); team.setItems(teams);
comboBox.setItemLabelGenerator(Object::toString); team.setItemLabelGenerator(Team::getName);
comboBox.setWidthFull(); team.setWidthFull();
return comboBox;
} }
private ComboBox<Employee.Gender> createGenderComboBox() { private ComboBox<Employee.Gender> createGenderComboBox() {
@ -317,6 +324,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
UUID employeeId = UUID.fromString(s); UUID employeeId = UUID.fromString(s);
var employee = employeeService.getEmployee(employeeId); var employee = employeeService.getEmployee(employeeId);
setEntityWithEnabledSave(employee); setEntityWithEnabledSave(employee);
team.setValue(employee.getTeam());
if ("edit".equals(action) && !s.isEmpty()) { if ("edit".equals(action) && !s.isEmpty()) {
saveButton.setVisible(true); saveButton.setVisible(true);