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