|
|
|
@ -36,7 +36,9 @@ public class RequestsListView extends Main {
|
|
|
|
|
private ComboBox<TimeOffRequestType> categoryFilter;
|
|
|
|
|
private ComboBox<TimeOffRequest.Status> stateFilter;
|
|
|
|
|
|
|
|
|
|
public RequestsListView(TimeOffRequestService requestService, EmployeeService employeeService, TeamService teamService) {
|
|
|
|
|
public RequestsListView(final TimeOffRequestService requestService,
|
|
|
|
|
final EmployeeService employeeService,
|
|
|
|
|
final TeamService teamService) {
|
|
|
|
|
this.requestService = requestService;
|
|
|
|
|
this.employeeService = employeeService;
|
|
|
|
|
this.teamService = teamService;
|
|
|
|
@ -60,7 +62,16 @@ public class RequestsListView extends Main {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setupRequestGrid() {
|
|
|
|
|
requestGrid.setColumns("category", "state", "availableDays", "expiration", "startDate", "endDate", "daysToBeTake", "daysBalance");
|
|
|
|
|
requestGrid.setColumns(
|
|
|
|
|
"category",
|
|
|
|
|
"state",
|
|
|
|
|
"availableDays",
|
|
|
|
|
"expiration",
|
|
|
|
|
"startDate",
|
|
|
|
|
"endDate",
|
|
|
|
|
"daysToBeTake",
|
|
|
|
|
"daysBalance"
|
|
|
|
|
);
|
|
|
|
|
requestGrid.addComponentColumn(this::createEmployeeSpan).setHeader("Employee");
|
|
|
|
|
requestGrid.addComponentColumn(this::createTeamSpan).setHeader("Team");
|
|
|
|
|
requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
|
|
|
|
@ -75,22 +86,28 @@ public class RequestsListView extends Main {
|
|
|
|
|
return new HorizontalLayout(viewButton, editButton, saveButton, closeButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void refreshRequestGrid(Employee employee, Team team, TimeOffRequestType category, TimeOffRequest.Status state) {
|
|
|
|
|
private void refreshRequestGrid(final Employee employee,
|
|
|
|
|
final Team team,
|
|
|
|
|
final TimeOffRequestType category,
|
|
|
|
|
final TimeOffRequest.Status state) {
|
|
|
|
|
requestGrid.setPagingDataProvider((page, pageSize) -> {
|
|
|
|
|
if (allFiltersAreNull(employee, team, category, state)) {
|
|
|
|
|
return fetchTimeOffRequests((int)page, pageSize);
|
|
|
|
|
return fetchTimeOffRequests((int) page, pageSize);
|
|
|
|
|
} else {
|
|
|
|
|
return fetchFilteredTimeOffRequests((int)page, pageSize, employee, team, category, state);
|
|
|
|
|
return fetchFilteredTimeOffRequests((int) page, pageSize, employee, team, category, state);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
requestGrid.getDataProvider().refreshAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean allFiltersAreNull(Employee employee, Team team, TimeOffRequestType category, TimeOffRequest.Status state) {
|
|
|
|
|
private boolean allFiltersAreNull(final Employee employee,
|
|
|
|
|
final Team team,
|
|
|
|
|
final TimeOffRequestType category,
|
|
|
|
|
final TimeOffRequest.Status state) {
|
|
|
|
|
return employee == null && team == null && category == null && state == null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<TimeOffRequest> fetchTimeOffRequests(int page, int pageSize) {
|
|
|
|
|
private List<TimeOffRequest> fetchTimeOffRequests(final int page, final int pageSize) {
|
|
|
|
|
int start = page * pageSize;
|
|
|
|
|
if (requestGrid.getSortOrder().isEmpty()) {
|
|
|
|
|
return requestService.findTimeOffRequests(start, pageSize);
|
|
|
|
@ -99,21 +116,31 @@ public class RequestsListView extends Main {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<TimeOffRequest> fetchSortedTimeOffRequests(int start, int pageSize) {
|
|
|
|
|
private List<TimeOffRequest> fetchSortedTimeOffRequests(final int start, final int pageSize) {
|
|
|
|
|
GridSortOrder<TimeOffRequest> sortOrder = requestGrid.getSortOrder().getFirst();
|
|
|
|
|
return requestService.findTimeOffRequests(start, pageSize, sortOrder.getSorted().getKey(), sortOrder.getDirection() == SortDirection.ASCENDING);
|
|
|
|
|
return requestService.findTimeOffRequests(
|
|
|
|
|
start,
|
|
|
|
|
pageSize,
|
|
|
|
|
sortOrder.getSorted().getKey(),
|
|
|
|
|
sortOrder.getDirection() == SortDirection.ASCENDING
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<TimeOffRequest> fetchFilteredTimeOffRequests(int page, int pageSize, Employee employee, Team team, TimeOffRequestType category, TimeOffRequest.Status state) {
|
|
|
|
|
private List<TimeOffRequest> fetchFilteredTimeOffRequests(final int page,
|
|
|
|
|
final int pageSize,
|
|
|
|
|
final Employee employee,
|
|
|
|
|
final Team team,
|
|
|
|
|
final TimeOffRequestType category,
|
|
|
|
|
final TimeOffRequest.Status state) {
|
|
|
|
|
return requestService.findTimeOffRequestBy(employee, team, category, state, page, pageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Span createEmployeeSpan(TimeOffRequest timeOffRequest) {
|
|
|
|
|
private Span createEmployeeSpan(final TimeOffRequest timeOffRequest) {
|
|
|
|
|
Employee employee = timeOffRequest.getEmployee();
|
|
|
|
|
return new Span(employee.getFirstName() + " " + employee.getLastName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Span createTeamSpan(TimeOffRequest timeOffRequest) {
|
|
|
|
|
private Span createTeamSpan(final TimeOffRequest timeOffRequest) {
|
|
|
|
|
return new Span(timeOffRequest.getTeam().getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -124,7 +151,14 @@ public class RequestsListView extends Main {
|
|
|
|
|
employeeFilter.setItems(employees);
|
|
|
|
|
employeeFilter.setItemLabelGenerator(this::getEmployeeLabel);
|
|
|
|
|
employeeFilter.setValue(employees.getFirst());
|
|
|
|
|
employeeFilter.addValueChangeListener(event -> refreshRequestGrid(event.getValue(), teamFilter.getValue(), categoryFilter.getValue(), stateFilter.getValue()));
|
|
|
|
|
employeeFilter.addValueChangeListener(event ->
|
|
|
|
|
refreshRequestGrid(
|
|
|
|
|
event.getValue(),
|
|
|
|
|
teamFilter.getValue(),
|
|
|
|
|
categoryFilter.getValue(),
|
|
|
|
|
stateFilter.getValue()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
return employeeFilter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -135,7 +169,14 @@ public class RequestsListView extends Main {
|
|
|
|
|
teamFilter.setItems(teams);
|
|
|
|
|
teamFilter.setItemLabelGenerator(this::getTeamLabel);
|
|
|
|
|
teamFilter.setValue(teams.getFirst());
|
|
|
|
|
teamFilter.addValueChangeListener(event -> refreshRequestGrid(employeeFilter.getValue(), event.getValue(), categoryFilter.getValue(), stateFilter.getValue()));
|
|
|
|
|
teamFilter.addValueChangeListener(event ->
|
|
|
|
|
refreshRequestGrid(
|
|
|
|
|
employeeFilter.getValue(),
|
|
|
|
|
event.getValue(),
|
|
|
|
|
categoryFilter.getValue(),
|
|
|
|
|
stateFilter.getValue()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
return teamFilter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -143,7 +184,14 @@ public class RequestsListView extends Main {
|
|
|
|
|
categoryFilter = new ComboBox<>("Category");
|
|
|
|
|
categoryFilter.setItems(TimeOffRequestType.values());
|
|
|
|
|
categoryFilter.setValue(TimeOffRequestType.values()[0]);
|
|
|
|
|
categoryFilter.addValueChangeListener(event -> refreshRequestGrid(employeeFilter.getValue(), teamFilter.getValue(), event.getValue(), stateFilter.getValue()));
|
|
|
|
|
categoryFilter.addValueChangeListener(event ->
|
|
|
|
|
refreshRequestGrid(
|
|
|
|
|
employeeFilter.getValue(),
|
|
|
|
|
teamFilter.getValue(),
|
|
|
|
|
event.getValue(),
|
|
|
|
|
stateFilter.getValue()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
return categoryFilter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -151,7 +199,14 @@ public class RequestsListView extends Main {
|
|
|
|
|
stateFilter = new ComboBox<>("State");
|
|
|
|
|
stateFilter.setItems(TimeOffRequest.Status.values());
|
|
|
|
|
stateFilter.setValue(TimeOffRequest.Status.values()[0]);
|
|
|
|
|
stateFilter.addValueChangeListener(event -> refreshRequestGrid(employeeFilter.getValue(), teamFilter.getValue(), categoryFilter.getValue(), event.getValue()));
|
|
|
|
|
stateFilter.addValueChangeListener(event ->
|
|
|
|
|
refreshRequestGrid(
|
|
|
|
|
employeeFilter.getValue(),
|
|
|
|
|
teamFilter.getValue(),
|
|
|
|
|
categoryFilter.getValue(),
|
|
|
|
|
event.getValue()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
return stateFilter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -167,11 +222,11 @@ public class RequestsListView extends Main {
|
|
|
|
|
return allTeamsOption;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getEmployeeLabel(Employee employee) {
|
|
|
|
|
private String getEmployeeLabel(final Employee employee) {
|
|
|
|
|
return "ALL".equals(employee.getFirstName()) ? "ALL" : employee.getFirstName() + " " + employee.getLastName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getTeamLabel(Team team) {
|
|
|
|
|
private String getTeamLabel(final Team team) {
|
|
|
|
|
return "ALL".equals(team.getName()) ? "ALL" : team.getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|