En-desarrollo #59
@ -63,22 +63,11 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
}
|
||||
|
||||
private void configureFormFields() {
|
||||
List<Employee> employees = employeeService.findAllEmployees();
|
||||
employeeComboBox.setItems(employees);
|
||||
employeeComboBox.setItems(employeeService.findAllEmployees());
|
||||
employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName());
|
||||
employeeComboBox.addValueChangeListener(event -> handleEmployeeSelection(event.getValue()));
|
||||
categoryComboBox.setEnabled(false);
|
||||
categoryComboBox.addValueChangeListener(event -> {
|
||||
clearForm();
|
||||
updateAvailableDays(event.getValue());
|
||||
});
|
||||
employeeComboBox.addValueChangeListener(event -> {
|
||||
clearForm();
|
||||
Employee selectedEmployee = event.getValue();
|
||||
if (event.getValue() != null) {
|
||||
categoryComboBox.setEnabled(true);
|
||||
filterCategories(selectedEmployee);
|
||||
}
|
||||
});
|
||||
categoryComboBox.addValueChangeListener(event -> handleCategorySelection(event.getValue()));
|
||||
startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues());
|
||||
endDatePicker.addValueChangeListener(event -> calculateDays());
|
||||
availableDaysField.setReadOnly(true);
|
||||
@ -86,7 +75,44 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
balanceDaysField.setReadOnly(true);
|
||||
}
|
||||
|
||||
private void filterCategories(Employee employee) {
|
||||
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(availableDaysField)
|
||||
.bind(TimeOffRequest::getAvailableDays, TimeOffRequest::setAvailableDays);
|
||||
|
||||
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(daysToBeTakenField)
|
||||
.bind(TimeOffRequest::getDaysToBeTake, TimeOffRequest::setDaysToBeTake);
|
||||
|
||||
binder.forField(balanceDaysField)
|
||||
.bind(TimeOffRequest::getDaysBalance, TimeOffRequest::setDaysBalance);
|
||||
|
||||
binder.setBean(new TimeOffRequest());
|
||||
}
|
||||
|
||||
private void handleEmployeeSelection(final Employee selectedEmployee) {
|
||||
clearForm();
|
||||
if (selectedEmployee != null) {
|
||||
categoryComboBox.setEnabled(true);
|
||||
filterCategories(selectedEmployee);
|
||||
}
|
||||
}
|
||||
|
||||
private void filterCategories(final Employee employee) {
|
||||
List<TimeOffRequest> employeeRequests = requestService.findRequestsByEmployeeId(employee.getId());
|
||||
List<TimeOffRequestType> requestedCategories = employeeRequests.stream()
|
||||
.map(TimeOffRequest::getCategory)
|
||||
@ -95,37 +121,39 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
.filter(category -> !requestedCategories.contains(category))
|
||||
.filter(category -> {
|
||||
if (employee.getGender() == Employee.Gender.MALE) {
|
||||
return category != TimeOffRequestType.MATERNITY &&
|
||||
category != TimeOffRequestType.MOTHERS_DAY &&
|
||||
category != TimeOffRequestType.INTERNATIONAL_WOMENS_DAY &&
|
||||
category != TimeOffRequestType.NATIONAL_WOMENS_DAY;
|
||||
return category != TimeOffRequestType.MATERNITY
|
||||
&& category != TimeOffRequestType.MOTHERS_DAY
|
||||
&& category != TimeOffRequestType.INTERNATIONAL_WOMENS_DAY
|
||||
&& category != TimeOffRequestType.NATIONAL_WOMENS_DAY;
|
||||
} else {
|
||||
return category != TimeOffRequestType.FATHERS_DAY &&
|
||||
category != TimeOffRequestType.PATERNITY;
|
||||
return category != TimeOffRequestType.FATHERS_DAY
|
||||
&& category != TimeOffRequestType.PATERNITY;
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
categoryComboBox.setItems(availableCategories);
|
||||
}
|
||||
|
||||
private void updateAvailableDays(TimeOffRequestType selectedCategory) {
|
||||
private void handleCategorySelection(final TimeOffRequestType selectedCategory) {
|
||||
clearForm();
|
||||
if (selectedCategory != null) {
|
||||
updateAvailableDays(selectedCategory);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAvailableDays(final TimeOffRequestType selectedCategory) {
|
||||
vacation = vacationService.findVacationByCategory(selectedCategory);
|
||||
if (vacation != null) {
|
||||
availableDaysField.setValue(vacation.getDuration());
|
||||
setDatePickerLimits(vacation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setDatePickerLimits(Vacation vacation) {
|
||||
private void setDatePickerLimits(final Vacation vacation) {
|
||||
LocalDate startDate;
|
||||
if (vacation.getVacationDate() != null) {
|
||||
startDate = vacation.getVacationDate();
|
||||
endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1);
|
||||
startDatePicker.setValue(startDate);
|
||||
endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1));
|
||||
|
||||
} else {
|
||||
startDate = LocalDate.now();
|
||||
endDate = null;
|
||||
@ -187,35 +215,6 @@ public class RequestRegisterView extends VerticalLayout {
|
||||
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(availableDaysField)
|
||||
.bind(TimeOffRequest::getAvailableDays, TimeOffRequest::setAvailableDays);
|
||||
|
||||
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(daysToBeTakenField)
|
||||
.bind(TimeOffRequest::getDaysToBeTake, TimeOffRequest::setDaysToBeTake);
|
||||
|
||||
binder.forField(balanceDaysField)
|
||||
.bind(TimeOffRequest::getDaysBalance, TimeOffRequest::setDaysBalance);
|
||||
|
||||
binder.setBean(new TimeOffRequest());
|
||||
}
|
||||
|
||||
private void setupFormLayout() {
|
||||
add(
|
||||
new H3("Add Vacation Request"),
|
||||
|
Loading…
Reference in New Issue
Block a user