Skip to content

Commit

Permalink
Added new blocks and some refactors (#138)
Browse files Browse the repository at this point in the history
* Added test project

* Added ADR docs

* Added basic unit tests

* added ADR

* updated folder structure

* restructure

* Added architecture diagram

* More unit tests

* Added DI test

* Added contentful model for richtext

* Updated content service (#82)

* Updated content service

* uncommented tests

* undid spacing change

---------

Co-authored-by: Simon FIRTH <[email protected]>
Co-authored-by: Tom Whittington <[email protected]>

* Created contentful stub

* Updated to query builder

* Add renderer for rich text content (#75)

* add renderer for rich text content

* Add interface for content renderer

* remove unused using statements

* refactor: use partial views to handle rich text rendering

* Add new project for e2e cypress tests

* remove magic strings

* wip: Add mock content for e2e tests

* Update page heading and add support for subheadings

* update mockContent for e2e tests

* add rich text support for horizontal rule

* add support for embedded image assets

* Add support for embedded video

* add support for embedded vimeo player

* Changed views to use explicit models

* Added dev settings to gitignore

* Removed main

---------

Co-authored-by: Tom Whittington <[email protected]>

* updated e2e and app settings

* Updated tests

* Fixed/ added some tests for coverage

* Added tests for HttpClients

* Added service tests

* Refactored tests

---------

Co-authored-by: Tom Whittington <[email protected]>

* Feature/ rework/linking (#86)

* Lowered HR to Hr

* Added support for linking to content

---------

Co-authored-by: Tom Whittington <[email protected]>

* wip: render linked entry and asset from within rich text

* wip: render download component

* display corresponding icon for download filetype

* update e2e tests

* Feature/ rework/embedded entries (#87)

* Added basic support for embeddedEntries

* Added includes to configuration

* Updated tests for new model

* Simplified include logic

* Fixed client test

---------

Co-authored-by: Tom Whittington <[email protected]>

* update entry partial

* revert ContentService changes

* use target variable in entry partial

* tweak entry partial

* update file icons

* Added terraform scripts

* add accordion component

* Added workflows and actions

* adding missing WAF and updated contentful environment

* update integration tests

* wip: add accessibility tweaks, accessibilty tests and page layout updates

* Added support for cards and grid containers. Updated dfeFrontend to 2.0.1 (#91)

* Updated DfeFrontend

* Added basic card support

* Card cleanup

* Added grid container

* Updated svgs

---------

Co-authored-by: Tom Whittington <[email protected]>

* use dfe container width and update header styling

* updated workflow

* TF changes to get inital build going

* fixed tflint

* removed unused vars from pr-check

* added dev environment

* lock updated

* reformatted locals.tf

* terraform-docs: automated action

* include hero in header

* fix e2e tests

* Updated JS + CSS files

* add support for multiple accordion sections

* resolve assets for e2e testing

* Capitalise development branch name (#93)

* Capitalise development branch name

* force workflow to appear in actions

* Matrix deploy push

* made context root

* moved docker file location

* adjusted docker file location

* lowercase dockerfile name

* moved docker file

* updated matrix deploy

* updated deploy script

* updated image name

* revision create change

* Added env variable

* updated to main

* updated cli version

* removed env

* updated workflow to dispatch

* Feature/app insights (#97)

* Capitalise development branch name

* force workflow to appear in actions

* Matrix deploy push

* made context root

* moved docker file location

* adjusted docker file location

* lowercase dockerfile name

* moved docker file

* updated matrix deploy

* updated deploy script

* updated image name

* revision create change

* Added env variable

* updated to main

* updated cli version

* removed env

* updated workflow to dispatch

* Added application insights + secret management

* Feature/vault (#98)

* Capitalise development branch name

* force workflow to appear in actions

* Matrix deploy push

* made context root

* moved docker file location

* adjusted docker file location

* lowercase dockerfile name

* moved docker file

* updated matrix deploy

* updated deploy script

* updated image name

* revision create change

* Added env variable

* updated to main

* updated cli version

* removed env

* updated workflow to dispatch

* Added application insights + secret management

* modified matrix deploy to run on completed PR

* Added Keyvault secret API to application startup

* fixed YAML

* modifed matrix deloy (#100)

* Updated workflow so it can be manually fired (#102)

* modifed matrix deloy

* changed to workflow dispatch

* removed env

* changed keyvault name

* changed keyvault name

* re-added env

* Adding landing page (#104)

* Created temp home page

* updated is Preview to true for home page

* Preview mode bug fixes for home page

---------

Co-authored-by: Tom Whittington <[email protected]>

* Added mapping layer to produce cleaner models (#96)

* Added basic caching layer (#106)

Co-authored-by: Tom Whittington <[email protected]>

* Added cache clear endpoint and ignoring cache when in preview (#107)

* Added cache clear endpoint and ignoring cache when in preview

* Added some tests for caching

* modifed cache controller to API type + respond with OK

* removed unused controller map

---------

Co-authored-by: Tom Whittington <[email protected]>
Co-authored-by: simonjfirth <[email protected]>

* add gtm and clarity tracking to application

* remove unnecessary ms clarity tag

* add cookie consent banner

* remove comments

* change consent cookie values to true or false

* add download last updated date and update styling

* Feature/model mapping refactor (#110)

* Model rework for better testability

* Added better tests for model mapping

---------

Co-authored-by: Tom Whittington <[email protected]>

* Feature/plantech prep (#112)

* Model rework for better testability

* Added better tests for model mapping

* Made modifications to allow c&s to run as part of plantech

---------

Co-authored-by: Tom Whittington <[email protected]>

* Made app settings not publish

* Removed some code smells

* Explicit types in tests

* Feature/update contentful (#113)

* Updated contentful secret value to it doesn't collide with PT integration

* removed temp code

* Cleaned up some more smells (#114)

* Cleaned up some more smells

* changed to index

---------

Co-authored-by: Tom Whittington <[email protected]>

* Hidden cookie banner (#115)

Co-authored-by: Tom Whittington <[email protected]>

* Added default page to handle base route (#116)

* feat: removed header text (#117)

Co-authored-by: Tom Whittington <[email protected]>

* feat: allowed accordions to display richtext (#118)

Co-authored-by: Tom Whittington <[email protected]>

* feat: added support for excel sheets (#119)

Co-authored-by: Tom Whittington <[email protected]>

* feat: added back to top button (#120)

Co-authored-by: Tom Whittington <[email protected]>

* Update download component mapping and styling

* Added citation block (#121)

* feat: added citation block

* fix: fixed tests

---------

Co-authored-by: Tom Whittington <[email protected]>

* feat: use current tab (#122)

Co-authored-by: Tom Whittington <[email protected]>

* Updated styling to elements and added missing classes (#123)

* feature: add feedback banner to all pages

* Removed route sitemap base route which was causing a multiple route match in PT (#125)

* add thankyou message to feedback banner

* feat: render or hide feedback banner based on contentful boolean

* wip: reenable content cookies to test conditional rendering for feedback banner

* Feature/side nav (#128)

* Started to create vertical navigation

* First draft of unit tests

* update to tests

* cleaned unit tests

* Updated JS + CSS files

* Cleanup

* Update to broken unit tests

* reverted flag

* removed ref

* removed unused controller tests

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* remove comment

* Added basic print button (#130)

Co-authored-by: Tom Whittington <[email protected]>

* add plan tech name to header (#131)

* Tidy up (#132)

* Added basic sonar check (#135)

* Added basic sonar check

* Build and test enabled

* Removed manual trigger on deploy

* Removed push builds

* Fixed branch name

---------

Co-authored-by: Tom Whittington <[email protected]>

* feat: update beta banner feedback link

* feat: added basic retry on contentful api calls (#137)

Co-authored-by: Tom Whittington <[email protected]>

---------

Co-authored-by: Tom Whittington <[email protected]>
Co-authored-by: Simon FIRTH <[email protected]>
Co-authored-by: simonjfirth <[email protected]>
Co-authored-by: jack-coggin <[email protected]>
Co-authored-by: jack.coggin <[email protected]>
Co-authored-by: Iain STANGER <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
9 people authored Aug 19, 2024
1 parent aef7257 commit 1f77a3a
Show file tree
Hide file tree
Showing 30 changed files with 881 additions and 117 deletions.
72 changes: 56 additions & 16 deletions .github/workflows/code-pr-check.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Code PR Check

on:
push:
branches: ["main", "Development"]
paths:
- "src/**"
- "tests/**"
pull_request:
branches: ["main", "Development"]
paths:
Expand All @@ -30,16 +25,61 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --verbosity normal

dotnet-version: ${{ env.DOTNET_VERSION }}
cache: false

- name: Install dotnet coverage
run: dotnet tool install --global dotnet-coverage --version 17.9.3

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Install SonarCloud scanners
run: dotnet tool install --global dotnet-sonarscanner

- name: Install latest JDK
uses: actions/setup-java@v4
with:
distribution: "microsoft"
java-version: "17"

# - name: Start SonarCloud scanner
# run: |
# dotnet-sonarscanner begin \
# /k:"DFE-Digital_sts-content-support" \
# /o:"dfe-digital" \
# /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \
# /d:sonar.host.url="https://sonarcloud.io" \
# /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \
# /d:sonar.coverage.exclusions=**/Program.cs,**/wwwroot/** \
# /d:sonar.issue.ignore.multicriteria=e1 \
# /d:sonar.issue.ignore.multicriteria.e1.ruleKey=csharpsquid:S6602 \
# /d:sonar.issue.ignore.multicriteria.e1.resourceKey=src/**/*.cs

- name: Build web app
uses: ./.github/actions/build-dotnet-app
with:
dotnet_version: ${{ env.DOTNET_VERSION }}
solution_filename: sts-contentsupport.sln

- name: Run unit tests
uses: ./.github/actions/run-unit-tests
with:
solution_filename: sts-contentsupport.sln

# - name: Merge test results
# run: dotnet-coverage merge -f xml -o "coverage.xml" -s "coverage.settings.xml" -r coverage.cobertura.xml
#
# - name: End SonarCloud Scanner
# run: dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
#
# - name: Archive code coverage results
# uses: actions/upload-artifact@v4
# with:
# name: code-coverage-report
# path: coverage.xml
#
8 changes: 4 additions & 4 deletions .github/workflows/matrix-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Multi stage build & deploy
on:
workflow_dispatch:
push:
branches: ["main", "development"]
branches: [ "main", "Development" ]
paths:
- "src/**"
- ".github/workflows/matrix-deploy.yml"
Expand Down Expand Up @@ -37,20 +37,20 @@ jobs:
checked-out-sha: ${{ needs.set-env.outputs.checked-out-sha }}

create-and-tag-release:
needs: [set-env, create-and-publish-image]
needs: [ set-env, create-and-publish-image ]
name: Create & Tag Release
uses: ./.github/workflows/create-tag-release.yml
secrets: inherit


deploy-to-dev:
needs: [set-env, create-and-publish-image]
needs: [ set-env, create-and-publish-image ]
name: Deployment to Dev & Test
strategy:
max-parallel: 1
fail-fast: true
matrix:
target: [Dev]
target: [ Dev ]
uses: ./.github/workflows/deploy-image.yml
with:
environment: ${{ matrix.target }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
:root {
--govuk-link-color: #1d70b8;
--govuk-black: #0b0c0c;
}

.dfe-vertical-nav__section-item {
list-style-type: none;
font-size: 1rem;
}

.dfe-vertical-nav__link {
display: block;
padding: 7px 30px 8px 10px;
border-left: 4px solid #b1b4b6;
text-decoration: none;
}

.dfe-vertical-nav__link--selected {
border-left: 4px solid var(--govuk-link-color);
background-color: #f3f2f1;
font-weight: bold;
}

.dfe-vertical-nav__link,
.dfe-vertical-nav__link--selected {
color: var(--govuk-link-color);

&:active, &:hover {
background-color: #fd0;
color: var(--govuk-black);
border-left: 4px solid var(--govuk-black);
font-weight: normal;
}
}

.dfe-vertical-nav__theme {
border-top: 1px solid var(--govuk-link-color);
padding-top: 5px;
margin-top: 10px;
margin-left: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace Dfe.ContentSupport.Web.Configuration;
public class CsContentfulOptions : ContentfulOptions
{
public int IncludeDepth { get; set; } = 10;
public int RetryAttempts { get; set; } = 3;
}
11 changes: 7 additions & 4 deletions src/Dfe.ContentSupport.Web/Controllers/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Dfe.ContentSupport.Web.Controllers;

[Route("/content")]
[AllowAnonymous]
public class ContentController(IContentService contentService)
public class ContentController(IContentService contentService, ILayoutService layoutService)
: Controller
{
public async Task<IActionResult> Home()
Expand All @@ -28,14 +28,17 @@ public async Task<IActionResult> Home()
return View(defaultModel);
}

[HttpGet("{slug}")]
public async Task<IActionResult> Index(string slug, bool isPreview = false)
[HttpGet("{slug}/{page?}")]
public async Task<IActionResult> Index(string slug, string page = "", bool isPreview = false)
{
if (!ModelState.IsValid) return RedirectToAction("error");
if (string.IsNullOrEmpty(slug)) return RedirectToAction("error");

var resp = await contentService.GetContent(slug, isPreview);
if (resp is null) return RedirectToAction("error");

resp = layoutService.GenerateLayout(resp, Request, page);

return View("CsIndex", resp);
}

Expand All @@ -48,6 +51,6 @@ public IActionResult Privacy()
public IActionResult Error()
{
return View(new ErrorViewModel
{ RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
{ RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static void InitCsDependencyInjection(this WebApplicationBuilder app)
app.Services.AddTransient<IModelMapper, ModelMapper>();
app.Services.AddTransient<IContentfulService, ContentfulService>();
app.Services.AddTransient<IContentService, ContentService>();
app.Services.AddTransient<ILayoutService, LayoutService>();

app.Services.Configure<CookiePolicyOptions>(options =>
{
Expand Down
18 changes: 17 additions & 1 deletion src/Dfe.ContentSupport.Web/Http/HttpContentfulClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ public async Task<ContentfulCollection<T>> Query<T>(QueryBuilder<T> queryBuilder
CancellationToken cancellationToken = default) where T : class
{
queryBuilder = queryBuilder.Include(options.IncludeDepth);
return await GetEntries(queryBuilder, cancellationToken);

for (int attempt = 1; attempt <= options.RetryAttempts; attempt++)
{
try
{
return await GetEntries(queryBuilder, cancellationToken);
}
catch (Exception)
{
if (attempt == options.RetryAttempts)
{
throw;
}
}
}

return default!;
}
}
4 changes: 4 additions & 0 deletions src/Dfe.ContentSupport.Web/Models/ContentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ namespace Dfe.ContentSupport.Web.Models;
public class ContentBase : ContentType
{
public string InternalName { get; set; } = null!;

public string? Title { get; set; } = null;

public string? Subtitle { get; set; } = null;
}
2 changes: 2 additions & 0 deletions src/Dfe.ContentSupport.Web/Models/Mapped/CsContentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace Dfe.ContentSupport.Web.Models.Mapped;
public class CsContentItem
{
public string InternalName { get; set; } = null!;
public string? Title { get; set; } = null;
public string? Subtitle { get; set; } = null;
}
5 changes: 5 additions & 0 deletions src/Dfe.ContentSupport.Web/Models/Mapped/CsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ public class CsPage
public string Slug { get; set; } = null!;
public bool IsSitemap { get; set; }
public bool HasCitation { get; set; }
public bool ShowVerticalNavigation { get; set; }
public bool HasBackToTop { get; set; }
public bool HasPrint { get; set; }
public List<CsContentItem> Content { get; set; } = null!;
public DateTime? CreatedAt { get; init; }
public DateTime? UpdatedAt { get; init; }
public bool HasFeedbackBanner { get; set; }
public List<PageLink>? MenuItems { get; set; }

}
10 changes: 10 additions & 0 deletions src/Dfe.ContentSupport.Web/Models/Mapped/PageLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Dfe.ContentSupport.Web.Models.Mapped
{
public class PageLink
{
public string? Title { get; set; } = null;
public string? Subtitle { get; set; } = null;
public required string Url { get; set; }
public required bool IsActive { get; set; }
}
}
4 changes: 3 additions & 1 deletion src/Dfe.ContentSupport.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void Main(string[] args)
builder.Services.AddControllers();
builder.Services.AddControllersWithViews();
builder.Services.AddApplicationInsightsTelemetry();
builder.Services.AddHealthChecks();

builder.Services.AddGovUkFrontend();
builder.Services.AddContentful(builder.Configuration);
Expand All @@ -39,6 +40,7 @@ public static void Main(string[] args)
app.UseRouting();
app.UseAuthorization();
app.UseCookiePolicy();
app.MapHealthChecks("/healthz");

app.MapControllerRoute(
"Default",
Expand All @@ -55,7 +57,7 @@ public static void Main(string[] args)

app.MapControllerRoute(
name: "slug",
pattern: "{slug}",
pattern: "{slug}/{page?}",
defaults: new { controller = "Content", action = "Index" });


Expand Down
10 changes: 10 additions & 0 deletions src/Dfe.ContentSupport.Web/Services/ILayoutService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Dfe.ContentSupport.Web.Models.Mapped;

namespace Dfe.ContentSupport.Web.Services
{
public interface ILayoutService
{
CsPage GenerateLayout(CsPage page, HttpRequest request, string pageName);

}
}
Loading

0 comments on commit 1f77a3a

Please sign in to comment.