diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/AvailableOrganizationController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/AvailableOrganizationController.java index f45d6e9..5f7a569 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/AvailableOrganizationController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/AvailableOrganizationController.java @@ -13,6 +13,15 @@ import ntnu.systemutvikling.team6.models.Charity; import ntnu.systemutvikling.team6.models.CharityRegistry; +/** + * This controller represents the available organization page, where the user can search for a + * charity and choose to donate to it. It also has a button to return to the front page. + * The user can search for a charity by typing in the search field, + * and the charities that match the search query will be displayed. + * The user can click on a charity to see more details about it, + * or click on the featured charity to see more details about it. + * The user can also switch to the charity page or donation page for the selected charity. + */ public class AvailableOrganizationController { @FXML private TextField searchField; @@ -21,6 +30,14 @@ public class AvailableOrganizationController { private Charity charity; private List allCharities; + /** + * This method is used to initialize the available organization page. + * It retrieves all charities from the database and sets up a listener on the search field + * to filter the charities based on the user's input. + * It also clears the cards container to prepare for displaying the filtered charities. + * The method is called automatically when the page is loaded, + * and it sets up the initial state of the page. + */ @FXML public void initialize() { DatabaseManager db = new DatabaseManager(); @@ -36,8 +53,9 @@ public void initialize() { } /** - * @param query - * @return + * This method filters the charities based on the user's input in the search field. + * @param query is the user's input in the search field, which is used to filter the charities. + * @return a list of charities that match the search query. */ private List filterCharities(String query) { List matches = new ArrayList<>(); @@ -60,7 +78,8 @@ private List filterCharities(String query) { } /** - * @param charities + * This method displays the charities in the cards container. + * @param charities is a list of charities to be displayed. */ private void displayCharities(List charities) { cardsContainer.getChildren().clear(); @@ -81,9 +100,8 @@ private void displayCharities(List charities) { } /** - * The method initialize the search in searchbar. - * - * @param query + * This method is used to set the initial search query in the search field. + * @param query is the initial search query. */ @FXML public void setInitialSearch(String query) { diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java index c9f968f..de2e43e 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java @@ -62,6 +62,10 @@ public void switchToDonationPage(ActionEvent event) { LoaderScene.LoadScene("donationPage", event, charity, null); } + /** + * This method is used to search for charities based on the input in the search field. + * @param event is the event that triggered the search. + */ @FXML public void handleSearch(ActionEvent event) { String query = charitySearchField.getText().trim(); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java index 4187cec..dc7e0d8 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java @@ -133,6 +133,10 @@ private void showAlert(Alert.AlertType type, String title, String message) { alert.showAndWait(); } + /** + * This method is used to handle the search action when the user clicks the search button. + * @param event is the event that triggered the search. + */ @FXML public void handleSearch(ActionEvent event) { String query = donationSearchField.getText().trim(); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java index e5ad7d5..2abff0b 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java @@ -116,11 +116,19 @@ public void switchToDonationPage(ActionEvent event) { LoaderScene.LoadScene("DonationPage", event, featuredCharity, null); } + /** + * This method is used to filter the charities based on the selected filters. + * @param event is the event that triggered the filter. + */ @FXML public void handleCategoryFilterChange(ActionEvent event) { displayCharities(getFilteredCharities()); } + /** + * This method is used to search for charities based on the input in the search field. + * @param event is the event that triggered the search. + */ @FXML public void handleFrontSearch(ActionEvent event) { String query = frontSearchField.getText().trim(); @@ -132,6 +140,10 @@ public void handleFrontSearch(ActionEvent event) { LoaderScene.LoadScene("availableOrganization", event, null, query); } + /** + * This method is used to filter the charities based on the selected filters. + * @return a list of filtered charities. + */ private List getFilteredCharities() { if (!verifiedFilter.isSelected() && !childrenFilter.isSelected() @@ -149,6 +161,11 @@ private List getFilteredCharities() { return filteredCharities; } + /** + * This method is used to check if a charity matches the selected filters. + * @param charity is the charity to be checked. + * @return true if the charity matches the selected filters, false otherwise. + */ private boolean matchesSelectedFilters(Charity charity) { return (verifiedFilter.isSelected() && charity.getPreApproved()) || (childrenFilter.isSelected() && matchesKeywordCategory(charity, "children")) @@ -156,6 +173,12 @@ private boolean matchesSelectedFilters(Charity charity) { || (emergencyAidFilter.isSelected() && matchesKeywordCategory(charity, "emergency")); } + /** + * This method is used to check if a charity matches a specific category. + * @param charity is the charity to be checked. + * @param category is the category to check against. + * @return true if the charity matches the category, false otherwise. + */ private boolean matchesKeywordCategory(Charity charity, String category) { String text = (charity.getName() + " " + charity.getDescription()).toLowerCase(); @@ -179,6 +202,10 @@ private boolean matchesKeywordCategory(Charity charity, String category) { }; } + /** + * This method is used to display the charities in the cards container. + * @param charities is the list of charities to be displayed. + */ private void displayCharities(List charities) { cardsContainer.getChildren().clear();