@ -7,7 +7,6 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -1,20 +1,12 @@
|
|||||||
package com.primefactorsolutions.service;
|
package com.primefactorsolutions.service;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.Document;
|
|
||||||
import com.primefactorsolutions.model.DocumentType;
|
|
||||||
import com.primefactorsolutions.model.Employee;
|
|
||||||
import com.primefactorsolutions.model.Team;
|
import com.primefactorsolutions.model.Team;
|
||||||
import com.primefactorsolutions.repositories.DocumentRepository;
|
|
||||||
import com.primefactorsolutions.repositories.TeamRepository;
|
import com.primefactorsolutions.repositories.TeamRepository;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.apache.commons.beanutils.BeanComparator;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -6,7 +6,6 @@ import lombok.AllArgsConstructor;
|
|||||||
import org.apache.commons.beanutils.BeanComparator;
|
import org.apache.commons.beanutils.BeanComparator;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.Time;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -56,11 +55,12 @@ public class TimeOffRequestService {
|
|||||||
return timeOffRequests.subList(start, end);
|
return timeOffRequests.subList(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TimeOffRequest> findTimeOffRequestBy(Employee employee,
|
public List<TimeOffRequest> findTimeOffRequestBy(final Employee employee,
|
||||||
Team team,
|
final Team team,
|
||||||
TimeOffRequestType category,
|
final TimeOffRequestType category,
|
||||||
TimeOffRequest.Status state,
|
final TimeOffRequest.Status state,
|
||||||
int start, int pageSize) {
|
final int start,
|
||||||
|
final int pageSize) {
|
||||||
List<TimeOffRequest> timeOffRequests = timeOffRequestRepository.findAll();
|
List<TimeOffRequest> timeOffRequests = timeOffRequestRepository.findAll();
|
||||||
if (employee != null && !"ALL".equals(employee.getFirstName())) {
|
if (employee != null && !"ALL".equals(employee.getFirstName())) {
|
||||||
timeOffRequests = timeOffRequests.stream()
|
timeOffRequests = timeOffRequests.stream()
|
||||||
|
@ -36,7 +36,9 @@ public class RequestsListView extends Main {
|
|||||||
private ComboBox<TimeOffRequestType> categoryFilter;
|
private ComboBox<TimeOffRequestType> categoryFilter;
|
||||||
private ComboBox<TimeOffRequest.Status> stateFilter;
|
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.requestService = requestService;
|
||||||
this.employeeService = employeeService;
|
this.employeeService = employeeService;
|
||||||
this.teamService = teamService;
|
this.teamService = teamService;
|
||||||
@ -60,7 +62,16 @@ public class RequestsListView extends Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupRequestGrid() {
|
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::createEmployeeSpan).setHeader("Employee");
|
||||||
requestGrid.addComponentColumn(this::createTeamSpan).setHeader("Team");
|
requestGrid.addComponentColumn(this::createTeamSpan).setHeader("Team");
|
||||||
requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
|
requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
|
||||||
@ -75,7 +86,10 @@ public class RequestsListView extends Main {
|
|||||||
return new HorizontalLayout(viewButton, editButton, saveButton, closeButton);
|
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) -> {
|
requestGrid.setPagingDataProvider((page, pageSize) -> {
|
||||||
if (allFiltersAreNull(employee, team, category, state)) {
|
if (allFiltersAreNull(employee, team, category, state)) {
|
||||||
return fetchTimeOffRequests((int) page, pageSize);
|
return fetchTimeOffRequests((int) page, pageSize);
|
||||||
@ -86,11 +100,14 @@ public class RequestsListView extends Main {
|
|||||||
requestGrid.getDataProvider().refreshAll();
|
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;
|
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;
|
int start = page * pageSize;
|
||||||
if (requestGrid.getSortOrder().isEmpty()) {
|
if (requestGrid.getSortOrder().isEmpty()) {
|
||||||
return requestService.findTimeOffRequests(start, pageSize);
|
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();
|
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);
|
return requestService.findTimeOffRequestBy(employee, team, category, state, page, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Span createEmployeeSpan(TimeOffRequest timeOffRequest) {
|
private Span createEmployeeSpan(final TimeOffRequest timeOffRequest) {
|
||||||
Employee employee = timeOffRequest.getEmployee();
|
Employee employee = timeOffRequest.getEmployee();
|
||||||
return new Span(employee.getFirstName() + " " + employee.getLastName());
|
return new Span(employee.getFirstName() + " " + employee.getLastName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Span createTeamSpan(TimeOffRequest timeOffRequest) {
|
private Span createTeamSpan(final TimeOffRequest timeOffRequest) {
|
||||||
return new Span(timeOffRequest.getTeam().getName());
|
return new Span(timeOffRequest.getTeam().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +151,14 @@ public class RequestsListView extends Main {
|
|||||||
employeeFilter.setItems(employees);
|
employeeFilter.setItems(employees);
|
||||||
employeeFilter.setItemLabelGenerator(this::getEmployeeLabel);
|
employeeFilter.setItemLabelGenerator(this::getEmployeeLabel);
|
||||||
employeeFilter.setValue(employees.getFirst());
|
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;
|
return employeeFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +169,14 @@ public class RequestsListView extends Main {
|
|||||||
teamFilter.setItems(teams);
|
teamFilter.setItems(teams);
|
||||||
teamFilter.setItemLabelGenerator(this::getTeamLabel);
|
teamFilter.setItemLabelGenerator(this::getTeamLabel);
|
||||||
teamFilter.setValue(teams.getFirst());
|
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;
|
return teamFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +184,14 @@ public class RequestsListView extends Main {
|
|||||||
categoryFilter = new ComboBox<>("Category");
|
categoryFilter = new ComboBox<>("Category");
|
||||||
categoryFilter.setItems(TimeOffRequestType.values());
|
categoryFilter.setItems(TimeOffRequestType.values());
|
||||||
categoryFilter.setValue(TimeOffRequestType.values()[0]);
|
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;
|
return categoryFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +199,14 @@ public class RequestsListView extends Main {
|
|||||||
stateFilter = new ComboBox<>("State");
|
stateFilter = new ComboBox<>("State");
|
||||||
stateFilter.setItems(TimeOffRequest.Status.values());
|
stateFilter.setItems(TimeOffRequest.Status.values());
|
||||||
stateFilter.setValue(TimeOffRequest.Status.values()[0]);
|
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;
|
return stateFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,11 +222,11 @@ public class RequestsListView extends Main {
|
|||||||
return allTeamsOption;
|
return allTeamsOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getEmployeeLabel(Employee employee) {
|
private String getEmployeeLabel(final Employee employee) {
|
||||||
return "ALL".equals(employee.getFirstName()) ? "ALL" : employee.getFirstName() + " " + employee.getLastName();
|
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();
|
return "ALL".equals(team.getName()) ? "ALL" : team.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user