#55 Perfil de Personal Administrativo - Añadir Vacaciones del Empleado
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 0s
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 0s
This commit is contained in:
parent
34940ff794
commit
85dad4900c
@ -144,6 +144,8 @@ public class MainLayout extends AppLayout {
|
|||||||
LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create());
|
LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create());
|
||||||
timeOff.addItem(new SideNavItem("Vacations", RequestsListView.class,
|
timeOff.addItem(new SideNavItem("Vacations", RequestsListView.class,
|
||||||
LineAwesomeIcon.SUN.create()));
|
LineAwesomeIcon.SUN.create()));
|
||||||
|
timeOff.addItem(new SideNavItem("Add Vacation", RequestRegisterView.class,
|
||||||
|
LineAwesomeIcon.SUN.create()));
|
||||||
SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class,
|
SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class,
|
||||||
LineAwesomeIcon.HOURGLASS_START_SOLID.create());
|
LineAwesomeIcon.HOURGLASS_START_SOLID.create());
|
||||||
timesheet.addItem(new SideNavItem("Hours Worked", HoursWorkedView.class,
|
timesheet.addItem(new SideNavItem("Hours Worked", HoursWorkedView.class,
|
||||||
|
@ -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