Skip to content

Commit

Permalink
javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
rtaylorzfin committed Nov 24, 2022
1 parent 23cbf25 commit e829d03
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
8 changes: 4 additions & 4 deletions source/org/zfin/framework/presentation/NavigationItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import lombok.Getter;
import lombok.Setter;

/**
* Similar to a record, or a DTO class for storing the data relevant to a "navigation item"
* as displayed on the left nav of a data view page.
*/
@Getter
@Setter
@Builder
public class NavigationItem {

private NavigationMenuOptions title;

//only show if user is logged in
@Builder.Default
private boolean requireAuthentication = false;

//only show if user is root
@Builder.Default
private boolean requireRoot = false;
Expand Down
53 changes: 34 additions & 19 deletions source/org/zfin/framework/presentation/NavigationMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import java.util.List;
import java.util.stream.Stream;

/**
* This class is basically a collection of NavigationItem entries.
* It has some helper methods for setting properties of its collection members
* and getting the collection of items that should be displayed in a specific context.
* Also used for the same logic for the sections that correspond to the left nav.
*/
@Getter
@Setter
public class NavigationMenu {
Expand All @@ -20,25 +26,22 @@ public NavigationMenu(NavigationItem.NavigationItemBuilder ...navigationItemBuil
.toList();
}

public void hide(NavigationMenuOptions option) {
setHidden(option, true);
}

public void show(NavigationMenuOptions option) {
setHidden(option, false);
}

public void setHidden(NavigationMenuOptions option, boolean value) {
/**
* Set the hidden attribute for the NavigationItem in this menu matching the given title
* @param title
* @param value
*/
public void setHidden(NavigationMenuOptions title, boolean value) {
for(NavigationItem item : navigationItems) {
if (item.getTitle().equals(option)) {
if (item.getTitle().equals(title)) {
item.setHidden(value);
}
}
}

/**
* Determine which sections to include based on each Menu Item's properties (isRequireRoot, isHidden, etc.)
* @return
* @return collection of NavigationItems for display
*/
public List<NavigationItem> getDisplayedNavigationItems() {
List<NavigationItem> filteredSections = new ArrayList<>();
Expand All @@ -54,6 +57,20 @@ public List<NavigationItem> getDisplayedNavigationItems() {
return filteredSections;
}

/**
* Given the title of a section of a view page, return true if it should be shown, otherwise false
*
* @param title The title of the section
* @return true if given section title should be displayed
*/
public boolean include(String title) {
return this.getDisplayedNavigationItems()
.stream()
.map(NavigationItem::toString)
.toList()
.contains(title);
}

public boolean include(NavigationItem item) {
return include(item.toString());
}
Expand All @@ -62,22 +79,20 @@ public boolean include(NavigationMenuOptions option) {
return include(option.toString());
}

public boolean include(String option) {
return this.getDisplayedNavigationItems()
.stream()
.map(NavigationItem::toString)
.toList()
.contains(option);
}

/**
* Create a builder for a NavigationItem starting with a title
* @return
* @return the builder
*/
protected static NavigationItem.NavigationItemBuilder title(NavigationMenuOptions title) {
return NavigationItem.builder().title(title);
}

/**
* Get the NavigationItem matching the given title
* @param title title of the item we are looking for (enum)
* @return the NavigationItem
*/
protected NavigationItem getNavigationItem(NavigationMenuOptions title) {
for(NavigationItem result : getNavigationItems()) {
if (result.getTitle().equals(title)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
import org.zfin.framework.featureflag.FeatureFlags;
import org.zfin.publication.Publication;

/**
* This class encapsulates the logic for which navigation items to show on the publication view page,
* and also some of the properties like showing counts, or borders.
* This is easier to maintain than having the logic in the JSP file.
*/
@Getter
@Setter
public class PublicationNavigationMenu extends NavigationMenu {

/**
* Set up the navigation menu.
* This uses the builder pattern available on the NavigationItem class through lombok
*/
public PublicationNavigationMenu() {
super(
title(NavigationMenuOptions.SUMMARY).showCount(false),
Expand All @@ -37,7 +46,7 @@ public PublicationNavigationMenu() {
//If we aren't using the counter on the left hand navigation, turn it off for all menu items
//We can remove this once this functionality is no longer behind a flag
if (!FeatureFlags.isFlagEnabled(FeatureFlagEnum.USE_NAVIGATION_COUNTER)) {
getNavigationItems().stream().forEach(item -> item.setShowCount(false));
getNavigationItems().forEach(item -> item.setShowCount(false));
}

}
Expand Down

0 comments on commit e829d03

Please sign in to comment.