From ea265eb71451945be85ac0d57d0adf2b485151e2 Mon Sep 17 00:00:00 2001 From: AdrianBalunan Date: Tue, 21 Apr 2026 03:16:25 +0200 Subject: [PATCH] Feat: Viewing donations work yey --- .../components/DonationCardController.java | 31 ++++ .../profileUserHistoryController.java | 114 ++++++++++++ .../profileUserInterestController.java | 1 - .../fxml/components/profileDonationCard.fxml | 29 +++ .../resources/fxml/profile_user_history.fxml | 173 +++--------------- .../resources/fxml/profile_user_inbox.fxml | 1 - 6 files changed, 202 insertions(+), 147 deletions(-) create mode 100644 helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/DonationCardController.java create mode 100644 helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserHistoryController.java create mode 100644 helpmehelpapplication/src/main/resources/fxml/components/profileDonationCard.fxml diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/DonationCardController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/DonationCardController.java new file mode 100644 index 00000000..596f18d8 --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/DonationCardController.java @@ -0,0 +1,31 @@ +package ntnu.systemutvikling.team6.controller.components; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import ntnu.systemutvikling.team6.models.Donation; +import ntnu.systemutvikling.team6.models.user.Message; + +public class DonationCardController extends BaseController{ + @FXML private Label charityNameLabel; + @FXML private Label purchaseIDLabel; + @FXML private Label dateLabel; + @FXML private Label AnonymousLabel; + @FXML private Label totalLabel; + + private Donation donation; + + @Override + protected void authTokenisSet() { + + } + + public void setDonation(Donation donation) { + this.donation = donation; + + charityNameLabel.setText(donation.getCharity().getName()); + purchaseIDLabel.setText(donation.getDonationID().toString()); + dateLabel.setText(donation.getDate().toString()); + AnonymousLabel.setText(donation.isAnonymous() ? "Yes" : "No"); + totalLabel.setText(String.valueOf(donation.getAmount())); + } +} diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserHistoryController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserHistoryController.java new file mode 100644 index 00000000..8e167b43 --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserHistoryController.java @@ -0,0 +1,114 @@ +package ntnu.systemutvikling.team6.controller.profileUser; + +import javafx.application.Platform; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.control.Alert; +import javafx.scene.control.Label; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import ntnu.systemutvikling.team6.controller.components.*; +import ntnu.systemutvikling.team6.database.DatabaseConnection; +import ntnu.systemutvikling.team6.database.Readers.DonationSelect; +import ntnu.systemutvikling.team6.models.Donation; +import ntnu.systemutvikling.team6.models.registry.DonationRegistry; +import ntnu.systemutvikling.team6.models.user.Inbox; +import ntnu.systemutvikling.team6.models.user.Message; +import ntnu.systemutvikling.team6.models.user.User; + +import java.io.IOException; +import java.util.List; + +public class profileUserHistoryController extends BaseController { + @FXML + private NavbarController navbarController; + @FXML private VBox cardsContainer; + @FXML private Label nameLabel; + @FXML private Label shortNameLabel; + @FXML private Label totalAmmount; + + @Override + protected void authTokenisSet() { + if (!isLoggedin()){ + showAlert(Alert.AlertType.ERROR, "Not logged inn", "You need to be logged inn to donate."); + Platform.runLater(() -> { + Stage stage = (Stage) Stage.getWindows().stream() + .filter(w -> w.isShowing()) + .findFirst() + .orElse(null); + if (stage != null) { + LoaderScene.LoadScene("loginSite", stage, null, null, authToken); + } + }); + } + navbarController.setAuthToken(authToken); + populateFields(); + } + + public void populateFields() { + User user = authToken.getCurrentUser(); + // Names + nameLabel.setText(user.getUsername()); + shortNameLabel.setText(user.getUsername().substring(0, 2).toUpperCase().trim()); + + // DonationHistory + DatabaseConnection conn = new DatabaseConnection(); + DonationSelect donationSelect = new DonationSelect(conn); + DonationRegistry donationRegistry = donationSelect.getDonationForUser(authToken.getCurrentUser().getId().toString()); + displayDonations(donationRegistry); + } + + private void displayDonations(DonationRegistry donationRegistry) { + cardsContainer.getChildren().clear(); + List donations = donationRegistry.getAllDonations(); + if(donations.isEmpty()){ + Label empty = new Label("You have no messages"); + empty.setStyle("-fx-text-fill: #777777; -fx-font-size: 14;"); + cardsContainer.getChildren().add(empty); + } + + for (Donation donation : donations) { + try { + FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/profileDonationCard.fxml")); + Parent card = loader.load(); + DonationCardController cardController = loader.getController(); + cardController.setDonation(donation); + cardController.setAuthToken(authToken); + cardsContainer.getChildren().add(card); + } catch (IOException e) { + throw new RuntimeException("Could not load organization card.", e); + } + } + } + + // Sidebar Methods + @FXML + private void handleLogout(ActionEvent event){ + authToken.logout(); + showAlert(Alert.AlertType.INFORMATION, "Logging out", "Logging out..."); + LoaderScene.LoadScene("FrontPage", event, null, null, authToken); + } + + @FXML + private void switchToFrontPage(ActionEvent event){ + LoaderScene.LoadScene("FrontPage", event, null, null, authToken); + } + + @FXML + private void switchToInterestPage(ActionEvent event){ + LoaderScene.LoadScene("profile_user_interests", event, null, null, authToken); + } + + @FXML + private void switchToInboxPage(ActionEvent event){ + LoaderScene.LoadScene("profile_user_inbox", event, null, null, authToken); + } + + @FXML + private void switchToSettingsPage(ActionEvent event){ + LoaderScene.LoadScene("profile_user_settings", event, null, null, authToken); + } +} diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserInterestController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserInterestController.java index 01458563..8183cffe 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserInterestController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserInterestController.java @@ -101,7 +101,6 @@ private void switchToFrontPage(ActionEvent event){ @FXML private void switchToInboxPage(ActionEvent event){ LoaderScene.LoadScene("profile_user_inbox", event, null, null, authToken); - } @FXML diff --git a/helpmehelpapplication/src/main/resources/fxml/components/profileDonationCard.fxml b/helpmehelpapplication/src/main/resources/fxml/components/profileDonationCard.fxml new file mode 100644 index 00000000..04de9952 --- /dev/null +++ b/helpmehelpapplication/src/main/resources/fxml/components/profileDonationCard.fxml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/helpmehelpapplication/src/main/resources/fxml/profile_user_history.fxml b/helpmehelpapplication/src/main/resources/fxml/profile_user_history.fxml index 2f4c695f..ce36fe82 100644 --- a/helpmehelpapplication/src/main/resources/fxml/profile_user_history.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/profile_user_history.fxml @@ -1,13 +1,9 @@ - - - - @@ -19,7 +15,8 @@ - + + @@ -34,80 +31,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -120,8 +45,14 @@ - @@ -130,11 +61,11 @@ - - @@ -144,26 +75,26 @@ - - - -