diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java index 189471f..6e361b7 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java @@ -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.*; @@ -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; @@ -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); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java index 42208dc..9c32776 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java @@ -212,6 +212,7 @@ private void displayCharities(List 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); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/InterestCardController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/InterestCardController.java new file mode 100644 index 0000000..e7aec6f --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/InterestCardController.java @@ -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); + } +} 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 new file mode 100644 index 0000000..444dfd7 --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserInterestController.java @@ -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 favourites = new ArrayList<>(favouritesDAO.getFavouritesForUser(authToken.getCurrentUser().getId().toString())); + displayFavourites(favourites); + } + + private void displayFavourites(ArrayList 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); + } +} diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserSettingsController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserSettingsController.java index 0e0bf58..0cb4b4f 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserSettingsController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserSettingsController.java @@ -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.*; @@ -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()); @@ -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 @@ -181,6 +188,7 @@ private void handleNewPreferences(ActionEvent event) { } + // Sidebar Methods @FXML private void handleLogout(ActionEvent event){ authToken.logout(); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/FavouritesDAO.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/FavouritesDAO.java index f903758..0f6fd2d 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/FavouritesDAO.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/FavouritesDAO.java @@ -68,8 +68,8 @@ public boolean removeFavourite(User user, Charity charity) { return false; } } - public CharityRegistry getFavouritesForUser(String user_id) { - CharityRegistry charityRegistry = null; + public List getFavouritesForUser(String user_id) { + CharityRegistry registry = null; Connection conn = null; try { conn = connection.getMySqlConnection(); @@ -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); @@ -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"), @@ -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"); @@ -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(); } } \ No newline at end of file diff --git a/helpmehelpapplication/src/main/resources/fxml/components/interestCard.fxml b/helpmehelpapplication/src/main/resources/fxml/components/interestCard.fxml new file mode 100644 index 0000000..5ffb496 --- /dev/null +++ b/helpmehelpapplication/src/main/resources/fxml/components/interestCard.fxml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/helpmehelpapplication/src/main/resources/fxml/profile_user_interests.fxml b/helpmehelpapplication/src/main/resources/fxml/profile_user_interests.fxml index b2ec69d..391d40a 100644 --- a/helpmehelpapplication/src/main/resources/fxml/profile_user_interests.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/profile_user_interests.fxml @@ -1,13 +1,10 @@ - - - - + @@ -15,10 +12,10 @@ - - + + @@ -33,80 +30,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -119,8 +44,14 @@ - @@ -129,14 +60,12 @@ - - @@ -146,21 +75,21 @@ -