added staff and customer images to desktop

This commit is contained in:
Alex
2026-04-14 22:43:24 -06:00
parent 2b4fcfe24c
commit 7baa780c7f
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.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Modality; import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.example.petshopdesktop.api.dto.user.UserResponse; import org.example.petshopdesktop.api.dto.user.UserResponse;
import org.example.petshopdesktop.api.endpoints.CustomerApi; import org.example.petshopdesktop.api.endpoints.CustomerApi;
import org.example.petshopdesktop.util.ActivityLogger; import org.example.petshopdesktop.util.ActivityLogger;
import org.example.petshopdesktop.util.DesktopImageSupport;
import org.example.petshopdesktop.util.TableViewSupport; import org.example.petshopdesktop.util.TableViewSupport;
import java.util.Comparator; import java.util.Comparator;
@@ -25,6 +29,9 @@ public class CustomerAccountsController {
@FXML @FXML
private TableView<UserResponse> tvCustomers; private TableView<UserResponse> tvCustomers;
@FXML
private TableColumn<UserResponse, String> colCustomerAvatar;
@FXML @FXML
private TableColumn<UserResponse, String> colCustomerUsername; private TableColumn<UserResponse, String> colCustomerUsername;
@@ -69,6 +76,13 @@ public class CustomerAccountsController {
@FXML @FXML
public void initialize() { 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())); colCustomerUsername.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getUsername()));
colCustomerName.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getFullName())); colCustomerName.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getFullName()));
colCustomerEmail.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getEmail())); colCustomerEmail.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getEmail()));
@@ -94,6 +108,27 @@ public class CustomerAccountsController {
refresh(); 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 @FXML
void btnRefreshClicked(ActionEvent event) { void btnRefreshClicked(ActionEvent event) {
txtSearchCustomer.clear(); txtSearchCustomer.clear();

View File

@@ -7,8 +7,11 @@ import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Modality; import javafx.stage.Modality;
import javafx.stage.Stage; 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.api.endpoints.EmployeeApi;
import org.example.petshopdesktop.auth.UserSession; import org.example.petshopdesktop.auth.UserSession;
import org.example.petshopdesktop.util.ActivityLogger; import org.example.petshopdesktop.util.ActivityLogger;
import org.example.petshopdesktop.util.DesktopImageSupport;
import org.example.petshopdesktop.util.TableViewSupport; import org.example.petshopdesktop.util.TableViewSupport;
import java.util.Comparator; import java.util.Comparator;
@@ -26,6 +30,7 @@ public class StaffAccountsController {
@FXML private VBox staffSection; @FXML private VBox staffSection;
@FXML private TableView<EmployeeResponse> tvStaff; @FXML private TableView<EmployeeResponse> tvStaff;
@FXML private TableColumn<EmployeeResponse, String> colStaffAvatar;
@FXML private TableColumn<EmployeeResponse, String> colUsername; @FXML private TableColumn<EmployeeResponse, String> colUsername;
@FXML private TableColumn<EmployeeResponse, String> colName; @FXML private TableColumn<EmployeeResponse, String> colName;
@FXML private TableColumn<EmployeeResponse, String> colEmail; @FXML private TableColumn<EmployeeResponse, String> colEmail;
@@ -47,6 +52,13 @@ public class StaffAccountsController {
@FXML @FXML
public void initialize() { 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())); colUsername.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getUsername()));
colName.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getFullName())); colName.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getFullName()));
colEmail.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getEmail())); colEmail.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getEmail()));
@@ -81,6 +93,27 @@ public class StaffAccountsController {
refresh(); 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 @FXML
void btnRefreshClicked(ActionEvent event) { void btnRefreshClicked(ActionEvent event) {
txtSearch.clear(); txtSearch.clear();

View File

@@ -69,6 +69,7 @@
<TableView fx:id="tvCustomers" style="-fx-background-color: white; -fx-background-radius: 12;" VBox.vgrow="ALWAYS"> <TableView fx:id="tvCustomers" style="-fx-background-color: white; -fx-background-radius: 12;" VBox.vgrow="ALWAYS">
<columns> <columns>
<TableColumn fx:id="colCustomerAvatar" prefWidth="70.0" text="Avatar" sortable="false" />
<TableColumn fx:id="colCustomerUsername" prefWidth="130.0" text="Username" /> <TableColumn fx:id="colCustomerUsername" prefWidth="130.0" text="Username" />
<TableColumn fx:id="colCustomerName" prefWidth="160.0" text="Name" /> <TableColumn fx:id="colCustomerName" prefWidth="160.0" text="Name" />
<TableColumn fx:id="colCustomerEmail" prefWidth="200.0" text="Email" /> <TableColumn fx:id="colCustomerEmail" prefWidth="200.0" text="Email" />

View File

@@ -78,6 +78,7 @@
<TableView fx:id="tvStaff" style="-fx-background-color: white; -fx-background-radius: 12;" VBox.vgrow="ALWAYS"> <TableView fx:id="tvStaff" style="-fx-background-color: white; -fx-background-radius: 12;" VBox.vgrow="ALWAYS">
<columns> <columns>
<TableColumn fx:id="colStaffAvatar" prefWidth="70.0" text="Avatar" sortable="false" />
<TableColumn fx:id="colUsername" prefWidth="140.0" text="Username" /> <TableColumn fx:id="colUsername" prefWidth="140.0" text="Username" />
<TableColumn fx:id="colName" prefWidth="170.0" text="Name" /> <TableColumn fx:id="colName" prefWidth="170.0" text="Name" />
<TableColumn fx:id="colEmail" prefWidth="210.0" text="Email" /> <TableColumn fx:id="colEmail" prefWidth="210.0" text="Email" />