diff --git a/LearningHub.Nhs.WebUI/Controllers/SearchController.cs b/LearningHub.Nhs.WebUI/Controllers/SearchController.cs index a87517b97..ac314f6c9 100644 --- a/LearningHub.Nhs.WebUI/Controllers/SearchController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/SearchController.cs @@ -296,5 +296,17 @@ public async Task Image(string name) return this.Ok(this.Content("No file found")); } } + + /// + /// GetAutoSuggestion returns the auto suggestion options. + /// + /// search term. + /// ActionResult. + [HttpGet("GetAutoSuggestion")] + public async Task GetAutoSuggestion(string term) + { + var autoSuggestions = await this.searchService.GetAutoSuggestionList(term); + return this.PartialView("_AutoComplete", autoSuggestions); + } } } \ No newline at end of file diff --git a/LearningHub.Nhs.WebUI/Interfaces/ISearchService.cs b/LearningHub.Nhs.WebUI/Interfaces/ISearchService.cs index b01be5bce..8a2f0aec1 100644 --- a/LearningHub.Nhs.WebUI/Interfaces/ISearchService.cs +++ b/LearningHub.Nhs.WebUI/Interfaces/ISearchService.cs @@ -84,5 +84,12 @@ public interface ISearchService /// The catalogue Search Request Model. /// The . Task GetAllCatalogueSearchResultAsync(AllCatalogueSearchRequestModel catalogueSearchRequestModel); + + /// + /// The Get AutoSuggestion List. + /// + /// The term. + /// The . + Task GetAutoSuggestionList(string term); } } diff --git a/LearningHub.Nhs.WebUI/Services/SearchService.cs b/LearningHub.Nhs.WebUI/Services/SearchService.cs index 8e22e0eeb..22f98dcdb 100644 --- a/LearningHub.Nhs.WebUI/Services/SearchService.cs +++ b/LearningHub.Nhs.WebUI/Services/SearchService.cs @@ -634,6 +634,31 @@ public async Task GetAllCatalogueSearchResultAsync( } } + /// + /// The GetAutoSuggestionList. + /// + /// The term. + /// The auto suggestion list. + public async Task GetAutoSuggestionList(string term) + { + var client = await this.LearningHubHttpClient.GetClientAsync(); + var request = $"Search/GetAutoSuggestionResult/{term}"; + var response = await client.GetAsync(request).ConfigureAwait(false); + + var viewModel = new AutoSuggestionModel(); + if (response.IsSuccessStatusCode) + { + var result = response.Content.ReadAsStringAsync().Result; + viewModel = JsonConvert.DeserializeObject(result); + } + else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden) + { + throw new Exception("AccessDenied"); + } + + return viewModel; + } + /// /// The RemoveHtmlTags. /// diff --git a/LearningHub.Nhs.WebUI/Styles/nhsuk/layout.scss b/LearningHub.Nhs.WebUI/Styles/nhsuk/layout.scss index 3bd13c109..c8935fd80 100644 --- a/LearningHub.Nhs.WebUI/Styles/nhsuk/layout.scss +++ b/LearningHub.Nhs.WebUI/Styles/nhsuk/layout.scss @@ -183,6 +183,57 @@ } } +.autosuggestion-menu { + padding: 16px 16px 0px 16px; + background-color: $color_nhsuk-white; + border-bottom: 1px solid $color_nhsuk-grey-4; + border-radius: 0px 0px 4px 4px; + border-left: 1px solid $color_nhsuk-grey-4; + border-right: 1px solid $color_nhsuk-grey-4; + box-shadow: 0px 2px 3px 0px $color_nhsuk-grey-4; + list-style: none; + overflow-x: hidden; + overflow-y: auto; + position: absolute; + width: 100%; + z-index: 1; + margin-bottom: 0; +} + +.autosuggestion-option { + margin-bottom: 0; + border-bottom: 1px solid $color_nhsuk-grey-4; + color: $color_nhsuk-blue; + cursor: pointer; + font-size: 16px; + padding-bottom: 12px; + text-align: left; + text-decoration: none; +} + +.autosuggestion-option .autosuggestion-icon { + fill: $color_nhsuk-grey-3 !important; + float: left; + height: 20px; + margin: 2px 8px 0 0; + width: 16px; +} + +.autosuggestion-option .autosuggestion-subtext { + color: $color_nhsuk-grey-2 !important; + padding-left: 24px; + margin: 0px; +} + +.autosuggestion-option .autosuggestion-link { + display: flex; + margin-bottom: 0px; + text-decoration: underline; +} + +li.autosuggestion-option:last-of-type { + border-bottom: none !important; +} /* large desktop */ @media (min-width: px2rem(990)) { @@ -314,6 +365,10 @@ box-shadow: 0 0 0 2px white; z-index: 10; } + + .autosuggestion-menu { + top: 100%; + } } /* tablet */ @@ -332,6 +387,10 @@ .nhsuk-header__menu .nhsuk-header__not-mobile { display: none; } + + .autosuggestion-menu { + top: 100%; + } } /* mobile */ @@ -430,4 +489,8 @@ .nhsuk-width-container.nhsuk-header__container.app-width-container { padding-bottom: 0; } + + .autosuggestion-menu { + top: 100%; + } } \ No newline at end of file diff --git a/LearningHub.Nhs.WebUI/Views/Search/_AutoComplete.cshtml b/LearningHub.Nhs.WebUI/Views/Search/_AutoComplete.cshtml new file mode 100644 index 000000000..ba031ab0e --- /dev/null +++ b/LearningHub.Nhs.WebUI/Views/Search/_AutoComplete.cshtml @@ -0,0 +1,45 @@ +@model LearningHub.Nhs.Models.Search.AutoSuggestionModel; +@{ + var counter = 0; + var counter_res = 0; +} +@if (Model != null) +{ + @foreach (var item in Model.ConceptDocument.ConceptDocumentList) + { + counter++; +
  • + + + + + + +
  • + } + @foreach (var item in Model.ResourceDocument.ResourceDocumentList) + { + counter_res++; +
  • + + + + + +

    Resource

    +
    +
  • + } + @foreach (var item in Model.CatalogueDocument.CatalogueDocumentList) + { +
  • + + + + + +

    Catalogue

    +
    +
  • + } +} \ No newline at end of file diff --git a/LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml b/LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml index 620d6cb76..7ec19feef 100644 --- a/LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Search/_SearchBar.cshtml @@ -1,9 +1,10 @@ @model string + \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs b/WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs index ab4e417d9..59a65c29d 100644 --- a/WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs +++ b/WebAPI/LearningHub.Nhs.API/Controllers/SearchController.cs @@ -224,6 +224,20 @@ public async Task GetAllCatalogueSearchResult(AllCatalogueSearchR return this.Ok(vm); } + /// + /// Get AutoSuggestionResults. + /// + /// The term. + /// The . + [HttpGet] + [Route("GetAutoSuggestionResult/{term}")] + public async Task GetAutoSuggestionResults(string term) + { + var autosuggestionViewModel = new AutoSuggestionModel(); + autosuggestionViewModel = await this.searchService.GetAutoSuggestionResultsAsync(term); + return this.Ok(autosuggestionViewModel); + } + /// /// Get search result. /// diff --git a/WebAPI/LearningHub.Nhs.API/appsettings.json b/WebAPI/LearningHub.Nhs.API/appsettings.json index 6b95e1a2f..623e0cd84 100644 --- a/WebAPI/LearningHub.Nhs.API/appsettings.json +++ b/WebAPI/LearningHub.Nhs.API/appsettings.json @@ -86,10 +86,11 @@ "FindWise": { "IndexUrl": "", "SearchUrl": "", - "CollectionIds": { - "Resource": "", - "Catalogue": "" - }, + "CollectionIds": { + "Resource": "", + "Catalogue": "", + "AutoSuggestion": "" + }, "UrlSearchComponent": "rest/apps/HEE/searchers/{0}", "UrlClickComponent": "rest/apps/HEE/searchers/hee/signals/hee/signal/click", "Token": "", diff --git a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseCollectionIdSettings.cs b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseCollectionIdSettings.cs index 25d91ec84..89b29fc90 100644 --- a/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseCollectionIdSettings.cs +++ b/WebAPI/LearningHub.Nhs.Api.Shared/Configuration/FindwiseCollectionIdSettings.cs @@ -14,5 +14,10 @@ public class FindwiseCollectionIdSettings /// Gets or sets the catalogue collection id. /// public string Catalogue { get; set; } + + /// + /// Gets or sets the AutoSuggestion collection id. + /// + public string AutoSuggestion { get; set; } } } diff --git a/WebAPI/LearningHub.Nhs.Services.Interface/ISearchService.cs b/WebAPI/LearningHub.Nhs.Services.Interface/ISearchService.cs index 2f1e0a63c..0fb99c731 100644 --- a/WebAPI/LearningHub.Nhs.Services.Interface/ISearchService.cs +++ b/WebAPI/LearningHub.Nhs.Services.Interface/ISearchService.cs @@ -175,5 +175,12 @@ public interface ISearchService /// The allcatalog search request model. /// The . Task GetAllCatalogueSearchResultsAsync(AllCatalogueSearchRequestModel catalogSearchRequestModel); + + /// + /// The Auto suggetion result method. + /// + /// the term. + /// The . + Task GetAutoSuggestionResultsAsync(string term); } } diff --git a/WebAPI/LearningHub.Nhs.Services/SearchService.cs b/WebAPI/LearningHub.Nhs.Services/SearchService.cs index 99ea20895..c98bddfcf 100644 --- a/WebAPI/LearningHub.Nhs.Services/SearchService.cs +++ b/WebAPI/LearningHub.Nhs.Services/SearchService.cs @@ -588,6 +588,51 @@ public async Task GetAllCatalogueSearchResultsAsy } } + /// + /// The Get Auto suggestion Results Async method. + /// + /// The term. + /// The . + public async Task GetAutoSuggestionResultsAsync(string term) + { + var viewmodel = new AutoSuggestionModel(); + + try + { + var client = await this.FindWiseHttpClient.GetClient(this.settings.Findwise.SearchUrl); + var request = string.Format( + this.settings.Findwise.UrlSearchComponent + "?q={1}&token={2}", + this.settings.Findwise.CollectionIds.AutoSuggestion, + this.EncodeSearchText(term), + this.settings.Findwise.Token); + + var response = await client.GetAsync(request).ConfigureAwait(false); + + if (response.IsSuccessStatusCode) + { + var result = response.Content.ReadAsStringAsync().Result; + viewmodel = JsonConvert.DeserializeObject(result); + } + else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Forbidden) + { + this.Logger.LogError($"Get Auto Suggetion Result failed in FindWise, HTTP Status Code:{response.StatusCode}"); + throw new Exception("AccessDenied to FindWise Server"); + } + else + { + var error = response.Content.ReadAsStringAsync().Result.ToString(); + this.Logger.LogError($"Get Auto Suggetion Result failed in FindWise, HTTP Status Code:{response.StatusCode}, Error Message:{error}"); + throw new Exception("Error with FindWise Server"); + } + + return viewmodel; + } + catch (Exception) + { + throw; + } + } + /// /// Send search click payload. ///