From 8816bb63b3862a77d2b89c33a5337b18a21756ec Mon Sep 17 00:00:00 2001 From: kevwhitt-hee Date: Thu, 2 Jan 2025 17:19:57 +0000 Subject: [PATCH 1/2] TD-5158 Implements add questions to which competencies form --- .../ImportCompetencies.cs | 47 ++++++++-- .../Models/BulkCompetenciesData.cs | 5 +- ...ddQuestionsToWhichCompetenciesViewModel.cs | 41 +++++++++ .../ImportCompetenciesPreProcessViewModel.cs | 5 -- .../AddQuestionsToWhichCompetencies.cshtml | 87 +++++++++++++++++++ 5 files changed, 173 insertions(+), 12 deletions(-) create mode 100644 DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs create mode 100644 DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/AddQuestionsToWhichCompetencies.cshtml diff --git a/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs b/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs index 1e77c8f05c..1a6150492c 100644 --- a/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs +++ b/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs @@ -1,14 +1,14 @@ -using ClosedXML.Excel; +using AngleSharp.Dom; +using ClosedXML.Excel; using DigitalLearningSolutions.Data.Exceptions; using DigitalLearningSolutions.Web.Helpers; using DigitalLearningSolutions.Web.Models; using DigitalLearningSolutions.Web.Services; using DigitalLearningSolutions.Web.ViewModels.Frameworks.Import; -using DocumentFormat.OpenXml.Office2010.ExcelAc; +using DocumentFormat.OpenXml.EMMA; using GDS.MultiPageFormData.Enums; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.DotNet.Scaffolding.Shared.Project; using System.Collections.Generic; using System.IO; using System.Linq; @@ -85,7 +85,7 @@ public IActionResult ImportCompleted() var resultsModel = new ImportCompetenciesPreProcessViewModel(results, data) { IsNotBlank = data.IsNotBlank, TabName = data.TabName }; data.CompetenciesToProcessCount = resultsModel.ToProcessCount; data.CompetenciesToAddCount = resultsModel.CompetenciesToAddCount; - data.CompetenciesToUpdateCount = resultsModel.CompetenciesToUpdateCount; + data.CompetenciesToUpdateCount = resultsModel.ToUpdateOrSkipCount; setBulkUploadData(data); return View("Developer/Import/ImportCompleted", resultsModel); } @@ -153,8 +153,45 @@ public IActionResult AddAssessmentQuestions(AddAssessmentQuestionsFormData model { data.CustomAssessmentQuestionID = null; } + if (data.CompetenciesToUpdateCount > 0) + { + data.AddAssessmentQuestionsOption = 2; + setBulkUploadData(data); + return RedirectToAction("AddQuestionsToWhichCompetencies", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName }); + } + else + { + data.AddAssessmentQuestionsOption = 1; + setBulkUploadData(data); + return RedirectToAction("Summary", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName }); + } + } + [Route("/Framework/{frameworkId}/{tabname}/Import/AssessmentQuestions/Competencies")] + public IActionResult AddQuestionsToWhichCompetencies() + { + var data = GetBulkUploadData(); + var model = new AddQuestionsToWhichCompetenciesViewModel + ( + data.FrameworkId, + data.FrameworkName, + data.FrameworkVocubulary, + data.DefaultQuestionIDs, + data.CustomAssessmentQuestionID, + data.AddAssessmentQuestionsOption, + data.CompetenciesToProcessCount, + data.CompetenciesToAddCount, + data.CompetenciesToUpdateCount + ); + return View("Developer/Import/AddQuestionsToWhichCompetencies", model); + } + [HttpPost] + [Route("/Framework/{frameworkId}/{tabname}/Import/AssessmentQuestions/Competencies")] + public IActionResult AddQuestionsToWhichCompetencies(int AddAssessmentQuestionsOption) + { + var data = GetBulkUploadData(); + data.AddAssessmentQuestionsOption = AddAssessmentQuestionsOption; setBulkUploadData(data); - return RedirectToAction("AddQuestionsToWhichCompetencies"); + return RedirectToAction("Summary", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName }); } private void setupBulkUploadData(int frameworkId, int adminUserID, string competenciessFileName, string tabName, bool isNotBlank) { diff --git a/DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs b/DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs index bf7cb9b61d..738acbf9ea 100644 --- a/DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs +++ b/DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs @@ -27,10 +27,11 @@ public BulkCompetenciesData(DetailFramework framework, int adminUserId, string c public int AdminUserId { get; set; } public bool IsNotBlank { get; set; } public string CompetenciesFileName { get; set; } - public List DefaultQuestionIDs { get; set; } = []; - public int? CustomAssessmentQuestionID { get; set; } public bool AddDefaultAssessmentQuestions { get; set; } = true; public bool AddCustomAssessmentQuestion { get; set; } = false; + public List DefaultQuestionIDs { get; set; } = []; + public int? CustomAssessmentQuestionID { get; set; } + public int AddAssessmentQuestionsOption { get; set; } //1 = only added, 2 = added and updated, 3 = all uploaded public int CompetenciesToProcessCount { get; set; } public int CompetenciesToAddCount { get; set; } public int CompetenciesToUpdateCount { get; set; } diff --git a/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs new file mode 100644 index 0000000000..d6cbae84ca --- /dev/null +++ b/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs @@ -0,0 +1,41 @@ +using DigitalLearningSolutions.Web.Helpers; +using System.Collections.Generic; +using System.Runtime.Versioning; + +namespace DigitalLearningSolutions.Web.ViewModels.Frameworks.Import +{ + public class AddQuestionsToWhichCompetenciesViewModel + { + public AddQuestionsToWhichCompetenciesViewModel + ( + int frameworkId, + string frameworkName, + string frameworkVocabulary, + List defaultQuestions, + int? customQuestionId, + int addAssessmentQuestionsOption, + int competenciesToProcessCount, + int competenciesToAddCount, + int competenciesToUpdateCount) + { + FrameworkID = frameworkId; + FrameworkName = frameworkName; + FrameworkVocabularySingular = FrameworkVocabularyHelper.VocabularySingular(frameworkVocabulary); + FrameworkVocabularyPlural = FrameworkVocabularyHelper.VocabularyPlural(frameworkVocabulary); + TotalQuestions = defaultQuestions.Count + (customQuestionId != null ? 1 : 0); + AddAssessmentQuestionsOption = addAssessmentQuestionsOption; + CompetenciesToProcessCount = competenciesToProcessCount; + CompetenciesToAddCount = competenciesToAddCount; + CompetenciesToUpdateCount = competenciesToUpdateCount; + } + public int FrameworkID { get; set; } + public string FrameworkName { get; set; } + public string FrameworkVocabularySingular { get; set; } + public string FrameworkVocabularyPlural { get; set; } + public int TotalQuestions { get; set; } + public int AddAssessmentQuestionsOption { get; set; } = 1; //1 = only added, 2 = added and updated, 3 = all uploaded + public int CompetenciesToProcessCount { get; set; } + public int CompetenciesToAddCount { get; set; } + public int CompetenciesToUpdateCount { get; set; } + } +} diff --git a/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/ImportCompetenciesPreProcessViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/ImportCompetenciesPreProcessViewModel.cs index f92f056115..67f604723a 100644 --- a/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/ImportCompetenciesPreProcessViewModel.cs +++ b/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/ImportCompetenciesPreProcessViewModel.cs @@ -18,8 +18,6 @@ public ImportCompetenciesPreProcessViewModel(ImportCompetenciesResult bulkCompet ToProcessCount = bulkCompetenciesResult.ProcessedCount; CompetenciesToAddCount = bulkCompetenciesResult.CompetencyAddedCount; ToUpdateOrSkipCount = bulkCompetenciesResult.CompetencyUpdatedCount; - CompetencyGroupsToAddCount = bulkCompetenciesResult.GroupAddedCount; - CompetencyGroupsToUpdateCount = bulkCompetenciesResult.GroupUpdatedCount; Errors = bulkCompetenciesResult.Errors.Select(x => (x.RowNumber, MapReasonToErrorMessage(x.Reason, FrameworkVocabularyHelper.VocabularySingular(bulkCompetenciesData.FrameworkVocubulary)))); } public string? FrameworkName { get; set; } @@ -30,9 +28,6 @@ public ImportCompetenciesPreProcessViewModel(ImportCompetenciesResult bulkCompet public int ErrorCount => Errors.Count(); public int ToProcessCount { get; set; } public int CompetenciesToAddCount { get; set; } - public int CompetenciesToUpdateCount { get; set; } - public int CompetencyGroupsToAddCount { get; set; } - public int CompetencyGroupsToUpdateCount { get; set; } public int ToUpdateOrSkipCount { get; set; } public string? ImportFile { get; set; } public bool IsNotBlank { get; set; } diff --git a/DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/AddQuestionsToWhichCompetencies.cshtml b/DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/AddQuestionsToWhichCompetencies.cshtml new file mode 100644 index 0000000000..bb5a3b3a5f --- /dev/null +++ b/DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/AddQuestionsToWhichCompetencies.cshtml @@ -0,0 +1,87 @@ +@using DigitalLearningSolutions.Web.Extensions +@using DigitalLearningSolutions.Web.ViewModels.Frameworks.Import + +@model AddQuestionsToWhichCompetenciesViewModel + +@{ + ViewData["Application"] = "Framework Service"; + ViewData["HeaderPathName"] = "Framework Service"; + var errorHasOccurred = !ViewData.ModelState.IsValid; + ViewData["Title"] = errorHasOccurred ? "Error: Add Assessment Questions" : "Add Assessment Questions"; + var cancelLinkData = Html.GetRouteValues(); +} + +@section NavMenuItems { + +} +@section NavBreadcrumbs { + +} +
+
+
+
+
+ +

+ Which @Model.FrameworkVocabularyPlural.ToLower() should the questions be added to? +

+
+
+ Choose which @Model.FrameworkVocabularyPlural.ToLower() you want to add the @Model.TotalQuestions assessment questions to +
+
+ Select one option +
+
+
+ @if (Model.CompetenciesToAddCount > 0) + { +
+ + +
+ @Model.TotalQuestions assessment questions will be added to the @Model.CompetenciesToAddCount new @Model.FrameworkVocabularyPlural.ToLower() +
+
+ } +
+ + +
+ @(Model.CompetenciesToAddCount > 0 ? Model.CompetenciesToAddCount + " new @Model.FrameworkVocabularyPlural.ToLower() and only those of the " : "Only those of the ") @Model.CompetenciesToUpdateCount existing @Model.FrameworkVocabularyPlural.ToLower() that have been modified in the sheet will have the assessment questions added +
+
+
+ + +
+ All @(Model.CompetenciesToProcessCount) @Model.FrameworkVocabularyPlural.ToLower() in the sheet that are will have the assessment questions added to them +
+
+
+
+ +
+ Back + +
+ +
+
+
From 54302338315898e3ae8190fbe96b340912db7ebd Mon Sep 17 00:00:00 2001 From: kevwhitt-hee Date: Thu, 2 Jan 2025 17:22:41 +0000 Subject: [PATCH 2/2] Removes spurious usings --- .../Controllers/FrameworksController/ImportCompetencies.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs b/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs index 1a6150492c..68d3e26d6f 100644 --- a/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs +++ b/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs @@ -1,11 +1,9 @@ -using AngleSharp.Dom; -using ClosedXML.Excel; +using ClosedXML.Excel; using DigitalLearningSolutions.Data.Exceptions; using DigitalLearningSolutions.Web.Helpers; using DigitalLearningSolutions.Web.Models; using DigitalLearningSolutions.Web.Services; using DigitalLearningSolutions.Web.ViewModels.Frameworks.Import; -using DocumentFormat.OpenXml.EMMA; using GDS.MultiPageFormData.Enums; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering;