#7 Perfil de Personal Administrativo - Listado de empleados #8
@ -1,5 +1,6 @@
|
|||||||
package com.primefactorsolutions.service;
|
package com.primefactorsolutions.service;
|
||||||
|
|
||||||
|
import com.primefactorsolutions.model.Candidate;
|
||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.repositories.EmployeeRepository;
|
import com.primefactorsolutions.repositories.EmployeeRepository;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -18,8 +19,9 @@ public class EmployeeService {
|
|||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Employee createOrUpdate(final Employee assessment) {
|
public Employee createOrUpdate(final Employee employee) {
|
||||||
return null;
|
final Employee saved = employeeRepository.save(employee);
|
||||||
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Employee> getEmployees() {
|
public List<Employee> getEmployees() {
|
||||||
|
@ -3,16 +3,20 @@ package com.primefactorsolutions.views;
|
|||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.service.EmployeeService;
|
import com.primefactorsolutions.service.EmployeeService;
|
||||||
import com.vaadin.flow.component.Component;
|
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.BeforeEvent;
|
||||||
import com.vaadin.flow.router.HasUrlParameter;
|
import com.vaadin.flow.router.HasUrlParameter;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
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 org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.vaadin.firitin.form.BeanValidationForm;
|
import org.vaadin.firitin.form.BeanValidationForm;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@SpringComponent
|
@SpringComponent
|
||||||
@PermitAll
|
@PermitAll
|
||||||
@ -20,22 +24,36 @@ import java.util.List;
|
|||||||
@PageTitle("Employee")
|
@PageTitle("Employee")
|
||||||
@Route(value = "/employees", layout = MainLayout.class)
|
@Route(value = "/employees", layout = MainLayout.class)
|
||||||
public class EmployeeView extends BeanValidationForm<Employee> implements HasUrlParameter<String> {
|
public class EmployeeView extends BeanValidationForm<Employee> implements HasUrlParameter<String> {
|
||||||
|
|
||||||
private final EmployeeService employeeService;
|
private final EmployeeService employeeService;
|
||||||
|
|
||||||
|
private TextField name = null;
|
||||||
|
|
||||||
public EmployeeView(final EmployeeService employeeService) {
|
public EmployeeView(final EmployeeService employeeService) {
|
||||||
super(Employee.class);
|
super(Employee.class);
|
||||||
this.employeeService = employeeService;
|
this.employeeService = employeeService;
|
||||||
}
|
name = new TextField();
|
||||||
|
name.setWidthFull();
|
||||||
|
name.setLabel("Name");
|
||||||
|
|
||||||
@Override
|
setSavedHandler((SavedHandler<Employee>) employee -> {
|
||||||
protected List<Component> getFormComponents() {
|
final Employee saved = employeeService.createOrUpdate(employee);
|
||||||
return null;
|
setEntityWithEnabledSave(saved);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setParameter(final BeforeEvent beforeEvent, final String s) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ public class EmployeesListView extends Main {
|
|||||||
hf.add(next);
|
hf.add(next);
|
||||||
final Button addEmployee = new Button("Add Employee");
|
final Button addEmployee = new Button("Add Employee");
|
||||||
addEmployee.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
addEmployee.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
//this.getUI().get().navigate(EmployeeView.class, "new");
|
this.getUI().get().navigate(EmployeeView.class, "new");
|
||||||
});
|
});
|
||||||
hf.add(addEmployee);
|
hf.add(addEmployee);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user