Detalles #87
@ -53,7 +53,6 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
||||
private Button saveButton;
|
||||
private Button viewDocumentButton;
|
||||
|
||||
|
||||
public DocumentView(final DocumentService documentService,
|
||||
final EmployeeService employeeService,
|
||||
final AuthenticationContext authContext) {
|
||||
|
@ -55,6 +55,7 @@ public class RequestsListView extends BaseView {
|
||||
|
||||
private ComboBox<Employee> employeeFilter;
|
||||
private ComboBox<Team> teamFilter;
|
||||
private ComboBox<TimeOffRequestType> categoryFilter;
|
||||
private ComboBox<Status> stateFilter;
|
||||
|
||||
public RequestsListView(final TimeOffRequestService requestService,
|
||||
@ -66,7 +67,7 @@ public class RequestsListView extends BaseView {
|
||||
this.teamService = teamService;
|
||||
this.vacationService = vacationService;
|
||||
initializeView();
|
||||
refreshGeneralRequestGrid(null, null, null);
|
||||
refreshGeneralRequestGrid(null, null, null, null);
|
||||
}
|
||||
|
||||
private void initializeView() {
|
||||
@ -82,6 +83,7 @@ public class RequestsListView extends BaseView {
|
||||
final HorizontalLayout hl = new HorizontalLayout();
|
||||
hl.add(createEmployeeFilter());
|
||||
hl.add(createTeamFilter());
|
||||
hl.add(createCategoryFilter());
|
||||
hl.add(createStateFilter());
|
||||
getCurrentPageLayout().add(hl);
|
||||
}
|
||||
@ -90,6 +92,7 @@ public class RequestsListView extends BaseView {
|
||||
requestGrid.addColumn(this::getEmployeeFullName).setHeader("Empleado");
|
||||
requestGrid.addColumn(this::getTeamName).setHeader("Equipo");
|
||||
requestGrid.addColumn(this::getEmployeeStatus).setHeader("Estado del empleado");
|
||||
requestGrid.addColumn(this::getCategory).setHeader("Categoria");
|
||||
requestGrid.addColumn(this::getGeneralTotal).setHeader("Total general");
|
||||
requestGrid.addComponentColumn((ValueProvider<Employee, Component>) employee -> {
|
||||
final MenuBar menuBar = new MenuBar();
|
||||
@ -107,10 +110,11 @@ public class RequestsListView extends BaseView {
|
||||
|
||||
private void refreshGeneralRequestGrid(final Employee employee,
|
||||
final Team team,
|
||||
final TimeOffRequestType category,
|
||||
final Status state) {
|
||||
requestGrid.setPagingDataProvider((page, pageSize) -> {
|
||||
int start = (int) (page * requestGrid.getPageSize());
|
||||
return fetchFilteredEmployees(start, pageSize, employee, team, state);
|
||||
return fetchFilteredEmployees(start, pageSize, employee, team, category, state);
|
||||
});
|
||||
requestGrid.getDataProvider().refreshAll();
|
||||
}
|
||||
@ -119,6 +123,7 @@ public class RequestsListView extends BaseView {
|
||||
final int pageSize,
|
||||
final Employee employee,
|
||||
final Team team,
|
||||
final TimeOffRequestType category,
|
||||
final Status state) {
|
||||
List<Employee> filteredEmployees = employeeService.findAllEmployees();
|
||||
|
||||
@ -134,6 +139,16 @@ public class RequestsListView extends BaseView {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (category != null && category != TimeOffRequestType.values()[0]) {
|
||||
filteredEmployees = filteredEmployees.stream()
|
||||
.filter(emp -> {
|
||||
Optional<TimeOffRequest> request = requestService
|
||||
.findByEmployeeAndState(emp.getId(), TimeOffRequestStatus.EN_USO);
|
||||
return request.isPresent() && request.get().getCategory() == category;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (state != null && state != Status.TODOS) {
|
||||
filteredEmployees = filteredEmployees.stream()
|
||||
.filter(emp -> {
|
||||
@ -168,6 +183,12 @@ public class RequestsListView extends BaseView {
|
||||
return activeRequest.isPresent() ? "EN_DESCANSO" : "EN_FUNCIONES";
|
||||
}
|
||||
|
||||
private String getCategory(final Employee employee) {
|
||||
Optional<TimeOffRequest> activeRequest = requestService
|
||||
.findByEmployeeAndState(employee.getId(), TimeOffRequestStatus.EN_USO);
|
||||
return activeRequest.map(request -> request.getCategory().toString()).orElse("");
|
||||
}
|
||||
|
||||
private String getGeneralTotal(final Employee employee) {
|
||||
List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
|
||||
List<Vacation> vacations = vacationService.findVacations();
|
||||
@ -363,6 +384,7 @@ public class RequestsListView extends BaseView {
|
||||
refreshGeneralRequestGrid(
|
||||
event.getValue(),
|
||||
teamFilter.getValue(),
|
||||
categoryFilter.getValue(),
|
||||
stateFilter.getValue()
|
||||
)
|
||||
);
|
||||
@ -380,12 +402,28 @@ public class RequestsListView extends BaseView {
|
||||
refreshGeneralRequestGrid(
|
||||
employeeFilter.getValue(),
|
||||
event.getValue(),
|
||||
categoryFilter.getValue(),
|
||||
stateFilter.getValue()
|
||||
)
|
||||
);
|
||||
return teamFilter;
|
||||
}
|
||||
|
||||
private ComboBox<TimeOffRequestType> createCategoryFilter() {
|
||||
categoryFilter = new ComboBox<>("Category");
|
||||
categoryFilter.setItems(TimeOffRequestType.values());
|
||||
categoryFilter.setValue(TimeOffRequestType.values()[0]);
|
||||
categoryFilter.addValueChangeListener(event ->
|
||||
refreshGeneralRequestGrid(
|
||||
employeeFilter.getValue(),
|
||||
teamFilter.getValue(),
|
||||
event.getValue(),
|
||||
stateFilter.getValue()
|
||||
)
|
||||
);
|
||||
return categoryFilter;
|
||||
}
|
||||
|
||||
private ComboBox<Status> createStateFilter() {
|
||||
stateFilter = new ComboBox<>("Estado del empleado");
|
||||
stateFilter.setItems(Status.values());
|
||||
@ -394,6 +432,7 @@ public class RequestsListView extends BaseView {
|
||||
refreshGeneralRequestGrid(
|
||||
employeeFilter.getValue(),
|
||||
teamFilter.getValue(),
|
||||
categoryFilter.getValue(),
|
||||
event.getValue()
|
||||
)
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user