-
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
9a608e2
commit 75d3138
Showing
9 changed files
with
311 additions
and
8 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
110 changes: 110 additions & 0 deletions
110
...plication/src/main/java/ntnu/systemutvikling/team6/controller/GiveFeedbackController.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,110 @@ | ||
| package ntnu.systemutvikling.team6.controller; | ||
|
|
||
| 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.TextArea; | ||
| import javafx.scene.layout.FlowPane; | ||
| import javafx.stage.Stage; | ||
| import ntnu.systemutvikling.team6.controller.components.*; | ||
| import ntnu.systemutvikling.team6.database.DAO.FeedbackDAO; | ||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.database.Readers.CharitySelect; | ||
| import ntnu.systemutvikling.team6.models.Charity; | ||
| import ntnu.systemutvikling.team6.models.Feedback; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
|
|
||
| public class GiveFeedbackController extends BaseController { | ||
| private Charity charity; | ||
| @FXML private NavbarController navbarController; | ||
| @FXML private FooterController footerController; | ||
|
|
||
| @FXML private FlowPane feedbackContainer; | ||
| @FXML private Label charityNameLabel; | ||
| @FXML private TextArea feedbackCommentArea; | ||
|
|
||
|
|
||
|
|
||
| @FXML | ||
| public void setCharity(Charity charity) { | ||
| this.charity = charity; | ||
|
|
||
| charityNameLabel.setText(charity.getName()); | ||
| } | ||
|
|
||
| @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); | ||
| footerController.setAuthToken(authToken); | ||
| populateFields(); | ||
| } | ||
| private void populateFields(){ | ||
| DatabaseConnection conn = new DatabaseConnection(); | ||
| CharitySelect charitySelect = new CharitySelect(conn); | ||
| ArrayList<Feedback> feedbacks = charitySelect.getFeedbackforCharityUUID(charity.getUUID().toString()); | ||
| displayFeedbacks(feedbacks); | ||
| } | ||
| private void displayFeedbacks(ArrayList<Feedback> feedbacks){ | ||
| feedbackContainer.getChildren().clear(); | ||
| if (feedbacks.isEmpty()) { | ||
| javafx.scene.control.Label empty = new javafx.scene.control.Label("You have no Feedbacks"); | ||
| empty.setStyle("-fx-text-fill: #777777; -fx-font-size: 14;"); | ||
| feedbackContainer.getChildren().add(empty); | ||
| } | ||
|
|
||
| for (Feedback feedback : feedbacks) { | ||
| try { | ||
| FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/feedbackCard.fxml")); | ||
| Parent card = loader.load(); | ||
| FeedbackCardController cardController = loader.getController(); | ||
| cardController.setMessage(feedback); | ||
| cardController.setAuthToken(authToken); | ||
| feedbackContainer.getChildren().add(card); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Could not load organization card.", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @FXML | ||
| private void handleSubmitFeedback(ActionEvent event){ | ||
| String feedbackCommentAreaText = feedbackCommentArea.getText(); | ||
| Feedback newFeedback = new Feedback(authToken.getCurrentUser(), feedbackCommentAreaText); | ||
|
|
||
| DatabaseConnection conn = new DatabaseConnection(); | ||
| FeedbackDAO feedbackDAO = new FeedbackDAO(conn); | ||
| boolean submitSuccess; | ||
| try { | ||
| submitSuccess = feedbackDAO.addFeedbackToCharity(newFeedback, charity); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred"); | ||
| return; | ||
| } | ||
| if (submitSuccess) { | ||
| showAlert( | ||
| Alert.AlertType.INFORMATION, | ||
| "Feedback received", | ||
| charity.getName() + " has gotten your feedback"); | ||
| LoaderScene.LoadScene("charityPage", event, charity, 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
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
44 changes: 44 additions & 0 deletions
44
helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/FeedbackDAO.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,44 @@ | ||
| package ntnu.systemutvikling.team6.database.DAO; | ||
|
|
||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.models.Charity; | ||
| import ntnu.systemutvikling.team6.models.Feedback; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.Date; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.SQLException; | ||
|
|
||
| public class FeedbackDAO { | ||
| private final DatabaseConnection connection; | ||
|
|
||
| public FeedbackDAO(DatabaseConnection connection){ | ||
| this.connection = connection; | ||
| } | ||
|
|
||
| public boolean addFeedbackToCharity(Feedback feedback, Charity toCharity){ | ||
| String sql = """ | ||
| INSERT INTO Feedback | ||
| (UUID_feedback, feedback_comment, feedback_date, isAnonymous, charity_id, user_id) | ||
| VALUES (?, ?, ?, ?, ?, ?); | ||
| """; | ||
|
|
||
| try (Connection conn = connection.getMySqlConnection(); | ||
| PreparedStatement ps = conn.prepareStatement(sql)) { | ||
|
|
||
| ps.setString(1, feedback.getFeedbackId().toString()); | ||
| ps.setString(2, feedback.getComment()); | ||
| ps.setDate(3, Date.valueOf(feedback.getDate())); | ||
| ps.setBoolean(4, feedback.getUser().getSettings().isAnonymous()); | ||
| ps.setString(5, toCharity.getUUID().toString()); | ||
| ps.setString(6, feedback.getUser().getId().toString()); | ||
| return ps.executeUpdate() > 0; | ||
|
|
||
| } catch (SQLException e) { | ||
| e.printStackTrace(); | ||
| 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
130 changes: 130 additions & 0 deletions
130
helpmehelpapplication/src/main/resources/fxml/giveFeedback.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,130 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import javafx.geometry.Insets?> | ||
| <?import javafx.scene.Cursor?> | ||
| <?import javafx.scene.control.Button?> | ||
| <?import javafx.scene.control.Label?> | ||
| <?import javafx.scene.control.ScrollPane?> | ||
| <?import javafx.scene.control.TextArea?> | ||
| <?import javafx.scene.layout.ColumnConstraints?> | ||
| <?import javafx.scene.layout.GridPane?> | ||
| <?import javafx.scene.layout.Region?> | ||
| <?import javafx.scene.layout.RowConstraints?> | ||
| <?import javafx.scene.layout.VBox?> | ||
| <?import javafx.scene.text.Font?> | ||
|
|
||
| <?import javafx.scene.layout.FlowPane?> | ||
| <?import javafx.scene.control.TextField?> | ||
|
|
||
| <GridPane hgap="0.0" prefHeight="900.0" prefWidth="1200.0" vgap="0.0" | ||
| xmlns="http://javafx.com/javafx/25" | ||
| xmlns:fx="http://javafx.com/fxml/1" | ||
| fx:controller="ntnu.systemutvikling.team6.controller.GiveFeedbackController"> | ||
|
|
||
| <columnConstraints> | ||
| <ColumnConstraints percentWidth="100.0" /> | ||
| </columnConstraints> | ||
|
|
||
| <rowConstraints> | ||
| <RowConstraints maxHeight="92.0" minHeight="92.0" prefHeight="92.0" /> | ||
| <RowConstraints vgrow="ALWAYS" /> | ||
| <RowConstraints maxHeight="180.0" minHeight="180.0" prefHeight="180.0" /> | ||
| </rowConstraints> | ||
|
|
||
| <fx:include fx:id="navbar" source="components/navbar.fxml" GridPane.rowIndex="0" /> | ||
|
|
||
| <ScrollPane fitToWidth="true" hbarPolicy="NEVER" | ||
| style="-fx-background: transparent; -fx-background-color: transparent;" | ||
| GridPane.rowIndex="1"> | ||
| <content> | ||
| <VBox spacing="28.0" style="-fx-background-color: #F5F5F5;"> | ||
| <padding> | ||
| <Insets bottom="42.0" left="40.0" right="42.0" top="34.0" /> | ||
| </padding> | ||
| <children> | ||
|
|
||
| <!-- PAGE TITLE --> | ||
| <VBox spacing="4.0"> | ||
| <children> | ||
| <Label style="-fx-text-fill: #222222;" text="Charity Feedback"> | ||
| <font><Font name="System Bold" size="36.0" /></font> | ||
| </Label> | ||
| <Label fx:id="charityNameLabel" style="-fx-text-fill: #2f8f8b;"> | ||
| <font><Font name="System Bold" size="18.0" /></font> | ||
| </Label> | ||
| </children> | ||
| </VBox> | ||
|
|
||
| <Region prefHeight="1.0" style="-fx-background-color: #DDDDDD;" /> | ||
|
|
||
| <!-- EXISTING FEEDBACK --> | ||
| <VBox spacing="16.0"> | ||
| <children> | ||
| <Label style="-fx-text-fill: #222222;" text="Donor Feedback"> | ||
| <font><Font name="System Bold" size="22.0" /></font> | ||
| </Label> | ||
| <Label style="-fx-text-fill: #8B8B8B;" | ||
| text="See what other donors have said about this organisation."> | ||
| <font><Font size="13.0" /></font> | ||
| </Label> | ||
| <VBox> | ||
| <FlowPane fx:id="feedbackContainer" hgap="20" vgap="20"> | ||
|
|
||
| </FlowPane> | ||
| </VBox> | ||
| </children> | ||
| </VBox> | ||
|
|
||
| <Region prefHeight="1.0" style="-fx-background-color: #DDDDDD;" /> | ||
|
|
||
| <!-- LEAVE FEEDBACK --> | ||
| <VBox spacing="16.0"> | ||
| <children> | ||
| <Label style="-fx-text-fill: #222222;" text="Leave Feedback"> | ||
| <font><Font name="System Bold" size="22.0" /></font> | ||
| </Label> | ||
| <Label style="-fx-text-fill: #8B8B8B;" | ||
| text="Share your experience. Only donors can leave feedback."> | ||
| <font><Font size="13.0" /></font> | ||
| </Label> | ||
|
|
||
| <VBox spacing="8.0"> | ||
| <children> | ||
| <Label style="-fx-text-fill: #444444;" text="Your comment"> | ||
| <font><Font name="System Bold" size="13.0" /></font> | ||
| </Label> | ||
| <TextArea fx:id="feedbackCommentArea" | ||
| prefHeight="120.0" | ||
| promptText="Write your feedback here..." | ||
| wrapText="true" | ||
| style="-fx-background-color: #FFFFFF; | ||
| -fx-border-color: #DDDDDD; | ||
| -fx-border-radius: 8; | ||
| -fx-background-radius: 8; | ||
| -fx-font-size: 13px; | ||
| -fx-padding: 10;" /> | ||
| </children> | ||
| </VBox> | ||
|
|
||
| <Button fx:id="submitFeedbackButton" | ||
| onAction="#handleSubmitFeedback" | ||
| text="Submit Feedback" | ||
| style="-fx-background-color: #2f8f8b; | ||
| -fx-text-fill: white; | ||
| -fx-font-size: 13px; | ||
| -fx-font-weight: bold; | ||
| -fx-background-radius: 8; | ||
| -fx-padding: 10 24 10 24;"> | ||
| <cursor><Cursor fx:constant="HAND" /></cursor> | ||
| </Button> | ||
| </children> | ||
| </VBox> | ||
|
|
||
| </children> | ||
| </VBox> | ||
| </content> | ||
| </ScrollPane> | ||
|
|
||
| <fx:include fx:id="footer" source="components/footer.fxml" GridPane.rowIndex="2" /> | ||
|
|
||
| </GridPane> |