Skip to content

Commit

Permalink
Amendments after PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hortha committed Oct 5, 2023
1 parent 733078d commit e7df96b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,19 @@
<h3 class="govuk-heading-s">Details</h3>
@if (!string.IsNullOrEmpty(@Model.Alert.Details))
{
<p class="govuk-body" data-testid="alert-details">
@{var lines = @Model.Alert.Details.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
@for (int i = 0; i < lines.Length; i++)
{
<span>@lines[i]</span>
@if (i < lines.Length - 1)
{
<br />
}
}
}
</p>
}
<form action="@LinkGenerator.Alert(Model.AlertId)" method="post">
<multi-line-text data-testid="alert-details" text="@Model.Alert.Details"/>
}
@if (Model.IsActive)
{
<govuk-button type="submit" class="govuk-!-margin-top-9" data-testid="deactivate-button">Mark alert as inactive</govuk-button>
<form asp-page-handler="SetInactive" method="post">
<govuk-button type="submit" class="govuk-!-margin-top-9" data-testid="deactivate-button">Mark alert as inactive</govuk-button>
</form>
}
else
{
<govuk-button type="submit" class="govuk-button--warning govuk-!-margin-top-9" data-testid="reactivate-button">Remove inactive status</govuk-button>
}
</form>
<form asp-page-handler="SetActive" method="post">
<govuk-button type="submit" class="govuk-button--warning govuk-!-margin-top-9" data-testid="reactivate-button">Remove inactive status</govuk-button>
</form>
}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,22 @@ public IndexModel(

public Guid? PersonId { get; set; }

public async Task<IActionResult> OnPost()
public async Task<IActionResult> OnPostSetActive()
{
await _crmQueryDispatcher.ExecuteQuery(new UpdateSanctionStateQuery(AlertId, IsActive ? dfeta_sanctionState.Inactive : dfeta_sanctionState.Active));
await _crmQueryDispatcher.ExecuteQuery(new UpdateSanctionStateQuery(AlertId, dfeta_sanctionState.Active));

IsActive = !IsActive;
TempData.SetFlashSuccess($"{(IsActive ? "Inactive status removed" : "Status changed to inactive")}");
IsActive = true;
TempData.SetFlashSuccess("Inactive status removed");

return Redirect(_linkGenerator.Alert(AlertId));
}

public async Task<IActionResult> OnPostSetInactive()
{
await _crmQueryDispatcher.ExecuteQuery(new UpdateSanctionStateQuery(AlertId, dfeta_sanctionState.Inactive));

IsActive = false;
TempData.SetFlashSuccess("Status changed to inactive");

return Redirect(_linkGenerator.Alert(AlertId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ else
<govuk-summary-list-row-value data-testid="[email protected]">
@if (!string.IsNullOrEmpty(@alert.Details))
{
var lines = @alert.Details.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
@for (int i = 0; i < lines.Length; i++)
{
<span>@lines[i]</span>
@if (i < lines.Length - 1)
{
<br />
}
}
<multi-line-text text="@alert.Details" />
}
</govuk-summary-list-row-value>
</govuk-summary-list-row>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace TeachingRecordSystem.SupportUi.TagHelpers;

public class MultiLineTextTagHelper : TagHelper
{
public string Text { get; set; } = string.Empty;

public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "p";
output.AddClass("govuk-body", HtmlEncoder.Default);

if (!string.IsNullOrWhiteSpace(Text))
{
var lines = Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
for (var i = 0; i < lines.Length; i++)
{
output.Content.Append(lines[i]);
if (i < lines.Length - 1)
{
output.Content.AppendHtml("<br />");
}
}
}

output.TagMode = TagMode.StartTagAndEndTag;
}
}

0 comments on commit e7df96b

Please sign in to comment.