-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vertical navigation changes (#161)
* feat: made urls use new slug value instead of internal name * chore: cleanedup lint issues * chore: linter issue * fix: updated tests for slug change * fix: updated tests for slug change * feat: now uses csPage heading when no page available or when new useParentHero option is selected in contentful * feat: added unsupported element when item type isn't recognised * Removed tests for removed endpoints * Update src/Dfe.ContentSupport.Web/Views/Shared/_VerticalNavigation.cshtml Co-authored-by: jimwashbrook <[email protected]> * chore: fixed formatting in test * chore: removed redundant case * changes method back to not static and removed Privacy.cshtml --------- Co-authored-by: Tom Whittington <[email protected]> Co-authored-by: jimwashbrook <[email protected]>
- Loading branch information
1 parent
c482ff4
commit 4075583
Showing
21 changed files
with
171 additions
and
180 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
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Dfe.ContentSupport.Web.Models; | ||
|
||
[ExcludeFromCodeCoverage] | ||
public class ContentBase : Contentful.Core.Models.Entry<ContentBase> | ||
{ | ||
public string InternalName { get; set; } = null!; | ||
|
||
public string? Title { get; set; } = null; | ||
|
||
public string? Subtitle { get; set; } = null; | ||
public string Slug { get; set; } = null!; | ||
public string? Title { get; set; } | ||
public string? Subtitle { get; set; } | ||
} |
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
using Dfe.ContentSupport.Web.Models.Mapped; | ||
|
||
namespace Dfe.ContentSupport.Web.Services | ||
{ | ||
public interface ILayoutService | ||
{ | ||
CsPage GenerateLayout(CsPage page, HttpRequest request, string pageName); | ||
namespace Dfe.ContentSupport.Web.Services; | ||
|
||
} | ||
} | ||
public interface ILayoutService | ||
{ | ||
CsPage GenerateLayout(CsPage page, HttpRequest request, string pageSlug); | ||
} |
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 |
---|---|---|
@@ -1,85 +1,78 @@ | ||
using Dfe.ContentSupport.Web.Models; | ||
using Dfe.ContentSupport.Web.Models.Mapped; | ||
|
||
namespace Dfe.ContentSupport.Web.Services; | ||
|
||
namespace Dfe.ContentSupport.Web.Services | ||
public class LayoutService : ILayoutService | ||
{ | ||
public class LayoutService : ILayoutService | ||
public CsPage GenerateLayout(CsPage page, HttpRequest request, string pageSlug) | ||
{ | ||
public CsPage GenerateLayout(CsPage page, HttpRequest request, string pageName) | ||
{ | ||
if (!page.ShowVerticalNavigation) return page; | ||
|
||
return new() | ||
{ | ||
Heading = GetHeading(page, pageName), | ||
MenuItems = GenerateVerticalNavigation(page, request, pageName), | ||
Content = GetVisiblePageList(page, pageName), | ||
UpdatedAt = page.UpdatedAt, | ||
CreatedAt = page.CreatedAt, | ||
HasCitation = page.HasCitation, | ||
HasBackToTop = page.HasBackToTop, | ||
IsSitemap = page.IsSitemap, | ||
ShowVerticalNavigation = page.ShowVerticalNavigation, | ||
Slug = page.Slug, | ||
}; | ||
} | ||
|
||
if (!page.ShowVerticalNavigation) return page; | ||
|
||
public Heading GetHeading(CsPage page, string pageName) | ||
return new CsPage | ||
{ | ||
var selectedPage = page.Content.Find(o => o.InternalName == pageName); | ||
Heading = GetHeading(page, pageSlug), | ||
MenuItems = GenerateVerticalNavigation(page, request, pageSlug), | ||
Content = GetVisiblePageList(page, pageSlug), | ||
UpdatedAt = page.UpdatedAt, | ||
CreatedAt = page.CreatedAt, | ||
HasCitation = page.HasCitation, | ||
HasBackToTop = page.HasBackToTop, | ||
IsSitemap = page.IsSitemap, | ||
ShowVerticalNavigation = page.ShowVerticalNavigation, | ||
Slug = page.Slug | ||
}; | ||
} | ||
|
||
if (selectedPage != null) | ||
return new() | ||
{ | ||
Title = selectedPage.Title ?? "", | ||
Subtitle = selectedPage.Subtitle ?? "" | ||
}; | ||
|
||
public Heading GetHeading(CsPage page, string pageSlug) | ||
{ | ||
var selectedPage = page.Content.Find(o => o.Slug == pageSlug); | ||
|
||
return new() | ||
if (selectedPage is { UseParentHero: false }) | ||
return new Heading | ||
{ | ||
Title = page.Content[0]?.Title ?? "", | ||
Subtitle = page.Content[0]?.Subtitle ?? "" | ||
Title = selectedPage.Title ?? string.Empty, | ||
Subtitle = selectedPage.Subtitle ?? string.Empty | ||
}; | ||
} | ||
|
||
return page.Heading; | ||
} | ||
|
||
public List<PageLink> GenerateVerticalNavigation(CsPage page, HttpRequest request, string pageName) | ||
{ | ||
var baseUrl = GetNavigationUrl(request); | ||
|
||
var menuItems = page.Content.Select(o => new PageLink() | ||
{ | ||
Title = o.Title ?? "", | ||
Subtitle = o.Subtitle ?? "", | ||
Url = $"{baseUrl}/{o.InternalName}", | ||
IsActive = pageName == o.InternalName | ||
}).ToList(); | ||
public List<PageLink> GenerateVerticalNavigation(CsPage page, HttpRequest request, | ||
string pageSlug) | ||
{ | ||
var baseUrl = GetNavigationUrl(request); | ||
|
||
if (string.IsNullOrEmpty(pageName) && menuItems.Count > 0) | ||
menuItems[0].IsActive = true; | ||
var menuItems = page.Content.Select(o => new PageLink | ||
{ | ||
Title = o.Title ?? "", | ||
Subtitle = o.Subtitle ?? "", | ||
Url = $"{baseUrl}/{o.Slug}", | ||
IsActive = pageSlug == o.Slug | ||
}).ToList(); | ||
|
||
return menuItems; | ||
} | ||
if (string.IsNullOrEmpty(pageSlug) && menuItems.Count > 0) | ||
menuItems[0].IsActive = true; | ||
|
||
return menuItems; | ||
} | ||
|
||
public List<CsContentItem> GetVisiblePageList(CsPage page, string pageName) | ||
{ | ||
if (!string.IsNullOrEmpty(pageName)) | ||
return page.Content.Where(o => o.InternalName == pageName).ToList(); | ||
|
||
public List<CsContentItem> GetVisiblePageList(CsPage page, string pageSlug) | ||
{ | ||
if (!string.IsNullOrEmpty(pageSlug)) | ||
return page.Content.Where(o => o.Slug == pageSlug).ToList(); | ||
|
||
return page.Content.GetRange(0, 1); | ||
} | ||
|
||
return page.Content.GetRange(0, 1); | ||
} | ||
|
||
public string GetNavigationUrl(HttpRequest request) | ||
{ | ||
var splitUrl = request.Path.ToString().Split("/"); | ||
return string.Join("/", splitUrl.Take(3)); | ||
} | ||
|
||
public string GetNavigationUrl(HttpRequest request) | ||
{ | ||
var splitUrl = request.Path.ToString().Split("/"); | ||
return string.Join("/", splitUrl.Take(3)); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.