#7 Perfil de Personal Administrativo - Listado de empleados #8

Merged
alex merged 6 commits from Rama-Ricardo into main 2024-08-27 19:17:53 +00:00
3 changed files with 28 additions and 8 deletions
Showing only changes of commit cde58ad1c3 - Show all commits

View File

@ -1,5 +1,6 @@
package com.primefactorsolutions.service;
import com.primefactorsolutions.model.Candidate;
import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.repositories.EmployeeRepository;
import lombok.Data;
@ -18,8 +19,9 @@ public class EmployeeService {
this.employeeRepository = employeeRepository;
}
public Employee createOrUpdate(final Employee assessment) {
return null;
public Employee createOrUpdate(final Employee employee) {
final Employee saved = employeeRepository.save(employee);
return saved;
}
public List<Employee> getEmployees() {

View File

@ -3,16 +3,20 @@ package com.primefactorsolutions.views;
import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.service.EmployeeService;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.form.BeanValidationForm;
import java.util.List;
import java.util.UUID;
@SpringComponent
@PermitAll
@ -20,22 +24,36 @@ import java.util.List;
@PageTitle("Employee")
@Route(value = "/employees", layout = MainLayout.class)
public class EmployeeView extends BeanValidationForm<Employee> implements HasUrlParameter<String> {
private final EmployeeService employeeService;
private TextField name = null;
public EmployeeView(final EmployeeService employeeService) {
super(Employee.class);
this.employeeService = employeeService;
}
name = new TextField();
name.setWidthFull();
name.setLabel("Name");
@Override
protected List<Component> getFormComponents() {
return null;
setSavedHandler((SavedHandler<Employee>) employee -> {
final Employee saved = employeeService.createOrUpdate(employee);
setEntityWithEnabledSave(saved);
});
}
@Override
public void setParameter(final BeforeEvent beforeEvent, final String s) {
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
var employee = employeeService.getEmployee(UUID.fromString(s));
setEntityWithEnabledSave(employee);
} else {
setEntityWithEnabledSave(new Employee());
}
}
@Override
protected List<Component> getFormComponents() {
return List.of(name);
}
}

View File

@ -117,7 +117,7 @@ public class EmployeesListView extends Main {
hf.add(next);
final Button addEmployee = new Button("Add Employee");
addEmployee.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
//this.getUI().get().navigate(EmployeeView.class, "new");
this.getUI().get().navigate(EmployeeView.class, "new");
});
hf.add(addEmployee);