Skip to content

Commit

Permalink
Feat: Updating descirptng (org_Edit) works.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 21, 2026
1 parent efd31df commit e64128b
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
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.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.controller.components.CategoryTagController;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.controller.components.NavbarController;
import ntnu.systemutvikling.team6.database.DAO.CharityUserDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.models.Charity;

import java.io.IOException;
import java.util.List;

public class profileOrgEditController extends BaseController {
@FXML
private NavbarController navbarController;
@FXML private Label charityNameLabel;
@FXML private TextArea descriptionField;

@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());
descriptionField.setText(usersCharity.getDescription());
}

@FXML
private void handleSaveDescription(ActionEvent event){
String descriptionFieldText = descriptionField.getText();


if (descriptionFieldText.isBlank()) {
showAlert(Alert.AlertType.ERROR, "Empty input", "Yeah, maybe it was empty before but now it need one");
return;
}

boolean updateSuccess;
DatabaseConnection conn = new DatabaseConnection();
CharityUserDAO userDataObject = new CharityUserDAO(conn);
Charity savedCharity = authToken.isCharityUser();
Charity minimalCharityWithJustNewDescription = new Charity(savedCharity.getUUID().toString(), savedCharity.getOrg_number(), savedCharity.getName(), null, savedCharity.getStatus(), savedCharity.getPreApproved(),descriptionFieldText, null, null, null);
try {
updateSuccess = userDataObject.updateCharityVanityDescription(minimalCharityWithJustNewDescription);
} 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().setDescription(descriptionFieldText);
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_Inbox", event, null, null, authToken);
}

@FXML
private void switchToSettingsPage(ActionEvent event){
LoaderScene.LoadScene("profile_user_Settings", 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ private void switchToPaymentsPage(ActionEvent event){

@FXML
private void switchToFeedbackPage(ActionEvent event){
LoaderScene.LoadScene("profile_org_", event, null, null, authToken);
LoaderScene.LoadScene("profile_org_Inbox", event, null, null, authToken);
}

@FXML
private void switchToEditPage(ActionEvent event){
LoaderScene.LoadScene("profile_user_inbox", event, null, null, authToken);
LoaderScene.LoadScene("profile_org_edit", event, null, null, authToken);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,28 @@ public boolean updateCharityVanityName(Charity charity){
}

}
public boolean updateCharityVanityDescription(Charity charity){
Connection conn = null;
String sql = """
UPDATE CharityVanity SET
description = ?
WHERE UUID_charity = ?;
""";
try {
conn = connection.getMySqlConnection();
PreparedStatement ps = conn.prepareStatement(sql);

System.out.println(charity.getUUID().toString());
ps.setString(1, charity.getDescription());
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;
}

}
}
193 changes: 46 additions & 147 deletions helpmehelpapplication/src/main/resources/fxml/profile_org_edit.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>

<GridPane prefHeight="900.0" prefWidth="1400.0" style="-fx-background-color: #F5F5F5;" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.OrganizationEditController">
<?import javafx.scene.control.TextArea?>
<GridPane prefHeight="900.0" prefWidth="1400.0" style="-fx-background-color: #F5F5F5;" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.profileCharity.profileOrgEditController">

<columnConstraints>
<ColumnConstraints percentWidth="100.0" />
Expand All @@ -33,80 +34,8 @@
<!-- NAVBAR -->
<StackPane style="-fx-background-color: #379894;" GridPane.rowIndex="0">
<children>
<GridPane maxWidth="1400.0" prefHeight="52.0" StackPane.alignment="CENTER">
<padding>
<Insets bottom="6.0" left="16.0" right="16.0" top="6.0" />
</padding>

<columnConstraints>
<ColumnConstraints minWidth="40.0" prefWidth="50.0" />
<ColumnConstraints minWidth="140.0" prefWidth="180.0" />
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints minWidth="170.0" prefWidth="190.0" />
</columnConstraints>

<rowConstraints>
<RowConstraints />
</rowConstraints>

<children>
<ImageView fitHeight="34.0" fitWidth="34.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="0">
<image>
<Image url="@../images/Logo.png" />
</image>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</ImageView>

<HBox alignment="CENTER_LEFT" spacing="0.0" GridPane.columnIndex="1">
<children>
<Label style="-fx-text-fill: #FFFFFF;" text="Help">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<Label style="-fx-text-fill: #C8E6C9;" text="Me">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<Label style="-fx-text-fill: #FFFFFF;" text="Help">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
</children>
</HBox>

<HBox alignment="CENTER" GridPane.columnIndex="2">
<children>
<TextField fx:id="searchField" maxWidth="461.0" prefHeight="28.0" prefWidth="461.0" promptText="Search" style="-fx-background-radius: 14; -fx-border-radius: 14; -fx-font-size: 10px; -fx-padding: 0 0 0 10; -fx-background-color: #FFFFFF;" />
</children>
</HBox>

<HBox alignment="CENTER_RIGHT" spacing="12.0" GridPane.columnIndex="3">
<children>
<StackPane prefHeight="46.0" prefWidth="46.0">
<children>
<Circle fill="WHITE" radius="23.0" />
<Label text="SJ" textFill="#222222">
<font>
<Font size="14.0" />
</font>
</Label>
</children>
</StackPane>

<Button style="-fx-background-color: transparent; -fx-padding: 0;">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
</children>
</HBox>
</children>
</GridPane>
<!-- Pull in the navbar from components with its own controller -->
<fx:include fx:id="navbar" source="components/navbar.fxml"/>
</children>
</StackPane>

Expand Down Expand Up @@ -147,7 +76,7 @@
<HBox alignment="CENTER_LEFT" spacing="12">
<children>
<Circle fill="#D99028" radius="6" />
<Button onAction="#switchToInboxPage" style="-fx-background-color: transparent; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Inbox" />
<Button onAction="#switchToFeedbackPage" style="-fx-background-color: transparent; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Feedbacks" />
</children>
</HBox>

Expand Down Expand Up @@ -182,92 +111,62 @@
</padding>

<children>
<!-- PAGE TITLE -->
<VBox spacing="4">
<children>
<Label text="Edit" textFill="#111111">
<font>
<Font size="42" />
</font>
<Label text="Edit Organisation" textFill="#111111">
<font><Font name="System Bold" size="32" /></font>
</Label>
<Label text="Edit page" textFill="#8B8B8B">
<font>
<Font size="18" />
</font>
<Label text="Update your organisation's public description." textFill="#8B8B8B">
<font><Font size="24" /></font>
</Label>
</children>
</VBox>

<!-- HEADER CARD -->
<HBox alignment="TOP_LEFT" spacing="24">
<!-- HEADER CARD (read-only) -->
<VBox spacing="8">
<children>
<StackPane maxWidth="1.7976931348623157E308" prefHeight="210" HBox.hgrow="ALWAYS">
<Label text="Organisation Name" textFill="#444444">
<font><Font name="System Regular" size="13" /></font>
</Label>
<StackPane>
<children>
<Rectangle arcHeight="16" arcWidth="16" fill="#E9ECEF" height="210" width="780" />
<VBox alignment="CENTER_LEFT" maxWidth="721.0" prefHeight="210.0" prefWidth="711.0" spacing="14">
<children>
<Label prefHeight="60.0" prefWidth="306.0" text="REDD BARNA NORGE" textFill="#111111">
<font>
<Font size="30" />
</font>
</Label>
<Label text="“Våre sparepenger skal ikke ødelegge barns liv”" textFill="#666666" wrapText="true">
<font>
<Font size="17" />
</font>
</Label>
</children>
</VBox>
<Rectangle arcHeight="12" arcWidth="12" fill="#EEEEEE" height="60" width="780" />
<Label fx:id="charityNameLabel" text="REDD BARNA NORGE" textFill="#888888"
style="-fx-padding: 0 0 0 18;">
<font><Font name="System Regular" size="20" /></font>
</Label>
</children>
</StackPane>

<Button minWidth="120" onAction="#handleEditHeader" style="-fx-background-color: transparent; -fx-font-size: 17px; -fx-text-fill: #D790A7; -fx-font-weight: bold;" text="Edit header" />
<Label text="Organisation name can only be changed in Settings." textFill="#AAAAAA">
<font><Font size="11" /></font>
</Label>
</children>
</HBox>
</VBox>

<!-- CONTENT CARD -->
<HBox alignment="TOP_LEFT" spacing="24">
<VBox spacing="8">
<children>
<StackPane maxWidth="1.7976931348623157E308" prefHeight="270" HBox.hgrow="ALWAYS">
<children>
<Rectangle arcHeight="16" arcWidth="16" fill="#E9ECEF" height="270" width="780" />

<HBox alignment="CENTER_LEFT" maxWidth="670" spacing="40">
<children>
<VBox spacing="14">
<children>
<Label prefHeight="75.0" prefWidth="95.0" text="Overview" textFill="#222222">
<font>
<Font size="24" />
</font>
</Label>
<Label prefHeight="45.0" prefWidth="166.0" text="“Example text”" textFill="#777777" wrapText="true">
<font>
<Font size="17" />
</font>
</Label>
</children>
</VBox>

<Region HBox.hgrow="ALWAYS" />

<StackPane>
<children>
<Rectangle arcHeight="10" arcWidth="10" fill="#F3DDE5" height="190" width="150.0" />
<Label text="Image" textFill="#D69BAE">
<font>
<Font name="System Bold Italic" size="20.0" />
</font>
</Label>
</children>
</StackPane>
</children>
</HBox>
</children>
</StackPane>

<Button minWidth="130" mnemonicParsing="false" onAction="#handleEditTextBox1" style="-fx-background-color: transparent; -fx-font-size: 17px; -fx-text-fill: #D790A7; -fx-font-weight: bold; -fx-alignment: TOP_LEFT;" text="Edit text box #1" wrapText="true" />
<Label text="Description" textFill="#444444">
<font><Font name="System Regular" size="13" /></font>
</Label>
<TextArea fx:id="descriptionField"
prefHeight="180"
promptText="Write a description of your organisation..."
style="-fx-background-color: #FFFFFF;
-fx-border-color: #DDDDDD;
-fx-border-radius: 10;
-fx-background-radius: 10;
-fx-font-size: 14px;
-fx-padding: 10;"
wrapText="true" />
<Button onAction="#handleSaveDescription"
text="Save Description"
style="-fx-padding: 8 20 8 20;">
<cursor><Cursor fx:constant="HAND" /></cursor>
</Button>
</children>
</HBox>
</VBox>

</children>
</VBox>
</content>
Expand Down
Loading

0 comments on commit e64128b

Please sign in to comment.