diff --git a/Childrens-Social-Care-CPD/Contentful/Models/Resource.cs b/Childrens-Social-Care-CPD/Contentful/Models/Resource.cs index 5e7ba1ef..dbb8467e 100644 --- a/Childrens-Social-Care-CPD/Contentful/Models/Resource.cs +++ b/Childrens-Social-Care-CPD/Contentful/Models/Resource.cs @@ -1,15 +1,20 @@ using Contentful.Core.Models; +using Newtonsoft.Json; 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 Title { get; set; } public string From { get; set; } - public string ResourceType { get; set; } - public List ResourceItems { get; set; } + public List Type { get; set; } + public string Summary { get; set; } + public string SearchSummary { get; set; } + public List Items { get; set; } + + // need these for queries + [JsonProperty("$metadata")] + public ContentfulMetadata Metadata { get; set; } + public SystemProperties Sys { get; set; } } diff --git a/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs b/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs index 3eafd507..df7e2d5a 100644 --- a/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs +++ b/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs @@ -4,7 +4,6 @@ using Contentful.Core.Models; using Contentful.Core.Search; using Microsoft.AspNetCore.Mvc; -using System.Reflection; namespace Childrens_Social_Care_CPD.Controllers; @@ -20,8 +19,7 @@ public partial class ResourcesController : Controller { private readonly ILogger _logger; private readonly ICpdContentfulClient _cpdClient; - - private static readonly List _tagInfos = new () { + private static readonly List _tagInfos = new() { new TagInfo("Type", "Case studies", "caseStudies"), new TagInfo("Type", "CPD", "cpd"), new TagInfo("Type", "Direct tools", "directTools"), @@ -30,7 +28,6 @@ public partial class ResourcesController : Controller new TagInfo("Career stage", "Experienced practitioner", "experiencedPractitioner"), new TagInfo("Career stage", "Manager", "manager"), }; - private static readonly IEnumerable _allTags = _tagInfos.Select(x => x.TagName); public ResourcesController(ILogger logger, ICpdContentfulClient cpdClient) @@ -67,11 +64,10 @@ private Task> FetchResourcesContentAsync() return _cpdClient.GetEntries(queryBuilder); } - private Task> FetchResourceSearchResultsAsync(int[] tags, int skip = 0, int limit = 5) + private Task> FetchResourceSearchResultsAsync(int[] tags, int skip = 0, int limit = 5) { - // TODO: we need to have the resources content model - var queryBuilder = QueryBuilder.New - .ContentTypeIs("content") + var queryBuilder = QueryBuilder.New + .ContentTypeIs("resource") .Include(1) .FieldIncludes("metadata.tags.sys.id", GetQueryTags(tags)) .OrderBy("-sys.createdAt") @@ -81,7 +77,7 @@ private Task> FetchResourceSearchResultsAsync(int[ return _cpdClient.GetEntries(queryBuilder); } - private async Task>> GetContentAsync(int[] tags, int skip = 0, int limit = 5) + private async Task>> GetContentAsync(int[] tags, int skip = 0, int limit = 5) { var pageContentTask = FetchResourcesContentAsync(); var searchContentTask = FetchResourceSearchResultsAsync(tags, skip, limit); @@ -90,7 +86,7 @@ private async Task>> GetContentAsyn return Tuple.Create(pageContentTask.Result?.FirstOrDefault(), searchContentTask.Result); } - private Tuple CalculatePaging(ResourcesQuery query) + private static Tuple CalculatePaging(ResourcesQuery query) { var pageSize = 8; var page = Math.Max(query.Page, 1); @@ -99,11 +95,11 @@ private Tuple CalculatePaging(ResourcesQuery query) return Tuple.Create(page, skip, pageSize); } - private string GetPagingFormatString(int[] tags) + private static string GetPagingFormatString(int[] tags) { var tagStrings = tags.Select(x => $"tags={x}"); var qsTags = string.Join("&", tagStrings); - + return string.IsNullOrEmpty(qsTags) ? $"/resources?page={{0}}" : $"/resources?page={{0}}&{qsTags}"; @@ -111,7 +107,7 @@ private string GetPagingFormatString(int[] tags) [Route("resources", Name = "Resource")] [HttpGet] - public async Task Index([FromQuery] ResourcesQuery query, bool preferencesSet = false) + public async Task Search([FromQuery] ResourcesQuery query, bool preferencesSet = false) { query ??= new ResourcesQuery(); query.Tags ??= Array.Empty(); diff --git a/Childrens-Social-Care-CPD/Models/ResourcesListViewModel.cs b/Childrens-Social-Care-CPD/Models/ResourcesListViewModel.cs index 761b4e3d..9f453d8f 100644 --- a/Childrens-Social-Care-CPD/Models/ResourcesListViewModel.cs +++ b/Childrens-Social-Care-CPD/Models/ResourcesListViewModel.cs @@ -6,7 +6,7 @@ namespace Childrens_Social_Care_CPD.Models; public record ResourcesListViewModel( Content Content, - ContentfulCollection SearchResults, + ContentfulCollection SearchResults, IEnumerable TagInfos, int[] SelectedTags, int CurrentPage = 0, diff --git a/Childrens-Social-Care-CPD/TagHelpers/GovUkPaginationTagHelper.cs b/Childrens-Social-Care-CPD/TagHelpers/GovUkPaginationTagHelper.cs index 256034f1..401d96c4 100644 --- a/Childrens-Social-Care-CPD/TagHelpers/GovUkPaginationTagHelper.cs +++ b/Childrens-Social-Care-CPD/TagHelpers/GovUkPaginationTagHelper.cs @@ -20,6 +20,12 @@ public class GovUkPaginationTagHelper : TagHelper public override void Process(TagHelperContext context, TagHelperOutput output) { + if (PageCount == 0) + { + output.TagName = null; + return; + } + output.TagName = "nav"; output.TagMode = TagMode.StartTagAndEndTag; output.AddClass("govuk-pagination", HtmlEncoder.Default); diff --git a/Childrens-Social-Care-CPD/Views/Resources/Index.cshtml b/Childrens-Social-Care-CPD/Views/Resources/Search.cshtml similarity index 93% rename from Childrens-Social-Care-CPD/Views/Resources/Index.cshtml rename to Childrens-Social-Care-CPD/Views/Resources/Search.cshtml index 455c46df..dc4fbe9b 100644 --- a/Childrens-Social-Care-CPD/Views/Resources/Index.cshtml +++ b/Childrens-Social-Care-CPD/Views/Resources/Search.cshtml @@ -116,7 +116,7 @@

There are no matching results.

Improve your search results by:

    -
  • removing filters
  • +
  • adding or removing filters
  • @*
  • double-checking your spelling
  • using fewer keywords
  • @@ -132,10 +132,13 @@ } -
    -
    - + if (Model.TotalPages > 1) + { +
    +
    + +
    -
    + } } } \ No newline at end of file diff --git a/Childrens-Social-Care-CPD/Views/Resources/_SearchResult.cshtml b/Childrens-Social-Care-CPD/Views/Resources/_SearchResult.cshtml index 75917a75..d5b8736d 100644 --- a/Childrens-Social-Care-CPD/Views/Resources/_SearchResult.cshtml +++ b/Childrens-Social-Care-CPD/Views/Resources/_SearchResult.cshtml @@ -1,15 +1,13 @@ @using Childrens_Social_Care_CPD.Contentful.Models; -@model Content +@model Resource -@{ var createdAt = (DateTime)Model.Sys.CreatedAt; }
    -

    @Model.Title

    -

    - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla interdum laoreet lacinia. Phasellus fringilla ligula at leo rutrum eleifend. - Nulla tempor, massa in congue lobortis, lectus turpis vulputate tellus, eget cursus massa orci eu purus. Aenean non dui libero. -

    -
      -
    • Created:
    • +

      @Model.Title

      +

      @Model.SearchSummary

      +
        +
      • From: @Model.From
      • +
      • Update:
      • +
      • Resource type: @string.Join(", ", Model.Type.ToArray())
    \ No newline at end of file diff --git a/Childrens-Social-Care-CPD/Views/Shared/_Resource.cshtml b/Childrens-Social-Care-CPD/Views/Shared/_Resource.cshtml index 9f927d74..3089dcf5 100644 --- a/Childrens-Social-Care-CPD/Views/Shared/_Resource.cshtml +++ b/Childrens-Social-Care-CPD/Views/Shared/_Resource.cshtml @@ -1,36 +1,77 @@ -@using Childrens_Social_Care_CPD.Contentful; -@using Childrens_Social_Care_CPD.Contentful.Models; -@using Childrens_Social_Care_CPD.Contentful.Renderers; -@using Contentful.Core.Models; +@using Childrens_Social_Care_CPD.Contentful +@using Childrens_Social_Care_CPD.Contentful.Models +@using Childrens_Social_Care_CPD.Contentful.Renderers +@using Contentful.Core.Models +@using Childrens_Social_Care_CPD.Controllers +@using Microsoft.AspNetCore.Html @model Resource
    - @Model.PreHeading -

    @Model.Heading

    + Resources +

    @Model.Title

    +

    @Model.Summary

    +
    - @{ -
      -
    • - From: @Model.From -
    • -
    • - Resource Type: : @Model.ResourceType -
    • -
    +
    +
    +
    + From +
    +
    + @Model.From +
    +
    + @if (Model.Sys.CreatedAt.HasValue) + { +
    +
    + Published +
    +
    + @Model.Sys.CreatedAt?.ToString("dd MMMM yyyy") +
    +
    + } + @if (Model.Sys.UpdatedAt.HasValue) + { +
    +
    + Updated +
    +
    + @Model.Sys.UpdatedAt?.ToString("dd MMMM yyyy") +
    +
    + } +
    +
    + Resource type +
    +
    + @string.Join(", ", Model.Type.ToArray()) +
    +
    +
    +
    +
    + +
    +
    + @{ ContextModel model = (ContextModel)ViewBag.ContextModel; // We use the content stack to track circular dependencies and prevent overflows - model.ContentStack.Push(Model.Id); + model.ContentStack.Push(Model.Title); - if (Model.ResourceItems != null) + if (Model.Items != null) { - foreach (var item in Model.ResourceItems) + foreach (var item in Model.Items) { var preventOverflow = item as Content; if (preventOverflow != null && model.ContentStack.Contains(preventOverflow.Id))