Skip to content

Commit

Permalink
Merge branch 'main' into chore/hook-up-advice-page
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-c-dfe authored Jul 3, 2024
2 parents 82985c1 + 9a533ae commit 080d7b8
Show file tree
Hide file tree
Showing 15 changed files with 892 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public static class ContentTypes
public const string DateQuestionPage = "dateQuestionPage";
public const string DropdownQuestionPage = "dropdownQuestionPage";
public const string QualificationListPage = "qualificationListPage";
public const string ConfirmQualificationPage = "confirmQualificationPage";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Dfe.EarlyYearsQualification.Content.Entities;

public class ConfirmQualificationPage
{
public string Heading { get; init; } = string.Empty;
public string QualificationLabel { get; init; } = string.Empty;
public string LevelLabel { get; init; } = string.Empty;
public string AwardingOrganisationLabel { get; init; } = string.Empty;
public string DateAddedLabel { get; init; } = string.Empty;
public string RadioHeading { get; init; } = string.Empty;
public List<Option> Options { get; init; } = [];
public string ErrorBannerHeading { get; init; } = string.Empty;
public string ErrorBannerLink { get; init; } = string.Empty;
public string ErrorText { get; init; } = string.Empty;
public string ButtonText { get; init; } = string.Empty;
public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ private readonly Dictionary<object, string> _contentTypes
{ typeof(CookiesBanner), ContentTypes.CookiesBanner },
{ typeof(DateQuestionPage), ContentTypes.DateQuestionPage },
{ typeof(DropdownQuestionPage), ContentTypes.DropdownQuestionPage },
{ typeof(QualificationListPage), ContentTypes.QualificationListPage }
{ typeof(QualificationListPage), ContentTypes.QualificationListPage },
{ typeof(ConfirmQualificationPage), ContentTypes.ConfirmQualificationPage},
};

public async Task<StartPage?> GetStartPage()
Expand Down Expand Up @@ -169,6 +170,18 @@ public async Task<List<Qualification>> GetQualifications()
return qualifications!.ToList();
}

public async Task<ConfirmQualificationPage?> GetConfirmQualificationPage()
{
var confirmQualificationEntities = await GetEntriesByType<ConfirmQualificationPage>();
if (confirmQualificationEntities is null || !confirmQualificationEntities.Any())
{
logger.LogWarning("No confirm qualification page entry returned");
return default;
}

return confirmQualificationEntities.First();
}

public async Task<QualificationListPage?> GetQualificationListPage()
{
var qualificationListPageEntities = await GetEntriesByType<QualificationListPage>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface IContentService
Task<List<Qualification>> GetQualifications();

Task<QualificationListPage?> GetQualificationListPage();

Task<ConfirmQualificationPage?> GetConfirmQualificationPage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ await Task.FromResult(CreateAdvicePage("Qualifications achieved outside the Unit
BackButton = new NavigationLink
{
DisplayText = "TEST",
Href = "/qualifications",
Href = "/confirm-qualification/eyq-240",
OpenInNewTab = false
}
});
Expand Down Expand Up @@ -215,6 +215,42 @@ public Task<List<Qualification>> GetQualifications()
});
}

public async Task<ConfirmQualificationPage?> GetConfirmQualificationPage()
{
return await Task.FromResult(new ConfirmQualificationPage
{
QualificationLabel = "Test qualification label",
BackButton = new NavigationLink
{
DisplayText = "Test back button",
OpenInNewTab = false,
Href = "/qualifications"
},
ErrorText = "Test error text",
ButtonText = "Test button text",
LevelLabel = "Test level label",
DateAddedLabel = "Test date added label",
Heading = "Test heading",
Options =
[
new Option
{
Label = "yes",
Value = "yes"
},
new Option
{
Label = "no",
Value = "no"
}
],
RadioHeading = "Test radio heading",
AwardingOrganisationLabel = "Test awarding organisation label",
ErrorBannerHeading = "Test error banner heading",
ErrorBannerLink = "Test error banner link"
});
}

public async Task<StartPage?> GetStartPage()
{
var preCtaButtonContent =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using Dfe.EarlyYearsQualification.Content.Entities;
using Dfe.EarlyYearsQualification.Content.Services;
using Dfe.EarlyYearsQualification.Web.Controllers.Base;
using Dfe.EarlyYearsQualification.Web.Models.Content;
using Dfe.EarlyYearsQualification.Web.Models.Content.QuestionModels;
using Microsoft.AspNetCore.Mvc;

namespace Dfe.EarlyYearsQualification.Web.Controllers;

[Route("confirm-qualification")]
public class ConfirmQualificationController(
ILogger<ConfirmQualificationController> logger,
IContentService contentService)
: ServiceController
{
[HttpGet]
[Route("{qualificationId}")]
public async Task<IActionResult> Index(string qualificationId)
{
if (string.IsNullOrEmpty(qualificationId))
{
return BadRequest();
}

var content = await contentService.GetConfirmQualificationPage();

if (content is null)
{
logger.LogError("No content for the cookies page");
return RedirectToAction("Index", "Error");
}

var qualification = await contentService.GetQualificationById(qualificationId);
if (qualification is null)
{
var loggedQualificationId = qualificationId.Replace(Environment.NewLine, "");
logger.LogError("Could not find details for qualification with ID: {QualificationId}",
loggedQualificationId);

return RedirectToAction("Index", "Error");
}

var model = Map(content, qualification);

return View(model);
}

[HttpPost]
public async Task<IActionResult> Confirm(ConfirmQualificationPageModel model)
{
if (!ModelState.IsValid)
{
var content = await contentService.GetConfirmQualificationPage();

if (content is null)
{
logger.LogError("No content for the cookies page");
return RedirectToAction("Index", "Error");
}

if (string.IsNullOrEmpty(model.QualificationId))
{
logger.LogError("No qualification id provided");
return RedirectToAction("Index", "Error");
}

var qualification = await contentService.GetQualificationById(model.QualificationId);
if (qualification is null)
{
var loggedQualificationId = model.QualificationId.Replace(Environment.NewLine, "");
logger.LogError("Could not find details for qualification with ID: {QualificationId}",
loggedQualificationId);

return RedirectToAction("Index", "Error");
}

model = Map(content, qualification);
model.HasErrors = true;

return View("Index", model);
}

return model.ConfirmQualificationAnswer == "yes" ? RedirectToAction("Index", "QualificationDetails", new { qualificationId = model.QualificationId }) : RedirectToAction("Get", "QualificationDetails");
}

private static ConfirmQualificationPageModel Map(ConfirmQualificationPage content, Qualification qualification)
{
return new ConfirmQualificationPageModel
{
Heading = content.Heading,
Options = content.Options.Select(x => new OptionModel { Label = x.Label, Value = x.Value }).ToList(),
ErrorText = content.ErrorText,
LevelLabel = content.LevelLabel,
QualificationLabel = content.QualificationLabel,
RadioHeading = content.RadioHeading,
DateAddedLabel = content.DateAddedLabel,
AwardingOrganisationLabel = content.AwardingOrganisationLabel,
ErrorBannerHeading = content.ErrorBannerHeading,
ErrorBannerLink = content.ErrorBannerLink,
ButtonText = content.ButtonText,
HasErrors = false,
QualificationName = qualification.QualificationName,
QualificationLevel = qualification.QualificationLevel.ToString(),
QualificationId = qualification.QualificationId,
QualificationAwardingOrganisation = qualification.AwardingOrganisationTitle,
QualificationDateAdded = qualification.FromWhichYear!,
BackButton = content.BackButton,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using Dfe.EarlyYearsQualification.Content.Entities;
using Dfe.EarlyYearsQualification.Web.Models.Content.QuestionModels;

namespace Dfe.EarlyYearsQualification.Web.Models.Content;

public class ConfirmQualificationPageModel
{
public string Heading { get; init; } = string.Empty;
public string QualificationLabel { get; init; } = string.Empty;
public string LevelLabel { get; init; } = string.Empty;
public string AwardingOrganisationLabel { get; init; } = string.Empty;
public string DateAddedLabel { get; init; } = string.Empty;
public string RadioHeading { get; init; } = string.Empty;
public List<OptionModel> Options { get; init; } = [];
public bool HasErrors { get; set; } = false;
public string ErrorBannerHeading { get; init; } = string.Empty;
public string ErrorBannerLink { get; init; } = string.Empty;
public string ErrorText { get; init; } = string.Empty;
[Required] public string? ConfirmQualificationAnswer { get; init; } = string.Empty;
public string ButtonText { get; init; } = string.Empty;
[Required] public string QualificationId { get; init; } = string.Empty;
public string QualificationName { get; init; } = string.Empty;
public string QualificationLevel { get; init; } = string.Empty;
public string QualificationAwardingOrganisation { get; init; } = string.Empty;
public string QualificationDateAdded { get; init; } = string.Empty;
public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
@model Dfe.EarlyYearsQualification.Web.Models.Content.ConfirmQualificationPageModel

@{
ViewData["Title"] = "Confirm Qualification";
}

@{
await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton);
}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
@if (Model.HasErrors)
{
<div id="error-banner" class="govuk-error-summary" data-module="govuk-error-summary">
<div role="alert">
<h2 class="govuk-error-summary__title">
@Model.ErrorBannerHeading
</h2>
<div class="govuk-error-summary__body">
<ul class="govuk-list govuk-error-summary__list">
<li>
<a id="error-banner-link" href="#confirm-qualification-choice-error">@Model.ErrorBannerLink</a>
</li>
</ul>
</div>
</div>
</div>
}
<h1 id="heading" class="govuk-heading-xl">@Model.Heading</h1>
<dl class="govuk-summary-list">
<div id="qualification-name-row" class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
@Model.QualificationLabel
</dt>
<dd class="govuk-summary-list__value">
@Model.QualificationName
</dd>
</div>
<div id="qualification-level-row" class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
@Model.LevelLabel
</dt>
<dd class="govuk-summary-list__value">
@Model.QualificationLevel
</dd>
</div>
<div id="qualification-org-row" class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
@Model.AwardingOrganisationLabel
</dt>
<dd class="govuk-summary-list__value">
@Model.QualificationAwardingOrganisation
</dd>
</div>
<div id="qualification-date-added-row" class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
@Model.DateAddedLabel
</dt>
<dd class="govuk-summary-list__value">
@Model.QualificationDateAdded
</dd>
</div>
</dl>
<form id="confirm-qualification" asp-controller="ConfirmQualification" asp-action="Confirm" method="post">
<input type="hidden" name="qualificationId" value="@Model.QualificationId">
<div id="confirm-qualification-form-group" class="govuk-form-group @(Model.HasErrors ? "govuk-form-group--error" : "")">
<h4 id="radio-heading" class="govuk-heading-m">@Model.RadioHeading</h4>
<fieldset class="govuk-fieldset" role="group" aria-describedby="confirm-qualification-choice-error">
@if (Model.HasErrors)
{
<p id="confirm-qualification-choice-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> @Model.ErrorText
</p>
}
@foreach (var option in Model.Options)
{
<div class="govuk-radios__item">
@Html.RadioButtonFor(x => x.ConfirmQualificationAnswer, option.Value, new { @class = "govuk-radios__input", id = option.Value })
<label class="govuk-label govuk-radios__label" for="@option.Value">
@option.Label
</label>
</div>
}
</fieldset>
</div>
<div class="govuk-form-group">
<button id="confirm-qualification-button" class="govuk-button" data-module="govuk-button">
@Model.ButtonText
</button>
</div>
</form>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
@foreach (var qualification in qualifications)
{
<tr class="govuk-table__row">
<td class="govuk-table__cell">@Html.ActionLink(qualification, "Index", new { qualificationId = qualification })</td>
<td class="govuk-table__cell">@Html.ActionLink(qualification, "Index", "ConfirmQualification", new { qualificationId = qualification })</td>
</tr>
}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}
else if ((cookie.HasApproved || cookie.IsRejected) && cookie.IsVisible)
{
<form method="post" asp-controller="Cookies" asp-action="HideBanner">
<form method="post" asp-controller="CookiesPreference" asp-action="HideBanner">
<input type="hidden" id="returnUrlHideBanner" name="returnUrl"/>
<div id="cookies-preference-chosen" class="govuk-cookie-banner" data-nosnippet role="region" aria-label="Cookies on [name of service]">
<div class="govuk-cookie-banner__message govuk-width-container">
Expand Down
Loading

0 comments on commit 080d7b8

Please sign in to comment.