Skip to content

Commit

Permalink
Feat: Interests/Favourities and favouriting works. Basically login, g…
Browse files Browse the repository at this point in the history
…o to donate, heart and check hearted charities.
  • Loading branch information
AdrianBalunan committed Apr 20, 2026
1 parent 61862b7 commit ee8ba2e
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 267 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ntnu.systemutvikling.team6.controller;

import java.util.Optional;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
Expand All @@ -25,7 +27,7 @@ public class DonationPageController extends BaseController {
@FXML private TextField donatioAmount;

@FXML private Label CharityName;
@FXML ToggleButton heartButton;
@FXML private ToggleButton heartButton;
@FXML private TextField donationSearchField;

@FXML private NavbarController navbarController;
Expand All @@ -39,8 +41,15 @@ public class DonationPageController extends BaseController {
protected void authTokenisSet() {
if (!isLoggedin()){
showAlert(Alert.AlertType.ERROR, "Not logged inn", "You need to be logged inn to donate.");
Stage stage = (Stage) donationSearchField.getScene().getWindow();
LoaderScene.LoadScene("loginSite", stage, null, null, authToken);
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);
footerController.setAuthToken(authToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ private void displayCharities(List<Charity> charities) {
Parent card = loader.load();
OrganizationCardController cardController = loader.getController();
cardController.setOrganization(charity);
cardController.setAuthToken(authToken);
cardsContainer.getChildren().add(card);
} catch (IOException e) {
throw new RuntimeException("Could not load organization card.", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ntnu.systemutvikling.team6.controller.components;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import ntnu.systemutvikling.team6.models.Charity;

public class InterestCardController extends BaseController{
@FXML private Label charityDescription;
@FXML private Label verifyLabel;
@FXML private Label charityNameLabel;

@FXML private Button detailsButton;
@FXML private Button donateButton;

private Charity charity;

@Override
protected void authTokenisSet() {

}

public void setOrganization(Charity charity) {
this.charity = charity;

charityNameLabel.setText(charity.getName());
verifyLabel.setText(charity.getPreApproved() ? "Verify" : "Unverified");
verifyLabel.setStyle(charity.getPreApproved() ? "-fx-background-color: #2f8f3a; -fx-alignment: CENTER_LEFT; -fx-text-fill: white;" : "-fx-alignment: CENTER_LEFT; -fx-background-color: #D11D27; -fx-text-fill: white;");
charityDescription.setText(charity.getDescription());

if(charity.getName().equals("You have no Favourites")){
detailsButton.setVisible(false);
donateButton.setVisible(false);
}
}

/* EVENTS */
@FXML
private void switchToCharity(ActionEvent event){
LoaderScene.LoadScene("CharityPage", event, charity, null, authToken);
}

@FXML
private void switchToDonate(ActionEvent event){
LoaderScene.LoadScene("DonationPage", event, charity, null, authToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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.control.ScrollPane;
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.DAO.FavouritesDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
import ntnu.systemutvikling.team6.models.user.Language;
import ntnu.systemutvikling.team6.models.user.Settings;
import ntnu.systemutvikling.team6.models.user.User;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class profileUserInterestController extends BaseController {
@FXML private NavbarController navbarController;
@FXML private FlowPane cardsContainer;
@FXML private Label nameLabel;
@FXML private Label shortNameLabel;

@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();
Settings settings = user.getSettings();
// Names
nameLabel.setText(user.getUsername());
shortNameLabel.setText(user.getUsername().substring(0, 2).toUpperCase().trim());

// Favourites
DatabaseConnection conn = new DatabaseConnection();
FavouritesDAO favouritesDAO = new FavouritesDAO(conn);
ArrayList<Charity> favourites = new ArrayList<>(favouritesDAO.getFavouritesForUser(authToken.getCurrentUser().getId().toString()));
displayFavourites(favourites);
}

private void displayFavourites(ArrayList<Charity> favourites) {
cardsContainer.getChildren().clear();
if(favourites.isEmpty()){
Charity noCharityMessageCharity = new Charity(
UUID.randomUUID().toString(),
"osdawdwa.com",
"You have no Favourites",
false,
"Verified"
);
favourites.add(noCharityMessageCharity);
}

for (Charity charity : favourites) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/interestCard.fxml"));
Parent card = loader.load();
InterestCardController cardController = loader.getController();
cardController.setOrganization(charity);
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 switchToInboxPage(ActionEvent event){
LoaderScene.LoadScene("profile_user_inbox", event, null, null, authToken);

}

@FXML
private void switchToHistoryPage(ActionEvent event){
LoaderScene.LoadScene("profile_user_history", 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
@@ -1,5 +1,6 @@
package ntnu.systemutvikling.team6.controller.profileUser;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
Expand All @@ -24,38 +25,45 @@ public class profileUserSettingsController extends BaseController {
@FXML private TextField EmailField;
@FXML private PasswordField PassWordField;
@FXML private TextField ConfirmPasswordField;
@FXML private Button ConfirmChangeSettings;
@FXML private Button ConfirmChangeSettings1;

// Sidebar FXML variables
@FXML private Label nameLabel;
@FXML private Label shortNameLabel;
@FXML private Label shortNameLabel2;

@FXML private Button ConfirmChangeSettings;
@FXML private Button ConfirmChangeSettings1;
@FXML private Button logoutButton;



@Override
protected void authTokenisSet() {
if (!isLoggedin()){
Stage stage = (Stage) anonymousLabel.getScene().getWindow();
LoaderScene.LoadScene("FrontPage", stage,null,null,authToken);
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();
}
@FXML
public void initialize() {
public void populateFields(){
languageComboBox.getItems().addAll("English", "Norwegian");
themeComboBox.getItems().addAll("Light mode", "Dark mode");
}

public void populateFields(){
User user = authToken.getCurrentUser();
Settings settings = user.getSettings();
// Names
nameLabel.setText(user.getUsername());
shortNameLabel.setText(user.getUsername().substring(0,2).toUpperCase().trim());
shortNameLabel2.setText(user.getUsername().substring(0,2).toUpperCase().trim());

NameField.setText(user.getUsername());
EmailField.setText(user.getEmail());

Expand All @@ -82,7 +90,6 @@ private void handleAnonymousToggle(ActionEvent event) {
"-fx-background-radius: 14; -fx-min-width: 32; -fx-min-height: 28;" +
"-fx-max-width: 52; -fx-max-height: 28;"
);
// save to settings
}

@FXML
Expand Down Expand Up @@ -181,6 +188,7 @@ private void handleNewPreferences(ActionEvent event) {

}

// Sidebar Methods
@FXML
private void handleLogout(ActionEvent event){
authToken.logout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public boolean removeFavourite(User user, Charity charity) {
return false;
}
}
public CharityRegistry getFavouritesForUser(String user_id) {
CharityRegistry charityRegistry = null;
public List<Charity> getFavouritesForUser(String user_id) {
CharityRegistry registry = null;
Connection conn = null;
try {
conn = connection.getMySqlConnection();
Expand All @@ -79,9 +79,12 @@ public CharityRegistry getFavouritesForUser(String user_id) {
uf.Favourite_Charity,
c.UUID_charities, c.org_number, c.pre_approved, c.status,
cv.charity_name, cv.charity_link, cv.description, cv.logoURL, cv.key_values, cv.logoBLOB,
cat.category
FROM User_has_favourites uf
INNER JOIN Charities c ON uf.Favourite_Charity = c.UUID_charities
INNER JOIN CharityVanity cv ON uf.Favourite_Charity = cv.UUID_charity
LEFT JOIN Charity_Categories cc ON cc.Charities_UUID_charities = c.UUID_charities
LEFT JOIN Categories cat ON cat.category_id = cc.Categories_category_id
WHERE Favourer = ?;
""";
PreparedStatement stmt = conn.prepareStatement(sql_query);
Expand All @@ -91,9 +94,11 @@ public CharityRegistry getFavouritesForUser(String user_id) {

Charity currentCharity = null;

registry = new CharityRegistry();
while (rs.next()) {
String currentId = rs.getString("UUID_charities");
if (currentCharity == null || !currentId.equals(currentCharity.getUUID().toString())) {
System.out.println("Adding Charities");
currentCharity =
new Charity(
rs.getString("UUID_charities"),
Expand All @@ -106,7 +111,7 @@ public CharityRegistry getFavouritesForUser(String user_id) {
rs.getString("logoURL"),
rs.getString("key_values"),
rs.getBytes("logoBLOB"));
charityRegistry.addCharity(currentCharity);
registry.addCharity(currentCharity);
}

String categoryName = rs.getString("category");
Expand All @@ -117,11 +122,11 @@ public CharityRegistry getFavouritesForUser(String user_id) {
}
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("ERROR: Something went wrong during updating charities table.");
throw new RuntimeException("ERROR: Something went wrong during updating.");
} finally {
conn = null;
}
return charityRegistry;
return registry.getAllCharities();
}

}
Loading

0 comments on commit ee8ba2e

Please sign in to comment.