diff --git a/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj b/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj index 21ec69f5e..dd474573d 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj +++ b/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj @@ -89,7 +89,7 @@ - + diff --git a/LearningHub.Nhs.WebUI/Controllers/SearchController.cs b/LearningHub.Nhs.WebUI/Controllers/SearchController.cs index 2cebfd11c..bfa441aae 100644 --- a/LearningHub.Nhs.WebUI/Controllers/SearchController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/SearchController.cs @@ -292,5 +292,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/LearningHub.Nhs.WebUI.csproj b/LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj index 9e46194b1..c1930e7fa 100644 --- a/LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj +++ b/LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj @@ -108,7 +108,7 @@ - + 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/LearningHub.Nhs.Api.csproj b/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj index 073baa1ff..67c025df9 100644 --- a/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj +++ b/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj @@ -27,7 +27,7 @@ - + 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.Api.Shared/LearningHub.Nhs.Api.Shared.csproj b/WebAPI/LearningHub.Nhs.Api.Shared/LearningHub.Nhs.Api.Shared.csproj index 722cefdee..4be0eeb12 100644 --- a/WebAPI/LearningHub.Nhs.Api.Shared/LearningHub.Nhs.Api.Shared.csproj +++ b/WebAPI/LearningHub.Nhs.Api.Shared/LearningHub.Nhs.Api.Shared.csproj @@ -9,7 +9,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WebAPI/LearningHub.Nhs.Api.UnitTests/LearningHub.Nhs.Api.UnitTests.csproj b/WebAPI/LearningHub.Nhs.Api.UnitTests/LearningHub.Nhs.Api.UnitTests.csproj index d47e3d417..063b86205 100644 --- a/WebAPI/LearningHub.Nhs.Api.UnitTests/LearningHub.Nhs.Api.UnitTests.csproj +++ b/WebAPI/LearningHub.Nhs.Api.UnitTests/LearningHub.Nhs.Api.UnitTests.csproj @@ -11,7 +11,7 @@ - + diff --git a/WebAPI/LearningHub.Nhs.Repository.Interface/LearningHub.Nhs.Repository.Interface.csproj b/WebAPI/LearningHub.Nhs.Repository.Interface/LearningHub.Nhs.Repository.Interface.csproj index 35d70c810..22ee37034 100644 --- a/WebAPI/LearningHub.Nhs.Repository.Interface/LearningHub.Nhs.Repository.Interface.csproj +++ b/WebAPI/LearningHub.Nhs.Repository.Interface/LearningHub.Nhs.Repository.Interface.csproj @@ -9,7 +9,7 @@ - + diff --git a/WebAPI/LearningHub.Nhs.Repository/LearningHub.Nhs.Repository.csproj b/WebAPI/LearningHub.Nhs.Repository/LearningHub.Nhs.Repository.csproj index 5e7e65365..0c1aed810 100644 --- a/WebAPI/LearningHub.Nhs.Repository/LearningHub.Nhs.Repository.csproj +++ b/WebAPI/LearningHub.Nhs.Repository/LearningHub.Nhs.Repository.csproj @@ -9,7 +9,7 @@ - + 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.Interface/LearningHub.Nhs.Services.Interface.csproj b/WebAPI/LearningHub.Nhs.Services.Interface/LearningHub.Nhs.Services.Interface.csproj index 5d2f278d4..41178c7f4 100644 --- a/WebAPI/LearningHub.Nhs.Services.Interface/LearningHub.Nhs.Services.Interface.csproj +++ b/WebAPI/LearningHub.Nhs.Services.Interface/LearningHub.Nhs.Services.Interface.csproj @@ -16,7 +16,7 @@ - + all diff --git a/WebAPI/LearningHub.Nhs.Services.UnitTests/LearningHub.Nhs.Services.UnitTests.csproj b/WebAPI/LearningHub.Nhs.Services.UnitTests/LearningHub.Nhs.Services.UnitTests.csproj index 9869ac4be..65fe0dcc3 100644 --- a/WebAPI/LearningHub.Nhs.Services.UnitTests/LearningHub.Nhs.Services.UnitTests.csproj +++ b/WebAPI/LearningHub.Nhs.Services.UnitTests/LearningHub.Nhs.Services.UnitTests.csproj @@ -13,7 +13,7 @@ - + diff --git a/WebAPI/LearningHub.Nhs.Services/LearningHub.Nhs.Services.csproj b/WebAPI/LearningHub.Nhs.Services/LearningHub.Nhs.Services.csproj index 44fefe844..ae225e64c 100644 --- a/WebAPI/LearningHub.Nhs.Services/LearningHub.Nhs.Services.csproj +++ b/WebAPI/LearningHub.Nhs.Services/LearningHub.Nhs.Services.csproj @@ -13,7 +13,7 @@ - + diff --git a/WebAPI/LearningHub.Nhs.Services/SearchService.cs b/WebAPI/LearningHub.Nhs.Services/SearchService.cs index a247d9aa1..21cc0147d 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. /// diff --git a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.ConsoleApp/LearningHub.Nhs.Migration.ConsoleApp.csproj b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.ConsoleApp/LearningHub.Nhs.Migration.ConsoleApp.csproj index de8df1a58..fdfb3d5d8 100644 --- a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.ConsoleApp/LearningHub.Nhs.Migration.ConsoleApp.csproj +++ b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.ConsoleApp/LearningHub.Nhs.Migration.ConsoleApp.csproj @@ -24,7 +24,7 @@ - + all diff --git a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Interface/LearningHub.Nhs.Migration.Interface.csproj b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Interface/LearningHub.Nhs.Migration.Interface.csproj index 52929fbd8..279defe85 100644 --- a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Interface/LearningHub.Nhs.Migration.Interface.csproj +++ b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Interface/LearningHub.Nhs.Migration.Interface.csproj @@ -9,7 +9,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Models/LearningHub.Nhs.Migration.Models.csproj b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Models/LearningHub.Nhs.Migration.Models.csproj index a3951c927..1aae28941 100644 --- a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Models/LearningHub.Nhs.Migration.Models.csproj +++ b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Models/LearningHub.Nhs.Migration.Models.csproj @@ -10,7 +10,7 @@ - + all diff --git a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Staging.Repository/LearningHub.Nhs.Migration.Staging.Repository.csproj b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Staging.Repository/LearningHub.Nhs.Migration.Staging.Repository.csproj index 7efd53fab..217743117 100644 --- a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Staging.Repository/LearningHub.Nhs.Migration.Staging.Repository.csproj +++ b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.Staging.Repository/LearningHub.Nhs.Migration.Staging.Repository.csproj @@ -9,7 +9,7 @@ - + diff --git a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.UnitTests/LearningHub.Nhs.Migration.UnitTests.csproj b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.UnitTests/LearningHub.Nhs.Migration.UnitTests.csproj index ad73a25cc..14710ab84 100644 --- a/WebAPI/MigrationTool/LearningHub.Nhs.Migration.UnitTests/LearningHub.Nhs.Migration.UnitTests.csproj +++ b/WebAPI/MigrationTool/LearningHub.Nhs.Migration.UnitTests/LearningHub.Nhs.Migration.UnitTests.csproj @@ -10,7 +10,7 @@ - + diff --git a/WebAPI/MigrationTool/LearningHub.Nhs.Migration/LearningHub.Nhs.Migration.csproj b/WebAPI/MigrationTool/LearningHub.Nhs.Migration/LearningHub.Nhs.Migration.csproj index 861270f13..58db5c448 100644 --- a/WebAPI/MigrationTool/LearningHub.Nhs.Migration/LearningHub.Nhs.Migration.csproj +++ b/WebAPI/MigrationTool/LearningHub.Nhs.Migration/LearningHub.Nhs.Migration.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive