-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Interests/Favourities and favouriting works. Basically login, g…
…o to donate, heart and check hearted charities.
- Loading branch information
AdrianBalunan
committed
Apr 20, 2026
1 parent
61862b7
commit ee8ba2e
Showing
9 changed files
with
319 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...rc/main/java/ntnu/systemutvikling/team6/controller/components/InterestCardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
121 changes: 121 additions & 0 deletions
121
...java/ntnu/systemutvikling/team6/controller/profileUser/profileUserInterestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.