Skip to content

Commit

Permalink
feat: javadock update
Browse files Browse the repository at this point in the history
  • Loading branch information
cathrkri committed Mar 31, 2026
1 parent 0987cd0 commit eebf598
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +30,14 @@ public class AvailableOrganizationController {
private Charity charity;
private List<Charity> 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();
Expand All @@ -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<Charity> filterCharities(String query) {
List<Charity> matches = new ArrayList<>();
Expand All @@ -60,7 +78,8 @@ private List<Charity> 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<Charity> charities) {
cardsContainer.getChildren().clear();
Expand All @@ -81,9 +100,8 @@ private void displayCharities(List<Charity> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<Charity> getFilteredCharities() {
if (!verifiedFilter.isSelected()
&& !childrenFilter.isSelected()
Expand All @@ -149,13 +161,24 @@ private List<Charity> 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"))
|| (healthFilter.isSelected() && matchesKeywordCategory(charity, "health"))
|| (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();

Expand All @@ -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<Charity> charities) {
cardsContainer.getChildren().clear();

Expand Down

0 comments on commit eebf598

Please sign in to comment.