Browse Source

Add FullSearchEnabledAsync method.

pull/2901/head
maliming 7 years ago
parent
commit
d6c9e6b13e
  1. 2
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs
  2. 11
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  3. 7
      modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs
  4. 20
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml
  5. 3
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs
  6. 5
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

2
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs

@ -17,5 +17,7 @@ namespace Volo.Docs.Documents
Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input); Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input);
Task<List<DocumentSearchOutput>> SearchAsync(DocumentSearchInput input); Task<List<DocumentSearchOutput>> SearchAsync(DocumentSearchInput input);
Task<bool> FullSearchEnabledAsync();
} }
} }

11
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Docs.Documents.FullSearch.Elastic; using Volo.Docs.Documents.FullSearch.Elastic;
@ -22,6 +23,7 @@ namespace Volo.Docs.Documents
protected IDistributedCache<DocumentUpdateInfo> DocumentUpdateCache { get; } protected IDistributedCache<DocumentUpdateInfo> DocumentUpdateCache { get; }
protected IHostEnvironment HostEnvironment { get; } protected IHostEnvironment HostEnvironment { get; }
private readonly IDocumentFullSearch _documentFullSearch; private readonly IDocumentFullSearch _documentFullSearch;
private readonly DocsElasticSearchOptions _docsElasticSearchOptions;
public DocumentAppService( public DocumentAppService(
IProjectRepository projectRepository, IProjectRepository projectRepository,
@ -31,7 +33,8 @@ namespace Volo.Docs.Documents
IDistributedCache<DocumentResourceDto> resourceCache, IDistributedCache<DocumentResourceDto> resourceCache,
IDistributedCache<DocumentUpdateInfo> documentUpdateCache, IDistributedCache<DocumentUpdateInfo> documentUpdateCache,
IHostEnvironment hostEnvironment, IHostEnvironment hostEnvironment,
IDocumentFullSearch documentFullSearch) IDocumentFullSearch documentFullSearch,
IOptions<DocsElasticSearchOptions> docsElasticSearchOptions)
{ {
_projectRepository = projectRepository; _projectRepository = projectRepository;
_documentRepository = documentRepository; _documentRepository = documentRepository;
@ -41,6 +44,7 @@ namespace Volo.Docs.Documents
DocumentUpdateCache = documentUpdateCache; DocumentUpdateCache = documentUpdateCache;
HostEnvironment = hostEnvironment; HostEnvironment = hostEnvironment;
_documentFullSearch = documentFullSearch; _documentFullSearch = documentFullSearch;
_docsElasticSearchOptions = docsElasticSearchOptions.Value;
} }
public virtual async Task<DocumentWithDetailsDto> GetAsync(GetDocumentInput input) public virtual async Task<DocumentWithDetailsDto> GetAsync(GetDocumentInput input)
@ -145,6 +149,11 @@ namespace Volo.Docs.Documents
}).ToList(); }).ToList();
} }
public async Task<bool> FullSearchEnabledAsync()
{
return await Task.FromResult(_docsElasticSearchOptions.Enable);
}
public async Task<DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input) public async Task<DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input)
{ {
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);

7
modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs

@ -54,6 +54,13 @@ namespace Volo.Docs.Documents
return DocumentAppService.SearchAsync(input); return DocumentAppService.SearchAsync(input);
} }
[HttpGet]
[Route("fullsearchenabled")]
public Task<bool> FullSearchEnabledAsync()
{
return DocumentAppService.FullSearchEnabledAsync();
}
[HttpGet] [HttpGet]
[Route("parameters")] [Route("parameters")]
public Task<DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input) public Task<DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input)

20
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml

@ -147,18 +147,20 @@
</div> </div>
</div> </div>
<div class="docs-version mb-4"> @if (Model.FullSearchEnabled)
<div class="version-select"> {
<div class="input-group"> <div class="docs-version mb-4">
<div class="input-group-prepend"> <div class="version-select">
<label class="input-group-text"><i class="fa fa-filter"></i></label> <div class="input-group">
</div> <div class="input-group-prepend">
<label class="input-group-text"><i class="fa fa-filter"></i></label>
</div>
<input class="form-control" id="fullsearch" type="search" data-fullsearch-url="/search/@Model.LanguageCode/@Model.ProjectName/@Model.Version/" placeholder="@L["FullSearch"].Value" aria-label="Filter"> <input class="form-control" id="fullsearch" type="search" data-fullsearch-url="/search/@Model.LanguageCode/@Model.ProjectName/@Model.Version/" placeholder="@L["FullSearch"].Value" aria-label="Filter">
</div>
</div> </div>
</div> </div>
</div> }
@if (Model.Navigation == null || !Model.Navigation.HasChildItems) @if (Model.Navigation == null || !Model.Navigation.HasChildItems)
{ {

3
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

@ -64,6 +64,8 @@ namespace Volo.Docs.Pages.Documents.Project
public DocumentParametersDto DocumentPreferences { get; set; } public DocumentParametersDto DocumentPreferences { get; set; }
public DocumentRenderParameters UserPreferences { get; set; } = new DocumentRenderParameters(); public DocumentRenderParameters UserPreferences { get; set; } = new DocumentRenderParameters();
public bool FullSearchEnabled { get; set; }
private readonly IDocumentAppService _documentAppService; private readonly IDocumentAppService _documentAppService;
private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory; private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory;
@ -106,6 +108,7 @@ namespace Volo.Docs.Pages.Documents.Project
{ {
DocumentsUrlPrefix = _uiOptions.RoutePrefix; DocumentsUrlPrefix = _uiOptions.RoutePrefix;
ShowProjectsCombobox = _uiOptions.ShowProjectsCombobox; ShowProjectsCombobox = _uiOptions.ShowProjectsCombobox;
FullSearchEnabled = await _documentAppService.FullSearchEnabledAsync();
try try
{ {

5
modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

@ -41,6 +41,11 @@ namespace Volo.Docs.Pages.Documents
public async Task<IActionResult> OnGetAsync(string keyword) public async Task<IActionResult> OnGetAsync(string keyword)
{ {
if (!await _documentAppService.FullSearchEnabledAsync())
{
return RedirectToPage("Index");
}
KeyWord = keyword; KeyWord = keyword;
Project = await _projectAppService.GetAsync(ProjectName); Project = await _projectAppService.GetAsync(ProjectName);

Loading…
Cancel
Save