Skip to content

Commit 6f468b8

Browse files
authored
Merge pull request #1520 from TechnologyEnhancedLearning/Develop/Fixes/TD-6429-LMS-Error-Occurring-in-Test-Environment-While-Launching-SCORM-Content
TD-6272: SIT fixes
2 parents 353ea38 + cc333c1 commit 6f468b8

File tree

3 files changed

+81
-59
lines changed

3 files changed

+81
-59
lines changed

AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,20 @@
9494
function DisplayCategory() {
9595
// Show the category selection div
9696
document.getElementById('divcategory').style.display = 'block';
97-
document.getElementById('example-error').style.display = 'none'
98-
document.getElementById('errortext').style.display = 'none'
99-
document.getElementById('diverror').classList.remove('nhsuk-form-group--error');
97+
var divexample = document.getElementById('example-error');
98+
if (divexample) {
99+
divexample.style.display = 'none';
100+
}
101+
var diverrortext = document.getElementById('errortext');
102+
if (diverrortext) {
103+
diverrortext.style.display = 'none';
104+
}
105+
var diverror = document.getElementById('diverror');
106+
if (diverror) {
107+
diverror.classList.remove('nhsuk-form-group--error');
108+
}
109+
110+
document.getElementById('selectedCategoryDisplay').style.display = 'none';
100111
101112
// Hide the selected category display div
102113
var selectedCategoryDiv = document.getElementById('selectedCategoryDisplay');

LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -249,62 +249,31 @@ public async Task<IActionResult> IndexAsync(string reference, string tab, int? n
249249
}
250250
}
251251

252-
if (tab == "browse")
252+
if (nodeId.HasValue)
253253
{
254-
if (nodeId.HasValue)
255-
{
256-
// if nodeId has a value it means the user is looking at a subfolder of the catalogue.
257-
// Get the folder name and description, plus folder path data needed for the breadcrumbs.
258-
viewModel.NodeDetails = await this.hierarchyService.GetNodeDetails(nodeId.Value);
259-
viewModel.NodePathNodes = await this.hierarchyService.GetNodePathNodes(viewModel.NodeDetails.NodePathId);
260-
}
261-
else
262-
{
263-
// Otherwise user is looking at catalogue root.
264-
nodeId = catalogue.NodeId;
254+
// if nodeId has a value it means the user is looking at a subfolder of the catalogue.
255+
// Get the folder name and description, plus folder path data needed for the breadcrumbs.
256+
viewModel.NodeDetails = await this.hierarchyService.GetNodeDetails(nodeId.Value);
257+
viewModel.NodePathNodes = await this.hierarchyService.GetNodePathNodes(viewModel.NodeDetails.NodePathId);
258+
}
259+
else
260+
{
261+
// Otherwise user is looking at catalogue root.
262+
nodeId = catalogue.NodeId;
265263

266-
viewModel.NodePathNodes = new List<NodeViewModel>
264+
viewModel.NodePathNodes = new List<NodeViewModel>
267265
{
268266
new NodeViewModel { Name = catalogue.Name },
269267
};
270-
}
271-
272-
bool includeEmptyFolder = viewModel.UserGroups.Any(x => x.RoleId == (int)RoleEnum.LocalAdmin || x.RoleId == (int)RoleEnum.Editor || x.RoleId == (int)RoleEnum.Previewer) || this.User.IsInRole("Administrator");
273-
var nodeContents = await this.hierarchyService.GetNodeContentsForCatalogueBrowse(nodeId.Value, includeEmptyFolder);
274-
viewModel.NodeContents = nodeContents;
275268
}
276-
else if (tab == "search")
277-
{
278-
if (viewModel.SearchResults == null)
279-
{
280-
viewModel.SearchResults = new Models.Search.SearchResultViewModel();
281-
}
282269

283-
if (search.Term != null)
284-
{
285-
search.CatalogueId = catalogue.NodeId;
286-
search.SearchId ??= 0;
287-
search.GroupId = !string.IsNullOrWhiteSpace(search.GroupId) && Guid.TryParse(search.GroupId, out Guid groupId) ? groupId.ToString() : Guid.NewGuid().ToString();
270+
bool includeEmptyFolder = viewModel.UserGroups.Any(x => x.RoleId == (int)RoleEnum.LocalAdmin || x.RoleId == (int)RoleEnum.Editor || x.RoleId == (int)RoleEnum.Previewer) || this.User.IsInRole("Administrator");
271+
var nodeContents = await this.hierarchyService.GetNodeContentsForCatalogueBrowse(nodeId.Value, includeEmptyFolder);
272+
viewModel.NodeContents = nodeContents;
288273

289-
var searchResult = await this.searchService.PerformSearch(this.User, search);
290-
searchResult.CatalogueId = catalogue.NodeId;
291-
searchResult.CatalogueUrl = catalogue.Url;
292-
if (search.SearchId == 0 && searchResult.ResourceSearchResult != null)
293-
{
294-
var searchId = await this.searchService.RegisterSearchEventsAsync(
295-
search,
296-
SearchFormActionTypeEnum.SearchWithinCatalogue,
297-
searchResult.ResourceSearchResult.TotalHits);
298-
299-
searchResult.ResourceSearchResult.SearchId = searchId;
300-
}
301-
302-
viewModel.SearchResults = searchResult;
303-
}
304-
}
305-
else if (tab == "courses")
274+
int categoryId = moodleCategoryId ?? await this.categoryService.GetCatalogueVersionCategoryAsync(catalogue.Id);
275+
if (categoryId > 0)
306276
{
307-
int categoryId = moodleCategoryId ?? await this.categoryService.GetCatalogueVersionCategoryAsync(catalogue.Id);
308277
var response = await this.categoryService.GetCoursesByCategoryIdAsync(categoryId);
309278
viewModel.Courses = response.Courses;
310279

@@ -353,6 +322,40 @@ public async Task<IActionResult> IndexAsync(string reference, string tab, int? n
353322
};
354323
}
355324
}
325+
else
326+
{
327+
viewModel.Catalogue.SelectedCategoryId = 0;
328+
}
329+
330+
if (tab == "search")
331+
{
332+
if (viewModel.SearchResults == null)
333+
{
334+
viewModel.SearchResults = new Models.Search.SearchResultViewModel();
335+
}
336+
337+
if (search.Term != null)
338+
{
339+
search.CatalogueId = catalogue.NodeId;
340+
search.SearchId ??= 0;
341+
search.GroupId = !string.IsNullOrWhiteSpace(search.GroupId) && Guid.TryParse(search.GroupId, out Guid groupId) ? groupId.ToString() : Guid.NewGuid().ToString();
342+
343+
var searchResult = await this.searchService.PerformSearch(this.User, search);
344+
searchResult.CatalogueId = catalogue.NodeId;
345+
searchResult.CatalogueUrl = catalogue.Url;
346+
if (search.SearchId == 0 && searchResult.ResourceSearchResult != null)
347+
{
348+
var searchId = await this.searchService.RegisterSearchEventsAsync(
349+
search,
350+
SearchFormActionTypeEnum.SearchWithinCatalogue,
351+
searchResult.ResourceSearchResult.TotalHits);
352+
353+
searchResult.ResourceSearchResult.SearchId = searchId;
354+
}
355+
356+
viewModel.SearchResults = searchResult;
357+
}
358+
}
356359

357360
return this.View(viewModel);
358361
}

LearningHub.Nhs.WebUI/Views/Catalogue/Index.cshtml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@
5555
}
5656
}
5757

58+
if (Model.Catalogue.SelectedCategoryId == 0)
59+
{
60+
ViewBag.ActiveTab = "browse";
61+
}
62+
5863
List<(string Title, string Url)> breadcrumbs;
5964
if (ViewBag.ActiveTab == "browse")
6065
{
6166
breadcrumbs = UtilityHelper.GetBreadcrumbsForFolderNodes(Model.NodePathNodes.SkipLast(1).ToList(), Model.Catalogue.Url);
6267
}
63-
else if (ViewBag.ActiveTab == "courses")
68+
else if (ViewBag.ActiveTab == "courses" && Model.Catalogue.SelectedCategoryId > 0)
6469
{
6570
breadcrumbs = UtilityHelper.GetBreadcrumbsForCourses(Model.MoodleCategories, Model.Catalogue.Url);
6671
}
@@ -145,13 +150,13 @@
145150
{
146151
<div class="nhsuk-u-margin-bottom-4">
147152
<a class="nhsuk-u-font-size-16" asp-controller="Bookmark" asp-action="BookmarkCatalogue"
148-
asp-route-bookmarked="@Model.Catalogue.IsBookmarked"
149-
asp-route-id="@Model.Catalogue.BookmarkId"
150-
asp-route-title="@Model.Catalogue.Name.Truncate(60)"
151-
asp-route-nodeId="@Model.Catalogue.NodeId"
152-
asp-route-path="@Model.Catalogue.Url"
153-
asp-route-returnUrl="@(Context.Request.Path + Context.Request.QueryString)"
154-
aria-label="@(Model.Catalogue.IsBookmarked ? "Remove from" : "Add to") my bookmarks">@(Model.Catalogue.IsBookmarked ? "Remove from" : "Add to") my bookmarks</a>
153+
asp-route-bookmarked="@Model.Catalogue.IsBookmarked"
154+
asp-route-id="@Model.Catalogue.BookmarkId"
155+
asp-route-title="@Model.Catalogue.Name.Truncate(60)"
156+
asp-route-nodeId="@Model.Catalogue.NodeId"
157+
asp-route-path="@Model.Catalogue.Url"
158+
asp-route-returnUrl="@(Context.Request.Path + Context.Request.QueryString)"
159+
aria-label="@(Model.Catalogue.IsBookmarked ? "Remove from" : "Add to") my bookmarks">@(Model.Catalogue.IsBookmarked ? "Remove from" : "Add to") my bookmarks</a>
155160
</div>
156161
}
157162

@@ -187,10 +192,13 @@
187192
</label>
188193
</div>
189194
<div class="navbar-collapse collapse" id="catalogue-details">
190-
<ul class="navbar-nav">
195+
<ul class="navbar-nav">
196+
@if (Model.NodeContents.Count() > 0)
197+
{
191198
<li class="subnavwhite-item @(ViewBag.ActiveTab == "browse" ? "active" : string.Empty)">
192199
<a tabindex="0" class="subnavwhite-link text-nowrap" asp-controller="Catalogue" asp-route-reference="@Model.Catalogue.Url" asp-route-tab="browse" asp-fragment="catalogue-details">Resources</a>
193200
</li>
201+
}
194202
@if (Model.Catalogue.SelectedCategoryId > 0)
195203
{
196204
<li class="subnavwhite-item @(ViewBag.ActiveTab == "courses" ? "active" : string.Empty)">

0 commit comments

Comments
 (0)