Skip to content

Commit

Permalink
refactor: changed view to work with new controller structure
Browse files Browse the repository at this point in the history
  • Loading branch information
emilfa committed Mar 24, 2026
1 parent 896ca24 commit 4cecbe4
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 100 deletions.
16 changes: 8 additions & 8 deletions src/main/java/edu/group5/app/view/Header.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package edu.group5.app.view;

import edu.group5.app.control.PageController;
import edu.group5.app.control.NavigationController;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;

public class Header extends BorderPane {
private final PageController controller;
private final NavigationController controller;

public Header(PageController controller) {
public Header(NavigationController controller) {
this.controller = controller;
getStylesheets().add(getClass().getResource("/header/header.css").toExternalForm());
setId("header");
Expand All @@ -24,7 +24,7 @@ private StackPane getLogoSection() {
StackPane logoSection = new StackPane();
logoSection.setId("logo-section");
logoSection.setAlignment(Pos.CENTER);
logoSection.setOnMouseClicked(e -> controller.handleHomeBtn());
logoSection.setOnMouseClicked(e -> controller.showHomePage());
logoSection.setStyle("-fx-cursor: hand;");

ImageView logo = new ImageView(
Expand All @@ -44,15 +44,15 @@ private HBox getNavBar() {
navbar.setSpacing(10);

Button home = new Button("Home");
home.setOnAction(e -> controller.handleHomeBtn());
home.setOnAction(e -> controller.showHomePage());
home.setStyle("-fx-cursor: hand;");

Button causes = new Button("Causes");
causes.setOnAction(e -> controller.handleCausesBtn());
causes.setOnAction(e -> controller.showCausesPage());
causes.setStyle("-fx-cursor: hand;");

Button about = new Button("About us");
about.setOnAction(e -> controller.handleAboutBtn());
about.setOnAction(e -> controller.showAboutUsPage());
about.setStyle("-fx-cursor: hand;");

navbar.getChildren().addAll(home, causes, about);
Expand All @@ -63,7 +63,7 @@ private StackPane getProfileSection() {
StackPane profileSection = new StackPane();
profileSection.setId("profile-section");
profileSection.setAlignment(Pos.CENTER);
profileSection.setOnMouseClicked(e -> controller.handleProfileBtn());
profileSection.setOnMouseClicked(e -> controller.showUserPage());
profileSection.setStyle("-fx-cursor: hand;");

ImageView avatar = new ImageView(
Expand Down
52 changes: 32 additions & 20 deletions src/main/java/edu/group5/app/view/causespage/CausesPageView.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package edu.group5.app.view.browsepage;
package edu.group5.app.view.causespage;

import edu.group5.app.control.PageController;
import edu.group5.app.control.NavigationController;
import edu.group5.app.control.OrganizationController;
import edu.group5.app.model.AppState;
import edu.group5.app.model.organization.Organization;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class BrowsePageView extends BorderPane {
private final PageController controller;
public class CausesPageView extends BorderPane {
private final AppState appState;
private final NavigationController nav;
private final OrganizationController orgController;

private GridPane organizationGrid;
private Map<Integer, Organization> allOrganizations;

public BrowsePageView(PageController controller) {
this.controller = controller;
public CausesPageView(AppState appState, NavigationController nav, OrganizationController orgController) {
this.appState = appState;
this.nav = nav;
this.orgController = orgController;

getStylesheets().add(getClass().getResource("/browsepage/browsepage.css").toExternalForm());
setCenter(createBody());
}
Expand Down Expand Up @@ -62,30 +71,33 @@ private GridPane createOrganizationSection(String searchTerm) {
grid.setMaxWidth(Double.MAX_VALUE);

if (allOrganizations == null) {
System.out.println("Controller: " + controller.getMainController().getOrganizationService());
allOrganizations = controller.getMainController().getOrganizationService().getTrustedOrganizations();
allOrganizations = orgController.getTrustedOrgs();
}

// Filter organizations by search term
Map<Integer, Organization> organizations = filterOrganizations(searchTerm);
Map<Integer, Organization> organizations = new HashMap<>();
if (searchTerm != null) {
// Filter organizations by search term
organizations = filterOrganizations(searchTerm);
} else {
organizations = allOrganizations;
}

int column = 0;
int row = 0;
for (int i = 0; i < 16; i++) {
for (Organization org : organizations.values()) {
String defaultImg = "/browsepage/images/children_of_shambala.png";
BrowseCard card = new BrowseCard(controller, org, defaultImg);
for (Organization org : organizations.values()) {
String defaultImg = "/browsepage/images/children_of_shambala.png";
OrganizationCard card = new OrganizationCard(appState, nav, org, defaultImg);

grid.add(card, column, row);
grid.add(card, column, row);

column++;
column++;

if (column == 4) {
column = 0;
row++;
}
if (column == 4) {
column = 0;
row++;
}
}

for (int i = 0; i < 4; i++) {
ColumnConstraints col = new ColumnConstraints();
col.setPercentWidth(25);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/edu/group5/app/view/causespage/OrganizationCard.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package edu.group5.app.view.causespage;

import edu.group5.app.control.NavigationController;
import edu.group5.app.model.AppState;
import edu.group5.app.model.organization.Organization;
import javafx.geometry.Pos;
import javafx.scene.image.Image;
Expand All @@ -8,12 +10,14 @@
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

public class OrgCard extends VBox {
public class OrganizationCard extends VBox {
private final AppState appState;
private final Organization organization;
private final PageController controller;
private final NavigationController nav;

public OrgCard(PageController controller, Organization org, String img) {
this.controller = controller;
public OrganizationCard(AppState appstate, NavigationController nav, Organization org, String img) {
this.appState = appstate;
this.nav = nav;
this.organization = org;
setId("mainContainer");
getStylesheets().add(getClass().getResource("/browsepage/browse_org.css").toExternalForm());
Expand All @@ -25,7 +29,8 @@ public OrgCard(PageController controller, Organization org, String img) {
);

setOnMouseClicked(e -> {
controller.handleBrowseCardClick(organization);
appstate.setCurrentOrganization(organization);
nav.showOrganizationPage();
});

setSpacing(10);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package edu.group5.app.view.donationpage;

import edu.group5.app.control.PageController;
import edu.group5.app.control.DonationController;
import edu.group5.app.control.NavigationController;
import edu.group5.app.model.AppState;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
Expand All @@ -20,12 +22,18 @@
import java.util.Map;

public class DonationPageView extends BorderPane {
private final PageController controller;
private final AppState appState;
private final NavigationController nav;
private final DonationController donationController;

private final List<Node> allDonationElements = new ArrayList<>();
private final Map<Object, BigDecimal> elementAmounts = new HashMap<>();

public DonationPageView(PageController controller) {
this.controller = controller;
public DonationPageView(AppState appState, NavigationController nav, DonationController donationController) {
this.appState = appState;
this.nav = nav;
this.donationController = donationController;

getStylesheets().add(getClass().getResource("/donationpage/donation.css").toExternalForm());

VBox content = new VBox();
Expand Down Expand Up @@ -94,7 +102,6 @@ private VBox createCustomButton() {
box.setAlignment(Pos.CENTER);
box.getStyleClass().add("donation-button");


box.setOnMouseClicked(e -> {
try {
BigDecimal amount = new BigDecimal(amountField.getText().trim());
Expand All @@ -103,7 +110,6 @@ private VBox createCustomButton() {
} catch (NumberFormatException exception) {
System.err.println("Invalid custom donation amount: " + amountField.getText());
}

});

allDonationElements.add(box);
Expand All @@ -112,7 +118,7 @@ private VBox createCustomButton() {
private HBox createDonateSection() {
Button donateBtn = new Button("Donate");
donateBtn.getStyleClass().add("donate-button");
donateBtn.setOnAction(e -> controller.handleDonationBtn());
donateBtn.setOnAction(e -> donationController.handleDonate());

HBox section = new HBox(donateBtn);
section.setAlignment(Pos.CENTER);
Expand All @@ -135,7 +141,7 @@ private void selectDonationElement(Node element) {
private void extractAndStoreAmount(Node element) {
BigDecimal amount = elementAmounts.get(element);
if (amount != null) {
controller.setCurrentDonationAmount(amount);
appState.setCurrentDonationAmount(amount);
} else {
System.err.println("Error: No amount found for selected element");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package edu.group5.app.view.donationpage;

import edu.group5.app.control.PageController;
import edu.group5.app.control.NavigationController;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
Expand All @@ -9,14 +9,13 @@
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;

import java.awt.*;
import java.util.Objects;

public class PaymentCompletePageView extends BorderPane {
private final PageController controller;
private final NavigationController nav;

public PaymentCompletePageView(PageController controller) {
this.controller = controller;
public PaymentCompletePageView(NavigationController nav) {
this.nav = nav;
getStylesheets().add(getClass().getResource("/donationpage/paymentcomplete.css").toExternalForm());

VBox content = new VBox(20);
Expand All @@ -40,7 +39,7 @@ public VBox getImageSection() {

public Button getHomeBtn() {
Button home = new Button("Home");
home.setOnAction(e -> controller.handleHomeBtn());
home.setOnAction(e -> nav.showHomePage());
home.setId("home-button");
return home;
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/edu/group5/app/view/homepage/HomePageView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.group5.app.view.homepage;

import edu.group5.app.control.PageController;
import edu.group5.app.control.NavigationController;
import edu.group5.app.model.AppState;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
Expand All @@ -10,10 +11,13 @@
import javafx.scene.text.Text;

public class HomePageView extends BorderPane {
private final PageController controller;
private final AppState appState;
private final NavigationController nav;

public HomePageView(AppState appState, NavigationController nav) {
this.appState = appState;
this.nav = nav;

public HomePageView(PageController controller) {
this.controller = controller;
getStylesheets().add(getClass().getResource("/homepage/homepage.css").toExternalForm());
setCenter(createBody());
}
Expand Down Expand Up @@ -42,10 +46,10 @@ private VBox createIntroductionSection() {
h2.setId("h2");

Button donateToACauseBtn = new Button("Donate to a cause");
donateToACauseBtn.setOnAction(e -> controller.handleDonateToACauseBtn());
donateToACauseBtn.setOnAction(e -> nav.showCausesPage());

Button aboutUsBtn = new Button("About us");
aboutUsBtn.setOnAction(e -> controller.handleAboutUsBtn());
aboutUsBtn.setOnAction(e -> nav.showAboutUsPage());

introductionSection.getChildren().addAll(h1, h2, donateToACauseBtn, aboutUsBtn);
return introductionSection;
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/edu/group5/app/view/loginpage/LoginPageView.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package edu.group5.app.view.loginpage;


import edu.group5.app.control.PageController;
import edu.group5.app.control.NavigationController;
import edu.group5.app.control.UserController;
import edu.group5.app.model.AppState;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
Expand All @@ -12,15 +13,18 @@
import java.util.Objects;

public class LoginPageView extends BorderPane {
private final PageController controller;
private final AppState appState;
private final NavigationController nav;
private final UserController userController;

private TextField emailField;
private PasswordField passwordField;
private Label errorLabel;

public LoginPageView(PageController controller) {
this.controller = controller;
LoginHeader loginHeaderView = new LoginHeader();
setTop(loginHeaderView);
public LoginPageView(AppState appState, NavigationController nav, UserController userController) {
this.appState = appState;
this.nav = nav;
this.userController = userController;

HBox content = new HBox();
content.setFillHeight(true);
Expand Down Expand Up @@ -55,6 +59,7 @@ private VBox getOuterSection() {
outerSection.getChildren().addAll(getLoginBox(), getRegisterBtn());
return outerSection;
}

private VBox getLoginBox() {
VBox loginSection = new VBox(12);
loginSection.setAlignment(Pos.CENTER);
Expand All @@ -78,6 +83,7 @@ private VBox getEmailBox() {
emailBox.getChildren().addAll(new Label("Email"), emailField);
return emailBox;
}

private VBox getPasswordBox() {
VBox passwordBox = new VBox();
passwordBox.setMaxWidth(300);
Expand All @@ -86,20 +92,27 @@ private VBox getPasswordBox() {
passwordBox.getChildren().addAll(new Label("Password"), passwordField);
return passwordBox;
}

private Button getLoginBtn() {
Button loginBtn = new Button("Log In");
loginBtn.setMaxWidth(300);
loginBtn.setId("login-btn");
loginBtn.setOnMouseClicked(e -> controller.handleLoginBtn());
loginBtn.setOnMouseClicked(e -> userController.handleLogin(
this,
getEmail(),
getPassword()
));
return loginBtn;
}

public Button getRegisterBtn() {
Button registerBtn = new Button("Don't have an account? Sign In");
registerBtn.setMaxWidth(300);
registerBtn.setOnMouseClicked(e -> controller.handleRegisterBtn());
registerBtn.setOnMouseClicked(e -> nav.showSignInPage());
registerBtn.setId("register-btn");
return registerBtn;
}

private StackPane getImageSection() {
StackPane imageSection = new StackPane();
imageSection.setId("image-section");
Expand Down
Loading

0 comments on commit 4cecbe4

Please sign in to comment.