Skip to content

Commit 1dde515

Browse files
committed
Merge branch 'DLS-Release-v1.2.0' into UAT
2 parents 37864f8 + 8240175 commit 1dde515

File tree

10 files changed

+228
-248
lines changed

10 files changed

+228
-248
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ bool zeroBased
130130

131131
IEnumerable<FrameworkCompetency> GetAllCompetenciesForAdminId(string name, int adminId);
132132

133-
int InsertCompetency(string name, string? description, int adminId);
133+
int InsertCompetency(string name, string? description, int adminId, bool alwaysShowDescription = false);
134134

135-
int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false);
135+
int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool addDefaultQuestions = true);
136136

137137
int AddCollaboratorToFramework(int frameworkId, string userEmail, bool canModify, int? centreID);
138138

@@ -618,7 +618,7 @@ FROM [FrameworkCompetencyGroups]
618618
return existingId;
619619
}
620620

621-
public int InsertCompetency(string name, string? description, int adminId)
621+
public int InsertCompetency(string name, string? description, int adminId, bool alwaysShowDescription = false)
622622
{
623623
if ((name.Length == 0) | (adminId < 1))
624624
{
@@ -630,10 +630,10 @@ public int InsertCompetency(string name, string? description, int adminId)
630630
description = (description?.Trim() == "" ? null : description);
631631

632632
var existingId = connection.QuerySingle<int>(
633-
@"INSERT INTO Competencies ([Name], [Description], UpdatedByAdminID)
633+
@"INSERT INTO Competencies ([Name], [Description], UpdatedByAdminID, AlwaysShowDescription)
634634
OUTPUT INSERTED.Id
635-
VALUES (@name, @description, @adminId)",
636-
new { name, description, adminId }
635+
VALUES (@name, @description, @adminId, @alwaysShowDescription)",
636+
new { name, description, adminId, alwaysShowDescription }
637637
);
638638

639639
return existingId;
@@ -644,7 +644,7 @@ public int InsertFrameworkCompetency(
644644
int? frameworkCompetencyGroupID,
645645
int adminId,
646646
int frameworkId,
647-
bool alwaysShowDescription = false
647+
bool addDefaultQuestions = true
648648
)
649649
{
650650
if ((competencyId < 1) | (adminId < 1) | (frameworkId < 1))
@@ -706,8 +706,10 @@ FROM [FrameworkCompetencies]
706706
new { competencyId, frameworkCompetencyGroupID }
707707
);
708708
}
709-
710-
AddDefaultQuestionsToCompetency(competencyId, frameworkId);
709+
if(addDefaultQuestions)
710+
{
711+
AddDefaultQuestionsToCompetency(competencyId, frameworkId);
712+
}
711713
return existingId;
712714
}
713715

DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Collections.Generic;
1111
using System.IO;
1212
using System.Linq;
13+
using System.Linq.Expressions;
1314

1415
namespace DigitalLearningSolutions.Web.Controllers.FrameworksController
1516
{
@@ -180,15 +181,16 @@ public IActionResult AddAssessmentQuestions()
180181
public IActionResult AddAssessmentQuestions(AddAssessmentQuestionsFormData model)
181182
{
182183
var data = GetBulkUploadData();
183-
data.AddDefaultAssessmentQuestions = model.AddDefaultAssessmentQuestions;
184+
184185
if (model.AddDefaultAssessmentQuestions)
185186
{
186-
data.DefaultQuestionIDs = model.DefaultAssessmentQuestionIDs;
187+
data.DefaultQuestionIDs = model.DefaultAssessmentQuestionIDs ?? [];
187188
}
188189
else
189190
{
190191
data.DefaultQuestionIDs = [];
191192
}
193+
data.AddDefaultAssessmentQuestions = (data.DefaultQuestionIDs.Count > 0 && model.AddDefaultAssessmentQuestions);
192194
data.AddCustomAssessmentQuestion = model.AddCustomAssessmentQuestion;
193195
if (model.AddCustomAssessmentQuestion)
194196
{
@@ -198,9 +200,8 @@ public IActionResult AddAssessmentQuestions(AddAssessmentQuestionsFormData model
198200
{
199201
data.CustomAssessmentQuestionID = null;
200202
}
201-
if (data.CompetenciesToUpdateCount > 0)
203+
if (data.CompetenciesToUpdateCount > 0 && (data.DefaultQuestionIDs.Count + (data.CustomAssessmentQuestionID != null ? 1 : 0) > 0))
202204
{
203-
data.AddAssessmentQuestionsOption = 2;
204205
setBulkUploadData(data);
205206
return RedirectToAction("AddQuestionsToWhichCompetencies", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
206207
}
@@ -260,11 +261,6 @@ public IActionResult ImportSummarySubmit()
260261
var workbook = new XLWorkbook(filePath);
261262
var results = importCompetenciesFromFileService.ProcessCompetenciesFromFile(workbook, adminId, data.FrameworkId, data.FrameworkVocubulary, data.ReorderCompetenciesOption, data.AddAssessmentQuestionsOption, data.AddCustomAssessmentQuestion ? (int)data.CustomAssessmentQuestionID : 0, data.AddDefaultAssessmentQuestions ? data.DefaultQuestionIDs : []);
262263
data.ImportCompetenciesResult = results;
263-
//TO DO apply ordering changes if required:
264-
if (data.ReorderCompetenciesOption == 2 && data.CompetenciesToReorderCount > 0)
265-
{
266-
267-
}
268264
setBulkUploadData(data);
269265
return RedirectToAction("UploadResults", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
270266
}
@@ -278,15 +274,25 @@ public IActionResult UploadResults()
278274
return View("Developer/Import/UploadResults", model);
279275
}
280276
[Route("CancelImport")]
281-
public IActionResult CancelImport()
277+
public IActionResult CancelImport(int? frameworkId)
282278
{
283-
var data = GetBulkUploadData();
284-
var frameworkId = data.FrameworkId;
285-
if (!string.IsNullOrWhiteSpace(data.CompetenciesFileName))
279+
try
286280
{
287-
FileHelper.DeleteFile(webHostEnvironment, data.CompetenciesFileName);
281+
var data = GetBulkUploadData();
282+
frameworkId = data.FrameworkId;
283+
if (!string.IsNullOrWhiteSpace(data.CompetenciesFileName))
284+
{
285+
FileHelper.DeleteFile(webHostEnvironment, data.CompetenciesFileName);
286+
}
287+
}
288+
catch
289+
{
290+
291+
}
292+
finally
293+
{
294+
TempData.Clear();
288295
}
289-
TempData.Clear();
290296
return RedirectToAction("ViewFramework", new { frameworkId, tabname = "Structure" });
291297
}
292298
private void setupBulkUploadData(int frameworkId, int adminUserID, string competenciessFileName, string tabName, bool isNotBlank)

DigitalLearningSolutions.Web/Helpers/StringHelper.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DigitalLearningSolutions.Web.Helpers
22
{
33
using System;
4+
using System.Text.RegularExpressions;
45
using DigitalLearningSolutions.Data.Extensions;
56
using Microsoft.Extensions.Configuration;
67

@@ -16,5 +17,17 @@ public static string GetLocalRedirectUrl(IConfiguration config, string basicUrl)
1617
var applicationPath = new Uri(config.GetAppRootPath()).AbsolutePath.TrimEnd('/');
1718
return applicationPath + basicUrl;
1819
}
20+
public static string StripHtmlTags(string input)
21+
{
22+
if (string.IsNullOrWhiteSpace(input))
23+
{
24+
return string.Empty;
25+
}
26+
27+
// Remove HTML tags
28+
string result = Regex.Replace(input, "<.*?>", string.Empty).Trim();
29+
30+
return string.IsNullOrEmpty(result) ? string.Empty : result;
31+
}
1932
}
2033
}

DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public BulkCompetenciesData(DetailFramework framework, int adminUserId, string c
3232
public bool AddCustomAssessmentQuestion { get; set; } = false;
3333
public List<int> DefaultQuestionIDs { get; set; } = [];
3434
public int? CustomAssessmentQuestionID { get; set; }
35-
public int AddAssessmentQuestionsOption { get; set; } = 1; //1 = only added, 2 = added and updated, 3 = all uploaded
35+
public int AddAssessmentQuestionsOption { get; set; } = 2; //1 = only added, 2 = added and updated, 3 = all uploaded
3636
public int CompetenciesToProcessCount { get; set; }
3737
public int CompetenciesToAddCount { get; set; }
3838
public int CompetenciesToUpdateCount { get; set; }

DigitalLearningSolutions.Web/Services/FrameworkService.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using DigitalLearningSolutions.Data.Models.Frameworks.Import;
66
using DigitalLearningSolutions.Data.Models.SelfAssessments;
77
using System.Collections.Generic;
8+
using DigitalLearningSolutions.Web.Helpers;
89
using AssessmentQuestion = DigitalLearningSolutions.Data.Models.Frameworks.AssessmentQuestion;
910
using CompetencyResourceAssessmentQuestionParameter =
1011
DigitalLearningSolutions.Data.Models.Frameworks.CompetencyResourceAssessmentQuestionParameter;
@@ -120,11 +121,11 @@ bool zeroBased
120121

121122
int InsertCompetencyGroup(string groupName, string? groupDescription, int adminId, int? frameworkId = null);
122123

123-
int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false);
124+
int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool addDefaultQuestions = true);
124125

125126
IEnumerable<FrameworkCompetency> GetAllCompetenciesForAdminId(string name, int adminId);
126127

127-
int InsertCompetency(string name, string? description, int adminId);
128+
int InsertCompetency(string name, string? description, int adminId, bool alwaysShowDescription = false);
128129

129130
int InsertFrameworkCompetencyGroup(int groupId, int frameworkID, int adminId);
130131

@@ -516,7 +517,12 @@ public FrameworkDefaultQuestionUsage GetFrameworkDefaultQuestionUsage(int framew
516517

517518
public DetailFramework? GetFrameworkDetailByFrameworkId(int frameworkId, int adminId)
518519
{
519-
return frameworkDataService.GetFrameworkDetailByFrameworkId(frameworkId, adminId);
520+
var detailFramework = frameworkDataService.GetFrameworkDetailByFrameworkId(frameworkId, adminId);
521+
if (StringHelper.StripHtmlTags(detailFramework.Description) == string.Empty)
522+
{
523+
detailFramework.Description = string.Empty;
524+
}
525+
return detailFramework;
520526
}
521527

522528
public FrameworkReview? GetFrameworkReview(int frameworkId, int adminId, int reviewId)
@@ -594,19 +600,19 @@ public int InsertComment(int frameworkId, int adminId, string comment, int? repl
594600
return frameworkDataService.InsertComment(frameworkId, adminId, comment, replyToCommentId);
595601
}
596602

597-
public int InsertCompetency(string name, string? description, int adminId)
603+
public int InsertCompetency(string name, string? description, int adminId, bool alwaysShowDescription = false)
598604
{
599-
return frameworkDataService.InsertCompetency(name, description, adminId);
605+
return frameworkDataService.InsertCompetency(name, description, adminId, alwaysShowDescription);
600606
}
601607

602608
public int InsertCompetencyGroup(string groupName, string? groupDescription, int adminId, int? frameworkId)
603609
{
604610
return frameworkDataService.InsertCompetencyGroup(groupName, groupDescription, adminId, frameworkId);
605611
}
606612

607-
public int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false)
613+
public int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool addDefaultQuestions = true)
608614
{
609-
return frameworkDataService.InsertFrameworkCompetency(competencyId, frameworkCompetencyGroupID, adminId, frameworkId, alwaysShowDescription);
615+
return frameworkDataService.InsertFrameworkCompetency(competencyId, frameworkCompetencyGroupID, adminId, frameworkId, addDefaultQuestions);
610616
}
611617

612618
public int InsertFrameworkCompetencyGroup(int groupId, int frameworkID, int adminId)

DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ CompetencyTableRow competencyRow
211211
else
212212
{
213213
//Check if competency already exists in framework competency group and add if not
214-
newCompetencyId = frameworkService.InsertCompetency(competencyRow.Competency, competencyRow.CompetencyDescription, adminId);
214+
newCompetencyId = frameworkService.InsertCompetency(competencyRow.Competency, competencyRow.CompetencyDescription, adminId, competencyRow.AlwaysShowDescription ?? false);
215215
if (newCompetencyId > 0)
216216
{
217-
newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminId, frameworkId, competencyRow.AlwaysShowDescription ?? false); //including always show desc flag
217+
newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminId, frameworkId, false);
218218
if (newFrameworkCompetencyId > maxFrameworkCompetencyId)
219219
{
220220
competencyRow.RowStatus = (competencyRow.RowStatus == RowStatus.CompetencyGroupInserted ? RowStatus.CompetencyGroupAndCompetencyInserted : RowStatus.CompetencyInserted);

DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DigitalLearningSolutions.Web.Helpers;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Runtime.Versioning;
45

56
namespace DigitalLearningSolutions.Web.ViewModels.Frameworks.Import

DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/ImportCompetenciesFormData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public class ImportCompetenciesFormData
88
{
9-
[Required(ErrorMessage = "Import competencies file is required")]
10-
[AllowedExtensions([".xlsx"], "Import competencies file must be in xlsx format")]
9+
[Required(ErrorMessage = "Import file is required")]
10+
[AllowedExtensions([".xlsx"], "Import file must be in xlsx format")]
1111
[MaxFileSize(5 * 1024 * 1024, "Maximum allowed file size is 5MB")]
1212
public IFormFile? ImportFile { get; set; }
1313
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
@if (Model.CompetenciesToAddCount > 0)
4848
{
4949
<div class="nhsuk-radios__item">
50-
<input class="nhsuk-radios__input" id="option-1" asp-for="@Model.AddAssessmentQuestionsOption" type="radio" value="1" aria-describedby="option-1-hint">
50+
<input class="nhsuk-radios__input" id="option-1" asp-for="AddAssessmentQuestionsOption" type="radio" value="1" aria-describedby="option-1-hint">
5151
<label class="nhsuk-label nhsuk-radios__label" for="option-1">
5252
Only add questions to new @Model.FrameworkVocabularyPlural.ToLower()
5353
</label>
@@ -57,7 +57,7 @@
5757
</div>
5858
}
5959
<div class="nhsuk-radios__item">
60-
<input class="nhsuk-radios__input" id="option-2" asp-for="@Model.AddAssessmentQuestionsOption" type="radio" value="2" aria-describedby="option-2-hint">
60+
<input class="nhsuk-radios__input" id="option-2" asp-for="AddAssessmentQuestionsOption" type="radio" value="2" aria-describedby="option-2-hint">
6161
<label class="nhsuk-label nhsuk-radios__label" for="option-2">
6262
Only add questions to @(Model.CompetenciesToAddCount > 0 ? " new and " : "") modified @Model.FrameworkVocabularyPlural.ToLower()
6363
</label>
@@ -66,7 +66,7 @@
6666
</div>
6767
</div>
6868
<div class="nhsuk-radios__item">
69-
<input class="nhsuk-radios__input" id="option-3" asp-for="@Model.AddAssessmentQuestionsOption" type="radio" value="3" aria-describedby="option-3-hint">
69+
<input class="nhsuk-radios__input" id="option-3" asp-for="AddAssessmentQuestionsOption" type="radio" value="3" aria-describedby="option-3-hint">
7070
<label class="nhsuk-label nhsuk-radios__label" for="option-3">
7171
Add questions to all @Model.FrameworkVocabularyPlural.ToLower() in my uploaded sheet
7272
</label>

0 commit comments

Comments
 (0)