#7 Perfil de Personal Administrativo - Listado de empleados
This commit is contained in:
parent
80e731f163
commit
8146aff041
@ -17,15 +17,7 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Employee extends BaseEntity {
|
||||
private String username;
|
||||
private String firstName;
|
||||
private String name;
|
||||
private String lastName;
|
||||
private LocalDate dob;
|
||||
private String personalEmail;
|
||||
@Type(JsonType.class)
|
||||
@Column(columnDefinition = "json")
|
||||
private List<String> phoneNumbers;
|
||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "employee", cascade = {CascadeType.ALL})
|
||||
private List<Document> documents;
|
||||
private Role role;
|
||||
private String status;
|
||||
}
|
||||
|
@ -7,19 +7,26 @@ import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@Data
|
||||
public class EmployeeService {
|
||||
private final EmployeeRepository employeeRepository;
|
||||
|
||||
private List<Employee> getEmployees() {
|
||||
// TODO: implement
|
||||
throw new NotImplementedException();
|
||||
public EmployeeService(EmployeeRepository employeeRepository) {
|
||||
this.employeeRepository = employeeRepository;
|
||||
}
|
||||
|
||||
private Employee createOrUpdateEmployee(final Employee employee) {
|
||||
// TODO: implement
|
||||
throw new NotImplementedException();
|
||||
public Employee createOrUpdate(final Employee assessment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Employee> getEmployees() {
|
||||
return employeeRepository.findAll();
|
||||
}
|
||||
|
||||
public Employee getEmployee(final UUID id) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,28 @@
|
||||
package com.primefactorsolutions.views;
|
||||
|
||||
import com.primefactorsolutions.model.Employee;
|
||||
import com.primefactorsolutions.service.EmployeeService;
|
||||
import com.vaadin.flow.component.ClickEvent;
|
||||
import com.vaadin.flow.component.Component;
|
||||
import com.vaadin.flow.component.ComponentEventListener;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.combobox.ComboBox;
|
||||
import com.vaadin.flow.component.html.H2;
|
||||
import com.vaadin.flow.component.html.Main;
|
||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||
import com.vaadin.flow.data.provider.DataProvider;
|
||||
import com.vaadin.flow.data.provider.DataProviderListener;
|
||||
import com.vaadin.flow.data.provider.Query;
|
||||
import com.vaadin.flow.function.ValueProvider;
|
||||
import com.vaadin.flow.router.PageTitle;
|
||||
import com.vaadin.flow.router.Route;
|
||||
import com.vaadin.flow.shared.Registration;
|
||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.vaadin.firitin.components.grid.VGrid;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SpringComponent
|
||||
@Scope("prototype")
|
||||
@ -13,4 +30,97 @@ import org.springframework.context.annotation.Scope;
|
||||
@Route(value = "/employees", layout = MainLayout.class)
|
||||
@PermitAll
|
||||
public class EmployeesListView extends Main {
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
public EmployeesListView(final EmployeeService employeeService) {
|
||||
this.employeeService = employeeService;
|
||||
final H2 title = new H2("Employees list");
|
||||
final HorizontalLayout hl = new HorizontalLayout();
|
||||
final HorizontalLayout hf = new HorizontalLayout();
|
||||
final Button employeeListAscendingOrder = new Button("Employee List in Ascending Order");
|
||||
employeeListAscendingOrder.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||
// no-op
|
||||
});
|
||||
hl.add(employeeListAscendingOrder);
|
||||
final Button employeeListDescendingOrder = new Button("Employee List in Descending Order");
|
||||
employeeListDescendingOrder.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||
// no-op
|
||||
});
|
||||
hl.add(employeeListDescendingOrder);
|
||||
final VGrid<Employee> grid = new VGrid<>(Employee.class);
|
||||
grid.setColumns("name", "lastName", "status");
|
||||
grid.setAllRowsVisible(true);
|
||||
grid.addComponentColumn((ValueProvider<Employee, Component>) employee -> {
|
||||
ComboBox<String> statusComboBox = new ComboBox<>();
|
||||
statusComboBox.setItems("Active", "Inactive");
|
||||
return statusComboBox;
|
||||
}).setHeader("Change Status");
|
||||
grid.addComponentColumn((ValueProvider<Employee, Component>) employee -> {
|
||||
final Button edit = new Button("Edit");
|
||||
edit.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||
// no-op
|
||||
});
|
||||
return edit;
|
||||
});
|
||||
grid.addComponentColumn((ValueProvider<Employee, Component>) employee -> {
|
||||
final Button save = new Button("Save");
|
||||
save.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||
// no-op
|
||||
});
|
||||
return save;
|
||||
});
|
||||
|
||||
grid.setDataProvider(new DataProvider<>() {
|
||||
@Override
|
||||
public boolean isInMemory() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size(final Query<Employee, Object> query) {
|
||||
return employeeService.getEmployees().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Employee> fetch(final Query<Employee, Object> query) {
|
||||
int limit = query.getLimit();
|
||||
int pagerSize = query.getPageSize();
|
||||
int page = query.getPage();
|
||||
return employeeService.getEmployees().stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshItem(final Employee employee) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshAll() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registration addDataProviderListener(final DataProviderListener<Employee> dataProviderListener) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
final Button previous = new Button("Previous");
|
||||
previous.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||
// no-op
|
||||
});
|
||||
hf.add(previous);
|
||||
final Button next = new Button("Next");
|
||||
next.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||
// no-op
|
||||
});
|
||||
hf.add(next);
|
||||
final Button addEmployee = new Button("Add Employee");
|
||||
addEmployee.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||
//this.getUI().get().navigate(EmployeeView.class, "new");
|
||||
});
|
||||
hf.add(addEmployee);
|
||||
|
||||
add(title, hl, grid, hf);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user