-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ebe83e
commit bf81cbc
Showing
24 changed files
with
724 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Gibe.Navigation.Umbraco.NodeTypes; | ||
|
||
namespace Gibe.Navigation.Umbraco | ||
{ | ||
public class DefaultNodeTypeFactory : INodeTypeFactory | ||
{ | ||
private readonly Dictionary<Type, INodeType> _nodeTypes; | ||
|
||
public DefaultNodeTypeFactory(IEnumerable<INodeType> nodeTypes) | ||
{ | ||
_nodeTypes = nodeTypes.ToDictionary(n => n.GetType(), n => n); | ||
} | ||
|
||
public INodeType GetNodeType<T>() where T : INodeType | ||
{ | ||
return _nodeTypes[typeof(T)]; | ||
} | ||
|
||
public INodeType GetNodeType(Type t) | ||
{ | ||
return _nodeTypes[t]; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Gibe.Navigation.Umbraco.V9/Filters/TemplateOrRedirectFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
using Umbraco.Extensions; | ||
|
||
namespace Gibe.Navigation.Umbraco.Filters | ||
{ | ||
public class TemplateOrRedirectFilter : INavigationFilter | ||
{ | ||
|
||
public bool IncludeInNavigation(IPublishedContent content) | ||
{ | ||
return HasTemplate(content) || IsRedirect(content); | ||
} | ||
|
||
private bool IsRedirect(IPublishedContent content) | ||
{ | ||
return content.HasValue("gibeNavigationRedirect"); | ||
} | ||
|
||
private bool HasTemplate(IPublishedContent content) | ||
{ | ||
return content.TemplateId != 0; | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
Gibe.Navigation.Umbraco.V9/Gibe.Navigation.Umbraco.V9.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<PackageId>Gibe.Navigation.Umbraco.V9</PackageId> | ||
<PackageVersion>9.0.0</PackageVersion> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<PackageTags>Gibe Navigation Umbraco</PackageTags> | ||
<Authors>Gibe Digital Ltd</Authors> | ||
<Version>9.0.0</Version> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Umbraco.Cms.Web.Website" Version="9.0.0-rc001" /> | ||
<ProjectReference Include="..\Gibe.Navigation\Gibe.Navigation.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Gibe.Navigation.Models; | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
|
||
namespace Gibe.Navigation.Umbraco | ||
{ | ||
public interface INavigationElementFactory | ||
{ | ||
INavigationElement Make(IPublishedContent content); | ||
|
||
INavigationElement HyrdateExtraProperties(IPublishedContent content, INavigationElement element); | ||
} | ||
|
||
public class FakeNavigationElementFactory : INavigationElementFactory | ||
{ | ||
private readonly INavigationElement _navigationElement; | ||
|
||
public FakeNavigationElementFactory(INavigationElement navigationElement) | ||
{ | ||
_navigationElement = navigationElement; | ||
} | ||
|
||
public INavigationElement Make(IPublishedContent content) | ||
{ | ||
return _navigationElement; | ||
} | ||
|
||
public INavigationElement HyrdateExtraProperties(IPublishedContent content, INavigationElement element) | ||
{ | ||
return _navigationElement; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
|
||
namespace Gibe.Navigation.Umbraco | ||
{ | ||
public interface INavigationFilter | ||
{ | ||
bool IncludeInNavigation(IPublishedContent content); | ||
} | ||
|
||
public class FakeNavigationFilter : INavigationFilter | ||
{ | ||
private readonly bool _includeInNavigation; | ||
|
||
public FakeNavigationFilter(bool includeInNavigation) | ||
{ | ||
_includeInNavigation = includeInNavigation; | ||
} | ||
public bool IncludeInNavigation(IPublishedContent content) | ||
{ | ||
return _includeInNavigation; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using Gibe.Navigation.Umbraco.NodeTypes; | ||
|
||
namespace Gibe.Navigation.Umbraco | ||
{ | ||
public interface INodeTypeFactory | ||
{ | ||
INodeType GetNodeType<T>() where T : INodeType; | ||
|
||
INodeType GetNodeType(Type t); | ||
} | ||
|
||
public class FakeNodeTypeFactory : INodeTypeFactory | ||
{ | ||
private readonly INodeType _nodeType; | ||
|
||
public FakeNodeTypeFactory(INodeType nodeType) | ||
{ | ||
_nodeType = nodeType; | ||
} | ||
|
||
public INodeType GetNodeType<T>() where T : INodeType | ||
{ | ||
return _nodeType; | ||
} | ||
|
||
public INodeType GetNodeType(Type t) | ||
{ | ||
return _nodeType; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Collections.Generic; | ||
using Gibe.Navigation.Umbraco.NodeTypes; | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
|
||
namespace Gibe.Navigation.Umbraco | ||
{ | ||
public interface IUmbracoNodeService | ||
{ | ||
/// <summary> | ||
/// Return the correct node for the given key. | ||
/// </summary> | ||
/// <param name="nodeType">The type of node to find</param> | ||
/// <returns>The node represented by that key</returns> | ||
IPublishedContent GetNode(INodeType nodeType); | ||
} | ||
|
||
public class FakeUmbracoNodeService : IUmbracoNodeService | ||
{ | ||
private readonly IDictionary<INodeType, IPublishedContent> _contentByNodeType; | ||
|
||
public FakeUmbracoNodeService(IDictionary<INodeType, IPublishedContent> contentByNodeType) | ||
{ | ||
_contentByNodeType = contentByNodeType; | ||
} | ||
|
||
public IPublishedContent GetNode(INodeType nodeKey) => _contentByNodeType[nodeKey]; | ||
} | ||
|
||
|
||
} |
70 changes: 70 additions & 0 deletions
70
Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Gibe.Navigation.Models; | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
using Umbraco.Extensions; | ||
|
||
namespace Gibe.Navigation.Umbraco.Models | ||
{ | ||
public class UmbracoNavigationElement : PublishedContentModel, INavigationElement | ||
{ | ||
public UmbracoNavigationElement(IPublishedContent content) : base(content, new NoopPublishedValueFallback()) | ||
{ | ||
Items = new List<INavigationElement>(); | ||
} | ||
|
||
public string Title => base.Name; | ||
public string NavTitle => this.Value<string>("NavTitle"); | ||
public bool IsActive { get; set; } | ||
public IEnumerable<INavigationElement> Items { get; set; } | ||
public string Target => "_self"; | ||
public bool IsVisible => !this.HasValue("umbracoNaviHide") || | ||
!this.Value<bool>("umbracoNaviHide"); | ||
public bool IsConcrete => true; | ||
public bool HasVisibleChildren => Items.Any(x => x.IsVisible); | ||
public string Url => this.Url(); | ||
|
||
public Dictionary<string, object> ExtraProperties { get; set; } | ||
|
||
public object Clone() | ||
{ | ||
return new UmbracoNavigationElement(this) | ||
{ | ||
IsActive = IsActive, | ||
Items = Items.Select(i => (INavigationElement)i.Clone()).ToList(), | ||
ExtraProperties = ExtraProperties | ||
}; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return obj is UmbracoNavigationElement && Equals((UmbracoNavigationElement)obj); | ||
} | ||
|
||
protected bool Equals(UmbracoNavigationElement other) | ||
{ | ||
return | ||
string.Equals(Title, other.Title) && | ||
string.Equals(NavTitle, other.NavTitle) && | ||
string.Equals(Url, other.Url) && | ||
IsActive == other.IsActive && | ||
Items.SequenceEqual(other.Items) && | ||
IsVisible == other.IsVisible; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = Title?.GetHashCode() ?? 0; | ||
hashCode = (hashCode * 397) ^ (NavTitle?.GetHashCode() ?? 0); | ||
hashCode = (hashCode * 397) ^ (Url?.GetHashCode() ?? 0); | ||
hashCode = (hashCode * 397) ^ IsActive.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ (Items?.GetHashCode() ?? 0); | ||
hashCode = (hashCode * 397) ^ IsVisible.GetHashCode(); | ||
return hashCode; | ||
} | ||
} | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationRedirectElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Gibe.Navigation.Models; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
using Umbraco.Extensions; | ||
|
||
namespace Gibe.Navigation.Umbraco.Models | ||
{ | ||
public class UmbracoNavigationRedirectElement : PublishedContentModel, INavigationElement | ||
{ | ||
public UmbracoNavigationRedirectElement(IPublishedContent content) : base(content, new NoopPublishedValueFallback()) | ||
{ | ||
|
||
} | ||
|
||
public string Title => base.Name; | ||
|
||
public string NavTitle => this.Value<string>("NavTitle"); | ||
|
||
private Link Redirect => this.Value<Link>("gibeNavigationRedirect"); | ||
|
||
public new string Url => Redirect?.Url; | ||
|
||
public bool IsActive { get; set; } | ||
public IEnumerable<INavigationElement> Items { get; set; } | ||
|
||
public string Target => Redirect?.Target; | ||
|
||
public bool IsVisible => !this.HasValue("umbracoNaviHide") || | ||
!this.Value<bool>("umbracoNaviHide"); | ||
public bool IsConcrete => false; | ||
public bool HasVisibleChildren => Items.Any(x => x.IsVisible); | ||
|
||
public Dictionary<string, object> ExtraProperties { get; set; } | ||
|
||
public object Clone() | ||
{ | ||
return new UmbracoNavigationRedirectElement(this) | ||
{ | ||
IsActive = IsActive, | ||
Items = Items.Select(i => (INavigationElement)i.Clone()).ToList(), | ||
}; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return obj is UmbracoNavigationRedirectElement && Equals((UmbracoNavigationRedirectElement)obj); | ||
} | ||
|
||
protected bool Equals(UmbracoNavigationRedirectElement other) | ||
{ | ||
return | ||
string.Equals(Title, other.Title) && | ||
string.Equals(NavTitle, other.NavTitle) && | ||
string.Equals(Redirect, other.Redirect) && | ||
IsActive == other.IsActive && | ||
Items.SequenceEqual(other.Items) && | ||
IsVisible == other.IsVisible; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = Title?.GetHashCode() ?? 0; | ||
hashCode = (hashCode * 397) ^ (NavTitle?.GetHashCode() ?? 0); | ||
hashCode = (hashCode * 397) ^ (Redirect?.GetHashCode() ?? 0); | ||
hashCode = (hashCode * 397) ^ IsActive.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ (Items?.GetHashCode() ?? 0); | ||
hashCode = (hashCode * 397) ^ IsVisible.GetHashCode(); | ||
return hashCode; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Gibe.Navigation.Models; | ||
using Gibe.Navigation.Umbraco.Models; | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
using Umbraco.Extensions; | ||
|
||
|
||
namespace Gibe.Navigation.Umbraco | ||
{ | ||
public class NavigationElementFactory : INavigationElementFactory | ||
{ | ||
public INavigationElement Make(IPublishedContent content) | ||
{ | ||
var model = IsRedirect(content) | ||
? new UmbracoNavigationRedirectElement(content) | ||
: (INavigationElement)new UmbracoNavigationElement(content); | ||
|
||
model = HyrdateExtraProperties(content, model); | ||
|
||
return model; | ||
} | ||
|
||
private bool IsRedirect(IPublishedContent content) | ||
{ | ||
return content.HasValue("gibeNavigationRedirect"); | ||
} | ||
|
||
public virtual INavigationElement HyrdateExtraProperties(IPublishedContent content, INavigationElement element) | ||
{ | ||
return element; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.