diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml b/AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml index bf8e441b..81ea1901 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml +++ b/AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml @@ -94,9 +94,20 @@ function DisplayCategory() { // Show the category selection div document.getElementById('divcategory').style.display = 'block'; - document.getElementById('example-error').style.display = 'none' - document.getElementById('errortext').style.display = 'none' - document.getElementById('diverror').classList.remove('nhsuk-form-group--error'); + var divexample = document.getElementById('example-error'); + if (divexample) { + divexample.style.display = 'none'; + } + var diverrortext = document.getElementById('errortext'); + if (diverrortext) { + diverrortext.style.display = 'none'; + } + var diverror = document.getElementById('diverror'); + if (diverror) { + diverror.classList.remove('nhsuk-form-group--error'); + } + + document.getElementById('selectedCategoryDisplay').style.display = 'none'; // Hide the selected category display div var selectedCategoryDiv = document.getElementById('selectedCategoryDisplay'); diff --git a/LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs b/LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs index c8cb93f4..b6c3e82f 100644 --- a/LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs @@ -249,62 +249,31 @@ public async Task IndexAsync(string reference, string tab, int? n } } - if (tab == "browse") + if (nodeId.HasValue) { - if (nodeId.HasValue) - { - // if nodeId has a value it means the user is looking at a subfolder of the catalogue. - // Get the folder name and description, plus folder path data needed for the breadcrumbs. - viewModel.NodeDetails = await this.hierarchyService.GetNodeDetails(nodeId.Value); - viewModel.NodePathNodes = await this.hierarchyService.GetNodePathNodes(viewModel.NodeDetails.NodePathId); - } - else - { - // Otherwise user is looking at catalogue root. - nodeId = catalogue.NodeId; + // if nodeId has a value it means the user is looking at a subfolder of the catalogue. + // Get the folder name and description, plus folder path data needed for the breadcrumbs. + viewModel.NodeDetails = await this.hierarchyService.GetNodeDetails(nodeId.Value); + viewModel.NodePathNodes = await this.hierarchyService.GetNodePathNodes(viewModel.NodeDetails.NodePathId); + } + else + { + // Otherwise user is looking at catalogue root. + nodeId = catalogue.NodeId; - viewModel.NodePathNodes = new List + viewModel.NodePathNodes = new List { new NodeViewModel { Name = catalogue.Name }, }; - } - - 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"); - var nodeContents = await this.hierarchyService.GetNodeContentsForCatalogueBrowse(nodeId.Value, includeEmptyFolder); - viewModel.NodeContents = nodeContents; } - else if (tab == "search") - { - if (viewModel.SearchResults == null) - { - viewModel.SearchResults = new Models.Search.SearchResultViewModel(); - } - if (search.Term != null) - { - search.CatalogueId = catalogue.NodeId; - search.SearchId ??= 0; - search.GroupId = !string.IsNullOrWhiteSpace(search.GroupId) && Guid.TryParse(search.GroupId, out Guid groupId) ? groupId.ToString() : Guid.NewGuid().ToString(); + 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"); + var nodeContents = await this.hierarchyService.GetNodeContentsForCatalogueBrowse(nodeId.Value, includeEmptyFolder); + viewModel.NodeContents = nodeContents; - var searchResult = await this.searchService.PerformSearch(this.User, search); - searchResult.CatalogueId = catalogue.NodeId; - searchResult.CatalogueUrl = catalogue.Url; - if (search.SearchId == 0 && searchResult.ResourceSearchResult != null) - { - var searchId = await this.searchService.RegisterSearchEventsAsync( - search, - SearchFormActionTypeEnum.SearchWithinCatalogue, - searchResult.ResourceSearchResult.TotalHits); - - searchResult.ResourceSearchResult.SearchId = searchId; - } - - viewModel.SearchResults = searchResult; - } - } - else if (tab == "courses") + int categoryId = moodleCategoryId ?? await this.categoryService.GetCatalogueVersionCategoryAsync(catalogue.Id); + if (categoryId > 0) { - int categoryId = moodleCategoryId ?? await this.categoryService.GetCatalogueVersionCategoryAsync(catalogue.Id); var response = await this.categoryService.GetCoursesByCategoryIdAsync(categoryId); viewModel.Courses = response.Courses; @@ -353,6 +322,40 @@ public async Task IndexAsync(string reference, string tab, int? n }; } } + else + { + viewModel.Catalogue.SelectedCategoryId = 0; + } + + if (tab == "search") + { + if (viewModel.SearchResults == null) + { + viewModel.SearchResults = new Models.Search.SearchResultViewModel(); + } + + if (search.Term != null) + { + search.CatalogueId = catalogue.NodeId; + search.SearchId ??= 0; + search.GroupId = !string.IsNullOrWhiteSpace(search.GroupId) && Guid.TryParse(search.GroupId, out Guid groupId) ? groupId.ToString() : Guid.NewGuid().ToString(); + + var searchResult = await this.searchService.PerformSearch(this.User, search); + searchResult.CatalogueId = catalogue.NodeId; + searchResult.CatalogueUrl = catalogue.Url; + if (search.SearchId == 0 && searchResult.ResourceSearchResult != null) + { + var searchId = await this.searchService.RegisterSearchEventsAsync( + search, + SearchFormActionTypeEnum.SearchWithinCatalogue, + searchResult.ResourceSearchResult.TotalHits); + + searchResult.ResourceSearchResult.SearchId = searchId; + } + + viewModel.SearchResults = searchResult; + } + } return this.View(viewModel); } diff --git a/LearningHub.Nhs.WebUI/Views/Catalogue/Index.cshtml b/LearningHub.Nhs.WebUI/Views/Catalogue/Index.cshtml index 386c54b9..9adac96c 100644 --- a/LearningHub.Nhs.WebUI/Views/Catalogue/Index.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Catalogue/Index.cshtml @@ -55,12 +55,17 @@ } } + if (Model.Catalogue.SelectedCategoryId == 0) + { + ViewBag.ActiveTab = "browse"; + } + List<(string Title, string Url)> breadcrumbs; if (ViewBag.ActiveTab == "browse") { breadcrumbs = UtilityHelper.GetBreadcrumbsForFolderNodes(Model.NodePathNodes.SkipLast(1).ToList(), Model.Catalogue.Url); } - else if (ViewBag.ActiveTab == "courses") + else if (ViewBag.ActiveTab == "courses" && Model.Catalogue.SelectedCategoryId > 0) { breadcrumbs = UtilityHelper.GetBreadcrumbsForCourses(Model.MoodleCategories, Model.Catalogue.Url); } @@ -145,13 +150,13 @@ {
@(Model.Catalogue.IsBookmarked ? "Remove from" : "Add to") my bookmarks + asp-route-bookmarked="@Model.Catalogue.IsBookmarked" + asp-route-id="@Model.Catalogue.BookmarkId" + asp-route-title="@Model.Catalogue.Name.Truncate(60)" + asp-route-nodeId="@Model.Catalogue.NodeId" + asp-route-path="@Model.Catalogue.Url" + asp-route-returnUrl="@(Context.Request.Path + Context.Request.QueryString)" + aria-label="@(Model.Catalogue.IsBookmarked ? "Remove from" : "Add to") my bookmarks">@(Model.Catalogue.IsBookmarked ? "Remove from" : "Add to") my bookmarks
} @@ -187,10 +192,13 @@