Skip to content

Commit 15e6706

Browse files
committed
conflicts resloved
2 parents e0ce050 + c881bdd commit 15e6706

File tree

14 files changed

+141
-11
lines changed

14 files changed

+141
-11
lines changed

LearningHub.Nhs.WebUI/Controllers/CatalogueController.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Net.Http;
7+
using System.Text.RegularExpressions;
78
using System.Threading.Tasks;
89
using LearningHub.Nhs.Caching;
910
using LearningHub.Nhs.Models.Catalogue;
@@ -109,6 +110,28 @@ public async Task<IActionResult> Index(int pageIndex = 1, string term = null)
109110
PageSize = itemsOnPage,
110111
});
111112

113+
// Did you mean suggestion when no hits found
114+
if (termCatalogues?.TotalHits == 0 && termCatalogues?.Spell?.Suggestions?.Count > 0)
115+
{
116+
// pass the spell suggestion as new search text - catalogues
117+
if (termCatalogues?.Spell?.Suggestions?.Count > 0)
118+
{
119+
var suggestedCatalogue = Regex.Replace(termCatalogues?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);
120+
121+
// calling findwise endpoint with new search text - catalogues
122+
termCatalogues = await this.searchService.GetCatalogueSearchResultAsync(
123+
new CatalogueSearchRequestModel
124+
{
125+
SearchText = suggestedCatalogue,
126+
PageIndex = pageIndex - 1,
127+
PageSize = itemsOnPage,
128+
});
129+
130+
catalogues.DidYouMeanEnabled = true;
131+
catalogues.SuggestedCatalogue = suggestedCatalogue;
132+
}
133+
}
134+
112135
catalogues.TotalCount = termCatalogues.TotalHits;
113136
catalogues.GroupId = Guid.NewGuid();
114137
catalogues.Catalogues = termCatalogues.DocumentModel.Select(t => new DashboardCatalogueViewModel

LearningHub.Nhs.WebUI/Controllers/LearningSessionsController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public async Task<IActionResult> ScormContent(string filePath)
8787

8888
var directory = filePath.Substring(0, filePath.LastIndexOf("/"));
8989
fileName = filePath.Substring(filePath.LastIndexOf("/") + 1, filePath.Length - filePath.LastIndexOf("/") - 1);
90+
string extension = Path.GetExtension(fileName);
9091

9192
var file = await this.fileService.DownloadFileAsync(directory, fileName);
9293

@@ -95,6 +96,11 @@ public async Task<IActionResult> ScormContent(string filePath)
9596
contentType = "application/octet-stream";
9697
}
9798

99+
if (extension == ".mp4")
100+
{
101+
contentType = "application/x-mpegURL";
102+
}
103+
98104
result = this.File(file.Content, contentType);
99105
bytesServed = file.ContentLength;
100106
}

LearningHub.Nhs.WebUI/Controllers/SearchController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,13 @@ public async Task<IActionResult> Image(string name)
306306
[HttpGet("GetAutoSuggestion")]
307307
public async Task<IActionResult> GetAutoSuggestion(string term)
308308
{
309+
if (!this.User.Identity.IsAuthenticated)
310+
{
311+
return this.RedirectToAction("AccessDenied", "Home");
312+
}
313+
309314
var autoSuggestions = await this.searchService.GetAutoSuggestionList(term);
315+
310316
return this.PartialView("_AutoComplete", autoSuggestions);
311317
}
312318

LearningHub.Nhs.WebUI/Models/Search/SearchResultViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,15 @@ public class SearchResultViewModel
8383
/// Gets or sets a value indicating whether Did You Mean Enabled or not.
8484
/// </summary>
8585
public bool DidYouMeanEnabled { get; set; }
86+
87+
/// <summary>
88+
/// Gets or sets Suggested Catalogue name.
89+
/// </summary>
90+
public string SuggestedCatalogue { get; set; }
91+
92+
/// <summary>
93+
/// Gets or sets Suggested Resource name.
94+
/// </summary>
95+
public string SuggestedResource { get; set; }
8696
}
8797
}

LearningHub.Nhs.WebUI/Scripts/vuesrc/resource/ResourceContent.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@
362362
// ]
363363
// }
364364
//};
365-
366365
this.player.load(sourceConfig)
367366
.then(() => {
368367
console.log("Source loaded successfully!");
@@ -723,7 +722,14 @@
723722
async launchScorm() {
724723
var targetWin;
725724
var targetWinName = "lhContent" + this.resourceItem.resourceId;
725+
// Use a placeholder window to avoid popup blockers
726+
targetWin = window.open("about:blank", targetWinName, "location=0,menubar=0,resizable=0,width=" + this.resourceItem.scormDetails.popupWidth + ",height=" + this.resourceItem.scormDetails.popupHeight);
726727
728+
// If the pop-up was blocked
729+
if (!targetWin) {
730+
alert("Please allow pop-ups to view this content.");
731+
return;
732+
}
727733
var activeContent = await userData.getActiveContent();
728734
729735
if (activeContent.filter(ac => ac.resourceId === this.resourceItem.resourceId).length > 0) {

LearningHub.Nhs.WebUI/Services/SearchService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
6464
var selectedSortItem = searchSortItemList.Where(x => x.SearchSortType == (SearchSortTypeEnum)searchSortType).FirstOrDefault();
6565
var groupId = Guid.Parse(searchRequest.GroupId);
6666
bool didYouMeanEnabled = false;
67+
var suggestedCatalogue = string.Empty;
68+
var suggestedResource = string.Empty;
6769

6870
var resourceSearchPageSize = this.settings.FindwiseSettings.ResourceSearchPageSize;
6971
var catalogueSearchPageSize = this.settings.FindwiseSettings.CatalogueSearchPageSize;
@@ -125,6 +127,7 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
125127
if (resourceResult?.Spell?.Suggestions?.Count > 0)
126128
{
127129
resourceSearchRequestModel.SearchText = Regex.Replace(resourceResult?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);
130+
suggestedResource = resourceSearchRequestModel.SearchText;
128131

129132
// calling findwise endpoint with new search text - resources
130133
resourceResultTask = this.GetSearchResultAsync(resourceSearchRequestModel);
@@ -134,6 +137,7 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
134137
if (catalogueResult?.Spell?.Suggestions?.Count > 0)
135138
{
136139
catalogueSearchRequestModel.SearchText = Regex.Replace(catalogueResult?.Spell?.Suggestions?.FirstOrDefault().ToString(), "<.*?>", string.Empty);
140+
suggestedCatalogue = catalogueSearchRequestModel.SearchText;
137141

138142
// calling findwise endpoint with new search text - catalogues
139143
catalogueResultTask = this.GetCatalogueSearchResultAsync(catalogueSearchRequestModel);
@@ -231,6 +235,8 @@ public async Task<SearchResultViewModel> PerformSearch(IPrincipal user, SearchRe
231235
TotalItems = catalogueResult?.TotalHits ?? 0,
232236
},
233237
DidYouMeanEnabled = didYouMeanEnabled,
238+
SuggestedCatalogue = suggestedCatalogue,
239+
SuggestedResource = suggestedResource,
234240
};
235241

236242
return searchResultViewModel;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
var hasSearchTerm = queryParams.ContainsKey("term");
1313
var searhTerm = hasSearchTerm ? queryParams["term"].ToString() : null;
1414
string cardStyle = "card-provider-details--blank";
15+
var suggestedTerm = Model.DidYouMeanEnabled ? Model.SuggestedCatalogue : searhTerm;
1516

1617
string GetCatalogueUrl(string catalogueUrl, SearchClickPayloadModel list, int catalogueId)
1718
{
1819
string encodedCatalogueUrl = HttpUtility.UrlEncode("/Catalogue/" + catalogueUrl);
1920
string searchSignalQueryEncoded = HttpUtility.UrlEncode(HttpUtility.UrlDecode(list?.SearchSignal?.Query));
2021
string groupId = HttpUtility.UrlEncode(Model.GroupId.ToString());
2122
var url = $@"/search/record-catalogue-click?url={encodedCatalogueUrl}&itemIndex={list?.HitNumber}
22-
&pageIndex={this.ViewBag.PageIndex}&totalNumberOfHits={list?.SearchSignal?.Stats.TotalHits}&searchText={searhTerm}&catalogueId={catalogueId}
23+
&pageIndex={this.ViewBag.PageIndex}&totalNumberOfHits={list?.SearchSignal?.Stats.TotalHits}&searchText={suggestedTerm}&catalogueId={catalogueId}
2324
&GroupId={groupId}&searchId={list?.SearchSignal.SearchId}&timeOfSearch={list?.SearchSignal.TimeOfSearch}&userQuery={HttpUtility.UrlEncode(list?.SearchSignal?.UserQuery)}
2425
&query={searchSignalQueryEncoded}&name={list?.DocumentFields?.Name}";
2526
return url;
@@ -42,7 +43,7 @@
4243
<vc:back-link asp-controller="Home" asp-action="Index" link-text="Back to: Learning Hub" />
4344
}
4445
<h1 class="nhsuk-u-margin-bottom-5">
45-
@(hasSearchTerm ? $"Search results for {searhTerm}" : "All catalogues")
46+
@(hasSearchTerm ? $"Search results for {suggestedTerm}" : "All catalogues")
4647
</h1>
4748

4849
<h2 class="nhsuk-u-margin-bottom-5">

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
}
1010

1111
<div class="search-page">
12-
<div class="nhsuk-width-container app-width-container">
13-
<h1 class="nhsuk-u-margin-top-5 nhsuk-u-margin-bottom-6">
14-
Search results @(!string.IsNullOrEmpty(Model.SearchString) ? "for " + Model.SearchString : string.Empty)
15-
</h1>
12+
<div class="nhsuk-width-container app-width-container">
1613
@if (Model.DidYouMeanEnabled)
1714
{
18-
<h6 class="nhsuk-u-margin-top-5 nhsuk-u-margin-bottom-6">
19-
We couldn't find a match for <em>@(Model.SearchString)</em>, try adjusting your search terms or explore the suggestions below.
20-
</h6>
15+
<p class="nhsuk-u-margin-top-5 nhsuk-u-margin-bottom-6 nhsuk-body-l">
16+
No results were found for <b>@(Model.SearchString)</b> please change your search term or explore the suggestions below
17+
</p>
18+
}
19+
else
20+
{
21+
<h1 class="nhsuk-u-margin-top-5 nhsuk-u-margin-bottom-6">
22+
Search results @(!string.IsNullOrEmpty(Model.SearchString) ? "for " + Model.SearchString : string.Empty)
23+
</h1>
2124
}
2225

2326
<div class="nhsuk-grid-row">
@@ -28,6 +31,12 @@
2831

2932
@if (Model.CatalogueSearchResult?.TotalHits > 0)
3033
{
34+
@if (Model.DidYouMeanEnabled)
35+
{
36+
<p class="nhsuk-u-margin-top-5 nhsuk-u-margin-bottom-6">
37+
Showing results for <b>@(Model.SuggestedCatalogue)</b>
38+
</p>
39+
}
3140
<div class="nhsuk-grid-row">
3241
<div class="nhsuk-grid-column-full">
3342
@await Html.PartialAsync("_CatalogueSearchResult", Model)
@@ -37,6 +46,12 @@
3746

3847
@if (Model.ResourceSearchResult?.TotalHits > 0)
3948
{
49+
@if (Model.DidYouMeanEnabled)
50+
{
51+
<p class="nhsuk-u-margin-top-5 nhsuk-u-margin-bottom-6">
52+
Showing results for <b>@(Model.SuggestedResource)</b>
53+
</p>
54+
}
4055
@await Html.PartialAsync("_ResourceFilter", Model)
4156

4257
<div class="nhsuk-grid-row">

LearningHub.Nhs.WebUI/Views/Search/_CatalogueSearchResult.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
var catalogueResult = Model.CatalogueSearchResult;
99
var pagingModel = Model.CatalogueResultPaging;
1010
var searchString = HttpUtility.UrlEncode(Model.SearchString);
11+
var suggestedSearchString = Model.DidYouMeanEnabled ? HttpUtility.UrlEncode(Model.SuggestedCatalogue) : HttpUtility.UrlEncode(Model.SearchString);
1112

1213
string GetCatalogueUrl(string catalogueUrl, int nodePathId, int itemIndex, int catalogueId, SearchClickPayloadModel payload)
1314
{
@@ -17,7 +18,7 @@
1718
string searchSignalQueryEncoded = HttpUtility.UrlEncode(HttpUtility.UrlDecode(searchSignal?.Query));
1819

1920
var url = $@"/search/record-catalogue-click?url={encodedCatalogueUrl}&nodePathId={nodePathId}&itemIndex={payload?.HitNumber}
20-
&pageIndex={pagingModel.CurrentPage}&totalNumberOfHits={payload?.SearchSignal?.Stats?.TotalHits}&searchText={searchString}&catalogueId={catalogueId}
21+
&pageIndex={pagingModel.CurrentPage}&totalNumberOfHits={payload?.SearchSignal?.Stats?.TotalHits}&searchText={suggestedSearchString}&catalogueId={catalogueId}
2122
&GroupId={groupId}&searchId={searchSignal?.SearchId}&timeOfSearch={searchSignal?.TimeOfSearch}&userQuery={HttpUtility.UrlEncode(searchSignal?.UserQuery)}
2223
&query={searchSignalQueryEncoded}&name={payload?.DocumentFields?.Name}";
2324
return url;

LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
xhr.open("GET", '@Url.Action("GetAutoSuggestion", "Search")' + '?term=' + encodeURIComponent(term), true);
2626
xhr.onload = function () {
2727
if (xhr.status >= 200 && xhr.status < 400) {
28+
if (xhr.responseText.includes('<script>')) {
29+
return;
30+
}
2831
if (xhr.responseText.trim().length > 5) {
2932
suggestionsList.style.display = "block";
3033
suggestionsList.innerHTML = xhr.responseText;

0 commit comments

Comments
 (0)