Skip to content

Commit 86add18

Browse files
committed
TD-5154 Implements upload results page with validation errors
1 parent 3880318 commit 86add18

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public IActionResult DownloadCompetencies(int frameworkId, int DownloadOption)
4040
}
4141
[HttpPost]
4242
[Route("/Framework/{frameworkId}/{tabname}/Import")]
43-
public IActionResult StartImport(ImportCompetenciesViewModel model, string tabname)
43+
[Route("/Framework/{frameworkId}/{tabname}/ImportCompleted")]
44+
public IActionResult StartImport(ImportCompetenciesViewModel model, string tabname, bool isNotBlank)
4445
{
4546
if (!ModelState.IsValid)
4647
return View("Developer/ImportCompetencies", model);
@@ -50,11 +51,11 @@ public IActionResult StartImport(ImportCompetenciesViewModel model, string tabna
5051
var workbook = new XLWorkbook(model.ImportFile.OpenReadStream());
5152
if (!workbook.Worksheets.Contains(ImportCompetenciesFromFileService.CompetenciesSheetName))
5253
{
53-
ModelState.AddModelError("InvalidWorksheet", CommonValidationErrorMessages.InvalidCompetenciesUploadExcelFile);
54+
ModelState.AddModelError("ImportFile", CommonValidationErrorMessages.InvalidCompetenciesUploadExcelFile);
5455
return View("Developer/ImportCompetencies", model);
5556
}
5657
var competenciesFileName = FileHelper.UploadFile(webHostEnvironment, model.ImportFile);
57-
setupBulkUploadData(model.FrameworkId, adminUserID, competenciesFileName, tabname);
58+
setupBulkUploadData(model.FrameworkId, adminUserID, competenciesFileName, tabname, isNotBlank);
5859

5960
return RedirectToAction("ImportCompleted", "Frameworks", new { frameworkId = model.FrameworkId, tabname });
6061
}
@@ -78,7 +79,7 @@ public IActionResult ImportCompleted()
7879
try
7980
{
8081
var results = importCompetenciesFromFileService.PreProcessCompetenciesTable(workbook);
81-
var resultsModel = new ImportCompetenciesPreProcessViewModel(results);
82+
var resultsModel = new ImportCompetenciesPreProcessViewModel(results) { IsNotBlank = data.IsNotBlank, TabName = data.TabName };
8283
data.CompetenciesToProcessCount = resultsModel.ToProcessCount;
8384
data.CompetenciesToAddCount = resultsModel.CompetenciesToAddCount;
8485
data.CompetenciesToUpdateCount = resultsModel.CompetenciesToUpdateCount;
@@ -92,12 +93,12 @@ public IActionResult ImportCompleted()
9293
}
9394
}
9495

95-
private void setupBulkUploadData(int frameworkId, int adminUserID, string competenciessFileName, string tabName)
96+
private void setupBulkUploadData(int frameworkId, int adminUserID, string competenciessFileName, string tabName, bool isNotBlank)
9697
{
9798
TempData.Clear();
9899
multiPageFormService.ClearMultiPageFormData(MultiPageFormDataFeature.AddCustomWebForm("BulkCompetencyDataCWF"), TempData);
99100
var today = clockUtility.UtcToday;
100-
var bulkUploadData = new BulkCompetenciesData(frameworkId, adminUserID, competenciessFileName, tabName);
101+
var bulkUploadData = new BulkCompetenciesData(frameworkId, adminUserID, competenciessFileName, tabName, isNotBlank);
101102
setBulkUploadData(bulkUploadData);
102103
}
103104
private void setBulkUploadData(BulkCompetenciesData bulkUploadData)

DigitalLearningSolutions.Web/Helpers/CommonValidationErrorMessages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static class CommonValidationErrorMessages
3636
public const string CentreNameAlreadyExist = "The centre name you have entered already exists, please enter a different centre name";
3737
public const string MaxBulkUploadRowsLimit = "File must contain no more than {0} rows";
3838
public const string InvalidBulkUploadExcelFile = "The uploaded file must contain a \"DelegatesBulkUpload\" worksheet. Use the \"Download delegates\" button to generate a template.";
39-
public const string InvalidCompetenciesUploadExcelFile = "The uploaded file must contain a \"CompetenciesBulkUpload\" worksheet. Use the \"Download competencies\" button to generate a template.";
39+
public const string InvalidCompetenciesUploadExcelFile = "The uploaded file must contain a \"CompetenciesBulkUpload\" worksheet. Use the \"Download template\" button to generate a template.";
4040
public const string ReportFilterReturnsTooManyRows = "The report frequency is too high for the date range. Choose a lower report frequency (or shorten the date range)";
4141
}
4242
}

DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ namespace DigitalLearningSolutions.Web.Models
66
public class BulkCompetenciesData
77
{
88
public BulkCompetenciesData() { }
9-
public BulkCompetenciesData(int frameworkId, int adminUserId, string competenciesFileName, string tabName)
9+
public BulkCompetenciesData(int frameworkId, int adminUserId, string competenciesFileName, string tabName, bool isNotBlank)
1010
{
1111
FrameworkId = frameworkId;
1212
AdminUserId = adminUserId;
1313
CompetenciesFileName = competenciesFileName;
1414
TabName = tabName;
15+
IsNotBlank = isNotBlank;
1516
}
1617
public int FrameworkId { get; set; }
1718
public string TabName { get; set; }
1819
public int AdminUserId { get; set; }
20+
public bool IsNotBlank { get; set; }
1921
public string CompetenciesFileName { get; set; }
2022
public List<int> AssessmentQuestionIDs { get; set; }
2123
public int? AddAssessmentQuestionOption { get; set; }

DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook
4444
}
4545
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow)
4646
{
47+
competencyRow.Validate();
4748
if (competencyRow.id == null)
4849
{
4950
competencyRow.RowStatus = RowStatus.CompetencyInserted;

DigitalLearningSolutions.Web/ViewModels/Frameworks/ImportCompetenciesPreProcessViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public ImportCompetenciesPreProcessViewModel(ImportCompetenciesResult bulkCompet
2626
public int CompetencyGroupsToAddCount { get; set; }
2727
public int CompetencyGroupsToUpdateCount { get; set; }
2828
public int ToUpdateOrSkipCount { get; set; }
29-
public string? CompetenciesFileName { get; set; }
29+
public string? ImportFile { get; set; }
30+
public bool IsNotBlank { get; set; }
31+
public string TabName { get; set; }
3032

3133
private static string MapReasonToErrorMessage(ImportCompetenciesResult.ErrorReason reason)
3234
{

DigitalLearningSolutions.Web/Views/Frameworks/Developer/ImportCompleted.cshtml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<p class="nhsuk-body-l">@(Model.ErrorCount == 0 ? "Your file is error free and ready to be processed. Check the information below looks, correct before processing" : "Your file contains the following, including some errors:")</p>
3131
<ul>
3232
<li>@Model.ToProcessCount @(Model.ToProcessCount == 1 ? "row" : "rows") to process</li>
33-
<li>@Model.CompetencyGroupsToAddCount new @(Model.CompetencyGroupsToAddCount == 1 ? "competency" : "competencies") to register</li>
33+
<li>@Model.CompetenciesToAddCount new @(Model.CompetenciesToAddCount == 1 ? "competency" : "competencies") to add</li>
3434
<li>@Model.ToUpdateOrSkipCount delegate @(Model.ToUpdateOrSkipCount == 1 ? "record" : "records") to update (or skip if unchanged)</li>
3535
@if (Model.ErrorCount > 0)
3636
{
@@ -71,9 +71,11 @@ else
7171
<p class="nhsuk-body-m">
7272
Once you have made corrections to the Excel competency workbook to address the errors above, save and restart the upload process.
7373
</p>
74-
<form class="nhsuk-u-margin-bottom-3" method="post" asp-action="StartUpload" enctype="multipart/form-data">
74+
<form class="nhsuk-u-margin-bottom-3" method="post" enctype="multipart/form-data">
7575

76-
<vc:file-input asp-for="@nameof(Model.CompetenciesFileName)" label="File with corrected competencies information" hint-text="" css-class="nhsuk-u-width-one-half" />
76+
<vc:file-input asp-for="@nameof(Model.ImportFile)" label="File with corrected competencies information" hint-text="" css-class="nhsuk-u-width-one-half" />
77+
<input type="hidden" asp-for="IsNotBlank" />
78+
<input type="hidden" asp-for="TabName"/>
7779

7880
<button class="nhsuk-button" type="submit">Upload file</button>
7981
</form>

0 commit comments

Comments
 (0)