Skip to content

Commit 2536588

Browse files
committed
Merge branch 'DLS-Release-v1.2.0' into UAT
2 parents 0613d03 + 7d00ef2 commit 2536588

File tree

9 files changed

+192
-129
lines changed

9 files changed

+192
-129
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ bool deleteFromExisting
266266
void DeleteCompetencyAssessmentQuestion(int frameworkCompetencyId, int assessmentQuestionId, int adminId);
267267

268268
void DeleteCompetencyLearningResource(int competencyLearningResourceId, int adminId);
269+
void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId);
269270
}
270271

271272
public class FrameworkDataService : IFrameworkDataService
@@ -2460,5 +2461,22 @@ public int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId)
24602461
new { frameworkId, competencyGroupId }
24612462
).Single();
24622463
}
2464+
2465+
public void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId)
2466+
{
2467+
var numberOfAffectedRows = connection.Execute(
2468+
@"UPDATE FrameworkCompetencies
2469+
SET FrameworkCompetencyGroupId = @frameworkCompetencyGroupId, UpdatedByAdminID = @adminId
2470+
WHERE ID = @competencyGroupId AND FrameworkCompetencyGroupId <> @frameworkCompetencyGroupId",
2471+
new { frameworkCompetencyGroupId, competencyGroupId, adminId }
2472+
);
2473+
if (numberOfAffectedRows < 1)
2474+
{
2475+
logger.LogWarning(
2476+
"Not updating framework competencies framework competency group id as db update failed. " +
2477+
$"frameworkCompetencyGroupId: {frameworkCompetencyGroupId}, competencyGroupId: {competencyGroupId}."
2478+
);
2479+
}
2480+
}
24632481
}
24642482
}

DigitalLearningSolutions.Web/Services/FrameworkService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ bool deleteFromExisting
261261
void DeleteCompetencyAssessmentQuestion(int frameworkCompetencyId, int assessmentQuestionId, int adminId);
262262

263263
void DeleteCompetencyLearningResource(int competencyLearningResourceId, int adminId);
264+
void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId);
264265
}
265266
public class FrameworkService : IFrameworkService
266267
{
@@ -729,5 +730,10 @@ public int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId)
729730
{
730731
return frameworkDataService.GetFrameworkCompetencyGroupId(frameworkId, competencyGroupId);
731732
}
733+
734+
public void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId)
735+
{
736+
frameworkDataService.UpdateFrameworkCompetencyFrameworkCompetencyGroup(competencyGroupId, frameworkCompetencyGroupId, adminId);
737+
}
732738
}
733739
}

DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook
3636
var competencyRows = table.Rows().Skip(1).Select(row => new CompetencyTableRow(table, row)).ToList();
3737
var newCompetencyIds = competencyRows.Select(row => row.ID ?? 0).ToList();
3838
var existingIds = frameworkService.GetFrameworkCompetencyOrder(frameworkId, newCompetencyIds);
39+
var existingGroups = frameworkService
40+
.GetFrameworkCompetencyGroups(frameworkId)
41+
.Select(row => row.Name)
42+
.Distinct()
43+
.ToList();
44+
var newGroups = competencyRows.Select(row => row.CompetencyGroup ?? "").ToList();
3945
foreach (var competencyRow in competencyRows)
4046
{
41-
PreProcessCompetencyRow(competencyRow, newCompetencyIds, existingIds);
47+
PreProcessCompetencyRow(competencyRow, newCompetencyIds, existingIds, existingGroups, newGroups);
4248
}
4349
return new ImportCompetenciesResult(competencyRows);
4450
}
45-
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int> newIds, List<int> existingIds)
51+
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int> newIds, List<int> existingIds, List<string> existingGroups, List<string> newGroups)
4652
{
53+
4754
if (competencyRow.ID == null)
4855
{
4956
competencyRow.RowStatus = RowStatus.CompetencyInserted;
@@ -64,6 +71,16 @@ private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int>
6471
{
6572
competencyRow.Reordered = true;
6673
}
74+
else
75+
{
76+
var groupName = (string)(competencyRow?.CompetencyGroup);
77+
originalIndex = existingGroups.IndexOf(groupName);
78+
newIndex = newGroups.IndexOf(groupName);
79+
if (originalIndex != newIndex)
80+
{
81+
competencyRow.Reordered = true;
82+
}
83+
}
6784
}
6885
}
6986
competencyRow.Validate();
@@ -124,10 +141,10 @@ internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int a
124141
if (reorderCompetenciesOption == 2)
125142
{
126143
var distinctCompetencyGroups = competenciesRows
127-
.Where(row => !string.IsNullOrWhiteSpace(row.CompetencyGroup))
128-
.Select(row => row.CompetencyGroup)
129-
.Distinct()
130-
.ToList();
144+
.Where(row => !string.IsNullOrWhiteSpace(row.CompetencyGroup))
145+
.Select(row => row.CompetencyGroup)
146+
.Distinct()
147+
.ToList();
131148
for (int i = 0; i < competencyGroupCount; i++)
132149
{
133150
var existingGroups = frameworkService.GetFrameworkCompetencyGroups(frameworkId).Select(row => new { row.ID, row.Name })
@@ -177,6 +194,7 @@ CompetencyTableRow competencyRow
177194
if (newCompetencyGroupId > 0)
178195
{
179196
frameworkCompetencyGroupId = frameworkService.InsertFrameworkCompetencyGroup(newCompetencyGroupId, frameworkId, adminId);
197+
frameworkService.UpdateFrameworkCompetencyFrameworkCompetencyGroup(competencyRow.ID, (int)frameworkCompetencyGroupId, adminId);
180198
if (frameworkCompetencyGroupId > maxFrameworkCompetencyGroupId)
181199
{
182200
maxFrameworkCompetencyGroupId = (int)frameworkCompetencyGroupId;
@@ -185,6 +203,7 @@ CompetencyTableRow competencyRow
185203
else
186204
{
187205
frameworkCompetencyGroupId = frameworkService.GetFrameworkCompetencyGroupId(frameworkId, newCompetencyGroupId);
206+
188207
var isUpdated = frameworkService.UpdateFrameworkCompetencyGroup((int)frameworkCompetencyGroupId, newCompetencyGroupId, competencyRow.CompetencyGroup, competencyRow.GroupDescription, adminId);
189208
competencyRow.RowStatus = RowStatus.CompetencyGroupUpdated;
190209
}
@@ -266,20 +285,23 @@ CompetencyTableRow competencyRow
266285
// Reorder competencies if required:
267286
if (reorderCompetenciesOption == 2)
268287
{
269-
var frameworkCompetencyId = (int)competencyRow.ID;
270-
var frameworkCompetency = frameworkService.GetFrameworkCompetencyById(frameworkCompetencyId);
271-
var placesToMove = Math.Abs(frameworkCompetency.Ordering - competencyRow.CompetencyOrderNumber);
272-
273-
if (placesToMove > 0)
288+
var frameworkCompetencyId = competencyRow.ID ?? 0;
289+
if (frameworkCompetencyId > 0)
274290
{
275-
var direction = frameworkCompetency.Ordering > competencyRow.CompetencyOrderNumber ? "UP" : "DOWN";
291+
var frameworkCompetency = frameworkService.GetFrameworkCompetencyById(frameworkCompetencyId);
292+
var placesToMove = Math.Abs(frameworkCompetency.Ordering - competencyRow.CompetencyOrderNumber);
276293

277-
for (int i = 0; i < placesToMove; i++)
294+
if (placesToMove > 0)
278295
{
279-
frameworkService.MoveFrameworkCompetency(frameworkCompetencyId, true, direction);
280-
}
296+
var direction = frameworkCompetency.Ordering > competencyRow.CompetencyOrderNumber ? "UP" : "DOWN";
281297

282-
competencyRow.Reordered = true;
298+
for (int i = 0; i < placesToMove; i++)
299+
{
300+
frameworkService.MoveFrameworkCompetency(frameworkCompetencyId, true, direction);
301+
}
302+
303+
competencyRow.Reordered = true;
304+
}
283305
}
284306
}
285307

DigitalLearningSolutions.Web/Views/SuperAdmin/AdminAccounts/Index.cshtml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@using DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Administrators
22
@model AdminAccountsViewModel
33
@{
4-
ViewData["Title"] = "Administrators";
4+
ViewData["Title"] = "Administrators";
55
}
66
<link rel="stylesheet" href="@Url.Content("~/css/superAdmin/users.css")" asp-append-version="true">
77
<div class="nhsuk-grid-row">
@@ -16,23 +16,23 @@
1616

1717
<div class="nhsuk-grid-column-three-quarters">
1818
<div class="nhsuk-grid-row">
19-
<div class="nhsuk-grid-column-one-half">
20-
<h1 class="nhsuk-heading-xl">@ViewData["Title"]</h1>
21-
</div>
22-
<div class="nhsuk-grid-column-one-half">
23-
<a class="nhsuk-button nhsuk-button--secondary nhsuk-u-float-right"
24-
id="export"
25-
asp-controller="AdminAccounts"
26-
asp-action="Export"
27-
asp-route-searchString="@Model.SearchString"
28-
asp-route-existingFilterString="@Model.ExistingFilterString"
29-
role="button">
30-
Export to Excel
31-
</a>
32-
</div>
19+
<div class="nhsuk-grid-column-one-half">
20+
<h1 class="nhsuk-heading-xl">@ViewData["Title"]</h1>
21+
</div>
22+
<div class="nhsuk-grid-column-one-half">
23+
<a class="nhsuk-button nhsuk-button--secondary nhsuk-u-float-right"
24+
id="export"
25+
asp-controller="AdminAccounts"
26+
asp-action="Export"
27+
asp-route-searchString="@Model.SearchString"
28+
asp-route-existingFilterString="@Model.ExistingFilterString"
29+
role="button">
30+
Export to Excel
31+
</a>
32+
</div>
3333
</div>
3434
<form class="nhsuk-u-margin-bottom-3" method="get" role="search" asp-controller="AdminAccounts" asp-action="Index" asp-route-page="@Model.Page">
35-
<input type="hidden" name="itemsPerPage" value="@Model.ItemsPerPage" />
35+
<input type="hidden" name="itemsPerPage" value="@Model.ItemsPerPage" />
3636
<div class="nhsuk-grid-row">
3737
<div id="search">
3838
<div class="nhsuk-grid-column-one-quarter">
@@ -64,24 +64,26 @@
6464
</div>
6565
</div>
6666
</div>
67+
</div>
68+
<div class="nhsuk-grid-row">
6769
<div class="filter-container nhsuk-u-margin-top-5">
68-
<div class="nhsuk-grid-column-one-quarter nhsuk-u-margin-right-3">
70+
<div class="nhsuk-grid-column-one-quarter nhsuk-u-margin-right-4">
6971
<vc:select-list asp-for="@nameof(Model.UserStatus)"
7072
label="Account status"
7173
value="@Model.UserStatus"
7274
required="true"
7375
hint-text=""
74-
css-class="nhsuk-grid-column-full nhsuk-u-width-full"
76+
css-class=""
7577
default-option=""
7678
select-list-options="@ViewBag.UserStatus" />
7779
</div>
78-
<div class="nhsuk-grid-column-one-quarter nhsuk-u-margin-right-3">
80+
<div class="nhsuk-grid-column-one-quarter nhsuk-u-margin-right-4">
7981
<vc:select-list asp-for="@nameof(Model.Role)"
8082
label="Role"
8183
value="@Model.Role"
8284
required="true"
8385
hint-text=""
84-
css-class="nhsuk-grid-column-full nhsuk-u-width-full"
86+
css-class=""
8587
default-option=""
8688
select-list-options="@ViewBag.Roles" />
8789
</div>
@@ -91,7 +93,7 @@
9193
value="@Model.CentreID.ToString()"
9294
hint-text=""
9395
required="true"
94-
css-class="nhsuk-grid-column-full nhsuk-u-width-full"
96+
css-class=""
9597
default-option=""
9698
select-list-options="@ViewBag.Centres" />
9799
</div>
@@ -115,7 +117,7 @@
115117
<partial name="_SearchableAdminAccountsCard" model="admin" />
116118
}
117119
</div>
118-
<partial name="SearchablePage/_BottomPagination" model="Model" />
120+
<partial name="SearchablePage/_BottomPagination" model="Model" />
119121
}
120122
</div>
121123
<nav class="side-nav-menu-bottom" aria-label="Bottom navigation bar">

0 commit comments

Comments
 (0)