Skip to content

Commit

Permalink
Merge branch 'Development' of https://github.com/DFE-Digital/sts-cont…
Browse files Browse the repository at this point in the history
…ent-support into Development
  • Loading branch information
simonjfirth committed Aug 7, 2024
2 parents d346c5a + 8b49d3e commit 80c7119
Show file tree
Hide file tree
Showing 39 changed files with 385 additions and 110 deletions.
27 changes: 25 additions & 2 deletions src/Dfe.ContentSupport.Web/Controllers/SitemapController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
using Dfe.ContentSupport.Web.Services;
using Dfe.ContentSupport.Web.Models.Mapped;
using Dfe.ContentSupport.Web.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Dfe.ContentSupport.Web.Controllers;

[Route("/sitemap")]
[AllowAnonymous]
public class SitemapController(IContentService contentfulService) : Controller
{
public async Task<IActionResult> Index()
[HttpGet]
[Route("/")]
public IActionResult Index()
{
var defaultModel = new CsPage
{
Heading = new Models.Heading
{
Title = "Department for Education",
Subtitle = "Content and Support"
}
};


return View(defaultModel);
}

[HttpGet]
[Route("/sitemap.xml")]
public async Task<IActionResult> Sitemap()
{
var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/";
var sitemap = await contentfulService.GenerateSitemap(baseUrl);
Expand Down
9 changes: 9 additions & 0 deletions src/Dfe.ContentSupport.Web/Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Dfe.ContentSupport.Web.Extensions;

public static class DateTimeExtensions
{
public static string ToLongString(this DateTime dateTime)
{
return dateTime.ToString("dd MMMM yyyy");
}
}
2 changes: 1 addition & 1 deletion src/Dfe.ContentSupport.Web/Models/ContentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Dfe.ContentSupport.Web.Models;

[ExcludeFromCodeCoverage]
public class ContentBase
public class ContentBase : ContentType
{
public string InternalName { get; set; } = null!;
}
3 changes: 1 addition & 2 deletions src/Dfe.ContentSupport.Web/Models/ContentItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace Dfe.ContentSupport.Web.Models;

[ExcludeFromCodeCoverage]
public class ContentItemBase
public class ContentItemBase:ContentBase
{
public string InternalName { get; set; } = null!;
public string NodeType { get; set; } = null!;
public Data Data { get; set; } = null!;
public List<ContentItem> Content { get; set; } = [];
Expand Down
4 changes: 4 additions & 0 deletions src/Dfe.ContentSupport.Web/Models/Mapped/CsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ public class CsPage
public Heading Heading { get; set; } = null!;
public string Slug { get; set; } = null!;
public bool IsSitemap { get; set; }
public bool HasCitation { get; set; }
public bool HasBackToTop { get; set; }
public List<CsContentItem> Content { get; set; } = null!;
public DateTime? CreatedAt { get; init; }
public DateTime? UpdatedAt { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public CustomAccordion()
}

public List<CustomAccordion> Accordions { get; set; } = null!;
public string Body { get; set; } = null!;
public RichTextContentItem? Body { get; set; }
public string SummaryLine { get; set; } = null!;
public string Title { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dfe.ContentSupport.Web.Models.Mapped.Types;
using Dfe.ContentSupport.Web.Models.Mapped.Types;
using System.Diagnostics.CodeAnalysis;

namespace Dfe.ContentSupport.Web.Models.Mapped.Custom;
Expand All @@ -15,4 +15,5 @@ public CustomAttachment()
public long Size { get; set; }
public string Title { get; set; } = null!;
public string Uri { get; set; } = null!;
public DateTime? UpdatedAt { get; set; } = null!;
}
2 changes: 2 additions & 0 deletions src/Dfe.ContentSupport.Web/Models/Sys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class Sys
{
public string Id { get; set; } = null!;
public ContentType? ContentType { get; set; } = null!;
public DateTime? CreatedAt { get; init; }
public DateTime? UpdatedAt { get; init; }
}
2 changes: 0 additions & 2 deletions src/Dfe.ContentSupport.Web/Models/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ namespace Dfe.ContentSupport.Web.Models;
public class Target : Entry
{
public Fields Fields { get; set; } = null!;
public Sys Sys { get; set; } = null!;
public string Title { get; set; } = null!;
public Asset Asset { get; set; } = null!;
public string SummaryLine { get; set; } = null!;
public string Body { get; set; } = null!;
public string Description { get; set; } = null!;
public string Meta { get; set; } = null!;
public string ImageAlt { get; set; } = null!;
Expand Down
5 changes: 1 addition & 4 deletions src/Dfe.ContentSupport.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void Main(string[] args)
app.UseCookiePolicy();

app.MapControllerRoute(
"sitemap",
"Default",
"sitemap.xml",
new { controller = "Sitemap", action = "Index" }
);
Expand All @@ -52,9 +52,6 @@ public static void Main(string[] args)
pattern: "{controller=Cache}/{action=Clear}"
);

app.MapControllerRoute(
name: "home",
pattern: "{controller=Home}/{action=Home}");

app.MapControllerRoute(
name: "slug",
Expand Down
17 changes: 11 additions & 6 deletions src/Dfe.ContentSupport.Web/Services/ModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public CsPage MapToCsPage(ContentSupportPage incoming)
Heading = incoming.Heading,
Slug = incoming.Slug,
IsSitemap = incoming.IsSitemap,
Content = MapEntriesToContent(incoming.Content)
HasCitation = incoming.HasCitation,
HasBackToTop = incoming.HasBackToTop,
Content = MapEntriesToContent(incoming.Content),
CreatedAt = incoming.Sys.CreatedAt,
UpdatedAt = incoming.Sys.UpdatedAt
};
return result;
}
Expand Down Expand Up @@ -124,7 +128,7 @@ public List<RichTextContentItem> MapRichTextNodes(List<ContentItem> nodes)
default:
return null;
}

item.Content = MapRichTextNodes(contentItem.Content);
item.Value = contentItem.Value;
item.InternalName = internalName;
Expand All @@ -150,7 +154,7 @@ private CustomAccordion GenerateCustomAccordion(Target target)
return new CustomAccordion
{
InternalName = target.InternalName,
Body = target.Body,
Body = MapRichTextContent(target.RichText),
SummaryLine = target.SummaryLine,
Title = target.Title,
Accordions = target.Content.Select(GenerateCustomAccordion).ToList()
Expand All @@ -165,7 +169,8 @@ private CustomAttachment GenerateCustomAttachment(Target target)
ContentType = target.Asset.File.ContentType,
Size = target.Asset.File.Details.Size,
Title = target.Title,
Uri = target.Asset.File.Url
Uri = target.Asset.File.Url,
UpdatedAt = target.Asset.SystemProperties.UpdatedAt
};
}

Expand Down Expand Up @@ -220,8 +225,8 @@ public RichTextNodeType ConvertToRichTextNodeType(string str)
_ => RichTextNodeType.Unknown
};
}


public AssetContentType ConvertToAssetContentType(string str)
{
if (supportedAssetTypes.ImageTypes.Contains(str)) return AssetContentType.Image;
Expand Down
6 changes: 2 additions & 4 deletions src/Dfe.ContentSupport.Web/ViewModels/ContentSupportPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class ContentSupportPage : ContentBase

public bool DisplayBackButton { get; init; }
public bool IsSitemap { get; init; }

public DateTime? CreatedAt { get; init; }

public DateTime? UpdatedAt { get; init; }
public bool HasCitation { get; init; }
public bool HasBackToTop { get; init; }
}
23 changes: 19 additions & 4 deletions src/Dfe.ContentSupport.Web/Views/Content/CsIndex.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
Layout = "_CsLayout";
}

@foreach (var content in Model.Content)
{
<partial name="_Content" model="@content"/>
}
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">

@foreach (var content in Model.Content)
{
<partial name="_Content" model="@content" />
}

@if (Model.HasCitation)
{
<partial name="_Citation" model="Model" />
}

@if (Model.HasBackToTop)
{
<partial name="_BackToTop" />
}
</div>
</div>
4 changes: 2 additions & 2 deletions src/Dfe.ContentSupport.Web/Views/Content/Home.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<h3 class="govuk-heading-m">
<a href="@url" class="govuk-link govuk-link--no-visited-state dfe-card-link--header">@csPage.Heading.Title</a>
</h3>
<p>@csPage.Heading.Subtitle</p>
<p>Slug: @csPage.Slug</p>
<p class="govuk-body">@csPage.Heading.Subtitle</p>
<p class="govuk-body">Slug: @csPage.Slug</p>
</div>
</div>
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dfe.ContentSupport.Web/Views/Content/Privacy.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
<p class="govuk-body">Use this page to detail your site's privacy policy.</p>
4 changes: 2 additions & 2 deletions src/Dfe.ContentSupport.Web/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

@if (Model.ShowRequestId)
{
<p>
<p class="govuk-body">
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
</p class="govuk-body">
}

<h3>Development Mode</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
</div>
<div id="@accordion.InternalName-content" class="govuk-accordion__section-content">
<p class="govuk-body">@accordion.Body</p>
<partial name="RichText/_RichText" model="@accordion.Body"/>
</div>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,64 @@
@using System
@model CustomAttachment

<section class="attachment govuk-!-margin-top-8">
<div class="attachment-thumbnail">
<a href="@Model.Uri" download>
@{
var fileExtension = Model.ContentType.Split('/').Last().ToLower();
switch (fileExtension)
{
case "pdf":
<img src="/assets/images/pdf-file-icon.svg" alt="pdf file type">
break;
case "csv":
case "xls":
case "xlsx":
<img src="/assets/images/spreadsheet-file-icon.svg" alt="spreadsheet file type" />
break;
case "html":
case "htm":
<img src="/assets/images/html-file-icon.svg" alt="html file type">
break;
default:
<img src="/assets/images/generic-file-icon.svg" alt="generic file type">
break;
<div class="guidance-container govuk-!-padding-8 govuk-!-margin-bottom-8">
<div class="attachment">
<div class="attachment-thumbnail govuk-!-margin-right-8">
<a href="@Model.Uri" download>
@{
var fileExtension = Model.ContentType.Split('/').Last().ToLower();
if (fileExtension == "vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
fileExtension = "xlsx";
}

switch (fileExtension)
{
case "pdf":
<img src="/assets/images/pdf-file-icon.svg" alt="pdf file type">
break;
case "csv":
case "xls":
case "xlsx":
<img src="/assets/images/spreadsheet-file-icon.svg" alt="spreadsheet file type" />
break;
case "html":
case "htm":
<img src="/assets/images/html-file-icon.svg" alt="html file type">
break;
default:
<img src="/assets/images/generic-file-icon.svg" alt="generic file type">
break;

}
}
}


</a>
</div>

<div class="attachment-details">
<h2 class="attachment-title">
<a href="@Model.Uri" aria-describedby="file-details"
class="govuk-link attachment-link" download>
@Model.Title
</a>
</h2>
</div>

<div class="attachment-details">
<h2 class="attachment-title">
<a href="@Model.Uri" aria-describedby="file-details" class="govuk-link attachment-link" download>
@Model.Title
</a>
</h2>

<p class="attachment-metadata">
<span class="attachment-attribute" aria-label="file type">@fileExtension.ToUpper()</span>,
<span class="attachment-attribute" aria-label="file size">
@(Model.Size / 1024) KB
</span>
</p>
@if (Model.UpdatedAt.HasValue)
{
<p class="attachment-metadata">
<span class="attachment-attribute" aria-label="updated date">Last updated
@Model.UpdatedAt.Value.ToString("d MMMM yyyy")
</span>
</p>
}
</div>

<p class="attachment-metadata">
<span class="attachment-attribute"
aria-label="file type">@Model.ContentType.Split('/').Last().ToUpper()</span>,
<span class="attachment-attribute" aria-label="file size">
@(Model.Size / 1024) KB
</span>
</p>
</div>
</section>
</div>
4 changes: 2 additions & 2 deletions src/Dfe.ContentSupport.Web/Views/Shared/RichText/_H.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
switch (Model.NodeType)
{
case RichTextNodeType.Heading2:
<h2 class="govuk-!-margin-top-4">
<h2 class="govuk-!-margin-top-4 govuk-heading-l">
<partial name="RichText/_Items" model="@Model"/>
</h2>
break;
case RichTextNodeType.Heading3:
<h3>
<h3 class="govuk-heading-m">
<partial name="RichText/_Items" model="@Model"/>
</h3>
break;
Expand Down
Loading

0 comments on commit 80c7119

Please sign in to comment.