Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Resource details page. #285

Merged
merged 4 commits into from
Sep 27, 2023
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 @@ -24,6 +24,7 @@ public class EntityResolverTests
[TestCase("imageCard", typeof(ImageCard))]
[TestCase("linkCard", typeof(LinkCard))]
[TestCase("linkListCard", typeof(LinkListCard))]
[TestCase("resource", typeof(Resource))]
[TestCase("richTextBlock", typeof(RichTextBlock))]
[TestCase("roleList", typeof(RoleList))]
[TestCase("sideMenu", typeof(SideMenu))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class PartialsFactoryTests
new object[] { new LinkCard(), "_LinkCard" },
new object[] { new ImageCard(), "_ImageCard" },
new object[] { new LinkListCard(), "_LinkListCard" },
new object[] { new Resource(), "_Resource" },
new object[] { new RichTextBlock(), "_RichTextBlock" },
new object[] { new RoleList(), "_RoleList" },
new object[] { new SideMenu(), "_SideMenu" },
Expand Down
1 change: 1 addition & 0 deletions Childrens-Social-Care-CPD/Contentful/EntityResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public Type Resolve(string contentTypeId)
"imageCard" => typeof(ImageCard),
"linkCard" => typeof(LinkCard),
"linkListCard" => typeof(LinkListCard),
"resource" => typeof(Resource),
"richTextBlock" => typeof(RichTextBlock),
"roleList" => typeof(RoleList),
"sideMenu" => typeof(SideMenu),
Expand Down
15 changes: 15 additions & 0 deletions Childrens-Social-Care-CPD/Contentful/Models/Resource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Contentful.Core.Models;

namespace Childrens_Social_Care_CPD.Contentful.Models;

public class Resource : IContent
{
public string Id { get; set; }
public string PreHeading { get; set; }
public string Heading { get; set; }
public string Summary { get; set; }
public string ResourceListSummary { get; set; }
public string From { get; set; }
public string ResourceType { get; set; }
public List<IContent> ResourceItems { get; set; }
}
1 change: 1 addition & 0 deletions Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static string GetPartialFor(IContent item)
case (ImageCard): return "_ImageCard";
case (LinkCard): return "_LinkCard";
case (LinkListCard): return "_LinkListCard";
case (Resource): return "_Resource";
case (RichTextBlock): return "_RichTextBlock";
case (RoleList): return "_RoleList";
case (SideMenu): return "_SideMenu";
Expand Down
2 changes: 1 addition & 1 deletion Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</a>
</li>
<li class="dfe-header__navigation-item" id="mmi-resources">
<a class="dfe-header__navigation-link" href="/training-resources">
<a class="dfe-header__navigation-link" href="/resources">
Resources
<svg class="dfe-icon dfe-icon__chevron-right" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" width="34" height="34">
<path d="M15.5 12a1 1 0 0 1-.29.71l-5 5a1 1 0 0 1-1.42-1.42l4.3-4.29-4.3-4.29a1 1 0 0 1 1.42-1.42l5 5a1 1 0 0 1 .29.71z"></path>
Expand Down
2 changes: 1 addition & 1 deletion Childrens-Social-Care-CPD/Views/Shared/_Header.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
RenderMenuItem("career", "Career stages", "career-stages", category == "Career information");
RenderMenuItem("developmentProgrammes", "Development programmes", "development-programmes", category == "Development programmes");
RenderMenuItem("exploreRoles", "Explore roles", "explore-roles", category == "Explore roles");
RenderMenuItem("resources", "Resources", "training-resources", category == "Resources");
RenderMenuItem("resources", "Resources", "resources", category == "Resources");

}
</ul>
Expand Down
49 changes: 49 additions & 0 deletions Childrens-Social-Care-CPD/Views/Shared/_Resource.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@using Childrens_Social_Care_CPD.Contentful;
@using Childrens_Social_Care_CPD.Contentful.Models;
@using Childrens_Social_Care_CPD.Contentful.Renderers;
@using Contentful.Core.Models;

@model Resource

<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">
<span class="govuk-caption-l">@Model.PreHeading</span>
<h1 class="govuk-heading-xl">@Model.Heading</h1>
</div>
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">
@{
<ul class="govuk-list">
<li>
<span class="govuk-!-font-size-16"><span class="govuk-!-font-size-16 govuk-!-font-weight-bold">From: </span>@Model.From</span>
</li>
<li>
<span class="govuk-!-font-size-16"><span class="govuk-!-font-size-16 govuk-!-font-weight-bold">Resource Type: </span>: @Model.ResourceType</span>
</li>
</ul>

ContextModel model = (ContextModel)ViewBag.ContextModel;
// We use the content stack to track circular dependencies and prevent overflows
model.ContentStack.Push(Model.Id);

if (Model.ResourceItems != null)
{
foreach (var item in Model.ResourceItems)
{
var preventOverflow = item as Content;
if (preventOverflow != null && model.ContentStack.Contains(preventOverflow.Id))
{
<partial name="_OverflowWarning" />
continue;
}

await Html.RenderContentfulPartialAsync(item);
}
}

model.ContentStack.Pop();
}
</div>
</div>