Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,32 @@ public List<NavigationItem> getItems() {
items = new ArrayList<>();
PageManager pageManager = currentPage.getPageManager();
for (com.adobe.cq.wcm.core.components.models.NavigationItem wcmItem : wcmNavigation.getItems()) {
Page page = pageManager.getPage(wcmItem.getPath());
if (shouldExpandCatalogRoot(page)) {
expandCatalogRoot(page, items);
} else {
String title = wcmItem.getTitle();
String url = wcmItem.getURL();
boolean active = wcmItem.isActive();
NavigationItem item = new PageNavigationItem(null, title, url, active, wcmItem);
items.add(item);
}

addItems(pageManager, null, wcmItem, this.items);
}
}
return items;
}

private boolean shouldExpandCatalogRoot(Page page) {
private void addItems(PageManager pageManager, AbstractNavigationItem parent,
com.adobe.cq.wcm.core.components.models.NavigationItem currentWcmItem, List<NavigationItem> itemList) {
Page page = pageManager.getPage(currentWcmItem.getPath());
if (shouldExpandCatalogRoot(page)) {
expandCatalogRoot(page, itemList);
} else {
NavigationItem item;
if (isCatalogRoot(page)) {
item = new CatalogPageNavigationItem(null, page, currentWcmItem);
} else {
String title = currentWcmItem.getTitle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only cosmetics and optimized by the compiler but these three variables are not really needed. Code can be reduced to one line.

String url = currentWcmItem.getURL();
boolean active = currentWcmItem.isActive();
item = new PageNavigationItem(parent, title, url, active, currentWcmItem);
}
itemList.add(item);
}
}

private boolean isCatalogPage(Page page) {
if (page == null) {
return false;
}
Expand All @@ -124,12 +133,25 @@ private boolean shouldExpandCatalogRoot(Page page) {
return false;
}

if (!contentResource.isResourceType(RT_CATALOG_PAGE)) {
return contentResource.isResourceType(RT_CATALOG_PAGE);
}

private boolean shouldExpandCatalogRoot(Page page) {
if (!isCatalogPage(page)) {
return false;
}

Boolean showMainCategories = contentResource.getValueMap().get(PN_SHOW_MAIN_CATEGORIES, Boolean.class);
return Boolean.TRUE.equals(showMainCategories);
Boolean showMainCategories = page.getContentResource().getValueMap().get(PN_SHOW_MAIN_CATEGORIES, Boolean.TRUE);
return showMainCategories;
}

private boolean isCatalogRoot(Page page) {
if (!isCatalogPage(page)) {
return false;
}

Boolean showMainCategories = page.getContentResource().getValueMap().get(PN_SHOW_MAIN_CATEGORIES, Boolean.TRUE);
return !showMainCategories;
}

private void expandCatalogRoot(Page catalogPage, List<NavigationItem> pages) {
Expand Down Expand Up @@ -174,7 +196,7 @@ public String getParentId() {
return null;
}

static class PageNavigationItem extends AbstractNavigationItem {
class PageNavigationItem extends AbstractNavigationItem {
private final com.adobe.cq.wcm.core.components.models.NavigationItem wcmItem;

PageNavigationItem(AbstractNavigationItem parent, String title, String url, boolean active,
Expand All @@ -192,15 +214,30 @@ public List<NavigationItem> getItems() {

List<NavigationItem> items = new ArrayList<>();
for (com.adobe.cq.wcm.core.components.models.NavigationItem item : children) {
String title = item.getTitle();
String url = item.getURL();
boolean active = item.isActive();
items.add(new PageNavigationItem(this, title, url, active, item));
PageManager pageManager = currentPage.getPageManager();
addItems(pageManager, this, item, items);
}
return items;
}
}

class CatalogPageNavigationItem extends PageNavigationItem {
private final Page page;

CatalogPageNavigationItem(AbstractNavigationItem parent, Page page,
com.adobe.cq.wcm.core.components.models.NavigationItem wcmItem) {
super(parent, wcmItem.getTitle(), wcmItem.getURL(), wcmItem.isActive(), wcmItem);
this.page = page;
}

@Override
public List<NavigationItem> getItems() {
final ArrayList<NavigationItem> items = new ArrayList<>();
expandCatalogRoot(page, items);
return items;
}
}

static class CategoryNavigationItem extends AbstractNavigationItem implements NavigationItem {
private CategoryTree category;
private SlingHttpServletRequest request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,83 @@
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Page"
sling:resourceType="cq/gui/components/authoring/dialog"
extraClientlibs="[cq.common.wcm,core.wcm.components.page.v2.editor,cq.wcm.msm.properties,granite.contexthub.configuration,cq.siteadmin.admin.properties]"
mode="edit"
xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Page"
sling:resourceType="cq/gui/components/authoring/dialog"
extraClientlibs="[cq.common.wcm,core.wcm.components.page.v2.editor,cq.wcm.msm.properties,granite.contexthub.configuration,cq.siteadmin.admin.properties]"
mode="edit"
trackingFeature="cif-core-components:catalogpage:v1">
<content granite:class="cq-dialog-content-page"
jcr:primaryType="nt:unstructured"
<content granite:class="cq-dialog-content-page"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<tabs granite:class="cq-siteadmin-admin-properties-tabs"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/tabs"
<tabs granite:class="cq-siteadmin-admin-properties-tabs"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/tabs"
size="L">
<items jcr:primaryType="nt:unstructured">
<commerce cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
jcr:title="Commerce"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
<commerce cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
jcr:title="Commerce"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
sling:orderBefore="cloudservices">
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured"
<column jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<magentoSection jcr:primaryType="nt:unstructured"
jcr:title="Magento Store Configuration"
<catalogsection jcr:primaryType="nt:unstructured"
jcr:title="Catalog Page"
sling:resourceType="granite/ui/components/coral/foundation/form/fieldset">
<items jcr:primaryType="nt:unstructured">
<storeview jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldDescription="Identifier to select Magento Store View. If empty, the default store will be used."
fieldLabel="Store View"
name="./magentoStore"
renderReadOnly="{Boolean}false">
<granite:data jcr:primaryType="nt:unstructured"
cq-msm-lockable="magentoStore" />
</storeview>
<showMainCategories cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
fieldDescription="If checked the navigation includes the child categories of the category provided in the field 'Root category ID', otherwise the navigation includes the catalog landing page."
fieldDescription="If checked the navigation includes the catalog page, otherwise the navigation includes the child categories of the category provided in the field 'Root category ID'."
name="./showMainCategories"
renderReadOnly="{Boolean}true"
text="Show main categories"
value="true">
deleteHint="{Boolean}false"
text="Show catalog page"
value="{Boolean}false">
<granite:data jcr:primaryType="nt:unstructured"
cq-msm-lockable="showMainCategories" />
</showMainCategories>
<categoryId cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="commerce/gui/components/common/cifcategoryfield"
fieldDescription="Select the root category to be used in navigation."
fieldLabel="Root category ID"
name="./magentoRootCategoryId"
renderReadOnly="{Boolean}true"
<showMainCategoriesTypeHint jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./showMainCategories@TypeHint"
value="Boolean" />
<showMainCategoriesDefaultValue jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./showMainCategories@DefaultValue"
value="{Boolean}true" />
<showMainCategoriesUseDefaultWhenMissing jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./showMainCategories@UseDefaultWhenMissing"
value="{Boolean}true" />
</items>
</catalogsection>
<magentoSection jcr:primaryType="nt:unstructured"
jcr:title="Magento Store Configuration"
sling:resourceType="granite/ui/components/coral/foundation/form/fieldset">
<items jcr:primaryType="nt:unstructured">
<storeview jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldDescription="Identifier to select Magento Store View. If empty, the default store will be used."
fieldLabel="Store View"
name="./magentoStore"
renderReadOnly="{Boolean}false">
<granite:data jcr:primaryType="nt:unstructured"
cq-msm-lockable="magentoStore" />
</storeview>
<categoryId cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="commerce/gui/components/common/cifcategoryfield"
fieldDescription="Select the root category to be used in navigation."
fieldLabel="Root category ID"
name="./magentoRootCategoryId"
renderReadOnly="{Boolean}true"
translateOptions="{Boolean}false">
<granite:data jcr:primaryType="nt:unstructured"
<granite:data jcr:primaryType="nt:unstructured"
cq-msm-lockable="magentoRootCategoryId" />
</categoryId>
</items>
Expand Down