Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ bool zeroBased

Competency? GetFrameworkCompetencyForPreview(int frameworkCompetencyId);
IEnumerable<BulkCompetency> GetBulkCompetenciesForFramework(int frameworkId);
List<int> GetFrameworkCompetencyOrder(int frameworkId, List<int> frameworkCompetencyIds);

// Comments:
IEnumerable<CommentReplies> GetCommentsForFrameworkId(int frameworkId, int adminId);
Expand Down Expand Up @@ -2429,5 +2430,16 @@ Competencies AS c INNER JOIN
}

}
public List<int> GetFrameworkCompetencyOrder(int frameworkId, List<int> frameworkCompetencyIds)
{
return connection.Query<int>(
@"SELECT fc.ID
FROM FrameworkCompetencies AS fc INNER JOIN
FrameworkCompetencyGroups AS fcg ON fc.FrameworkCompetencyGroupID = fcg.ID
WHERE (fc.FrameworkID = @frameworkId) AND (fc.ID IN @frameworkCompetencyIds)
ORDER BY fcg.Ordering, fc.Ordering",
new { frameworkId, frameworkCompetencyIds }
).ToList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum RowStatus
CompetencyGroupAndCompetencyInserted,
CompetencyInserted,
CompetencyUpdated,
CompetencyUpdatedAndReordered,
CompetencyGroupInserted,
CompetencyGroupUpdated,
CompetencyGroupAndCompetencyUpdated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ IReadOnlyCollection<CompetencyTableRow> competencyTableRows
{
ProcessedCount = competencyTableRows.Count;
CompetencyAddedCount = competencyTableRows.Count(dr => dr.RowStatus == RowStatus.CompetencyInserted | dr.RowStatus == RowStatus.CompetencyGroupAndCompetencyInserted);
CompetencyUpdatedCount = competencyTableRows.Count(dr => dr.RowStatus == RowStatus.CompetencyUpdated);
CompetencyUpdatedCount = competencyTableRows.Count(dr => dr.RowStatus == RowStatus.CompetencyUpdated | dr.RowStatus == RowStatus.CompetencyUpdatedAndReordered);
CompetencyReorderedCount = competencyTableRows.Count(dr => dr.RowStatus == RowStatus.CompetencyUpdatedAndReordered);
GroupAddedCount = competencyTableRows.Count(dr => dr.RowStatus == RowStatus.CompetencyGroupInserted | dr.RowStatus == RowStatus.CompetencyGroupAndCompetencyInserted);
SkippedCount = competencyTableRows.Count(dr => dr.RowStatus == RowStatus.Skipped);
Errors = competencyTableRows.Where(dr => dr.Error.HasValue).Select(dr => (dr.RowNumber, dr.Error!.Value));
Expand All @@ -47,6 +48,7 @@ IReadOnlyCollection<CompetencyTableRow> competencyTableRows
public int ProcessedCount { get; set; }
public int CompetencyAddedCount { get; set; }
public int CompetencyUpdatedCount { get; set; }
public int CompetencyReorderedCount { get; set; }
public int GroupAddedCount { get; set; }
public int GroupUpdatedCount { get; set; }
public int SkippedCount { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public IActionResult ImportCompleted()
data.CompetenciesToProcessCount = resultsModel.ToProcessCount;
data.CompetenciesToAddCount = resultsModel.CompetenciesToAddCount;
data.CompetenciesToUpdateCount = resultsModel.ToUpdateOrSkipCount;
data.CompetenciesToReorderCount = results.CompetencyReorderedCount;
setBulkUploadData(data);
return View("Developer/Import/ImportCompleted", resultsModel);
}
Expand All @@ -93,6 +94,30 @@ public IActionResult ImportCompleted()
return View("Developer/Import/ImportFailed");
}
}
[Route("/Framework/{frameworkId}/{tabname}/Import/Ordering")]
public IActionResult ApplyCompetencyOrdering()
{
var data = GetBulkUploadData();
if (data.CompetenciesToReorderCount > 0)
{
var model = new ApplyCompetencyOrderingViewModel(data.FrameworkId, data.FrameworkName, data.FrameworkVocubulary, data.CompetenciesToReorderCount, data.ReorderCompetenciesOption);
return View("Developer/Import/ApplyCompetencyOrdering", model);
}
return RedirectToAction("AddAssessmentQuestions", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
}
[HttpPost]
[Route("/Framework/{frameworkId}/{tabname}/Import/Ordering")]
public IActionResult ApplyCompetencyOrdering(int reorderCompetenciesOption)
{
var data = GetBulkUploadData();

if (data.ReorderCompetenciesOption != reorderCompetenciesOption)
{
data.ReorderCompetenciesOption = reorderCompetenciesOption;
setBulkUploadData(data);
}
return RedirectToAction("AddAssessmentQuestions", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
}
[Route("/Framework/{frameworkId}/{tabname}/Import/AssessmentQuestions")]
public IActionResult AddAssessmentQuestions()
{
Expand All @@ -119,6 +144,7 @@ public IActionResult AddAssessmentQuestions()
data.PublishStatusID,
data.CompetenciesToAddCount,
data.CompetenciesToUpdateCount,
data.CompetenciesToReorderCount,
defaultQuestions,
questionSelectList
);
Expand Down Expand Up @@ -191,6 +217,15 @@ public IActionResult AddQuestionsToWhichCompetencies(int AddAssessmentQuestionsO
setBulkUploadData(data);
return RedirectToAction("Summary", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
}
[Route("CancelImport")]
public IActionResult CancelImport()
{
var data = GetBulkUploadData();
var frameworkId = data.FrameworkId;
FileHelper.DeleteFile(webHostEnvironment, data.CompetenciesFileName);
TempData.Clear();
return RedirectToAction("ViewFramework", new { frameworkId, tabname = "Structure" });
}
private void setupBulkUploadData(int frameworkId, int adminUserID, string competenciessFileName, string tabName, bool isNotBlank)
{
TempData.Clear();
Expand Down
2 changes: 2 additions & 0 deletions DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public BulkCompetenciesData(DetailFramework framework, int adminUserId, string c
public int CompetenciesToProcessCount { get; set; }
public int CompetenciesToAddCount { get; set; }
public int CompetenciesToUpdateCount { get; set; }
public int CompetenciesToReorderCount { get; set; }
public int ReorderCompetenciesOption { get; set; } = 1; //1 = ignore order, 2 = apply order
public int LastRowProcessed { get; set; }
public int SubtotalCompetenciesAdded { get; set; }
public int SubtotalCompetenciesUpdated { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions DigitalLearningSolutions.Web/Services/FrameworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public interface IFrameworkService

int GetMaxFrameworkCompetencyGroupID();
IEnumerable<BulkCompetency> GetBulkCompetenciesForFramework(int frameworkId);
List<int> GetFrameworkCompetencyOrder(int frameworkId, List<int> frameworkCompetencyIds);

// Assessment questions:
IEnumerable<AssessmentQuestion> GetAllCompetencyQuestions(int adminId);
Expand Down Expand Up @@ -386,6 +387,11 @@ public IEnumerable<BulkCompetency> GetBulkCompetenciesForFramework(int framework
return frameworkDataService.GetBulkCompetenciesForFramework(frameworkId);
}

public List<int> GetFrameworkCompetencyOrder(int frameworkId, List<int> frameworkCompetencyIds)
{
return frameworkDataService.GetFrameworkCompetencyOrder(frameworkId, frameworkCompetencyIds);
}

public CollaboratorNotification? GetCollaboratorNotification(int id, int invitedByAdminId)
{
return frameworkDataService.GetCollaboratorNotification(id, invitedByAdminId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,39 @@ public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook
{
var table = OpenCompetenciesTable(workbook, vocabulary);
var competencyRows = table.Rows().Skip(1).Select(row => new CompetencyTableRow(table, row)).ToList();
var existingCompetencies = frameworkService.GetBulkCompetenciesForFramework(frameworkId);
var existingIds = existingCompetencies.Select(bc => (int)bc.ID).ToList();
var newCompetencyIds = competencyRows.Select(row => row.ID ?? 0).ToList();
var existingIds = frameworkService.GetFrameworkCompetencyOrder(frameworkId, newCompetencyIds);
foreach (var competencyRow in competencyRows)
{
PreProcessCompetencyRow(competencyRow, existingIds);
PreProcessCompetencyRow(competencyRow, newCompetencyIds, existingIds);
}
return new ImportCompetenciesResult(competencyRows);
}
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int> existingIds)
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int> newIds, List<int> existingIds)
{
if (competencyRow.ID == null)
{
competencyRow.RowStatus = RowStatus.CompetencyInserted;
}
else
{
if (!existingIds.Contains((int)(competencyRow?.ID)))
var id = (int)(competencyRow?.ID);
if (!existingIds.Contains(id))
{
competencyRow.RowStatus = RowStatus.InvalidId;
}
else
{
competencyRow.RowStatus = RowStatus.CompetencyUpdated;
int originalIndex = existingIds.IndexOf(id);
int newIndex = newIds.IndexOf(id);
if(originalIndex == newIndex)
{
competencyRow.RowStatus = RowStatus.CompetencyUpdated;
}
else
{
competencyRow.RowStatus = RowStatus.CompetencyUpdatedAndReordered;
}
}
}
competencyRow.Validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AddAssessmentQuestionsViewModel(
int publishStatusId,
int newCompetencies,
int existingCompetencies,
int competenciesToReorderCount,
IEnumerable<AssessmentQuestion> defaultQuestions,
SelectList questionSelectList
) : AddAssessmentQuestionsFormData
Expand All @@ -23,6 +24,7 @@ SelectList questionSelectList
public int PublishStatusID { get; set; } = publishStatusId;
public int NewCompetencies { get; set; } = newCompetencies;
public int ExistingCompetencies { get; set; } = existingCompetencies;
public int CompetenciesToReorderCount { get; set; } = competenciesToReorderCount;
public IEnumerable<AssessmentQuestion>? DefaultQuestions { get; set; } = defaultQuestions;
public SelectList? QuestionSelectList { get; set; } = questionSelectList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ public AddQuestionsToWhichCompetenciesViewModel
public int CompetenciesToProcessCount { get; set; }
public int CompetenciesToAddCount { get; set; }
public int CompetenciesToUpdateCount { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using DigitalLearningSolutions.Web.Helpers;

namespace DigitalLearningSolutions.Web.ViewModels.Frameworks.Import
{
public class ApplyCompetencyOrderingViewModel
{
public ApplyCompetencyOrderingViewModel
(
int frameworkId,
string frameworkName,
string frameworkVocabulary,
int competenciesToReorderCount,
int reorderCompetenciesOption
)
{
FrameworkID = frameworkId;
FrameworkName = frameworkName;
FrameworkVocabularySingular = FrameworkVocabularyHelper.VocabularySingular(frameworkVocabulary);
FrameworkVocabularyPlural = FrameworkVocabularyHelper.VocabularyPlural(frameworkVocabulary);
CompetenciesToReorderCount = competenciesToReorderCount;
ReorderCompetenciesOption = reorderCompetenciesOption;
}
public int FrameworkID { get; set; }
public string FrameworkName { get; set; }
public string FrameworkVocabularySingular { get; set; }
public string FrameworkVocabularyPlural { get; set; }
public int ReorderCompetenciesOption { get; set; } = 1; //1 = ignore order, 2 = apply order
public int CompetenciesToReorderCount { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public ImportCompetenciesPreProcessViewModel(ImportCompetenciesResult bulkCompet
FrameworkVocabularyPlural = FrameworkVocabularyHelper.VocabularyPlural(bulkCompetenciesData.FrameworkVocubulary);
ToProcessCount = bulkCompetenciesResult.ProcessedCount;
CompetenciesToAddCount = bulkCompetenciesResult.CompetencyAddedCount;
CompetenciesToReorderCount = bulkCompetenciesResult.CompetencyReorderedCount;
ToUpdateOrSkipCount = bulkCompetenciesResult.CompetencyUpdatedCount;
Errors = bulkCompetenciesResult.Errors.Select(x => (x.RowNumber, MapReasonToErrorMessage(x.Reason, FrameworkVocabularyHelper.VocabularySingular(bulkCompetenciesData.FrameworkVocubulary))));
FlagCount = bulkCompetenciesResult.FlagCount;
Expand All @@ -31,6 +32,7 @@ public ImportCompetenciesPreProcessViewModel(ImportCompetenciesResult bulkCompet
public int ErrorCount => Errors.Count();
public int ToProcessCount { get; set; }
public int CompetenciesToAddCount { get; set; }
public int CompetenciesToReorderCount { get; set; }
public int ToUpdateOrSkipCount { get; set; }
public string? ImportFile { get; set; }
public bool IsNotBlank { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@
</div>
</fieldset>
</div>
<a asp-controller="Frameworks" asp-action="@(Model.CompetenciesToReorderCount == 0 ? "ImportCompleted" : "ApplyCompetencyOrdering")" asp-all-route-data="@cancelLinkData" role="button" class="nhsuk-button nhsuk-button--secondary">Back</a>
<button class="nhsuk-button" type="submit">Next</button>
</form>
<vc:back-link asp-controller="Frameworks" asp-action="Index" asp-all-route-data="@null" link-text="Cancel" />
<vc:cancel-link asp-controller="Frameworks" asp-action="CancelImport" asp-all-route-data="@cancelLinkData" link-text="Cancel" />
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-full">
<div class="nhsuk-u-reading-width">
<form class="nhsuk-u-margin-bottom-3" method="post" asp-action="SubmitAddWhoToGroup" enctype="multipart/form-data">
<form class="nhsuk-u-margin-bottom-3" method="post" enctype="multipart/form-data">
<fieldset class="nhsuk-fieldset">
<legend class="nhsuk-fieldset__legend nhsuk-fieldset__legend--l">
<h1 class="nhsuk-fieldset__heading">
Expand Down Expand Up @@ -81,7 +81,7 @@
<a asp-controller="Frameworks" asp-action="AddAssessmentQuestions" asp-all-route-data="@cancelLinkData" role="button" class="nhsuk-button nhsuk-button--secondary">Back</a>
<button class="nhsuk-button" type="submit">Next</button>
</form>
<vc:back-link asp-controller="Frameworks" asp-action="Index" asp-all-route-data="@null" link-text="Cancel" />
<vc:cancel-link asp-controller="Frameworks" asp-action="CancelImport" asp-all-route-data="@cancelLinkData" link-text="Cancel" />
</div>
</div>
</div>
Loading
Loading