Harden appointment dialog
This commit is contained in:
@@ -19,6 +19,7 @@ import org.example.petshopdesktop.auth.UserSession;
|
|||||||
import org.example.petshopdesktop.util.ActivityLogger;
|
import org.example.petshopdesktop.util.ActivityLogger;
|
||||||
|
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -101,6 +102,11 @@ public class AppointmentDialogController {
|
|||||||
|
|
||||||
cbAppointmentStatus.setItems(statusList);
|
cbAppointmentStatus.setItems(statusList);
|
||||||
cbPet.setDisable(true);
|
cbPet.setDisable(true);
|
||||||
|
cbPet.setPromptText("Select a customer first");
|
||||||
|
cbCustomer.setPromptText("Select a customer");
|
||||||
|
cbService.setPromptText("Select a service");
|
||||||
|
dpAppointmentDate.setValue(LocalDate.now().plusDays(1));
|
||||||
|
cbAppointmentStatus.setValue("Booked");
|
||||||
|
|
||||||
// Hours 9 AM - 5 PM
|
// Hours 9 AM - 5 PM
|
||||||
for (int i = 9; i <= 17; i++) {
|
for (int i = 9; i <= 17; i++) {
|
||||||
@@ -161,8 +167,10 @@ public class AppointmentDialogController {
|
|||||||
cbPet.setItems(FXCollections.observableArrayList());
|
cbPet.setItems(FXCollections.observableArrayList());
|
||||||
cbPet.setDisable(customerId == null);
|
cbPet.setDisable(customerId == null);
|
||||||
if (customerId != null) {
|
if (customerId != null) {
|
||||||
|
cbPet.setPromptText("Loading customer pets...");
|
||||||
loadCustomerPets(customerId);
|
loadCustomerPets(customerId);
|
||||||
} else {
|
} else {
|
||||||
|
cbPet.setPromptText("Select a customer first");
|
||||||
pendingPetSelectionId = null;
|
pendingPetSelectionId = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -304,14 +312,25 @@ public class AppointmentDialogController {
|
|||||||
List<DropdownOption> pets = DropdownApi.getInstance().getCustomerPets(customerId);
|
List<DropdownOption> pets = DropdownApi.getInstance().getCustomerPets(customerId);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
cbPet.setItems(FXCollections.observableArrayList(pets));
|
cbPet.setItems(FXCollections.observableArrayList(pets));
|
||||||
cbPet.setDisable(false);
|
cbPet.setDisable(pets == null || pets.isEmpty());
|
||||||
|
cbPet.setPromptText(pets == null || pets.isEmpty() ? "No pets for selected customer" : "Select a pet");
|
||||||
if (pendingPetSelectionId != null) {
|
if (pendingPetSelectionId != null) {
|
||||||
|
boolean matched = false;
|
||||||
for (DropdownOption pet : cbPet.getItems()) {
|
for (DropdownOption pet : cbPet.getItems()) {
|
||||||
if (pet.getId() != null && pet.getId().equals(pendingPetSelectionId)) {
|
if (pet.getId() != null && pet.getId().equals(pendingPetSelectionId)) {
|
||||||
cbPet.setValue(pet);
|
cbPet.setValue(pet);
|
||||||
|
matched = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!matched && selectedAppointment != null && selectedAppointment.getPetName() != null && !selectedAppointment.getPetName().isBlank()) {
|
||||||
|
DropdownOption legacy = new DropdownOption();
|
||||||
|
legacy.setId(pendingPetSelectionId);
|
||||||
|
legacy.setLabel(selectedAppointment.getPetName() + " (legacy appointment pet)");
|
||||||
|
cbPet.getItems().add(0, legacy);
|
||||||
|
cbPet.setValue(legacy);
|
||||||
|
cbPet.setDisable(false);
|
||||||
|
}
|
||||||
pendingPetSelectionId = null;
|
pendingPetSelectionId = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -322,6 +341,7 @@ public class AppointmentDialogController {
|
|||||||
ex,
|
ex,
|
||||||
"Loading customer pets for appointment dialog");
|
"Loading customer pets for appointment dialog");
|
||||||
cbPet.setDisable(true);
|
cbPet.setDisable(true);
|
||||||
|
cbPet.setPromptText("Unable to load pets");
|
||||||
showError("Error loading pets for selected customer");
|
showError("Error loading pets for selected customer");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user