Compare commits
4 Commits
5a270d6795
...
dac11494ea
Author | SHA1 | Date | |
---|---|---|---|
dac11494ea | |||
85dad4900c | |||
34940ff794 | |||
3b085e835b |
@ -144,6 +144,8 @@ public class MainLayout extends AppLayout {
|
||||
LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create());
|
||||
timeOff.addItem(new SideNavItem("Vacations", RequestsListView.class,
|
||||
LineAwesomeIcon.SUN.create()));
|
||||
timeOff.addItem(new SideNavItem("Add Vacation", RequestRegisterView.class,
|
||||
LineAwesomeIcon.SUN.create()));
|
||||
SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class,
|
||||
LineAwesomeIcon.HOURGLASS_START_SOLID.create());
|
||||
timesheet.addItem(new SideNavItem("Hours Worked", HoursWorkedView.class,
|
||||
|
@ -20,6 +20,7 @@ import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
import java.time.Year;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -44,7 +45,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
public RequestEmployeeView(final TimeOffRequestService requestService, final EmployeeService employeeService) {
|
||||
this.requestService = requestService;
|
||||
this.employeeService = employeeService;
|
||||
initializeView();
|
||||
}
|
||||
|
||||
private void initializeView() {
|
||||
@ -97,9 +97,17 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
}
|
||||
|
||||
private VerticalLayout createSummaryLayout() {
|
||||
int totalVacations = 15;
|
||||
int totalTimeOff = 2;
|
||||
int totalAvailableDays = totalVacations + totalTimeOff;
|
||||
int currentYear = Year.now().getValue();
|
||||
String yearCategory = "YEAR_" + currentYear;
|
||||
double totalVacations = requests.stream()
|
||||
.filter(req -> req.getCategory().name().equals(yearCategory))
|
||||
.mapToDouble(TimeOffRequest::getAvailableDays)
|
||||
.sum();
|
||||
double totalTimeOff = requests.stream()
|
||||
.filter(req -> !req.getCategory().name().startsWith("YEAR"))
|
||||
.mapToDouble(TimeOffRequest::getDaysBalance)
|
||||
.sum();
|
||||
double totalAvailableDays = totalVacations + totalTimeOff;
|
||||
return new VerticalLayout(
|
||||
new Span("TOTAL HOLIDAYS: " + totalVacations),
|
||||
new Span("TOTAL TIME OFF: " + totalTimeOff),
|
||||
@ -176,6 +184,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
||||
requests = requestService.findRequestsByEmployeeId(employeeId);
|
||||
setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName());
|
||||
requestGrid.setItems(requests);
|
||||
initializeView();
|
||||
}
|
||||
|
||||
private void setViewTitle(final String employeeName, final String employeeTeam) {
|
||||
|
@ -0,0 +1,128 @@
|
||||
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.datepicker.DatePicker;
|
||||
import com.vaadin.flow.component.html.H3;
|
||||
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.component.textfield.NumberField;
|
||||
import com.vaadin.flow.data.binder.Binder;
|
||||
import com.vaadin.flow.router.*;
|
||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringComponent
|
||||
@PermitAll
|
||||
@Scope("prototype")
|
||||
@PageTitle("Request")
|
||||
@Route(value = "/requests/new", layout = MainLayout.class)
|
||||
public class RequestRegisterView extends VerticalLayout {
|
||||
|
||||
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
||||
private final ComboBox<TimeOffRequestType> categoryComboBox = new ComboBox<>("Category");
|
||||
private final DatePicker startDatePicker = new DatePicker("Start Date");
|
||||
private final DatePicker endDatePicker = new DatePicker("End Date");
|
||||
private final NumberField availableDaysField = new NumberField("Available Days");
|
||||
private final NumberField daysToBeTakenField = new NumberField("Days To Be Taken");
|
||||
private final NumberField balanceDaysField = new NumberField("Balance Days");
|
||||
|
||||
private final TimeOffRequestService requestService;
|
||||
private final EmployeeService employeeService;
|
||||
private final Binder<TimeOffRequest> binder;
|
||||
|
||||
private Button saveButton;
|
||||
private Button closeButton;
|
||||
|
||||
public RequestRegisterView(final TimeOffRequestService requestService,
|
||||
final EmployeeService employeeService) {
|
||||
this.requestService = requestService;
|
||||
this.employeeService = employeeService;
|
||||
this.binder = new Binder<>(TimeOffRequest.class);
|
||||
|
||||
configureFormFields();
|
||||
configureButtons();
|
||||
configureBinder();
|
||||
setupFormLayout();
|
||||
}
|
||||
|
||||
private void configureFormFields() {
|
||||
List<Employee> employees = employeeService.findAllEmployees();
|
||||
employeeComboBox.setItems(employees);
|
||||
employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName());
|
||||
categoryComboBox.setItems(TimeOffRequestType.values());
|
||||
}
|
||||
|
||||
private void configureButtons() {
|
||||
saveButton = new Button("Save", event -> saveRequest());
|
||||
closeButton = new Button("Close", event -> closeForm());
|
||||
}
|
||||
|
||||
private void configureBinder() {
|
||||
binder.forField(employeeComboBox)
|
||||
.asRequired("Employee is required")
|
||||
.bind(TimeOffRequest::getEmployee, TimeOffRequest::setEmployee);
|
||||
|
||||
binder.forField(categoryComboBox)
|
||||
.asRequired("Category is required")
|
||||
.bind(TimeOffRequest::getCategory, TimeOffRequest::setCategory);
|
||||
|
||||
binder.forField(startDatePicker)
|
||||
.asRequired("Start date is required")
|
||||
.bind(TimeOffRequest::getStartDate, TimeOffRequest::setStartDate);
|
||||
|
||||
binder.forField(endDatePicker)
|
||||
.asRequired("End date is required")
|
||||
.bind(TimeOffRequest::getEndDate, TimeOffRequest::setEndDate);
|
||||
|
||||
binder.forField(availableDaysField)
|
||||
.asRequired("Available days is required")
|
||||
.bind(TimeOffRequest::getAvailableDays, TimeOffRequest::setAvailableDays);
|
||||
|
||||
binder.forField(daysToBeTakenField)
|
||||
.asRequired("Days to be taken is required")
|
||||
.bind(TimeOffRequest::getDaysToBeTake, TimeOffRequest::setDaysToBeTake);
|
||||
|
||||
binder.forField(balanceDaysField)
|
||||
.asRequired("Balance days is required")
|
||||
.bind(TimeOffRequest::getDaysBalance, TimeOffRequest::setDaysBalance);
|
||||
|
||||
binder.setBean(new TimeOffRequest());
|
||||
}
|
||||
|
||||
private void setupFormLayout() {
|
||||
add(
|
||||
new H3("Add Vacation Request"),
|
||||
employeeComboBox,
|
||||
categoryComboBox,
|
||||
startDatePicker,
|
||||
endDatePicker,
|
||||
availableDaysField,
|
||||
daysToBeTakenField,
|
||||
balanceDaysField,
|
||||
new HorizontalLayout(saveButton, closeButton)
|
||||
);
|
||||
}
|
||||
|
||||
private void saveRequest() {
|
||||
if (binder.validate().isOk()) {
|
||||
TimeOffRequest request = binder.getBean();
|
||||
requestService.saveTimeOffRequest(request);
|
||||
Notification.show("Request saved successfully.");
|
||||
closeForm();
|
||||
} else {
|
||||
Notification.show("Please fill all required fields correctly.");
|
||||
}
|
||||
}
|
||||
|
||||
private void closeForm() {
|
||||
getUI().ifPresent(ui -> ui.navigate(RequestsListView.class));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user