-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create edit an alert end date journey in trs console (#1538)
- Loading branch information
Showing
21 changed files
with
1,547 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@page "/alerts/{alertId}/{handler?}" | ||
@model TeachingRecordSystem.SupportUi.Pages.Alerts.Alert.IndexModel | ||
@{ | ||
} |
10 changes: 10 additions & 0 deletions
10
TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace TeachingRecordSystem.SupportUi.Pages.Alerts.Alert; | ||
|
||
public class IndexModel : PageModel | ||
{ | ||
[FromRoute] | ||
public Guid AlertId { get; set; } | ||
} |
13 changes: 13 additions & 0 deletions
13
...ngRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/AlertChangeEndDateReasonOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace TeachingRecordSystem.SupportUi.Pages.Alerts.EditAlert.EndDate; | ||
|
||
public enum AlertChangeEndDateReasonOption | ||
{ | ||
[Display(Name = "Incorrect end date")] | ||
IncorrectEndDate, | ||
[Display(Name = "Change of end date")] | ||
ChangeOfEndDate, | ||
[Display(Name = "Another reason")] | ||
AnotherReason | ||
} |
60 changes: 60 additions & 0 deletions
60
...tem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/CheckAnswers.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
@page "/alerts/{alertId}/end-date/check-answers/{handler?}" | ||
@model TeachingRecordSystem.SupportUi.Pages.Alerts.EditAlert.EndDate.CheckAnswersModel | ||
@{ | ||
ViewBag.Title = "Check details and confirm change"; | ||
} | ||
|
||
@section BeforeContent { | ||
<govuk-back-link href="@LinkGenerator.AlertEditEndDateReason(Model.AlertId, Model.JourneyInstance!.InstanceId)">Back</govuk-back-link> | ||
} | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-full-from-desktop"> | ||
<form action="@LinkGenerator.AlertEditEndDateCheckAnswers(Model.AlertId, Model.JourneyInstance!.InstanceId)" method="post"> | ||
<span class="govuk-caption-l">Change previous alert - @Model.PersonName</span> | ||
<h1 class="govuk-heading-l" data-testid="title">@ViewBag.Title</h1> | ||
|
||
<govuk-summary-list data-testid="change-summary"> | ||
<govuk-summary-list-row> | ||
<govuk-summary-list-row-key>New end date</govuk-summary-list-row-key> | ||
<govuk-summary-list-row-value data-testid="new-end-date">@Model.NewEndDate!.Value.ToString("d MMMM yyyy")</govuk-summary-list-row-value> | ||
<govuk-summary-list-row-actions> | ||
<govuk-summary-list-row-action href="@LinkGenerator.AlertEditEndDate(Model.AlertId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)">Change</govuk-summary-list-row-action> | ||
</govuk-summary-list-row-actions> | ||
</govuk-summary-list-row> | ||
<govuk-summary-list-row> | ||
<govuk-summary-list-row-key>Current end date</govuk-summary-list-row-key> | ||
<govuk-summary-list-row-value data-testid="current-end-date" use-empty-fallback>@Model.CurrentEndDate?.ToString("d MMMM yyyy")</govuk-summary-list-row-value> | ||
</govuk-summary-list-row> | ||
<govuk-summary-list-row> | ||
<govuk-summary-list-row-key>Reason for change</govuk-summary-list-row-key> | ||
<govuk-summary-list-row-value><multi-line-text text="@Model.ChangeReason" data-testid="change-reason" /></govuk-summary-list-row-value> | ||
<govuk-summary-list-row-actions> | ||
<govuk-summary-list-row-action href="@LinkGenerator.AlertEditEndDateReason(Model.AlertId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)">Change</govuk-summary-list-row-action> | ||
</govuk-summary-list-row-actions> | ||
</govuk-summary-list-row> | ||
<govuk-summary-list-row> | ||
<govuk-summary-list-row-key>Evidence</govuk-summary-list-row-key> | ||
<govuk-summary-list-row-value data-testid="evidence"> | ||
@if (Model.UploadedEvidenceFileUrl is not null) | ||
{ | ||
<a href="@Model.UploadedEvidenceFileUrl" class="govuk-link" rel="noreferrer noopener" target="_blank" data-testid="uploaded-evidence-link">@($"{Model.EvidenceFileName} (opens in new tab)")</a> | ||
} | ||
else | ||
{ | ||
<span data-testid="uploaded-evidence-link" use-empty-fallback></span> | ||
} | ||
</govuk-summary-list-row-value> | ||
<govuk-summary-list-row-actions> | ||
<govuk-summary-list-row-action href="@LinkGenerator.AlertEditEndDateReason(Model.AlertId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)">Change</govuk-summary-list-row-action> | ||
</govuk-summary-list-row-actions> | ||
</govuk-summary-list-row> | ||
</govuk-summary-list> | ||
|
||
<div class="govuk-button-group"> | ||
<govuk-button type="submit">Confirm change</govuk-button> | ||
<govuk-button formaction="@LinkGenerator.AlertEditEndDateCheckAnswersCancel(Model.AlertId, Model.JourneyInstance!.InstanceId)" class="govuk-button--secondary" type="submit">Cancel and return to record</govuk-button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> |
121 changes: 121 additions & 0 deletions
121
.../src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/CheckAnswers.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using TeachingRecordSystem.Core.DataStore.Postgres; | ||
using TeachingRecordSystem.Core.Services.Files; | ||
|
||
namespace TeachingRecordSystem.SupportUi.Pages.Alerts.EditAlert.EndDate; | ||
|
||
[Journey(JourneyNames.EditAlertEndDate), RequireJourneyInstance] | ||
public class CheckAnswersModel( | ||
TrsDbContext dbContext, | ||
TrsLinkGenerator linkGenerator, | ||
IFileService fileService, | ||
IClock clock) : PageModel | ||
{ | ||
private static readonly TimeSpan _fileUrlExpiresAfter = TimeSpan.FromMinutes(15); | ||
|
||
public JourneyInstance<EditAlertEndDateState>? JourneyInstance { get; set; } | ||
|
||
[FromRoute] | ||
public Guid AlertId { get; set; } | ||
|
||
[FromQuery] | ||
public bool FromCheckAnswers { get; set; } | ||
|
||
public Guid PersonId { get; set; } | ||
|
||
public string? PersonName { get; set; } | ||
|
||
public DateOnly? NewEndDate { get; set; } | ||
|
||
public DateOnly? CurrentEndDate { get; set; } | ||
|
||
public string? ChangeReason { get; set; } | ||
|
||
public string? EvidenceFileName { get; set; } | ||
|
||
public string? EvidenceFileSizeDescription { get; set; } | ||
|
||
public string? UploadedEvidenceFileUrl { get; set; } | ||
|
||
public async Task<IActionResult> OnPost() | ||
{ | ||
var now = clock.UtcNow; | ||
|
||
var alert = await dbContext.Alerts | ||
.SingleAsync(a => a.AlertId == AlertId); | ||
|
||
var changes = NewEndDate != alert.EndDate ? | ||
AlertUpdatedEventChanges.EndDate : | ||
AlertUpdatedEventChanges.None; | ||
|
||
if (changes != AlertUpdatedEventChanges.None) | ||
{ | ||
var oldAlertEventModel = EventModels.Alert.FromModel(alert); | ||
|
||
alert.EndDate = NewEndDate; | ||
alert.UpdatedOn = now; | ||
|
||
var updatedEvent = new AlertUpdatedEvent() | ||
{ | ||
EventId = Guid.NewGuid(), | ||
CreatedUtc = now, | ||
RaisedBy = User.GetUserId(), | ||
PersonId = PersonId, | ||
Alert = EventModels.Alert.FromModel(alert), | ||
OldAlert = oldAlertEventModel, | ||
ChangeReason = ChangeReason, | ||
EvidenceFile = JourneyInstance!.State.EvidenceFileId is Guid fileId ? | ||
new EventModels.File() | ||
{ | ||
FileId = fileId, | ||
Name = JourneyInstance.State.EvidenceFileName! | ||
} : | ||
null, | ||
Changes = changes | ||
}; | ||
|
||
dbContext.AddEvent(updatedEvent); | ||
|
||
await dbContext.SaveChangesAsync(); | ||
} | ||
|
||
await JourneyInstance!.CompleteAsync(); | ||
TempData.SetFlashSuccess("Alert changed"); | ||
|
||
return Redirect(linkGenerator.PersonAlerts(PersonId)); | ||
} | ||
|
||
public async Task<IActionResult> OnPostCancel() | ||
{ | ||
await JourneyInstance!.DeleteAsync(); | ||
return Redirect(linkGenerator.Alert(AlertId)); | ||
} | ||
|
||
public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) | ||
{ | ||
if (!JourneyInstance!.State.IsComplete) | ||
{ | ||
context.Result = Redirect(linkGenerator.AlertEditEndDate(AlertId, JourneyInstance.InstanceId)); | ||
return; | ||
} | ||
|
||
var personInfo = context.HttpContext.GetCurrentPersonFeature(); | ||
var alertInfo = context.HttpContext.GetCurrentAlertFeature(); | ||
|
||
PersonId = personInfo.PersonId; | ||
PersonName = personInfo.Name; | ||
NewEndDate = JourneyInstance!.State.EndDate; | ||
CurrentEndDate = alertInfo.Alert.EndDate; | ||
ChangeReason = JourneyInstance.State.ChangeReason != AlertChangeEndDateReasonOption.AnotherReason ? | ||
JourneyInstance.State.ChangeReason!.GetDisplayName() : | ||
JourneyInstance!.State.ChangeReasonDetail; | ||
EvidenceFileName = JourneyInstance.State.EvidenceFileName; | ||
UploadedEvidenceFileUrl = JourneyInstance!.State.EvidenceFileId is not null ? | ||
await fileService.GetFileUrl(JourneyInstance!.State.EvidenceFileId!.Value, _fileUrlExpiresAfter) : | ||
null; | ||
|
||
await next(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...rc/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/EditAlertEndDateState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace TeachingRecordSystem.SupportUi.Pages.Alerts.EditAlert.EndDate; | ||
|
||
public class EditAlertEndDateState | ||
{ | ||
public bool Initialized { get; set; } | ||
|
||
public DateOnly? CurrentEndDate { get; set; } | ||
|
||
public DateOnly? EndDate { get; set; } | ||
|
||
public AlertChangeEndDateReasonOption? ChangeReason { get; set; } | ||
|
||
public string? ChangeReasonDetail { get; set; } | ||
|
||
public bool? UploadEvidence { get; set; } | ||
|
||
public Guid? EvidenceFileId { get; set; } | ||
|
||
public string? EvidenceFileName { get; set; } | ||
|
||
public string? EvidenceFileSizeDescription { get; set; } | ||
|
||
[JsonIgnore] | ||
[MemberNotNullWhen(true, nameof(EndDate), nameof(ChangeReason), nameof(UploadEvidence), nameof(EvidenceFileId))] | ||
public bool IsComplete => EndDate is not null && | ||
ChangeReason.HasValue && | ||
(ChangeReason.Value == AlertChangeEndDateReasonOption.AnotherReason ? !string.IsNullOrWhiteSpace(ChangeReasonDetail) : true) && | ||
UploadEvidence.HasValue && | ||
(!UploadEvidence.Value || (UploadEvidence.Value && EvidenceFileId.HasValue)); | ||
|
||
public void EnsureInitialized(CurrentAlertFeature alertInfo) | ||
{ | ||
if (Initialized) | ||
{ | ||
return; | ||
} | ||
|
||
EndDate = CurrentEndDate = alertInfo.Alert.EndDate; | ||
Initialized = true; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...cordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@page "/alerts/{alertId}/end-date/{handler?}" | ||
@model TeachingRecordSystem.SupportUi.Pages.Alerts.EditAlert.EndDate.IndexModel | ||
@{ | ||
ViewBag.Title = "Enter a new end date"; | ||
} | ||
|
||
@section BeforeContent { | ||
<govuk-back-link href="@(Model.FromCheckAnswers == true ? LinkGenerator.AlertEditEndDateCheckAnswers(Model.AlertId, Model.JourneyInstance!.InstanceId) : LinkGenerator.PersonAlerts(Model.PersonId))">Back</govuk-back-link> | ||
} | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds-from-desktop"> | ||
<form action="@LinkGenerator.AlertEditEndDate(Model.AlertId, Model.JourneyInstance!.InstanceId, Model.FromCheckAnswers)" method="post"> | ||
<span class="govuk-caption-l">Change previous alert - @Model.PersonName</span> | ||
|
||
<govuk-date-input asp-for="EndDate"> | ||
<govuk-date-input-fieldset> | ||
<govuk-date-input-fieldset-legend is-page-heading="true" class="govuk-fieldset__legend--l" /> | ||
</govuk-date-input-fieldset> | ||
</govuk-date-input> | ||
|
||
<div class="govuk-button-group"> | ||
<govuk-button type="submit">Continue</govuk-button> | ||
<govuk-button formaction="@LinkGenerator.AlertEditEndDateCancel(Model.AlertId, Model.JourneyInstance!.InstanceId)" class="govuk-button--secondary" type="submit">Cancel and return to record</govuk-button> | ||
</div> | ||
</form> | ||
</<div> | ||
</div> |
Oops, something went wrong.