Skip to content

Commit

Permalink
Added citation block (#121)
Browse files Browse the repository at this point in the history
* feat: added citation block

* fix: fixed tests

---------

Co-authored-by: Tom Whittington <[email protected]>
  • Loading branch information
ThomasWhittington and Tom Whittington authored Aug 5, 2024
1 parent 4717926 commit 6c7ee39
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/Dfe.ContentSupport.Web/Controllers/SitemapController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Dfe.ContentSupport.Web.Models.Mapped;
using Dfe.ContentSupport.Web.Services;
using Dfe.ContentSupport.Web.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -12,7 +11,7 @@ public class SitemapController(IContentService contentfulService) : Controller
{
[HttpGet]
[Route("/")]
public async Task<IActionResult> Index()
public IActionResult Index()
{
var defaultModel = new CsPage
{
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: 3 additions & 0 deletions src/Dfe.ContentSupport.Web/Models/Mapped/CsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +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; }
}
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
11 changes: 7 additions & 4 deletions src/Dfe.ContentSupport.Web/Services/ModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public CsPage MapToCsPage(ContentSupportPage incoming)
Heading = incoming.Heading,
Slug = incoming.Slug,
IsSitemap = incoming.IsSitemap,
HasCitation = incoming.HasCitation,
HasBackToTop = incoming.HasBackToTop,
Content = MapEntriesToContent(incoming.Content)
Content = MapEntriesToContent(incoming.Content),
CreatedAt = incoming.Sys.CreatedAt,
UpdatedAt = incoming.Sys.UpdatedAt
};
return result;
}
Expand Down Expand Up @@ -125,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 Down Expand Up @@ -222,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
5 changes: 1 addition & 4 deletions src/Dfe.ContentSupport.Web/ViewModels/ContentSupportPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public class ContentSupportPage : ContentBase

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

public DateTime? CreatedAt { get; init; }

public DateTime? UpdatedAt { get; init; }
}
5 changes: 5 additions & 0 deletions src/Dfe.ContentSupport.Web/Views/Content/CsIndex.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<partial name="_Content" model="@content"/>
}

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

@if (Model.HasBackToTop)
{
<partial name="_BackToTop"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
else
{
<a href="@Model.Uri">
<a href="@Model.Uri" target="_blank">
<partial name="RichText/_Items" model="@Model"/>
</a>
}
6 changes: 4 additions & 2 deletions src/Dfe.ContentSupport.Web/Views/Shared/_BackToTop.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<a class="govuk-link govuk-link--no-visited-state" href="#">
<div id="backtotop-button">
<a class="govuk-link govuk-link--no-visited-state" href="#">
<svg class="app-back-to-top__icon" xmlns="http://www.w3.org/2000/svg" width="13" height="17" viewBox="0 0 13 17">
<path fill="currentColor" d="M6.5 0L0 6.5 1.4 8l4-4v12.7h2V4l4.3 4L13 6.4z"></path>
</svg> Back to top
</a>
</a>
</div>
15 changes: 15 additions & 0 deletions src/Dfe.ContentSupport.Web/Views/Shared/_Citation.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@using Dfe.ContentSupport.Web.Extensions
@model CsPage

<div class="citation">
<div class="gem-c-metadata" data-gem-toggle-module-started="true" data-metadata-module-started="true" data-module="gem-toggle metadata">
<dl class="gem-c-metadata__list" data-gem-track-click-module-started="true" data-module="gem-track-click">
<dt class="gem-c-metadata__term">From:</dt>
<dd class="gem-c-metadata__definition">
<a class="govuk-link" href="https://www.gov.uk/government/organisations/department-for-education">Department for Education</a>
</dd>
<dt class="gem-c-metadata__term">Published:</dt><dd class="gem-c-metadata__definition">@Model.CreatedAt!.Value.ToLongString()</dd>
<dt class="gem-c-metadata__term">Updated:</dt><dd class="gem-c-metadata__definition">@Model.UpdatedAt!.Value.ToLongString()</dd>
</dl>
</div>
</div>
145 changes: 144 additions & 1 deletion src/Dfe.ContentSupport.Web/wwwroot/css/cands-site.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,148 @@ video {

.guidance-container {
border: 1px solid #b1b4b6;

}

#backtotop-button {
margin-top: 2rem;
}

.gem-c-metadata {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 400;
font-size: 14px;
font-size: 0.875rem;
line-height: 1.1429;
}

@media (min-width: 40.0625em) {
.gem-c-metadata {
font-size: 16px;
font-size: 1rem;
line-height: 1.25;
}

.gem-c-metadata a {
font-family: sans-serif;
}

.gem-c-metadata--inverse-padded .gem-c-metadata__list {
margin: 15px;
}

.gem-c-metadata__term {
box-sizing: border-box;
float: left;
clear: left;
padding-right: 5px;
margin-top: 0;
}

.gem-c-metadata__term .gem-c-metadata__definition {
line-height: 1.4;
}

.gem-c-metadata__definition:not(:last-of-type) {
margin-bottom: 5px;
}
}

.gem-c-metadata a {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-decoration: underline;
font-weight: bold;
color: #0b0c0c;
}

.gem-c-metadata .gem-c-metadata::after {
content: "";
display: block;
clear: both;
}

.gem-c-metadata .direction-rtl {
direction: rtl;
text-align: start;
}

.gem-c-metadata-inverse {
color: #ffffff;
}

.gem-c-metadata-inverse a:link,
.gem-c-metadata-inverse a:hover,
.gem-c-metadata-inverse a:visited,
.gem-c-metadata-inverse a:active {
color: #ffffff;
}

.gem-c-metadata-inverse a:focus {
color: #0b0c0c;
}

.gem-c-metadata-inverse-padded {
padding: 10px;
}

.gem-c-metadata-inverse-padded .gem-c-metadata-inverse.gem-c-metadata__list {
margin: 10px;
}

.gem-c-metadata__definition {
margin: 0;
}

.gem-c-metadata__toggle-wrap {
display: none;
}

.gem-c-metadata .gem-c-metadata__definition-link {
font-weight: normal;
}

.gem-c-metadata.direction-rtl .gem-c-metadata__definition {
float: right;
}

@media (min-width: 40.0625em) {
.gem-c-metadata--inverse-padded .gem-c-metadata__list {
margin: 15px;
}
}

@media (min-width: 40.0625em) {
.gem-c-metadata.direction-rtl .gem-c-metadata__term {
padding-left: 5px;
padding-right: 0;
}
}

@media print {
.gem-c-metadata {
color: #000000;
font-family: sans-serif;
font-size: 14pt;
line-height: 1.2;
}
}

.js-enabled .gem-c-metadata__toggle-wrap {
display: block;
}

.js-enabled .gem-c-metadata__toggle-items .js-hidden {
display: none;
}

dl.gem-c-metadata__list {
margin: 0;
}

.citation {
background: rgba(238, 238, 238, 0.4588235294);
padding: 15px 10px 15px 20px;
margin-top: 60px;
border-left: 5px solid #347ca9;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ private SitemapController GetController()
}

[Fact]
public async Task Index_Calls_Service_GenerateSitemap()
public async Task Sitemap_Calls_Service_GenerateSitemap()
{
var sut = GetController();
sut.ControllerContext.HttpContext = new DefaultHttpContext();
var baseUrl =
$"{sut.ControllerContext.HttpContext.Request.Scheme}://{sut.ControllerContext.HttpContext.Request.Host}/";

await sut.Index();
await sut.Sitemap();
_contentServiceMock.Verify(o => o.GenerateSitemap(baseUrl), Times.Once);
}

[Fact]
public async Task Index_Calls_Returns_ContentResult_XmlModel()
public async Task Sitemap_Calls_Returns_ContentResult_XmlModel()
{
const string sitemap = "dummy";
_contentServiceMock.Setup(o => o.GenerateSitemap(It.IsAny<string>()))
Expand All @@ -41,7 +41,7 @@ public async Task Index_Calls_Returns_ContentResult_XmlModel()
var sut = GetController();
sut.ControllerContext.HttpContext = new DefaultHttpContext();

var result = await sut.Index();
var result = await sut.Sitemap();

result.Should().BeEquivalentTo(expected);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Dfe.ContentSupport.Web.Extensions;

namespace Dfe.ContentSupport.Web.Tests.Extensions;

public class DateTimeExtensionsTests
{
[Fact]
public void ToLongString_Formats_Returns_Expected()
{
var testValue = new DateTime(2024, 2, 1, 0, 0, 0, DateTimeKind.Local);
const string expected = "01 February 2024";

var result = testValue.ToLongString();

result.Should().Be(expected);
}
}
Loading

0 comments on commit 6c7ee39

Please sign in to comment.