Skip to content

Commit

Permalink
Merge pull request #1037 from DFE-Digital/feature/form-a-mat-search-c…
Browse files Browse the repository at this point in the history
…hanges

Changes for adding project to existing FAM
  • Loading branch information
paullocknimble authored Apr 9, 2024
2 parents de1e3b1 + 0a1e035 commit fa9d75b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public async Task<IActionResult> OnGet(string urn, string isFormAMat, string has

public async Task<IActionResult> OnGetSearch(string searchQuery)
{
string[] searchSplit = SplitOnBrackets(searchQuery);
string[] searchSplit = SplitOnBrackets(searchQuery);

IEnumerable<FormAMatProject> projects = (await _repository.SearchFormAMatProjects(searchQuery)).Body;

return new JsonResult(projects.Select(s => new { suggestion = HighlightSearchMatch($"{s.ProposedTrustName} ({DeduceReferenceNumber(s)})", searchSplit[0].Trim(), s), value = $"{DeduceReferenceNumber(s)}" }));
return new JsonResult(projects.Select(s => new { suggestion = HighlightSearchMatch($"{s.ProposedTrustName} ({s.ReferenceNumber}){IncludeA2BReferenceNumberIfAvailable(s)}", searchSplit[0].Trim(), s), value = $"{s.ProposedTrustName} ({s.ReferenceNumber}){IncludeA2BReferenceNumberIfAvailable(s)}" }));
}

public async Task<IActionResult> OnPost(string ukprn, string urn, string redirect)
Expand All @@ -77,14 +77,15 @@ public async Task<IActionResult> OnPost(string ukprn, string urn, string redirec
_errorService.AddError("Application Reference", "Please enter a application reference with more than three characters");
return Page();
}

var applicationReference = SearchQuery;
string[] splitSearch = SplitOnBrackets(SearchQuery);
// Fam reference should always be second in array
var FamReference = splitSearch[1];

var nextPage = Links.NewProject.Summary.Page;

redirect = string.IsNullOrEmpty(redirect) ? nextPage : redirect;

return RedirectToPage(redirect, new { ukprn, urn, HasSchoolApplied, IsFormAMat, IsProjectInPrepare, applicationReference });
return RedirectToPage(redirect, new { ukprn, urn, HasSchoolApplied, IsFormAMat, IsProjectInPrepare, FamReference });
}

private static string HighlightSearchMatch(string input, string toReplace, FormAMatProject project)
Expand All @@ -105,8 +106,8 @@ private static string[] SplitOnBrackets(string input)
return input.Split(new[] { '(', ')' }, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
}

private static string DeduceReferenceNumber(FormAMatProject project)
private static string IncludeA2BReferenceNumberIfAvailable(FormAMatProject project)
{
return !string.IsNullOrEmpty(project.ReferenceNumber) ? project.ReferenceNumber : project.ApplicationReference;
return !string.IsNullOrEmpty(project.ApplicationReference) ? $"({project.ApplicationReference})" : string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
</div>
}

@if (Model.ApplicationReference != null)
@if (Model.IsFormAMat != null)
{
<div class="govuk-grid-column-two-thirds">

Expand All @@ -283,9 +283,27 @@
</dd>
<dd class="govuk-summary-list__value"></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
@if (Model.FamReference != null)
{
<div class="govuk-summary-list__row" isv>
<dt class="govuk-summary-list__key">
FAM Reference
</dt>
<dd class="govuk-summary-list__value" data-cy="a2b-reference">
@Model.FamReference
</dd>
<dd class="govuk-summary-list__actions">
<a asp-page="@Links.NewProject.LinkFormAMatProject.Page" class="govuk-link" data-cy="change-fam-reference"
asp-all-route-data="@backLinkRouteParams">
Change<span class="govuk-visually-hidden">FAM reference</span>
</a>
</dd>
</div>
}
@if (Model.ApplicationReference != null)
{
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
A2B Reference
</dt>
<dd class="govuk-summary-list__value" data-cy="a2b-reference">
Expand All @@ -298,6 +316,7 @@
</a>
</dd>
</div>
}

</dl>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public SummaryModel(IGetEstablishment getEstablishment,
public string IsProjectInPrepare { get; set; }
public string IsProjectAlreadyInPrepare { get; set; }
public string ApplicationReference { get; set; }
public string FamReference { get; set; }


public async Task<IActionResult> OnGetAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string isFormAMat, string isProjectInPrepare, string applicationReference)
public async Task<IActionResult> OnGetAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string isFormAMat, string isProjectInPrepare, string famReference)
{
Establishment = await _getEstablishment.GetEstablishmentByUrn(urn);
if (!string.IsNullOrEmpty(ukprn))
Expand All @@ -51,18 +52,22 @@ public async Task<IActionResult> OnGetAsync(string urn, string ukprn, string has
IsFormAMat = isFormAMat ?? "no";
IsProjectInPrepare = isProjectInPrepare ?? "no";
ProposedTrustName = proposedTrustName ?? null;
ApplicationReference = applicationReference ?? null;
FamReference = famReference ?? null;
ApplicationReference = null;

if (ApplicationReference != null)
if (FamReference != null)
{
var results = await _academyConversionProjectRepository.SearchFormAMatProjects(ApplicationReference);
ProposedTrustName = results.Body.First().ProposedTrustName;
var results = await _academyConversionProjectRepository.SearchFormAMatProjects(FamReference);
var famProject = results.Body.First();

ProposedTrustName = famProject.ProposedTrustName;
ApplicationReference = string.IsNullOrEmpty(famProject.ApplicationReference) ? null : famProject.ApplicationReference;
}

return Page();
}

public async Task<IActionResult> OnPostAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string isFormAMat, string applicationReference)
public async Task<IActionResult> OnPostAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string isFormAMat, string famReference)
{
Academies.Contracts.V4.Establishments.EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn);

Expand All @@ -83,7 +88,7 @@ public async Task<IActionResult> OnPostAsync(string urn, string ukprn, string ha
if (_isFormAMAT && proposedTrustName == null)
{
var createdProject = await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust, true));
var formAMatProject = await _academyConversionProjectRepository.SearchFormAMatProjects(applicationReference);
var formAMatProject = await _academyConversionProjectRepository.SearchFormAMatProjects(famReference);

int projectId = createdProject.Body.Id;
var formAMatProjectID = formAMatProject.Body.First().Id;
Expand Down

0 comments on commit fa9d75b

Please sign in to comment.