Skip to content

Commit

Permalink
Feat: Viewing donations work yey
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 21, 2026
1 parent fad1306 commit ea265eb
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 147 deletions.
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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<Donation> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<HBox spacing="20.0"
style="-fx-background-color: #FFFFFF; -fx-border-color: transparent transparent #EEEEEE transparent; -fx-border-width: 1; -fx-padding: 0 20 0 20;"
xmlns="http://javafx.com/javafx/25"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ntnu.systemutvikling.team6.controller.components.DonationCardController">
<children>
<Label fx:id="charityNameLabel" prefWidth="265.0" style="-fx-text-fill: #111111; -fx-padding: 10 0 14 0;">
<font><Font name="System Bold" size="12.0" /></font>
</Label>
<Label fx:id="purchaseIDLabel" prefWidth="210.0" style="-fx-text-fill: #777777; -fx-padding: 10 0 14 0;">
<font><Font size="12.0" /></font>
</Label>
<Label fx:id="dateLabel" prefWidth="160.0" style="-fx-text-fill: #777777; -fx-padding: 10 0 14 0;">
<font><Font size="12.0" /></font>
</Label>
<Label fx:id="AnonymousLabel" prefWidth="120.0" style="-fx-text-fill: #777777; -fx-padding: 10 0 14 0;">
<font><Font size="12.0" /></font>
</Label>
<Label fx:id="totalLabel" prefWidth="100.0" style="-fx-text-fill: #2f8f8b; -fx-padding: 10 0 14 0;">
<font><Font name="System Bold" size="12.0" /></font>
</Label>
</children>
</HBox>
Loading

0 comments on commit ea265eb

Please sign in to comment.