diff --git a/docs/SqlDatabase/ER-DiagramFile.mwb b/docs/SqlDatabase/ER-DiagramFile.mwb index 3e2e8b9..5105a8b 100644 Binary files a/docs/SqlDatabase/ER-DiagramFile.mwb and b/docs/SqlDatabase/ER-DiagramFile.mwb differ diff --git a/docs/SqlDatabase/ER-DiagramFile.mwb.bak b/docs/SqlDatabase/ER-DiagramFile.mwb.bak index 15fa8f6..eb0ba08 100644 Binary files a/docs/SqlDatabase/ER-DiagramFile.mwb.bak and b/docs/SqlDatabase/ER-DiagramFile.mwb.bak differ diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/CategoryTagController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/CategoryTagController.java new file mode 100644 index 0000000..5fecbbc --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/CategoryTagController.java @@ -0,0 +1,42 @@ +package ntnu.systemutvikling.team6.controller.components; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; + +public class CategoryTagController extends BaseController{ + @FXML private Button button; + private static final String[][] TAG_COLORS = { + {"#E5F0D7", "#6E8A5C"}, // green + {"#D7E8F0", "#5C7A8A"}, // blue + {"#F0E5D7", "#8A6E5C"}, // orange + {"#EFD7F0", "#8A5C8A"}, // purple + {"#F0D7D7", "#8A5C5C"}, // red + {"#D7F0EE", "#5C8A87"}, // teal + {"#F0EDD7", "#8A845C"}, // yellow + }; + + private String[] getRandomTagColor() { + return TAG_COLORS[(int) (Math.random() * TAG_COLORS.length)]; + } + + private String category; + + @Override + protected void authTokenisSet() { + + } + + public void setCategory(String category) { + this.category = category; + + button.setText(category); + String[] colors = getRandomTagColor(); + button.setStyle( + "-fx-background-color: " + colors[0] + ";" + + "-fx-text-fill: " + colors[1] + ";" + + "-fx-background-radius: 20;" + + "-fx-font-size: 11px;" + + "-fx-padding: 4 10 4 10;" + ); + } +} diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/NavbarController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/NavbarController.java index f9bbc34..8052ef1 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/NavbarController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/NavbarController.java @@ -70,6 +70,6 @@ private void switchToLoginPage(ActionEvent event) { @FXML private void switchToCharityUserPage(ActionEvent event) { System.out.println("Click!"); - LoaderScene.LoadScene("loginSite", event, null, null, authToken); + LoaderScene.LoadScene("profile_org_settings", event, null, null, authToken); } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgSettingsController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgSettingsController.java new file mode 100644 index 0000000..e494249 --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgSettingsController.java @@ -0,0 +1,144 @@ +package ntnu.systemutvikling.team6.controller.profileCharity; + +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.TextField; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; +import ntnu.systemutvikling.team6.controller.components.*; +import ntnu.systemutvikling.team6.database.DAO.CharityUserDAO; +import ntnu.systemutvikling.team6.database.DAO.UserDAO; +import ntnu.systemutvikling.team6.database.DatabaseConnection; +import ntnu.systemutvikling.team6.database.Readers.UserSelect; +import ntnu.systemutvikling.team6.models.Charity; +import ntnu.systemutvikling.team6.models.Donation; +import ntnu.systemutvikling.team6.models.registry.DonationRegistry; +import ntnu.systemutvikling.team6.models.user.User; +import ntnu.systemutvikling.team6.security.PasswordHasher; + +import java.io.IOException; +import java.util.Base64; +import java.util.List; + +public class profileOrgSettingsController extends BaseController { + @FXML private NavbarController navbarController; + @FXML private Label charityNameLabel; + @FXML private TextField organizationNameField; + @FXML private HBox tagContainer; + + @Override + protected void authTokenisSet() { + if (!isLoggedin() || authToken.isCharityUser() == null){ + showAlert(Alert.AlertType.ERROR, "Not logged inn or dont have privileges", "You need to be logged inn an account with Charity User priviliges."); + 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); + } + }); + return; + } + navbarController.setAuthToken(authToken); + populateFields(); + } + + private void populateFields(){ + Charity usersCharity = authToken.isCharityUser(); + charityNameLabel.setText(usersCharity.getName()); + organizationNameField.setText(usersCharity.getName()); + + // Tags + List categories = usersCharity.getCategory(); + displayCategories(categories); + + } + + private void displayCategories(List categories) { + tagContainer.getChildren().clear(); + if(categories.isEmpty()){ + Label empty = new Label("No categories"); + empty.setStyle("-fx-text-fill: #777777; -fx-font-size: 14;"); + tagContainer.getChildren().add(empty); + return; + } + + for (String category : categories) { + try { + FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/categoryTag.fxml")); + Parent card = loader.load(); + CategoryTagController cardController = loader.getController(); + cardController.setCategory(category); + cardController.setAuthToken(authToken); + tagContainer.getChildren().add(card); + } catch (IOException e) { + throw new RuntimeException("Could not load organization card.", e); + } + } + } + + @FXML + private void handleNewName(ActionEvent event){ + String organizationNameFieldText = organizationNameField.getText(); + + + if (organizationNameFieldText.isBlank()) { + showAlert(Alert.AlertType.ERROR, "Empty input", "Please fill out all fields"); + return; + } + + boolean updateSuccess; + DatabaseConnection conn = new DatabaseConnection(); + CharityUserDAO userDataObject = new CharityUserDAO(conn); + Charity savedCharity = authToken.isCharityUser(); + Charity minimalCharityWithJustNewName = new Charity(savedCharity.getUUID().toString(), savedCharity.getOrg_number(), organizationNameFieldText, null, savedCharity.getStatus(), savedCharity.getPreApproved(),null, null, null, null); + try { + updateSuccess = userDataObject.updateCharityVanityName(minimalCharityWithJustNewName); + } catch (Exception e) { + e.printStackTrace(); + showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred"); + return; + } + if (updateSuccess) { + showAlert( + Alert.AlertType.INFORMATION, + "Settings updated", + "You have successfully changed your settings"); + authToken.isCharityUser().setName(organizationNameFieldText); + LoaderScene.LoadScene("profile_user_settings", event, null, null, authToken); + } else { + System.out.println("Something went wrong when updating Settings"); + } + + } + + @FXML + private void switchToPaymentsPage(ActionEvent event){ + LoaderScene.LoadScene("profile_org_Payments", event, null, null, authToken); + } + + @FXML + private void switchToFeedbackPage(ActionEvent event){ + LoaderScene.LoadScene("profile_org_", event, null, null, authToken); + } + + @FXML + private void switchToEditPage(ActionEvent event){ + LoaderScene.LoadScene("profile_user_inbox", event, null, null, authToken); + } + + + @FXML + private void handleLogout(ActionEvent event){ + authToken.logout(); + showAlert(Alert.AlertType.INFORMATION, "Logging out", "Logging out..."); + LoaderScene.LoadScene("FrontPage", event, null, null, authToken); + } +} diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/CharityUserDAO.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/CharityUserDAO.java new file mode 100644 index 0000000..3cff1c8 --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/CharityUserDAO.java @@ -0,0 +1,43 @@ +package ntnu.systemutvikling.team6.database.DAO; + +import ntnu.systemutvikling.team6.database.DatabaseConnection; +import ntnu.systemutvikling.team6.models.Charity; +import ntnu.systemutvikling.team6.models.user.Settings; +import ntnu.systemutvikling.team6.models.user.User; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class CharityUserDAO { + + private DatabaseConnection connection; + + public CharityUserDAO(DatabaseConnection connection) { + this.connection = connection; + } + public boolean updateCharityVanityName(Charity charity){ + Connection conn = null; + String sql = """ + UPDATE CharityVanity SET + charity_name = ? + WHERE UUID_charity = ?; + """; + try { + conn = connection.getMySqlConnection(); + PreparedStatement ps = conn.prepareStatement(sql); + + System.out.println(charity.getUUID().toString()); + ps.setString(1, charity.getName()); + ps.setString(2, charity.getUUID().toString()); + + return ps.executeUpdate() > 0; + + } catch (SQLException e) { + e.printStackTrace(); + System.out.println("Something went wrong when updating ah"); + return false; + } + + } +} diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/UserSelect.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/UserSelect.java index 8e212f1..bc5da17 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/UserSelect.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/UserSelect.java @@ -64,7 +64,7 @@ public boolean isEmailTaken(String email){ public Charity getUserCharityUser(String uuid){ if (uuid == null || uuid.isBlank()) { throw new IllegalArgumentException( - "Email cannot be null or blank," + " and must contain '@' and '.'"); + "UUID cannot be null or blank"); } Charity currentCharity = null; Connection conn = null; @@ -81,7 +81,7 @@ public Charity getUserCharityUser(String uuid){ INNER JOIN CharityVanity cv ON cv.UUID_charity = c.UUID_charities 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 CharityUserId = ?; + WHERE CharityUserId = ? """; PreparedStatement stmt = conn.prepareStatement(sql_query); stmt.setString(1, uuid); @@ -108,7 +108,7 @@ public Charity getUserCharityUser(String uuid){ } String categoryName = rs.getString("category"); - if (categoryName != null & !currentCharity.getCategory().contains(categoryName)) { + if (categoryName != null && !currentCharity.getCategory().contains(categoryName)) { currentCharity.getCategory().add(categoryName); } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java index 3f4a8cd..09d6ad0 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java @@ -169,6 +169,11 @@ public byte[] getLogoBlob() { return this.logoBlob; } + /** Setter for new name */ + public void setName(String name) { + this.name = name; + } + /** Setter for verification status. This one sets the charity as verified. */ public void setVerified() { this.status = "approved"; diff --git a/helpmehelpapplication/src/main/resources/fxml/components/categoryTag.fxml b/helpmehelpapplication/src/main/resources/fxml/components/categoryTag.fxml new file mode 100644 index 0000000..3e50953 --- /dev/null +++ b/helpmehelpapplication/src/main/resources/fxml/components/categoryTag.fxml @@ -0,0 +1,13 @@ + + + + + + + + + + + - - - - + + @@ -125,7 +50,7 @@ -