-
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.
- Loading branch information
AdrianBalunan
committed
Apr 21, 2026
1 parent
6cf34de
commit efd31df
Showing
10 changed files
with
261 additions
and
104 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions
42
...src/main/java/ntnu/systemutvikling/team6/controller/components/CategoryTagController.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,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;" | ||
| ); | ||
| } | ||
| } |
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
144 changes: 144 additions & 0 deletions
144
...va/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgSettingsController.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,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<String> categories = usersCharity.getCategory(); | ||
| displayCategories(categories); | ||
|
|
||
| } | ||
|
|
||
| private void displayCategories(List<String> 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); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
...helpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/CharityUserDAO.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,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; | ||
| } | ||
|
|
||
| } | ||
| } |
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
13 changes: 13 additions & 0 deletions
13
helpmehelpapplication/src/main/resources/fxml/components/categoryTag.fxml
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,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import java.lang.*?> | ||
| <?import java.util.*?> | ||
| <?import javafx.scene.*?> | ||
| <?import javafx.scene.control.*?> | ||
| <?import javafx.scene.layout.*?> | ||
|
|
||
| <VBox alignment="CENTER" spacing="8" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.components.CategoryTagController"> | ||
| <children> | ||
| <Button fx:id="Button" style="-fx-background-color: #E5F0D7; -fx-text-fill: #6E8A5C; -fx-font-size: 16px;" text="Non-profit" /> | ||
| </children> | ||
| </VBox> |
Oops, something went wrong.