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
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
97 changes: 50 additions & 47 deletions LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,62 +249,31 @@ public async Task<IActionResult> 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<NodeViewModel>
viewModel.NodePathNodes = new List<NodeViewModel>
{
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;

Expand Down Expand Up @@ -353,6 +322,40 @@ public async Task<IActionResult> 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);
}
Expand Down
26 changes: 17 additions & 9 deletions LearningHub.Nhs.WebUI/Views/Catalogue/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -145,13 +150,13 @@
{
<div class="nhsuk-u-margin-bottom-4">
<a class="nhsuk-u-font-size-16" asp-controller="Bookmark" asp-action="BookmarkCatalogue"
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</a>
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</a>
</div>
}

Expand Down Expand Up @@ -187,10 +192,13 @@
</label>
</div>
<div class="navbar-collapse collapse" id="catalogue-details">
<ul class="navbar-nav">
<ul class="navbar-nav">
@if (Model.NodeContents.Count() > 0)
{
<li class="subnavwhite-item @(ViewBag.ActiveTab == "browse" ? "active" : string.Empty)">
<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>
</li>
}
@if (Model.Catalogue.SelectedCategoryId > 0)
{
<li class="subnavwhite-item @(ViewBag.ActiveTab == "courses" ? "active" : string.Empty)">
Expand Down
Loading