added staff and customer images to desktop

This commit is contained in:
Alex
2026-04-14 22:43:24 -06:00
parent aca52efc44
commit 9c47f5ac76
4 changed files with 70 additions and 0 deletions

View File

@@ -7,13 +7,17 @@ import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.example.petshopdesktop.api.dto.user.UserResponse;
import org.example.petshopdesktop.api.endpoints.CustomerApi;
import org.example.petshopdesktop.util.ActivityLogger;
import org.example.petshopdesktop.util.DesktopImageSupport;
import org.example.petshopdesktop.util.TableViewSupport;
import java.util.Comparator;
@@ -25,6 +29,9 @@ public class CustomerAccountsController {
@FXML
private TableView<UserResponse> tvCustomers;
@FXML
private TableColumn<UserResponse, String> colCustomerAvatar;
@FXML
private TableColumn<UserResponse, String> colCustomerUsername;
@@ -69,6 +76,13 @@ public class CustomerAccountsController {
@FXML
public void initialize() {
colCustomerAvatar.setCellValueFactory(data -> {
Long id = data.getValue().getId();
if (id == null) return new javafx.beans.property.SimpleStringProperty("");
return new javafx.beans.property.SimpleStringProperty("/api/v1/users/" + id + "/avatar/file");
});
configureAvatarColumn(colCustomerAvatar);
colCustomerUsername.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getUsername()));
colCustomerName.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getFullName()));
colCustomerEmail.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getEmail()));
@@ -94,6 +108,27 @@ public class CustomerAccountsController {
refresh();
}
private void configureAvatarColumn(TableColumn<UserResponse, String> column) {
column.setCellFactory(col -> new TableCell<>() {
private final ImageView imageView = new ImageView();
private final StackPane container = new StackPane(imageView);
{
container.setAlignment(Pos.CENTER);
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null || item.isBlank()) {
setGraphic(null);
return;
}
DesktopImageSupport.loadImageInto(imageView, item, 48, 48);
setGraphic(container);
}
});
}
@FXML
void btnRefreshClicked(ActionEvent event) {
txtSearchCustomer.clear();

View File

@@ -7,8 +7,11 @@ import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
@@ -16,6 +19,7 @@ import org.example.petshopdesktop.api.dto.employee.EmployeeResponse;
import org.example.petshopdesktop.api.endpoints.EmployeeApi;
import org.example.petshopdesktop.auth.UserSession;
import org.example.petshopdesktop.util.ActivityLogger;
import org.example.petshopdesktop.util.DesktopImageSupport;
import org.example.petshopdesktop.util.TableViewSupport;
import java.util.Comparator;
@@ -26,6 +30,7 @@ public class StaffAccountsController {
@FXML private VBox staffSection;
@FXML private TableView<EmployeeResponse> tvStaff;
@FXML private TableColumn<EmployeeResponse, String> colStaffAvatar;
@FXML private TableColumn<EmployeeResponse, String> colUsername;
@FXML private TableColumn<EmployeeResponse, String> colName;
@FXML private TableColumn<EmployeeResponse, String> colEmail;
@@ -47,6 +52,13 @@ public class StaffAccountsController {
@FXML
public void initialize() {
colStaffAvatar.setCellValueFactory(data -> {
Long id = data.getValue().getId();
if (id == null) return new javafx.beans.property.SimpleStringProperty("");
return new javafx.beans.property.SimpleStringProperty("/api/v1/users/" + id + "/avatar/file");
});
configureAvatarColumn(colStaffAvatar);
colUsername.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getUsername()));
colName.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getFullName()));
colEmail.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getEmail()));
@@ -81,6 +93,27 @@ public class StaffAccountsController {
refresh();
}
private void configureAvatarColumn(TableColumn<EmployeeResponse, String> column) {
column.setCellFactory(col -> new TableCell<>() {
private final ImageView imageView = new ImageView();
private final StackPane container = new StackPane(imageView);
{
container.setAlignment(Pos.CENTER);
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null || item.isBlank()) {
setGraphic(null);
return;
}
DesktopImageSupport.loadImageInto(imageView, item, 48, 48);
setGraphic(container);
}
});
}
@FXML
void btnRefreshClicked(ActionEvent event) {
txtSearch.clear();