Skip to content

Commit

Permalink
Feat: Added fx:id with variables in the controller and pimped it the …
Browse files Browse the repository at this point in the history
…view model a little
  • Loading branch information
AdrianBalunan committed Mar 12, 2026
1 parent dd1e3fa commit 6b64e7f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,67 @@
package ntnu.systemutvikling.team6.controller;

import java.util.List;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import ntnu.systemutvikling.team6.database.DatabaseManager;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.CharityRegistry;
import ntnu.systemutvikling.team6.models.Donation;
import ntnu.systemutvikling.team6.models.DonationRegistry;

import java.util.Random;
import java.util.stream.Collectors;

public class FrontpageController {

@FXML private FlowPane cardsContainer;


@FXML
private FlowPane cardsContainer;
@FXML
private Label Carosel_Organisasjon;
@FXML
private Label Carosel_Beskrivelse;
@FXML
private Label Total_Orgnisasjon;
@FXML
private Label Total_Donations;
@FXML
private Label PreApproved_Percentage;

@FXML
public void initialize() {
try {
DatabaseManager db = new DatabaseManager();
CharityRegistry Charities = db.getCharitiesFromDB();
DonationRegistry Donations = db.getDonationFromDB();
for (Charity ch : Charities.getAllCharities()) {

/*
for (Charity ch : charities) {

FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/organizationCard.fxml"));

Parent card = loader.load();

OrganizationCardController cardController = loader.getController();

System.out.println("Added Name: " + ch.getName() + " Added Description: " + ch.getDescription());
cardController.setOrganization(ch.getName(), ch.getDescription());

cardsContainer.getChildren().add(card);
}
*/
int Charities_size = Charities.getAllCharities().size();
Random random = new Random();
int randomIndex = random.nextInt(Charities_size);
Charity randomCharity = Charities.getAllCharities().get(randomIndex);
Carosel_Organisasjon.setText(randomCharity.getName());
Carosel_Beskrivelse.setText(randomCharity.getDescription());
Total_Orgnisasjon.setText(Integer.toString(Charities_size));
Total_Donations.setText(Double.toString(Donations.getAllDonations().stream().mapToDouble(Donation::getAmount).sum()));
PreApproved_Percentage.setText(
String.format("%.2f", Charities.getAllCharities().stream().filter(Charity::getPreApproved).count() * 100.0 / Charities_size)
+ "%");

} catch (Exception e) {
e.printStackTrace();
Expand Down
27 changes: 13 additions & 14 deletions helpmehelpapplication/src/main/resources/fxml/frontPage.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
</Label>
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0">
<VBox alignment="CENTER" prefHeight="54.0" prefWidth="100.0">
<children>
<Label text="0">
<Label fx:id="Total_Orgnisasjon" text="0">
<font>
<Font size="20.0" />
</font>
Expand All @@ -125,9 +125,9 @@
<Label text="Organizations" />
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0">
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0">
<children>
<Label text="0">
<Label fx:id="Total_Donations" text="0">
<font>
<Font size="20.0" />
</font>
Expand All @@ -138,9 +138,9 @@
<Label text="NOK Donated" />
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0">
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0">
<children>
<Label text="0%">
<Label fx:id="PreApproved_Percentage" text="0%">
<font>
<Font size="20.0" />
</font>
Expand Down Expand Up @@ -168,23 +168,22 @@
<Font size="42.0" />
</font>
</Button>
<Region prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
<StackPane prefHeight="220.0" prefWidth="370.0">
<Region prefHeight="171.0" prefWidth="252.0" HBox.hgrow="ALWAYS" />
<StackPane prefHeight="171.0" prefWidth="509.0">
<children>
<VBox fillWidth="false" spacing="20.0" StackPane.alignment="CENTER_LEFT">
<VBox alignment="TOP_CENTER" fillWidth="false" prefHeight="171.0" prefWidth="228.0" spacing="20.0" StackPane.alignment="CENTER_LEFT">
<children>
<Label text="Organisasjon" textFill="WHITE" VBox.vgrow="ALWAYS">
<Label fx:id="Carosel_Organisasjon" alignment="CENTER" prefHeight="53.0" prefWidth="222.0" text="Organisasjon" textFill="WHITE" VBox.vgrow="ALWAYS">
<font>
<Font size="36.0" />
</font>
</Label>
<Label maxWidth="500.0" text="Beskrivelse" textFill="WHITE" wrapText="true" VBox.vgrow="ALWAYS">
<Label fx:id="Carosel_Beskrivelse" alignment="TOP_CENTER" maxWidth="500.0" prefHeight="32.0" prefWidth="182.0" text="Beskrivelse" textFill="WHITE" wrapText="true" VBox.vgrow="ALWAYS">
<font>
<Font size="22.0" />
</font>
</Label>
<HBox prefHeight="50.0" prefWidth="150.0" style="-fx-background-color: rgba(47, 143, 139, 1); -fx-background-radius: 30; -fx-padding: 10 18 10 18;">
<HBox alignment="TOP_CENTER" prefHeight="45.0" prefWidth="180.0" style="-fx-background-color: rgba(47, 143, 139, 1); -fx-background-radius: 30; -fx-padding: 10 18 10 18;">
<children>
<Label text="" textFill="LIME">
<font>
Expand All @@ -205,7 +204,7 @@
</VBox>
</children>
</StackPane>
<Region prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<Region prefHeight="171.0" prefWidth="16.0" HBox.hgrow="ALWAYS" />
<VBox alignment="CENTER" prefHeight="152.0" prefWidth="301.0" spacing="18.0">
<children>
<Button mnemonicParsing="false" style="-fx-background-color: #2E7D32; -fx-text-fill: white; -fx-font-size: 16; -fx-font-weight: bold; -fx-background-radius: 30; -fx-padding: 15 35 15 35; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.2, 0, 3);" text="Donate Now" />
Expand Down

0 comments on commit 6b64e7f

Please sign in to comment.