Skip to content

Commit 6995c8d

Browse files
committed
TD-5155 Implements conditional preselected checkboxes for default questions
1 parent e1f0f26 commit 6995c8d

File tree

9 files changed

+177
-66
lines changed

9 files changed

+177
-66
lines changed

DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
using DigitalLearningSolutions.Web.Models;
55
using DigitalLearningSolutions.Web.Services;
66
using DigitalLearningSolutions.Web.ViewModels.Frameworks.Import;
7+
using DocumentFormat.OpenXml.Office2010.ExcelAc;
78
using GDS.MultiPageFormData.Enums;
89
using Microsoft.AspNetCore.Mvc;
910
using Microsoft.AspNetCore.Mvc.Rendering;
11+
using Microsoft.DotNet.Scaffolding.Shared.Project;
12+
using System.Collections.Generic;
1013
using System.IO;
1114
using System.Linq;
1215

@@ -89,7 +92,7 @@ public IActionResult ImportCompleted()
8992
catch (InvalidHeadersException)
9093
{
9194
FileHelper.DeleteFile(webHostEnvironment, data.CompetenciesFileName);
92-
return View("ImportFailed");
95+
return View("Developer/Import/ImportFailed");
9396
}
9497
}
9598
[Route("/Framework/{frameworkId}/{tabname}/Import/AssessmentQuestions")]
@@ -98,6 +101,16 @@ public IActionResult AddAssessmentQuestions()
98101
var data = GetBulkUploadData();
99102
var adminId = GetAdminId();
100103
var defaultQuestions = frameworkService.GetFrameworkDefaultQuestionsById(data.FrameworkId, adminId);
104+
if (!data.DefaultQuestionIDs.Any() && defaultQuestions.Any() && data.AddDefaultAssessmentQuestions == true)
105+
{
106+
var defaultQuestionsList = new List<int>();
107+
foreach (var question in defaultQuestions)
108+
{
109+
defaultQuestionsList.Add(question.ID);
110+
}
111+
data.DefaultQuestionIDs = defaultQuestionsList;
112+
setBulkUploadData(data);
113+
}
101114
var questionList = frameworkService.GetAssessmentQuestions(data.FrameworkId, adminId).ToList();
102115
var questionSelectList = new SelectList(questionList, "ID", "Label");
103116
var model = new AddAssessmentQuestionsViewModel
@@ -111,9 +124,11 @@ public IActionResult AddAssessmentQuestions()
111124
defaultQuestions,
112125
questionSelectList
113126
);
127+
model.AddDefaultAssessmentQuestions = data.AddDefaultAssessmentQuestions;
128+
model.AddCustomAssessmentQuestion = data.AddCustomAssessmentQuestion;
114129
model.DefaultAssessmentQuestionIDs = data.DefaultQuestionIDs;
115130
model.OtherAssessmentQuestionIDs = data.AssessmentQuestionIDs;
116-
return View(model);
131+
return View("Developer/Import/AddAssessmentQuestions", model);
117132
}
118133
private void setupBulkUploadData(int frameworkId, int adminUserID, string competenciessFileName, string tabName, bool isNotBlank)
119134
{

DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public BulkCompetenciesData(DetailFramework framework, int adminUserId, string c
2727
public int AdminUserId { get; set; }
2828
public bool IsNotBlank { get; set; }
2929
public string CompetenciesFileName { get; set; }
30-
public List<int> DefaultQuestionIDs { get; set; }
31-
public List<int> AssessmentQuestionIDs { get; set; }
32-
public int? AddAssessmentQuestionOption { get; set; }
30+
public List<int> DefaultQuestionIDs { get; set; } = [];
31+
public List<int> AssessmentQuestionIDs { get; set; } = [];
32+
public bool AddDefaultAssessmentQuestions { get; set; } = true;
33+
public bool AddCustomAssessmentQuestion { get; set; } = false;
3334
public int CompetenciesToProcessCount { get; set; }
3435
public int CompetenciesToAddCount { get; set; }
3536
public int CompetenciesToUpdateCount { get; set; }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace DigitalLearningSolutions.Web.ViewModels.Frameworks.Import
44
{
55
public class AddAssessmentQuestionsFormData
66
{
7+
public bool AddDefaultAssessmentQuestions { get; set; }
8+
public bool AddCustomAssessmentQuestion { get; set; }
79
public List<int> DefaultAssessmentQuestionIDs { get; set; }
810
public List<int> OtherAssessmentQuestionIDs { get; set; }
911
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
namespace DigitalLearningSolutions.Web.ViewModels.Frameworks.Import
77
{
88
public class AddAssessmentQuestionsViewModel(
9-
DetailFramework framework,
9+
int frameworkId,
10+
string frameworkName,
11+
string frameworkVocabulary,
12+
int publishStatusId,
1013
int newCompetencies,
1114
int existingCompetencies,
1215
IEnumerable<AssessmentQuestion> defaultQuestions,
1316
SelectList questionSelectList
1417
) : AddAssessmentQuestionsFormData
1518
{
16-
public int FrameworkID { get; set; } = framework.ID;
17-
public string FrameworkName { get; set; } = framework.FrameworkName;
18-
public string FrameworkVocabularySingular { get; set; } = FrameworkVocabularyHelper.VocabularySingular(framework.FrameworkConfig);
19-
public string FrameworkVocabularyPlural { get; set; } = FrameworkVocabularyHelper.VocabularyPlural(framework.FrameworkConfig);
20-
public int PublishStatusID { get; set; } = framework.PublishStatusID;
19+
public int FrameworkID { get; set; } = frameworkId;
20+
public string FrameworkName { get; set; } = frameworkName;
21+
public string FrameworkVocabularySingular { get; set; } = FrameworkVocabularyHelper.VocabularySingular(frameworkVocabulary);
22+
public string FrameworkVocabularyPlural { get; set; } = FrameworkVocabularyHelper.VocabularyPlural(frameworkVocabulary);
23+
public int PublishStatusID { get; set; } = publishStatusId;
2124
public int NewCompetencies { get; set; } = newCompetencies;
2225
public int ExistingCompetencies { get; set; } = existingCompetencies;
2326
public IEnumerable<AssessmentQuestion>? DefaultQuestions { get; set; } = defaultQuestions;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
@using DigitalLearningSolutions.Web.Extensions
2+
@using DigitalLearningSolutions.Web.ViewModels.Frameworks.Import
3+
4+
@model AddAssessmentQuestionsViewModel
5+
6+
@{
7+
ViewData["Application"] = "Framework Service";
8+
ViewData["HeaderPathName"] = "Framework Service";
9+
var errorHasOccurred = !ViewData.ModelState.IsValid;
10+
var checkListErrorClass = !ViewData.ModelState.IsValid && Model.AddDefaultAssessmentQuestions == null ? "nhsuk-form-group nhsuk-form-group--error" : "nhsuk-form-group";
11+
ViewData["Title"] = errorHasOccurred ? "Error: Add Assessment Questions" : "Add Assessment Questions";
12+
var cancelLinkData = Html.GetRouteValues();
13+
var hintTextString = Model.NewCompetencies != 0 && Model.ExistingCompetencies != 0 ? "new and/or updated " : (Model.NewCompetencies == 0 ? "updated " : "new ");
14+
}
15+
<link rel="stylesheet" href="@Url.Content("~/css/frameworks/frameworksShared.css")" asp-append-version="true">
16+
@section NavMenuItems {
17+
<partial name="Shared/_NavMenuItems" />
18+
}
19+
@section NavBreadcrumbs {
20+
<nav class="nhsuk-breadcrumb" aria-label="Breadcrumb">
21+
<div class="nhsuk-width-container">
22+
<ol class="nhsuk-breadcrumb__list">
23+
<li class="nhsuk-breadcrumb__item"><a class="nhsuk-breadcrumb__link trigger-loader" asp-action="ViewFrameworks" asp-route-tabname="Mine">Frameworks</a></li>
24+
<li class="nhsuk-breadcrumb__item"><a class="nhsuk-breadcrumb__link trigger-loader" asp-action="ViewFramework" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-tabname="Structure">Framework Structure</a></li>
25+
<li class="nhsuk-breadcrumb__item">Bulk upload</li>
26+
</ol>
27+
<p class="nhsuk-breadcrumb__back"><a class="nhsuk-breadcrumb__backlink" asp-action="ViewFramework" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-tabname="Structure">Back to framework structure</a></p>
28+
</div>
29+
</nav>
30+
}
31+
<div class="nhsuk-grid-row">
32+
<div class="nhsuk-grid-column-full">
33+
<div class="nhsuk-u-reading-width">
34+
@if (errorHasOccurred)
35+
{
36+
<vc:error-summary order-of-property-names="@(new []{ nameof(AddAssessmentQuestionsFormData.DefaultAssessmentQuestionIDs), nameof(AddAssessmentQuestionsFormData.OtherAssessmentQuestionIDs) })" />
37+
}
38+
<form enctype="multipart/form-data">
39+
<div class="nhsuk-form-group">
40+
<fieldset class="nhsuk-fieldset" aria-describedby="@(!ViewData.ModelState.IsValid && Model.AddDefaultAssessmentQuestions == null ? "check-list-error" : "")">
41+
<legend class="nhsuk-fieldset__legend nhsuk-fieldset__legend--l">
42+
<h1 class="nhsuk-fieldset__heading">
43+
@ViewData["Title"]
44+
</h1>
45+
</legend>
46+
<div class="nhsuk-hint" id="contact-hint">
47+
Which assessment questions would you like to attach to the @hintTextString @Model.FrameworkVocabularyPlural.ToLower()?
48+
</div>
49+
<div class="nhsuk-checkboxes nhsuk-checkboxes--conditional">
50+
@if (Model.DefaultQuestions.Any())
51+
{
52+
<div class="nhsuk-checkboxes__item">
53+
<input class="nhsuk-checkboxes__input" id="defaultQuestions" name="defaultQuestions" type="checkbox" asp-for="@Model.AddDefaultAssessmentQuestions" aria-controls="conditional-default-questions" aria-expanded="false">
54+
<label class="nhsuk-label nhsuk-checkboxes__label" for="defaultQuestions">
55+
Default framework questions
56+
</label>
57+
</div>
58+
<div class="nhsuk-checkboxes__conditional nhsuk-checkboxes__conditional--hidden" id="conditional-default-questions">
59+
60+
<div class="nhsuk-form-group">
61+
<div class="nhsuk-checkboxes">
62+
@foreach (var (defaultQuestion, index) in Model.DefaultQuestions.Select((t, i) => (t, i)))
63+
{
64+
<div class="nhsuk-checkboxes__item">
65+
<input class="nhsuk-checkboxes__input default-question-checkbox"
66+
type="checkbox"
67+
name="@($"{nameof(Model.DefaultQuestions)}[{index}].{nameof(defaultQuestion.ID)}")"
68+
69+
checked="@Model.DefaultAssessmentQuestionIDs.Contains(@defaultQuestion.ID)"
70+
value="true" />
71+
<label class="nhsuk-label nhsuk-checkboxes__label word-break" for="[email protected]">
72+
@defaultQuestion.Question
73+
</label>
74+
</div>
75+
}
76+
</div>
77+
</div>
78+
</div>
79+
}
80+
</div>
81+
</fieldset>
82+
</div>
83+
</form>
84+
</div>
85+
</div>
86+
</div>

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

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,60 +26,64 @@
2626
</div>
2727
</nav>
2828
}
29-
<h1 class="nhsuk-heading-xl">Delegate file uploaded</h1>
30-
<div class="nhsuk-width-container">
31-
<p class="nhsuk-body-l">@(Model.ErrorCount == 0 ? "Your file is error free and ready to be processed. Check the information below looks, correct before processing" : "Your file contains the following, including some errors:")</p>
32-
<ul>
33-
<li>@Model.ToProcessCount @(Model.ToProcessCount == 1 ? "row" : "rows") to process</li>
34-
<li>@Model.CompetenciesToAddCount new @(Model.CompetenciesToAddCount == 1 ? Model.FrameworkVocabularySingular.ToLower() : Model.FrameworkVocabularyPlural.ToLower()) to add</li>
35-
<li>@Model.ToUpdateOrSkipCount @Model.FrameworkVocabularySingular.ToLower() @(Model.ToUpdateOrSkipCount == 1 ? "record" : "records") to update (or skip if unchanged)</li>
36-
@if (Model.ErrorCount > 0)
37-
{
38-
<li>@Model.ErrorCount @(Model.ErrorCount == 1 ? "row" : "rows") containing errors that cannot be processed</li>
39-
}
40-
else
41-
{
42-
<li>No errors</li>
43-
}
44-
</ul>
45-
@if (Model.ErrorCount == 0)
46-
{
47-
<a asp-controller="Frameworks" role="button" asp-route-tabname="Structure" asp-action="AddAssessmentQuestions" class="nhsuk-button">Continue</a>
48-
}
49-
else
50-
{
51-
<p class="nhsuk-body-l">Check the information below. You will need fix these errors before continuing or remove the rows with errors from your spreadsheet:</p>
52-
<div class="nhsuk-form-group nhsuk-form-group--error">
53-
<span class="nhsuk-error-message" id="error-list">
54-
<span class="nhsuk-u-visually-hidden">Error:</span> @Model.ErrorCount @Model.FrameworkVocabularySingular.ToLower() @(Model.ErrorCount == 1 ? "row" : "rows") contain errors and cannot be processed
55-
</span>
56-
<dl class="nhsuk-summary-list">
57-
@foreach (var (rowNumber, errorMessage) in Model.Errors)
29+
<div class="nhsuk-grid-row">
30+
<div class="nhsuk-grid-column-full">
31+
<h1 class="nhsuk-heading-xl">Delegate file uploaded</h1>
32+
<div class="nhsuk-u-reading-width">
33+
<p class="nhsuk-body-l">@(Model.ErrorCount == 0 ? "Your file is error free and ready to be processed. Check the information below looks, correct before processing" : "Your file contains the following, including some errors:")</p>
34+
<ul>
35+
<li>@Model.ToProcessCount @(Model.ToProcessCount == 1 ? "row" : "rows") to process</li>
36+
<li>@Model.CompetenciesToAddCount new @(Model.CompetenciesToAddCount == 1 ? Model.FrameworkVocabularySingular.ToLower() : Model.FrameworkVocabularyPlural.ToLower()) to add</li>
37+
<li>@Model.ToUpdateOrSkipCount @Model.FrameworkVocabularySingular.ToLower() @(Model.ToUpdateOrSkipCount == 1 ? "record" : "records") to update (or skip if unchanged)</li>
38+
@if (Model.ErrorCount > 0)
5839
{
59-
<div class="nhsuk-summary-list__row">
60-
<dt class="nhsuk-summary-list__key">
61-
Row @rowNumber
62-
</dt>
63-
<dd class="nhsuk-summary-list__value">
64-
@errorMessage
65-
</dd>
66-
67-
</div>
40+
<li>@Model.ErrorCount @(Model.ErrorCount == 1 ? "row" : "rows") containing errors that cannot be processed</li>
6841
}
69-
</dl>
70-
</div>
71-
<h2>Upload corrected file</h2>
72-
<p class="nhsuk-body-m">
73-
Once you have made corrections to the Excel competency workbook to address the errors above, save and restart the upload process.
74-
</p>
75-
<form class="nhsuk-u-margin-bottom-3" method="post" enctype="multipart/form-data">
42+
else
43+
{
44+
<li>No errors</li>
45+
}
46+
</ul>
47+
@if (Model.ErrorCount == 0)
48+
{
49+
<a asp-controller="Frameworks" role="button" asp-route-frameworkId="@ViewContext.RouteData.Values["frameworkId"]" asp-route-tabname="Structure" asp-action="AddAssessmentQuestions" class="nhsuk-button">Continue</a>
50+
}
51+
else
52+
{
53+
<p class="nhsuk-body-l">Check the information below. You will need fix these errors before continuing or remove the rows with errors from your spreadsheet:</p>
54+
<div class="nhsuk-form-group nhsuk-form-group--error">
55+
<span class="nhsuk-error-message" id="error-list">
56+
<span class="nhsuk-u-visually-hidden">Error:</span> @Model.ErrorCount @Model.FrameworkVocabularySingular.ToLower() @(Model.ErrorCount == 1 ? "row" : "rows") contain errors and cannot be processed
57+
</span>
58+
<dl class="nhsuk-summary-list">
59+
@foreach (var (rowNumber, errorMessage) in Model.Errors)
60+
{
61+
<div class="nhsuk-summary-list__row">
62+
<dt class="nhsuk-summary-list__key">
63+
Row @rowNumber
64+
</dt>
65+
<dd class="nhsuk-summary-list__value">
66+
@errorMessage
67+
</dd>
68+
69+
</div>
70+
}
71+
</dl>
72+
</div>
73+
<h2>Upload corrected file</h2>
74+
<p class="nhsuk-body-m">
75+
Once you have made corrections to the Excel competency workbook to address the errors above, save and restart the upload process.
76+
</p>
77+
<form class="nhsuk-u-margin-bottom-3" method="post" enctype="multipart/form-data">
7678

77-
<vc:file-input asp-for="@nameof(Model.ImportFile)" label="File with corrected @Model.FrameworkVocabularyPlural.ToLower() information" hint-text="" css-class="nhsuk-u-width-one-half" />
78-
<input type="hidden" asp-for="IsNotBlank" />
79-
<input type="hidden" asp-for="TabName" />
79+
<vc:file-input asp-for="@nameof(Model.ImportFile)" label="File with corrected @Model.FrameworkVocabularyPlural.ToLower() information" hint-text="" css-class="nhsuk-u-width-one-half" />
80+
<input type="hidden" asp-for="IsNotBlank" />
81+
<input type="hidden" asp-for="TabName" />
8082

81-
<button class="nhsuk-button" type="submit">Upload file</button>
82-
</form>
83-
}
84-
<vc:back-link asp-controller="Frameworks" asp-action="Index" asp-all-route-data="@null" link-text="Cancel" />
83+
<button class="nhsuk-button" type="submit">Upload file</button>
84+
</form>
85+
}
86+
<vc:back-link asp-controller="Frameworks" asp-action="Index" asp-all-route-data="@null" link-text="Cancel" />
87+
</div>
88+
</div>
8589
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<div class="nhsuk-grid-row">
3131
<div class="nhsuk-grid-column-full">
3232
<h1 class="nhsuk-heading-xl">Import failed</h1>
33-
<div class="nhsuk-width-container">
33+
<div class="nhsuk-u-reading-width">
3434
<p class="nhsuk-body-m">
3535
The file that you uploaded either does not have the correct column headers on the first row or is not formatted as a table.
3636
</p>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.ImportFile) })" />
3232
}
3333
<h1 class="nhsuk-heading-xl">Bulk upload @(Model.IsNotBlank ? "or update" : "") @Model.FrameworkVocabularyPlural.ToLower()</h1>
34-
<div class="nhsuk-width-container">
34+
<div class="nhsuk-u-reading-width">
3535
@if (Model.PublishStatusID == 3)
3636
{
3737
<partial name="Shared/_PublishedWarning" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<div class="nhsuk-grid-row">
3131
<div class="nhsuk-grid-column-full">
3232
<h1 class="nhsuk-heading-xl">Import competencies complete</h1>
33-
<div class="nhsuk-width-container">
33+
<div class="nhsuk-u-reading-width">
3434
<h2>Summary of results:</h2>
3535
<ul>
3636
<li>@Model.ProcessedCount @(Model.ProcessedCount == 1 ? "line" : "lines") processed</li>

0 commit comments

Comments
 (0)