Fix dialog issues

This commit is contained in:
2026-04-08 08:47:10 -06:00
parent 8fb4c82a67
commit 0fdd603232
3 changed files with 52 additions and 10 deletions

View File

@@ -18,6 +18,7 @@ import org.example.petshopdesktop.api.endpoints.DropdownApi;
import org.example.petshopdesktop.auth.UserSession;
import org.example.petshopdesktop.util.ActivityLogger;
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.time.LocalDate;
import java.util.List;
@@ -65,7 +66,15 @@ public class AppointmentDialogController {
cbPet.setPromptText("Select a customer first");
cbCustomer.setPromptText("Select a customer");
cbService.setPromptText("Select a service");
dpAppointmentDate.setValue(LocalDate.now().plusDays(1));
LocalDate minDate = minAppointmentDate();
dpAppointmentDate.setValue(minDate);
dpAppointmentDate.setDayCellFactory(picker -> new javafx.scene.control.DateCell() {
@Override
public void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);
setDisable(empty || item.isBefore(minDate));
}
});
cbAppointmentStatus.setValue("Booked");
for (int i = 9; i <= 17; i++) {
@@ -315,9 +324,20 @@ public class AppointmentDialogController {
try {
List<DropdownOption> pets = DropdownApi.getInstance().getCustomerPets(customerId);
Platform.runLater(() -> {
cbPet.setItems(FXCollections.observableArrayList(pets));
cbPet.setDisable(pets == null || pets.isEmpty());
cbPet.setPromptText(pets == null || pets.isEmpty() ? "No pets for selected customer" : "Select a pet");
ObservableList<DropdownOption> petOptions = FXCollections.observableArrayList(pets != null ? pets : List.of());
if (pendingPetSelectionId != null) {
boolean found = petOptions.stream().anyMatch(p -> pendingPetSelectionId.equals(p.getId()));
if (!found && selectedAppointment != null && selectedAppointment.getPetId() > 0) {
DropdownOption placeholder = new DropdownOption();
placeholder.setId((long) selectedAppointment.getPetId());
placeholder.setLabel(selectedAppointment.getPetName() != null && !selectedAppointment.getPetName().isBlank()
? selectedAppointment.getPetName() : "Pet #" + selectedAppointment.getPetId());
petOptions.add(0, placeholder);
}
}
cbPet.setItems(petOptions);
cbPet.setDisable(petOptions.isEmpty());
cbPet.setPromptText(petOptions.isEmpty() ? "No pets for selected customer" : "Select a pet");
if (pendingPetSelectionId != null) {
for (DropdownOption pet : cbPet.getItems()) {
if (pet.getId() != null && pet.getId().equals(pendingPetSelectionId)) {
@@ -392,6 +412,19 @@ public class AppointmentDialogController {
}).start();
}
private LocalDate minAppointmentDate() {
LocalDate date = LocalDate.now();
int businessDaysAdded = 0;
while (businessDaysAdded < 2) {
date = date.plusDays(1);
DayOfWeek dow = date.getDayOfWeek();
if (dow != DayOfWeek.SATURDAY && dow != DayOfWeek.SUNDAY) {
businessDaysAdded++;
}
}
return date;
}
private void loadEmployees() {
new Thread(() -> {
try {

View File

@@ -247,7 +247,7 @@ public class PetDialogController {
request.setPetAge(age);
String status = cbPetStatus.getValue();
if ("Owned".equalsIgnoreCase(status) && cbCustomer.getValue() != null) {
if (("Owned".equalsIgnoreCase(status) || "Adopted".equalsIgnoreCase(status)) && cbCustomer.getValue() != null) {
request.setCustomerId(cbCustomer.getValue().getId());
}
if (requiresStore(status) && cbStore.getValue() != null) {
@@ -432,9 +432,9 @@ public class PetDialogController {
}
private void updateStatusFieldVisibility(String status) {
boolean owned = "Owned".equalsIgnoreCase(status);
boolean needsCustomer = "Owned".equalsIgnoreCase(status) || "Adopted".equalsIgnoreCase(status);
boolean storeBased = requiresStore(status);
setFieldVisibility(vbCustomerField, owned);
setFieldVisibility(vbCustomerField, needsCustomer);
setFieldVisibility(vbStoreField, storeBased);
}