refactor docs

pull/3274/head
Alper Ebicoglu 6 years ago
parent e3e8e9a9fe
commit a4731f76fb

@ -23,8 +23,8 @@ namespace Volo.Docs.Admin.Documents
public DocumentAdminAppService(IProjectRepository projectRepository,
IDocumentRepository documentRepository,
IDocumentSourceFactory documentStoreFactory,
IDistributedCache<DocumentUpdateInfo> documentUpdateCache,
IDocumentSourceFactory documentStoreFactory,
IDistributedCache<DocumentUpdateInfo> documentUpdateCache,
IDocumentFullSearch documentFullSearch)
{
_projectRepository = projectRepository;
@ -91,11 +91,21 @@ namespace Volo.Docs.Admin.Documents
foreach (var doc in docs)
{
var project = projects.FirstOrDefault(x => x.Id == doc.ProjectId);
if (project != null && (doc.FileName == project.NavigationDocumentName || doc.FileName == project.ParametersDocumentName))
if (project == null)
{
continue;
}
if (doc.FileName == project.NavigationDocumentName)
{
continue;
}
if (doc.FileName == project.ParametersDocumentName)
{
continue;
}
await _documentFullSearch.AddOrUpdateAsync(doc);
}
}

@ -23,7 +23,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
public async Task CreateIndexIfNeededAsync(CancellationToken cancellationToken = default)
{
CheckEsEnabled();
ValidateElasticSearchEnabled();
var client = _clientProvider.GetClient();
@ -51,11 +51,11 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
public async Task AddOrUpdateAsync(Document document, CancellationToken cancellationToken = default)
{
CheckEsEnabled();
ValidateElasticSearchEnabled();
var client = _clientProvider.GetClient();
var existsResponse = await client.DocumentExistsAsync<EsDocument>(DocumentPath<EsDocument>.Id(document.Id),
var existsResponse = await client.DocumentExistsAsync(DocumentPath<EsDocument>.Id(document.Id),
x => x.Index(_options.IndexName), cancellationToken);
HandleError(existsResponse);
@ -73,12 +73,12 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
if (!existsResponse.Exists)
{
HandleError(await client.IndexAsync<EsDocument>(esDocument,
HandleError(await client.IndexAsync(esDocument,
x => x.Id(document.Id).Index(_options.IndexName), cancellationToken));
}
else
{
HandleError(await client.UpdateAsync<EsDocument>(DocumentPath<EsDocument>.Id(document.Id),
HandleError(await client.UpdateAsync(DocumentPath<EsDocument>.Id(document.Id),
x => x.Doc(esDocument).Index(_options.IndexName), cancellationToken));
}
@ -86,7 +86,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
public async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default)
{
CheckEsEnabled();
ValidateElasticSearchEnabled();
HandleError(await _clientProvider.GetClient()
.DeleteAsync(DocumentPath<Document>.Id(id), x => x.Index(_options.IndexName), cancellationToken));
@ -96,7 +96,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
string version, int? skipCount = null, int? maxResultCount = null,
CancellationToken cancellationToken = default)
{
CheckEsEnabled();
ValidateElasticSearchEnabled();
var request = new SearchRequest
{
@ -150,7 +150,6 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
}
};
//var json = _clientProvider.GetClient().RequestResponseSerializer.SerializeToString(request);
var response = await _clientProvider.GetClient().SearchAsync<EsDocument>(request, cancellationToken);
HandleError(response);
@ -178,7 +177,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
}
}
protected void CheckEsEnabled()
protected void ValidateElasticSearchEnabled()
{
if (!_options.Enable)
{

@ -90,7 +90,10 @@
</label>
</div>
<select asp-items="Model.ProjectSelectItems" class="form-control" onchange="window.location.pathname = this.value"></select>
<select asp-items="Model.ProjectSelectItems"
class="form-control"
onchange="window.location.pathname = this.value">
</select>
</div>
</div>
</div>
@ -109,7 +112,10 @@
</label>
</div>
<select asp-items="Model.VersionSelectItems" class="form-control" onchange="if (this.value) { window.location.replace(this.value) }"></select>
<select asp-items="Model.VersionSelectItems"
class="form-control"
onchange="if (this.value) { window.location.replace(this.value) }">
</select>
</div>
</div>
</div>
@ -127,7 +133,10 @@
<i class="fa fa-globe" aria-hidden="true" data-toggle="tooltip" title="@L["Language"]"></i>
</label>
</div>
<select asp-items="Model.LanguageSelectListItems" class="form-control" onchange="window.location.replace(this.value)"></select>
<select asp-items="Model.LanguageSelectListItems"
class="form-control"
onchange="window.location.replace(this.value)">
</select>
</div>
</div>
</div>
@ -142,7 +151,12 @@
<label class="input-group-text"><i class="fa fa-filter"></i></label>
</div>
<input class="form-control" id="filter" type="search" data-search-url="@Model." placeholder="@L["FilterTopics"].Value" aria-label="Filter">
<input class="form-control"
id="filter"
type="search"
data-search-url="@Model."
placeholder="@L["FilterTopics"].Value"
aria-label="Filter">
</div>
</div>
</div>
@ -156,7 +170,12 @@
<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>
@ -204,7 +223,9 @@
<div class="float-right">
@if (!string.IsNullOrEmpty(Model.Document.EditLink))
{
<a href="@Model.Document.EditLink" target="_blank"> <i class="fa fa-edit"></i> @(L["Edit"]) (@L["LastEditTime"]: @Model.Document.LastUpdatedTime.ToShortDateString())</a>
<a href="@Model.Document.EditLink" target="_blank">
<i class="fa fa-edit"></i> @(L["Edit"]) (@L["LastEditTime"]: @Model.Document.LastUpdatedTime.ToShortDateString())
</a>
}
</div>
@ -216,7 +237,11 @@
{
<a href="@contributor.UserProfileUrl" target="_blank">
<img src="@contributor.AvatarUrl"
class="rounded-circle" height="21" width="21" title="@contributor.Username" />
class="rounded-circle"
alt="Avatar"
height="21"
width="21"
title="@contributor.Username" />
</a>
}
}
@ -290,9 +315,7 @@
</div>
<div class="col-md-2 docs-page-index position-relative bg-light">
<div id="scroll-index" class="docs-inner-anchors mt-2">
<h5>@L["InThisDocument"]</h5>
<nav id="docs-sticky-index" class="navbar index-scroll">
</nav>
@ -302,10 +325,8 @@
<a href="javascript:;" class="scroll-top-btn"><i class="fa fa-chevron-up"></i> @L["GoToTop"]</a>
</div>
</div>
</div>
</div>
}
else
{
@ -318,7 +339,6 @@
</a>
</div>
}
</div>
</div>
}

Loading…
Cancel
Save