Skip to content
Permalink
Browse files

Added ability to hide children in primary Navigation

Moved HTML metadata tags to a shared location across projects
  • Loading branch information...
Eldblom committed Nov 15, 2016
1 parent 0320fe8 commit fc09f6eaa592e59deea6df80c708df3936fa229a
Showing with 247 additions and 233 deletions.
  1. +2 −2 .editorconfig
  2. +21 −18 src/Feature/Metadata/code/App_Config/Include/Feature/Feature.Metadata.Serialization.config
  3. +14 −14 ...al/Metadata Keywords.yml → Feature/Metadata/serialization/Feature.Metadata.Settings/Metadata.yml}
  4. +1 −1 ...etadata/serialization/Feature.Metadata.Templates/Metadata/_PageMetadata/Metadata/MetaKeywords.yml
  5. +1 −0 src/Feature/Navigation/code/Models/NavigationItem.cs
  6. +124 −123 src/Feature/Navigation/code/Repositories/NavigationRepository.cs
  7. +1 −0 src/Feature/Navigation/code/Templates.cs
  8. +1 −1 src/Feature/Navigation/code/Views/Navigation/PrimaryMenu.cshtml
  9. +7 −0 src/Feature/Navigation/serialization/Feature.Navigation.Templates/Navigation/_Navigable.yml
  10. +1 −1 ...eature/Navigation/serialization/Feature.Navigation.Templates/Navigation/_Navigable/Navigation.yml
  11. +1 −1 ...n/serialization/Feature.Navigation.Templates/Navigation/_Navigable/Navigation/NavigationTitle.yml
  12. +32 −0 ...tion/serialization/Feature.Navigation.Templates/Navigation/_Navigable/Navigation/ShowChildren.yml
  13. +3 −1 ...ialization/Common.Website.Templates/Common/Content Types/MetaKeyword folder/__Standard Values.yml
  14. +38 −37 src/Project/Habitat/code/App_Config/Include/Project/Habitat.Website.Serialization.config
  15. +0 −17 ...roject/Habitat/serialization/Habitat.Website.Content/Habitat/Global/Metadata Keywords/habitat.yml
  16. +0 −17 ...oject/Habitat/serialization/Habitat.Website.Content/Habitat/Global/Metadata Keywords/sitecore.yml
@@ -1,7 +1,7 @@
; Top-most EditorConfig file
root = true

; 2-column space indentation
; 4-column space indentation
[*]
indent_style = space
indent_size = 2
indent_size = 4
@@ -1,20 +1,23 @@
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<unicorn>
<configurations>
<configuration name="Feature.Metadata" description="Feature Metadata" dependencies="Foundation.Serialization" patch:after="configuration[@name='Foundation.Serialization']">
<targetDataStore physicalRootPath="$(sourceFolder)\feature\metadata\serialization" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" />
<predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true">
<include name="Feature.Metadata.Templates" database="master" path="/sitecore/templates/Feature/Metadata" />
<include name="Feature.Metadata.Renderings" database="master" path="/sitecore/layout/renderings/Feature/Metadata" />
<include name="Feature.Metadata.Media" database="master" path="/sitecore/media library/Feature/Metadata" />
</predicate>
<roleDataStore type="Unicorn.Roles.Data.FilesystemRoleDataStore, Unicorn.Roles" physicalRootPath="$(sourceFolder)\feature\metadata\serialization\Feature.Metadata.Roles" singleInstance="true"/>
<rolePredicate type="Unicorn.Roles.RolePredicates.ConfigurationRolePredicate, Unicorn.Roles" singleInstance="true">
<include domain="modules" pattern="^Feature Metadata .*$" />
</rolePredicate>
</configuration>
</configurations>
</unicorn>
</sitecore>
<sitecore>
<unicorn>
<configurations>
<configuration name="Feature.Metadata" description="Feature Metadata" dependencies="Foundation.Serialization" patch:after="configuration[@name='Foundation.Serialization']">
<targetDataStore physicalRootPath="$(sourceFolder)\feature\metadata\serialization" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" />
<predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true">
<include name="Feature.Metadata.Templates" database="master" path="/sitecore/templates/Feature/Metadata" />
<include name="Feature.Metadata.Renderings" database="master" path="/sitecore/layout/renderings/Feature/Metadata" />
<include name="Feature.Metadata.Media" database="master" path="/sitecore/media library/Feature/Metadata" />
<include name="Feature.Metadata.Settings" database="master" path="/sitecore/system/settings/Feature/Metadata">
<exclude children="true" />
</include>
</predicate>
<roleDataStore type="Unicorn.Roles.Data.FilesystemRoleDataStore, Unicorn.Roles" physicalRootPath="$(sourceFolder)\feature\metadata\serialization\Feature.Metadata.Roles" singleInstance="true" />
<rolePredicate type="Unicorn.Roles.RolePredicates.ConfigurationRolePredicate, Unicorn.Roles" singleInstance="true">
<include domain="modules" pattern="^Feature Metadata .*$" />
</rolePredicate>
</configuration>
</configurations>
</unicorn>
</sitecore>
</configuration>
@@ -1,14 +1,14 @@
---
ID: "553d3cc1-b549-4aa1-9ed9-e8e06e14a683"
Parent: "4b67a7f9-7246-4a59-a051-961095c2dc70"
Template: "cd047791-c29a-4596-aeee-db5e70421c1f"
Path: /sitecore/content/Habitat/Global/Metadata Keywords
DB: master
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20160113T155509Z
---
ID: "553d3cc1-b549-4aa1-9ed9-e8e06e14a683"
Parent: "256655ec-8f3a-45b5-ad90-b63bc25b8067"
Template: "cd047791-c29a-4596-aeee-db5e70421c1f"
Path: /sitecore/system/Settings/Feature/Metadata
DB: master
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20160113T155509Z
@@ -7,7 +7,7 @@ DB: master
SharedFields:
- ID: "1eb8ae32-e190-44a6-968d-ed904c794ebf"
Hint: Source
Value: /sitecore/content/Habitat/Global/Metadata Keywords
Value: /sitecore/system/Settings/Feature/Metadata
- ID: "ab162cc0-dc80-4abf-8871-998ee5d7ba32"
Hint: Type
Value: Treelist
@@ -10,5 +10,6 @@ public class NavigationItem
public int Level { get; set; }
public NavigationItems Children { get; set; }
public string Target { get; set; }
public bool ShowChildren { get; set; }
}
}
@@ -1,145 +1,146 @@
namespace Sitecore.Feature.Navigation.Repositories
{
using System;
using System.Collections.Generic;
using System.Linq;
using Sitecore.Data.Items;
using Sitecore.Feature.Navigation.Models;
using Sitecore.Foundation.SitecoreExtensions.Extensions;

public class NavigationRepository : INavigationRepository
{
public Item ContextItem { get; }
public Item NavigationRoot { get; }

public NavigationRepository(Item contextItem)
using System;
using System.Collections.Generic;
using System.Linq;
using Sitecore.Data.Items;
using Sitecore.Feature.Navigation.Models;
using Sitecore.Foundation.SitecoreExtensions.Extensions;

public class NavigationRepository : INavigationRepository
{
this.ContextItem = contextItem;
this.NavigationRoot = this.GetNavigationRoot(this.ContextItem);
if (this.NavigationRoot == null)
{
throw new InvalidOperationException($"Cannot determine navigation root from '{this.ContextItem.Paths.FullPath}'");
}
}
public Item ContextItem { get; }
public Item NavigationRoot { get; }

public Item GetNavigationRoot(Item contextItem)
{
return contextItem.GetAncestorOrSelfOfTemplate(Templates.NavigationRoot.ID) ?? Context.Site.GetContextItem(Templates.NavigationRoot.ID);
}
public NavigationRepository(Item contextItem)
{
this.ContextItem = contextItem;
this.NavigationRoot = this.GetNavigationRoot(this.ContextItem);
if (this.NavigationRoot == null)
{
throw new InvalidOperationException($"Cannot determine navigation root from '{this.ContextItem.Paths.FullPath}'");
}
}

public NavigationItems GetBreadcrumb()
{
var items = new NavigationItems
{
Items = this.GetNavigationHierarchy(true).Reverse().ToList()
};

for (var i = 0; i < items.Items.Count - 1; i++)
{
items.Items[i].Level = i;
items.Items[i].IsActive = i == items.Items.Count - 1;
}

return items;
}
public Item GetNavigationRoot(Item contextItem)
{
return contextItem.GetAncestorOrSelfOfTemplate(Templates.NavigationRoot.ID) ?? Context.Site.GetContextItem(Templates.NavigationRoot.ID);
}

public NavigationItems GetPrimaryMenu()
{
var navItems = this.GetChildNavigationItems(this.NavigationRoot, 0, 1);
public NavigationItems GetBreadcrumb()
{
var items = new NavigationItems
{
Items = this.GetNavigationHierarchy(true).Reverse().ToList()
};

for (var i = 0; i < items.Items.Count - 1; i++)
{
items.Items[i].Level = i;
items.Items[i].IsActive = i == items.Items.Count - 1;
}

return items;
}

this.AddRootToPrimaryMenu(navItems);
return navItems;
}
public NavigationItems GetPrimaryMenu()
{
var navItems = this.GetChildNavigationItems(this.NavigationRoot, 0, 1);

private void AddRootToPrimaryMenu(NavigationItems navItems)
{
if (!this.IncludeInNavigation(this.NavigationRoot))
{
return;
}

var navigationItem = this.CreateNavigationItem(this.NavigationRoot, 0, 0);
//Root navigation item is only active when we are actually on the root item
navigationItem.IsActive = this.ContextItem.ID == this.NavigationRoot.ID;
navItems?.Items?.Insert(0, navigationItem);
}
this.AddRootToPrimaryMenu(navItems);
return navItems;
}

private bool IncludeInNavigation(Item item, bool forceShowInMenu = false)
{
return item.HasContextLanguage() && item.IsDerived(Templates.Navigable.ID) && (forceShowInMenu || MainUtil.GetBool(item[Templates.Navigable.Fields.ShowInNavigation], false));
}
private void AddRootToPrimaryMenu(NavigationItems navItems)
{
if (!this.IncludeInNavigation(this.NavigationRoot))
{
return;
}

var navigationItem = this.CreateNavigationItem(this.NavigationRoot, 0, 0);
//Root navigation item is only active when we are actually on the root item
navigationItem.IsActive = this.ContextItem.ID == this.NavigationRoot.ID;
navItems?.Items?.Insert(0, navigationItem);
}

public NavigationItem GetSecondaryMenuItem()
{
var rootItem = this.GetSecondaryMenuRoot();
return rootItem == null ? null : this.CreateNavigationItem(rootItem, 0, 3);
}
private bool IncludeInNavigation(Item item, bool forceShowInMenu = false)
{
return item.HasContextLanguage() && item.IsDerived(Templates.Navigable.ID) && (forceShowInMenu || MainUtil.GetBool(item[Templates.Navigable.Fields.ShowInNavigation], false));
}

public NavigationItems GetLinkMenuItems(Item menuRoot)
{
if (menuRoot == null)
{
throw new ArgumentNullException(nameof(menuRoot));
}
return this.GetChildNavigationItems(menuRoot, 0, 0);
}
public NavigationItem GetSecondaryMenuItem()
{
var rootItem = this.GetSecondaryMenuRoot();
return rootItem == null ? null : this.CreateNavigationItem(rootItem, 0, 3);
}

private Item GetSecondaryMenuRoot()
{
return this.FindActivePrimaryMenuItem();
}
public NavigationItems GetLinkMenuItems(Item menuRoot)
{
if (menuRoot == null)
{
throw new ArgumentNullException(nameof(menuRoot));
}
return this.GetChildNavigationItems(menuRoot, 0, 0);
}

private Item FindActivePrimaryMenuItem()
{
var primaryMenuItems = this.GetPrimaryMenu();
//Find the active primary menu item
var activePrimaryMenuItem = primaryMenuItems.Items.FirstOrDefault(i => i.Item.ID != this.NavigationRoot.ID && i.IsActive);
return activePrimaryMenuItem?.Item;
}
private Item GetSecondaryMenuRoot()
{
return this.FindActivePrimaryMenuItem();
}

private IEnumerable<NavigationItem> GetNavigationHierarchy(bool forceShowInMenu = false)
{
var item = this.ContextItem;
while (item != null)
{
if (this.IncludeInNavigation(item, forceShowInMenu))
private Item FindActivePrimaryMenuItem()
{
yield return this.CreateNavigationItem(item, 0);
var primaryMenuItems = this.GetPrimaryMenu();
//Find the active primary menu item
var activePrimaryMenuItem = primaryMenuItems.Items.FirstOrDefault(i => i.Item.ID != this.NavigationRoot.ID && i.IsActive);
return activePrimaryMenuItem?.Item;
}

item = item.Parent;
}
}
private IEnumerable<NavigationItem> GetNavigationHierarchy(bool forceShowInMenu = false)
{
var item = this.ContextItem;
while (item != null)
{
if (this.IncludeInNavigation(item, forceShowInMenu))
{
yield return this.CreateNavigationItem(item, 0);
}

item = item.Parent;
}
}

private NavigationItem CreateNavigationItem(Item item, int level, int maxLevel = -1)
{
Item targetItem = item.IsDerived(Templates.Link.ID) ? item.TargetItem(Templates.Link.Fields.Link) : item;
return new NavigationItem
{
Item = item,
Url = item.IsDerived(Templates.Link.ID) ? item.LinkFieldUrl(Templates.Link.Fields.Link) : item.Url(),
Target = item.IsDerived(Templates.Link.ID) ? item.LinkFieldTarget(Templates.Link.Fields.Link) : "",
IsActive = this.IsItemActive(targetItem ?? item),
Children = this.GetChildNavigationItems(item, level + 1, maxLevel)
};
}
private NavigationItem CreateNavigationItem(Item item, int level, int maxLevel = -1)
{
var targetItem = item.IsDerived(Templates.Link.ID) ? item.TargetItem(Templates.Link.Fields.Link) : item;
return new NavigationItem
{
Item = item,
Url = item.IsDerived(Templates.Link.ID) ? item.LinkFieldUrl(Templates.Link.Fields.Link) : item.Url(),
Target = item.IsDerived(Templates.Link.ID) ? item.LinkFieldTarget(Templates.Link.Fields.Link) : "",
IsActive = this.IsItemActive(targetItem ?? item),
Children = this.GetChildNavigationItems(item, level + 1, maxLevel),
ShowChildren = !item.IsDerived(Templates.Navigable.ID) || item.Fields[Templates.Navigable.Fields.ShowChildren].IsChecked()
};
}

private NavigationItems GetChildNavigationItems(Item parentItem, int level, int maxLevel)
{
if (level > maxLevel || !parentItem.HasChildren)
{
return null;
}
var childItems = parentItem.Children.Where(item => this.IncludeInNavigation(item)).Select(i => this.CreateNavigationItem(i, level, maxLevel));
return new NavigationItems
{
Items = childItems.ToList()
};
}
private NavigationItems GetChildNavigationItems(Item parentItem, int level, int maxLevel)
{
if (level > maxLevel || !parentItem.HasChildren)
{
return null;
}
var childItems = parentItem.Children.Where(item => this.IncludeInNavigation(item)).Select(i => this.CreateNavigationItem(i, level, maxLevel));
return new NavigationItems
{
Items = childItems.ToList()
};
}

private bool IsItemActive(Item item)
{
return this.ContextItem.ID == item.ID || this.ContextItem.Axes.GetAncestors().Any(a => a.ID == item.ID);
private bool IsItemActive(Item item)
{
return this.ContextItem.ID == item.ID || this.ContextItem.Axes.GetAncestors().Any(a => a.ID == item.ID);
}
}
}
}
@@ -17,6 +17,7 @@ public struct Fields
{
public static readonly ID ShowInNavigation = new ID("{5585A30D-B115-4753-93CE-422C3455DEB2}");
public static readonly ID NavigationTitle = new ID("{1B483E91-D8C4-4D19-BA03-462074B55936}");
public static readonly ID ShowChildren = new ID("{68016087-AA00-45D6-922A-678475C50D4A}");
}
}

@@ -8,7 +8,7 @@
{
foreach (var item in Model.Items)
{
var hasChildren = item.Children != null && item.Children.Items.Any();
var hasChildren = item.Children != null && item.Children.Items.Any() && item.ShowChildren;
var cssClass = "";
if (hasChildren)
{
Oops, something went wrong.

0 comments on commit fc09f6e

Please sign in to comment.
You can’t perform that action at this time.