Compare commits

..

No commits in common. "7d3b63f6a822661b78dc8f55cb44cb55c5178c4b" and "2a47bb8d9aa66ca7122714331cf4d00409f6fe1d" have entirely different histories.

6 changed files with 175 additions and 406 deletions

View File

@ -6,7 +6,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDate; import java.util.Date;
@Data @Data
@Entity @Entity
@ -20,11 +20,24 @@ public class TimeOffRequest extends BaseEntity {
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private TimeOffRequestType category; private TimeOffRequestType category;
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private TimeOffRequestStatus state; private Status state;
private Double availableDays; private Double availableDays;
private LocalDate expiration; private Date expiration;
private LocalDate startDate; private Date startDate;
private LocalDate endDate; private Date endDate;
private Double daysToBeTake; private Double daysToBeTake;
private Double daysBalance; private Double daysBalance;
public enum Status {
ALL,
TAKEN,
REQUESTED,
APPROVED,
IN_USE,
UNDER_REVIEW,
PENDING,
REJECTED,
COMPLETED,
CANCELLED,
EXPIRED,
}
} }

View File

@ -1,15 +0,0 @@
package com.primefactorsolutions.model;
public enum TimeOffRequestStatus {
ALL,
TAKEN,
REQUESTED,
APPROVED,
IN_USE,
UNDER_REVIEW,
PENDING,
REJECTED,
COMPLETED,
CANCELLED,
EXPIRED
}

View File

@ -1,18 +1,13 @@
package com.primefactorsolutions.views; package com.primefactorsolutions.views;
import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Employee;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.applayout.AppLayout; import com.vaadin.flow.component.applayout.AppLayout;
import com.vaadin.flow.component.applayout.DrawerToggle; import com.vaadin.flow.component.applayout.DrawerToggle;
import com.vaadin.flow.component.avatar.Avatar; import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.contextmenu.HasMenuItems; import com.vaadin.flow.component.html.Footer;
import com.vaadin.flow.component.contextmenu.MenuItem; import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.contextmenu.SubMenu; import com.vaadin.flow.component.html.Header;
import com.vaadin.flow.component.html.*; import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.menubar.MenuBar;
import com.vaadin.flow.component.menubar.MenuBarVariant;
import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.Scroller; import com.vaadin.flow.component.orderedlayout.Scroller;
@ -43,26 +38,18 @@ public class MainLayout extends AppLayout {
} }
private void addHeaderContent() { private void addHeaderContent() {
final DrawerToggle toggle = new DrawerToggle(); DrawerToggle toggle = new DrawerToggle();
toggle.setAriaLabel("Menu toggle"); toggle.setAriaLabel("Menu toggle");
viewTitle = new H1(); viewTitle = new H1();
viewTitle.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.Margin.NONE); viewTitle.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.Margin.NONE);
final HorizontalLayout header = authContext.getAuthenticatedUser(UserDetails.class) HorizontalLayout
header =
authContext.getAuthenticatedUser(UserDetails.class)
.map(user -> { .map(user -> {
final Avatar loggedUser = new Avatar(user.getUsername()); final Button logout = new Button("Logout", click -> this.authContext.logout());
loggedUser.getStyle().set("display", "block"); final Span loggedUser = new Span("Welcome " + user.getUsername());
loggedUser.getElement().setAttribute("tabindex", "-1");
final MenuBar menuBar = new MenuBar();
menuBar.addThemeVariants(MenuBarVariant.LUMO_ICON);
final MenuItem actions = createIconItem(menuBar, VaadinIcon.ELLIPSIS_V, null, "",
false);
final SubMenu actionsSubMenu = actions.getSubMenu();
final MenuItem signOutMenuItem = createIconItem(actionsSubMenu, VaadinIcon.EXIT, "Sign-out",
null, true);
signOutMenuItem.addClickListener(c -> this.authContext.logout());
String employeeId = "N/A"; String employeeId = "N/A";
if (user instanceof Employee) { if (user instanceof Employee) {
@ -77,7 +64,7 @@ public class MainLayout extends AppLayout {
.withText("Employee id: " + employeeId) .withText("Employee id: " + employeeId)
.withPosition(Tooltip.TooltipPosition.TOP_START); .withPosition(Tooltip.TooltipPosition.TOP_START);
final HorizontalLayout hl = new HorizontalLayout(loggedUser, menuBar); final HorizontalLayout hl = new HorizontalLayout(loggedUser, logout);
hl.setJustifyContentMode(FlexComponent.JustifyContentMode.END); hl.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
return hl; return hl;
@ -88,40 +75,18 @@ public class MainLayout extends AppLayout {
addToNavbar(true, toggle, viewTitle, header); addToNavbar(true, toggle, viewTitle, header);
} }
private MenuItem createIconItem(final HasMenuItems menu, final VaadinIcon iconName,
final String label, final String ariaLabel, final boolean isChild) {
final Icon icon = new Icon(iconName);
if (isChild) {
icon.getStyle().set("width", "var(--lumo-icon-size-s)");
icon.getStyle().set("height", "var(--lumo-icon-size-s)");
icon.getStyle().set("marginRight", "var(--lumo-space-s)");
}
final MenuItem item = menu.addItem(icon, e -> {
});
if (ariaLabel != null) {
item.setAriaLabel(ariaLabel);
}
if (label != null) {
item.add(new Text(label));
}
return item;
}
private void addDrawerContent() { private void addDrawerContent() {
final Span appName = new Span("pfs-intra"); Span appName = new Span("pfs-intra");
appName.addClassNames(LumoUtility.FontWeight.SEMIBOLD, LumoUtility.FontSize.LARGE); appName.addClassNames(LumoUtility.FontWeight.SEMIBOLD, LumoUtility.FontSize.LARGE);
final Header header = new Header(appName); Header header = new Header(appName);
final Scroller scroller = new Scroller(createNavigation());
Scroller scroller = new Scroller(createNavigation());
addToDrawer(header, scroller, createFooter()); addToDrawer(header, scroller, createFooter());
} }
private SideNav createNavigation() { private SideNav createNavigation() {
final SideNav nav = new SideNav(); SideNav nav = new SideNav();
authContext.getAuthenticatedUser(UserDetails.class).ifPresent(u -> { authContext.getAuthenticatedUser(UserDetails.class).ifPresent(u -> {
SideNavItem recruiting = new SideNavItem("Recruiting", MainView.class, SideNavItem recruiting = new SideNavItem("Recruiting", MainView.class,
@ -134,7 +99,7 @@ public class MainLayout extends AppLayout {
LineAwesomeIcon.QUESTION_SOLID.create())); LineAwesomeIcon.QUESTION_SOLID.create()));
SideNavItem admin = new SideNavItem("Admin", MainView.class, SideNavItem admin = new SideNavItem("Admin", MainView.class,
LineAwesomeIcon.BUILDING.create()); LineAwesomeIcon.SUPERSCRIPT_SOLID.create());
admin.addItem(new SideNavItem("Employees", EmployeesListView.class, admin.addItem(new SideNavItem("Employees", EmployeesListView.class,
LineAwesomeIcon.USER_EDIT_SOLID.create())); LineAwesomeIcon.USER_EDIT_SOLID.create()));
admin.addItem(new SideNavItem("Documents", DocumentsListView.class, admin.addItem(new SideNavItem("Documents", DocumentsListView.class,
@ -164,7 +129,9 @@ public class MainLayout extends AppLayout {
} }
private Footer createFooter() { private Footer createFooter() {
return new Footer(); Footer layout = new Footer();
return layout;
} }
@Override @Override

View File

@ -1,185 +0,0 @@
package com.primefactorsolutions.views;
import com.primefactorsolutions.model.*;
import com.primefactorsolutions.service.EmployeeService;
import com.primefactorsolutions.service.TimeOffRequestService;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("RequestEmployee")
@Route(value = "/requests", layout = MainLayout.class)
public class RequestEmployeeView extends Div implements HasUrlParameter<String> {
private final TimeOffRequestService requestService;
private final EmployeeService employeeService;
private final Grid<TimeOffRequest> requestGrid = new Grid<>(TimeOffRequest.class);
private List<TimeOffRequest> requests = Collections.emptyList();
private ComboBox<TimeOffRequestType> categoryFilter;
private ComboBox<TimeOffRequestStatus> stateFilter;
private UUID employeeId;
private TimeOffRequest request;
public RequestEmployeeView(final TimeOffRequestService requestService, final EmployeeService employeeService) {
this.requestService = requestService;
this.employeeService = employeeService;
initializeView();
}
private void initializeView() {
setupFilters();
setupGrid();
add(requestGrid, createSummaryLayout(), createActionButtons());
refreshRequestGrid(null, null);
}
private void setupFilters() {
categoryFilter = createCategoryFilter();
stateFilter = createStateFilter();
add(categoryFilter, stateFilter);
}
private ComboBox<TimeOffRequestType> createCategoryFilter() {
categoryFilter = new ComboBox<>("Category");
categoryFilter.setItems(TimeOffRequestType.values());
categoryFilter.setValue(TimeOffRequestType.values()[0]);
categoryFilter.addValueChangeListener(event -> refreshRequestGrid(event.getValue(), stateFilter.getValue()));
return categoryFilter;
}
private ComboBox<TimeOffRequestStatus> createStateFilter() {
stateFilter = new ComboBox<>("State");
stateFilter.setItems(TimeOffRequestStatus.values());
stateFilter.setValue(TimeOffRequestStatus.values()[0]);
stateFilter.addValueChangeListener(event -> refreshRequestGrid(categoryFilter.getValue(), event.getValue()));
return stateFilter;
}
private void setupGrid() {
requestGrid.setColumns(
"category",
"state",
"availableDays",
"expiration",
"startDate",
"endDate",
"daysToBeTake",
"daysBalance"
);
requestGrid.setAllRowsVisible(true);
requestGrid.asSingleSelect().addValueChangeListener(event -> {
TimeOffRequest selectedRequest = event.getValue();
if (selectedRequest != null) {
request = selectedRequest;
}
});
}
private VerticalLayout createSummaryLayout() {
int totalVacations = 15;
int totalTimeOff = 2;
int totalAvailableDays = totalVacations + totalTimeOff;
return new VerticalLayout(
new Span("TOTAL HOLIDAYS: " + totalVacations),
new Span("TOTAL TIME OFF: " + totalTimeOff),
new Span("TOTAL AVAILABLE DAYS: " + totalAvailableDays)
);
}
private HorizontalLayout createActionButtons() {
Button viewButton = new Button("View", event -> {
if (request != null) {
navigateToViewRequest(request);
} else {
Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE);
}
});
Button editButton = new Button("Edit", event -> {
if (request != null) {
navigateToEditRequest(request);
} else {
Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE);
}
});
Button closeButton = new Button("Close", event -> navigateToRequestsListView());
return new HorizontalLayout(viewButton, editButton, closeButton);
}
private void navigateToRequestsListView() {
getUI().ifPresent(ui -> ui.navigate(RequestsListView.class));
}
private void navigateToEditRequest(final TimeOffRequest request) {
navigateToRequestView(request, "edit");
}
private void navigateToViewRequest(final TimeOffRequest request) {
navigateToRequestView(request, "view");
}
private void navigateToRequestView(final TimeOffRequest request, final String action) {
getUI().ifPresent(ui -> ui.navigate(RequestView.class, request.getId().toString() + "/" + action));
}
private void refreshRequestGrid(final TimeOffRequestType category, final TimeOffRequestStatus state) {
List<TimeOffRequest> filteredRequests = allFiltersAreNull(category, state)
? requestService.findRequestsByEmployeeId(employeeId)
: fetchFilteredTimeOffRequests(category, state);
requestGrid.setItems(filteredRequests);
}
private boolean allFiltersAreNull(final TimeOffRequestType category, final TimeOffRequestStatus state) {
return category == null && state == null;
}
private List<TimeOffRequest> fetchFilteredTimeOffRequests(final TimeOffRequestType category,
final TimeOffRequestStatus state) {
requests = requestService.findRequestsByEmployeeId(employeeId);
if (category != null && !"ALL".equals(category.name())) {
requests = requests.stream()
.filter(req -> req.getCategory().equals(category))
.collect(Collectors.toList());
}
if (state != null && !"ALL".equals(state.name())) {
requests = requests.stream()
.filter(req -> req.getState().equals(state))
.collect(Collectors.toList());
}
return requests;
}
@Override
public void setParameter(final BeforeEvent event, final String parameter) {
employeeId = UUID.fromString(parameter);
Employee employee = employeeService.getEmployee(employeeId);
requests = requestService.findRequestsByEmployeeId(employeeId);
setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName());
requestGrid.setItems(requests);
}
private void setViewTitle(final String employeeName, final String employeeTeam) {
addComponentAsFirst(new H3("Name: " + employeeName));
addComponentAtIndex(1, new H3("Team: " + employeeTeam));
}
}

View File

@ -1,169 +1,156 @@
package com.primefactorsolutions.views; package com.primefactorsolutions.views;
import com.primefactorsolutions.model.*; import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.model.TimeOffRequest;
import com.primefactorsolutions.model.TimeOffRequestType;
import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.EmployeeService;
import com.primefactorsolutions.service.TeamService;
import com.primefactorsolutions.service.TimeOffRequestService; import com.primefactorsolutions.service.TimeOffRequestService;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.datepicker.DatePicker; import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H3; import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.textfield.NumberField; import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.router.*; import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.PageTitle;
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.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.form.BeanValidationForm;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@SpringComponent @SpringComponent
@PermitAll @PermitAll
@Scope("prototype") @Scope("prototype")
@PageTitle("Request") @PageTitle("Request")
@Route(value = "/requests/:requestId?/:action?", layout = MainLayout.class) @Route(value = "/requests", layout = MainLayout.class)
public class RequestView extends BeanValidationForm<TimeOffRequest> implements HasUrlParameter<String> { public class RequestView extends Div implements HasUrlParameter<String> {
private final ComboBox<TimeOffRequestStatus> state = new ComboBox<>("State");
private final DatePicker expiration = new DatePicker("Expiration");
private final DatePicker startDate = new DatePicker("Start Date");
private final DatePicker endDate = new DatePicker("End Date");
private final NumberField availableDays = new NumberField("Available Days");
private final NumberField daysToBeTake = new NumberField("Days To Be Take");
private final TimeOffRequestService requestService; private final TimeOffRequestService requestService;
private final EmployeeService employeeService; private final EmployeeService employeeService;
private TimeOffRequest request; private final Grid<TimeOffRequest> requestGrid = new Grid<>(TimeOffRequest.class);
private Employee employee; private List<TimeOffRequest> requests = Collections.emptyList();
private ComboBox<TimeOffRequestType> categoryFilter;
private ComboBox<TimeOffRequest.Status> stateFilter;
private UUID employeeId;
private Button saveButton; public RequestView(final TimeOffRequestService requestService, final EmployeeService employeeService) {
public RequestView(final TimeOffRequestService requestService,
final EmployeeService employeeService,
final TeamService teamService) {
super(TimeOffRequest.class);
this.requestService = requestService; this.requestService = requestService;
this.employeeService = employeeService; this.employeeService = employeeService;
state.setItems(List.of(TimeOffRequestStatus.values())); initializeView();
} }
@Override private void initializeView() {
public void setParameter(final BeforeEvent beforeEvent, final String action) { setupFilters();
final RouteParameters params = beforeEvent.getRouteParameters(); setupGrid();
final String requestIdString = params.get("requestId").orElse(null); add(requestGrid, createSummaryLayout(), createActionButtons());
refreshRequestGrid(null, null);
if ("new".equals(action)) {
setEntityWithEnabledSave(new TimeOffRequest());
} else {
assert requestIdString != null;
UUID requestId = UUID.fromString(requestIdString);
request = requestService.findTimeOffRequest(requestId);
UUID employeeId = request.getEmployee().getId();
employee = employeeService.getEmployee(employeeId);
setEntity(request);
configureViewOrEditAction(action);
}
} }
@Override private void setupFilters() {
protected List<Component> getFormComponents() { categoryFilter = createCategoryFilter();
return List.of( stateFilter = createStateFilter();
createEmployeeHeader(), add(categoryFilter, stateFilter);
createTeamHeader(), }
createCategoryHeader(),
state, private ComboBox<TimeOffRequestType> createCategoryFilter() {
expiration, categoryFilter = new ComboBox<>("Category");
startDate, categoryFilter.setItems(TimeOffRequestType.values());
endDate, categoryFilter.setValue(TimeOffRequestType.values()[0]);
availableDays, categoryFilter.addValueChangeListener(event -> refreshRequestGrid(event.getValue(), stateFilter.getValue()));
daysToBeTake, return categoryFilter;
createCloseButton() }
private ComboBox<TimeOffRequest.Status> createStateFilter() {
stateFilter = new ComboBox<>("State");
stateFilter.setItems(TimeOffRequest.Status.values());
stateFilter.setValue(TimeOffRequest.Status.values()[0]);
stateFilter.addValueChangeListener(event -> refreshRequestGrid(categoryFilter.getValue(), event.getValue()));
return stateFilter;
}
private void setupGrid() {
requestGrid.setColumns(
"category",
"state",
"availableDays",
"expiration",
"startDate",
"endDate",
"daysToBeTake",
"daysBalance"
);
requestGrid.setAllRowsVisible(true);
}
private VerticalLayout createSummaryLayout() {
int totalVacations = 15;
int totalTimeOff = 2;
int totalAvailableDays = totalVacations + totalTimeOff;
return new VerticalLayout(
new Span("TOTAL HOLIDAYS: " + totalVacations),
new Span("TOTAL TIME OFF: " + totalTimeOff),
new Span("TOTAL AVAILABLE DAYS: " + totalAvailableDays)
); );
} }
protected Button createSaveButton() { private HorizontalLayout createActionButtons() {
saveButton = new Button("Save"); Button viewButton = new Button("View");
saveButton.addClickListener(event -> saveRequest()); Button editButton = new Button("Edit");
return saveButton; Button saveButton = new Button("Save");
Button closeButton = new Button("Close", event -> navigateToRequestsListView());
return new HorizontalLayout(viewButton, editButton, saveButton, closeButton);
} }
protected Button createCloseButton() { private void navigateToRequestsListView() {
Button closeButton = new Button("Close"); getUI().ifPresent(ui -> ui.navigate(RequestsListView.class));
closeButton.addClickListener(event -> closeForm());
return closeButton;
} }
private void setFieldsReadOnly(final boolean option) { private void refreshRequestGrid(final TimeOffRequestType category, final TimeOffRequest.Status state) {
state.setReadOnly(option); List<TimeOffRequest> filteredRequests = allFiltersAreNull(category, state)
expiration.setReadOnly(option); ? requestService.findRequestsByEmployeeId(employeeId)
startDate.setReadOnly(option); : fetchFilteredTimeOffRequests(category, state);
endDate.setReadOnly(option); requestGrid.setItems(filteredRequests);
availableDays.setReadOnly(option);
daysToBeTake.setReadOnly(option);
} }
private void saveRequest() { private boolean allFiltersAreNull(final TimeOffRequestType category, final TimeOffRequest.Status state) {
if (isFormValid()) { return category == null && state == null;
TimeOffRequest request = getEntity();
setRequestFieldValues(request);
requestService.saveTimeOffRequest(request);
Notification.show("Request saved successfully.");
clearForm();
}
} }
private void setRequestFieldValues(TimeOffRequest request) { private List<TimeOffRequest> fetchFilteredTimeOffRequests(final TimeOffRequestType category,
request.setState(state.getValue()); final TimeOffRequest.Status state) {
request.setExpiration(expiration.getValue()); requests = requestService.findRequestsByEmployeeId(employeeId);
request.setStartDate(startDate.getValue()); if (category != null && !"ALL".equals(category.name())) {
request.setEndDate(endDate.getValue()); requests = requests.stream()
request.setAvailableDays(availableDays.getValue()); .filter(req -> req.getCategory().equals(category))
request.setDaysToBeTake(daysToBeTake.getValue()); .collect(Collectors.toList());
}
if (state != null && !"ALL".equals(state.name())) {
requests = requests.stream()
.filter(req -> req.getState().equals(state))
.collect(Collectors.toList());
}
return requests;
} }
private void closeForm() { @Override
getUI().ifPresent(ui -> ui.navigate("requests/" + employee.getId().toString())); public void setParameter(final BeforeEvent event, final String parameter) {
employeeId = UUID.fromString(parameter);
Employee employee = employeeService.getEmployee(employeeId);
requests = requestService.findRequestsByEmployeeId(employeeId);
setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName());
requestGrid.setItems(requests);
} }
private boolean isFormValid() { private void setViewTitle(final String employeeName, final String employeeTeam) {
return !state.isEmpty() addComponentAsFirst(new H3("Name: " + employeeName));
&& expiration.getValue() != null addComponentAtIndex(1, new H3("Team: " + employeeTeam));
&& startDate.getValue() != null
&& endDate.getValue() != null
&& availableDays.getValue() != null
&& daysToBeTake.getValue() != null;
}
private void clearForm() {
state.clear();
expiration.clear();
startDate.clear();
endDate.clear();
availableDays.clear();
daysToBeTake.clear();
}
private void configureViewOrEditAction(final String action) {
if ("edit".equals(action) && !request.getId().toString().isEmpty()) {
setFieldsReadOnly(false);
} else if ("view".equals(action) && !request.getId().toString().isEmpty()) {
setFieldsReadOnly(true);
saveButton.setEnabled(false);
}
}
private H3 createEmployeeHeader() {
return new H3("Employee: " + employee.getFirstName() + " " + employee.getLastName());
}
private H3 createTeamHeader() {
return new H3("Team: " + employee.getTeam().getName());
}
private H3 createCategoryHeader() {
return new H3("Category: " + request.getCategory());
} }
} }

View File

@ -37,7 +37,7 @@ public class RequestsListView extends Main {
private ComboBox<Employee> employeeFilter; private ComboBox<Employee> employeeFilter;
private ComboBox<Team> teamFilter; private ComboBox<Team> teamFilter;
private ComboBox<TimeOffRequestType> categoryFilter; private ComboBox<TimeOffRequestType> categoryFilter;
private ComboBox<TimeOffRequestStatus> stateFilter; private ComboBox<TimeOffRequest.Status> stateFilter;
private UUID selectedEmployeeId; private UUID selectedEmployeeId;
public RequestsListView(final TimeOffRequestService requestService, public RequestsListView(final TimeOffRequestService requestService,
@ -96,14 +96,16 @@ public class RequestsListView extends Main {
Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE); Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE);
} }
}); });
Button editButton = new Button("Edit");
Button saveButton = new Button("Save");
Button closeButton = new Button("Close", event -> navigateToMainView()); Button closeButton = new Button("Close", event -> navigateToMainView());
return new HorizontalLayout(viewButton, closeButton); return new HorizontalLayout(viewButton, editButton, saveButton, closeButton);
} }
private void refreshRequestGrid(final Employee employee, private void refreshRequestGrid(final Employee employee,
final Team team, final Team team,
final TimeOffRequestType category, final TimeOffRequestType category,
final TimeOffRequestStatus state) { final TimeOffRequest.Status state) {
requestGrid.setPagingDataProvider((page, pageSize) -> { requestGrid.setPagingDataProvider((page, pageSize) -> {
requests = requestService.findAllTimeOffRequests(); requests = requestService.findAllTimeOffRequests();
@ -120,7 +122,7 @@ public class RequestsListView extends Main {
private boolean allFiltersAreNull(final Employee employee, private boolean allFiltersAreNull(final Employee employee,
final Team team, final Team team,
final TimeOffRequestType category, final TimeOffRequestType category,
final TimeOffRequestStatus state) { final TimeOffRequest.Status state) {
return employee == null && team == null && category == null && state == null; return employee == null && team == null && category == null && state == null;
} }
@ -137,7 +139,7 @@ public class RequestsListView extends Main {
final Employee employee, final Employee employee,
final Team team, final Team team,
final TimeOffRequestType category, final TimeOffRequestType category,
final TimeOffRequestStatus state) { final TimeOffRequest.Status state) {
if (employee != null && !"ALL".equals(employee.getFirstName())) { if (employee != null && !"ALL".equals(employee.getFirstName())) {
requests = requests.stream() requests = requests.stream()
.filter(request -> request.getEmployee().getId().equals(employee.getId())) .filter(request -> request.getEmployee().getId().equals(employee.getId()))
@ -226,10 +228,10 @@ public class RequestsListView extends Main {
return categoryFilter; return categoryFilter;
} }
private ComboBox<TimeOffRequestStatus> createStateFilter() { private ComboBox<TimeOffRequest.Status> createStateFilter() {
stateFilter = new ComboBox<>("State"); stateFilter = new ComboBox<>("State");
stateFilter.setItems(TimeOffRequestStatus.values()); stateFilter.setItems(TimeOffRequest.Status.values());
stateFilter.setValue(TimeOffRequestStatus.values()[0]); stateFilter.setValue(TimeOffRequest.Status.values()[0]);
stateFilter.addValueChangeListener(event -> stateFilter.addValueChangeListener(event ->
refreshRequestGrid( refreshRequestGrid(
employeeFilter.getValue(), employeeFilter.getValue(),