-
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: Inbox works and some minor fixes to stuff
- Loading branch information
AdrianBalunan
committed
Apr 20, 2026
1 parent
dc0737a
commit 23f53a9
Showing
6 changed files
with
223 additions
and
210 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...n/src/main/java/ntnu/systemutvikling/team6/controller/components/InboxCardController.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,31 @@ | ||
| 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; | ||
| import ntnu.systemutvikling.team6.models.user.Message; | ||
|
|
||
| public class InboxCardController extends BaseController{ | ||
| @FXML private Label messageFrom; | ||
| @FXML private Label messageTitle; | ||
| @FXML private Label messageContent; | ||
| @FXML private Label messageDate; | ||
|
|
||
| private Message message; | ||
|
|
||
| @Override | ||
| protected void authTokenisSet() { | ||
|
|
||
| } | ||
|
|
||
| public void setMessage(Message message) { | ||
| this.message = message; | ||
|
|
||
| messageFrom.setText(message.getFrom().getName()); | ||
| messageTitle.setText(message.getTitle()); | ||
| messageContent.setStyle(message.getContent()); | ||
| messageDate.setText(message.getTimeAndDate().toString()); | ||
| } | ||
| } |
111 changes: 111 additions & 0 deletions
111
...in/java/ntnu/systemutvikling/team6/controller/profileUser/profileUserInboxController.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,111 @@ | ||
| 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.layout.FlowPane; | ||
| 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.user.Inbox; | ||
| import ntnu.systemutvikling.team6.models.user.Message; | ||
| 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 profileUserInboxController 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(); | ||
| // Names | ||
| nameLabel.setText(user.getUsername()); | ||
| shortNameLabel.setText(user.getUsername().substring(0, 2).toUpperCase().trim()); | ||
|
|
||
| // Messages | ||
| Inbox inbox = authToken.getCurrentUser().getInbox(); | ||
| displayInbox(inbox); | ||
| } | ||
|
|
||
| private void displayInbox(Inbox inbox) { | ||
| cardsContainer.getChildren().clear(); | ||
| List<Message> messages = inbox.getMessages(); | ||
| if(messages.isEmpty()){ | ||
| Label empty = new Label("You have no messages"); | ||
| empty.setStyle("-fx-text-fill: #777777; -fx-font-size: 14;"); | ||
| cardsContainer.getChildren().add(empty); | ||
| } | ||
|
|
||
| for (Message message : messages) { | ||
| try { | ||
| FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/inboxCard.fxml")); | ||
| Parent card = loader.load(); | ||
| InboxCardController cardController = loader.getController(); | ||
| cardController.setMessage(message); | ||
| 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 switchToInterestPage(ActionEvent event){ | ||
| LoaderScene.LoadScene("profile_user_interests", 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
43 changes: 43 additions & 0 deletions
43
helpmehelpapplication/src/main/resources/fxml/components/inboxCard.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,43 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import javafx.scene.control.Label?> | ||
| <?import javafx.scene.layout.HBox?> | ||
| <?import javafx.scene.layout.VBox?> | ||
| <?import javafx.scene.shape.Circle?> | ||
| <?import javafx.scene.text.Font?> | ||
|
|
||
| <HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="400.0" spacing="16.0" style="-fx-background-color: #1E1E1E; -fx-border-color: #333333; -fx-border-width: 1.2; -fx-border-radius: 16; -fx-background-radius: 16; -fx-padding: 16 22 16 22;" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.components.InboxCardController"> | ||
| <children> | ||
|
|
||
| <!-- Avatar circle --> | ||
| <Circle fill="#3A3A3A" radius="26.0" /> | ||
|
|
||
| <!-- Text content --> | ||
| <VBox alignment="CENTER_LEFT" spacing="4.0" HBox.hgrow="ALWAYS"> | ||
| <children> | ||
|
|
||
| <!-- Sender name --> | ||
| <Label fx:id="messageFrom" style="-fx-text-fill: #FFFFFF; -fx-font-weight: bold;" text="Something"> | ||
| <font><Font size="13.0" /></font> | ||
| </Label> | ||
|
|
||
| <!-- Subject --> | ||
| <Label fx:id="messageTitle" style="-fx-text-fill: #CCCCCC;" text="Something"> | ||
| <font><Font size="13.0" /></font> | ||
| </Label> | ||
|
|
||
| <!-- Preview --> | ||
| <Label fx:id="messageContent" style="-fx-text-fill: #777777;" text="Something"> | ||
| <font><Font size="11.0" /></font> | ||
| </Label> | ||
|
|
||
| </children> | ||
| </VBox> | ||
|
|
||
| <!-- Date pushed to the right --> | ||
| <Label fx:id="messageDate" style="-fx-text-fill: #555555;" text="Something" HBox.hgrow="NEVER"> | ||
| <font><Font size="10.0" /></font> | ||
| </Label> | ||
|
|
||
| </children> | ||
| </HBox> |
Oops, something went wrong.