Skip to content

Commit 38cf879

Browse files
committed
TD-5216 Uses custom competency vocabulary in Excel file processing
1 parent 0d51709 commit 38cf879

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

DigitalLearningSolutions.Data/Models/Frameworks/Import/CompetencyTableRow.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public CompetencyTableRow(IXLTable table, IXLRangeRow row)
2626

2727
RowNumber = row.RowNumber();
2828
id = row.Cell(1).GetValue<int?>();
29-
CompetencyGroup = FindFieldValue("CompetencyGroup");
30-
Competency = FindFieldValue("Competency");
31-
CompetencyDescription = FindFieldValue("CompetencyDescription");
32-
GroupDescription = FindFieldValue("GroupDescription");
29+
CompetencyGroup = row.Cell(2).GetValue<string?>();
30+
GroupDescription = row.Cell(3).GetValue<string?>();
31+
Competency = row.Cell(4).GetValue<string?>();
32+
CompetencyDescription = row.Cell(5).GetValue<string?>();
3333
AlwaysShowDescriptionRaw = FindFieldValue("AlwaysShowDescription");
3434
AlwaysShowDescription = bool.TryParse(AlwaysShowDescriptionRaw, out var hasPrn) ? hasPrn : (bool?)null;
3535
FlagsCsv = FindFieldValue("FlagsCSV");

DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public IActionResult ImportCompetencies(int frameworkId, string tabname, bool is
2424

2525
return View("Developer/Import/Index", model);
2626
}
27-
public IActionResult DownloadCompetencies(int frameworkId, int DownloadOption)
27+
public IActionResult DownloadCompetencies(int frameworkId, int DownloadOption, string vocabulary)
2828
{
29-
string fileName = DownloadOption == 2 ? $"DLS Competencies for Bulk Update {clockUtility.UtcToday:yyyy-MM-dd}.xlsx" : "DLS Competencies for Bulk Upload.xlsx";
29+
string fileName = DownloadOption == 2 ? $"DLS {FrameworkVocabularyHelper.VocabularyPlural(vocabulary)} for Bulk Update {clockUtility.UtcToday:yyyy-MM-dd}.xlsx" : $"DLS {FrameworkVocabularyHelper.VocabularyPlural(vocabulary)} for Bulk Upload.xlsx";
3030
var content = importCompetenciesFromFileService.GetCompetencyFileForFramework(
31-
frameworkId, DownloadOption == 2 ? false : true
31+
frameworkId, DownloadOption == 2 ? false : true, vocabulary
3232
);
3333
return File(
3434
content,
@@ -76,7 +76,7 @@ public IActionResult ImportCompleted()
7676
var workbook = new XLWorkbook(filePath);
7777
try
7878
{
79-
var results = importCompetenciesFromFileService.PreProcessCompetenciesTable(workbook);
79+
var results = importCompetenciesFromFileService.PreProcessCompetenciesTable(workbook, data.FrameworkVocubulary);
8080
var resultsModel = new ImportCompetenciesPreProcessViewModel(results, data) { IsNotBlank = data.IsNotBlank, TabName = data.TabName };
8181
data.CompetenciesToProcessCount = resultsModel.ToProcessCount;
8282
data.CompetenciesToAddCount = resultsModel.CompetenciesToAddCount;

DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,27 @@ namespace DigitalLearningSolutions.Web.Services
1212
using DigitalLearningSolutions.Data.Exceptions;
1313
using DigitalLearningSolutions.Data.Helpers;
1414
using DigitalLearningSolutions.Data.Models.Frameworks.Import;
15-
using DigitalLearningSolutions.Web.Models;
16-
using Microsoft.AspNetCore.Http;
1715

1816
public interface IImportCompetenciesFromFileService
1917
{
20-
byte[] GetCompetencyFileForFramework(int frameworkId, bool v);
21-
public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook);
22-
public ImportCompetenciesResult ProcessCompetenciesFromFile(IXLWorkbook workbook, int adminUserId, int frameworkId);
18+
byte[] GetCompetencyFileForFramework(int frameworkId, bool isBlank, string vocabulary);
19+
public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook, string vocabulary);
20+
public ImportCompetenciesResult ProcessCompetenciesFromFile(IXLWorkbook workbook, int adminUserId, int frameworkId, string vocabulary);
2321
}
2422
public class ImportCompetenciesFromFileService : IImportCompetenciesFromFileService
2523
{
2624
private readonly IFrameworkService frameworkService;
2725
private static readonly XLTableTheme TableTheme = XLTableTheme.TableStyleLight9;
28-
public const string CompetenciesSheetName = "CompetenciesBulkUpload";
26+
public const string CompetenciesSheetName = "FrameworkBulkUpload";
2927
public ImportCompetenciesFromFileService(
3028
IFrameworkService frameworkService
3129
)
3230
{
3331
this.frameworkService = frameworkService;
3432
}
35-
public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook)
33+
public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook, string vocabulary)
3634
{
37-
var table = OpenCompetenciesTable(workbook);
35+
var table = OpenCompetenciesTable(workbook, vocabulary);
3836
var competencyRows = table.Rows().Skip(1).Select(row => new CompetencyTableRow(table, row)).ToList();
3937
foreach (var competencyRow in competencyRows)
4038
{
@@ -54,14 +52,14 @@ private void PreProcessCompetencyRow(CompetencyTableRow competencyRow)
5452
competencyRow.RowStatus = RowStatus.CompetencyUpdated;
5553
}
5654
}
57-
public ImportCompetenciesResult ProcessCompetenciesFromFile(IXLWorkbook workbook, int adminUserId, int frameworkId)
55+
public ImportCompetenciesResult ProcessCompetenciesFromFile(IXLWorkbook workbook, int adminUserId, int frameworkId, string vocabulary)
5856
{
5957
int maxFrameworkCompetencyId = frameworkService.GetMaxFrameworkCompetencyID();
6058
int maxFrameworkCompetencyGroupId = frameworkService.GetMaxFrameworkCompetencyGroupID();
61-
var table = OpenCompetenciesTable(workbook);
59+
var table = OpenCompetenciesTable(workbook, vocabulary);
6260
return ProcessCompetenciesTable(table, adminUserId, frameworkId, maxFrameworkCompetencyId, maxFrameworkCompetencyGroupId);
6361
}
64-
internal IXLTable OpenCompetenciesTable(IXLWorkbook workbook)
62+
internal IXLTable OpenCompetenciesTable(IXLWorkbook workbook, string vocabulary)
6563
{
6664
var worksheet = workbook.Worksheet(1);
6765
worksheet.Columns(1, 15).Unhide();
@@ -70,7 +68,7 @@ internal IXLTable OpenCompetenciesTable(IXLWorkbook workbook)
7068
throw new InvalidHeadersException();
7169
}
7270
var table = worksheet.Tables.Table(0);
73-
if (!ValidateHeaders(table))
71+
if (!ValidateHeaders(table, vocabulary))
7472
{
7573
throw new InvalidHeadersException();
7674
}
@@ -132,26 +130,26 @@ CompetencyTableRow competencyRow
132130
return maxFrameworkCompetencyGroupId;
133131
}
134132

135-
private static bool ValidateHeaders(IXLTable table)
133+
private static bool ValidateHeaders(IXLTable table, string Vocabulary)
136134
{
137135
var expectedHeaders = new List<string>
138136
{
139137
"ID",
140-
"CompetencyGroup",
138+
Vocabulary + "Group",
141139
"GroupDescription",
142-
"Competency",
143-
"CompetencyDescription",
140+
Vocabulary,
141+
Vocabulary + "Description",
144142
"AlwaysShowDescription",
145143
"FlagsCSV"
146144
}.OrderBy(x => x);
147145
var actualHeaders = table.Fields.Select(x => x.Name).OrderBy(x => x);
148146
return actualHeaders.SequenceEqual(expectedHeaders);
149147
}
150148

151-
public byte[] GetCompetencyFileForFramework(int frameworkId, bool blank)
149+
public byte[] GetCompetencyFileForFramework(int frameworkId, bool blank, string vocabulary)
152150
{
153151
using var workbook = new XLWorkbook();
154-
PopulateCompetenciesSheet(workbook, frameworkId, blank);
152+
PopulateCompetenciesSheet(workbook, frameworkId, blank, vocabulary);
155153
if (blank)
156154
{
157155
ClosedXmlHelper.HideWorkSheetColumn(workbook, "ID");
@@ -167,7 +165,7 @@ public byte[] GetCompetencyFileForFramework(int frameworkId, bool blank)
167165
workbook.SaveAs(stream);
168166
return stream.ToArray();
169167
}
170-
private void PopulateCompetenciesSheet(IXLWorkbook workbook, int frameworkId, bool blank)
168+
private void PopulateCompetenciesSheet(IXLWorkbook workbook, int frameworkId, bool blank, string vocabulary)
171169
{
172170

173171

@@ -184,8 +182,10 @@ private void PopulateCompetenciesSheet(IXLWorkbook workbook, int frameworkId, bo
184182
FlagsCSV = x.FlagsCsv,
185183
}
186184
);
187-
188185
ClosedXmlHelper.AddSheetToWorkbook(workbook, CompetenciesSheetName, competencies, TableTheme);
186+
ClosedXmlHelper.RenameWorksheetColumn(workbook, "CompetencyGroup", vocabulary + "Group");
187+
ClosedXmlHelper.RenameWorksheetColumn(workbook, "Competency", vocabulary);
188+
ClosedXmlHelper.RenameWorksheetColumn(workbook, "CompetencyDescription", vocabulary + "Description");
189189
}
190190
}
191191
}

DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/Index.cshtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
This Excel file will be empty.<br />
6767
New @Model.FrameworkVocabularyPlural.ToLower() can be added by including their details on a blank row.
6868
</div>
69-
<a class="nhsuk-button nhsuk-button--secondary" role="button" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-DownloadOption="1" asp-controller="Frameworks" asp-action="DownloadCompetencies" target="_blank">
69+
<a class="nhsuk-button nhsuk-button--secondary" role="button" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-vocabulary="@Model.FrameworkVocabularySingular" asp-route-DownloadOption="1" asp-controller="Frameworks" asp-action="DownloadCompetencies" target="_blank">
7070
Download template
7171
</a>
7272
</div>
@@ -81,7 +81,7 @@
8181
This Excel file will include all existing @Model.FrameworkVocabularyPlural.ToLower() whose details you can update.<br />
8282
New @Model.FrameworkVocabularyPlural.ToLower() can be added by including their details on a blank row.
8383
</div>
84-
<a class="nhsuk-button nhsuk-button--secondary" role="button" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-DownloadOption="2" asp-controller="Frameworks" asp-action="DownloadCompetencies" target="_blank">
84+
<a class="nhsuk-button nhsuk-button--secondary" role="button" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-vocabulary="@Model.FrameworkVocabularySingular" asp-route-DownloadOption="2" asp-controller="Frameworks" asp-action="DownloadCompetencies" target="_blank">
8585
Download @Model.FrameworkVocabularyPlural.ToLower()
8686
</a>
8787
</div>
@@ -94,7 +94,7 @@
9494
<p class="nhsuk-body-m">
9595
Download a blank template for bulk adding @Model.FrameworkVocabularyPlural.ToLower() to your framework, <strong>@Model.FrameworkName</strong>. This Excel file will be empty. New @Model.FrameworkVocabularyPlural.ToLower() can be added by including their details on a blank row.
9696
</p>
97-
<a class="nhsuk-button nhsuk-button--secondary" role="button" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-DownloadOption="1" asp-controller="Frameworks" asp-action="DownloadCompetencies" target="_blank">
97+
<a class="nhsuk-button nhsuk-button--secondary" role="button" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-vocabulary="@Model.FrameworkVocabularySingular" asp-route-DownloadOption="1" asp-controller="Frameworks" asp-action="DownloadCompetencies" target="_blank">
9898
Download template
9999
</a>
100100
}

0 commit comments

Comments
 (0)