docs partial templates: refactor and fixes

pull/2722/head
Yunus Emre Kalkan 5 years ago
parent fc9f8ac7c7
commit 1bc2b3377f

@ -8,8 +8,6 @@ namespace Volo.Docs.Documents
public string Path { get; set; }
public List<string> SelfParameters { get; set; }
public List<string> ParentParameters { get; set; }
public List<string> Parameters { get; set; }
}
}

@ -134,22 +134,21 @@ namespace Volo.Docs.HtmlConverting
var afterJsonOpener = documentContent.Substring(
documentContent.IndexOf(jsonOpener, StringComparison.Ordinal) + jsonOpener.Length);
var json = afterJsonOpener.Substring(0,
var betweenJsonOpenerAndCloser = afterJsonOpener.Substring(0,
afterJsonOpener.IndexOf(jsonCloser, StringComparison.Ordinal));
documentContent = afterJsonOpener.Substring(
afterJsonOpener.IndexOf(jsonCloser, StringComparison.Ordinal) + jsonCloser.Length);
if (!json.Contains(docs_templates))
if (!betweenJsonOpenerAndCloser.Contains(docs_templates))
{
continue;
}
json = json.Substring(json.IndexOf(docs_templates, StringComparison.Ordinal) + docs_templates.Length);
var json = betweenJsonOpenerAndCloser.Substring(betweenJsonOpenerAndCloser.IndexOf(docs_templates, StringComparison.Ordinal) + docs_templates.Length);
var template = JsonConvert.DeserializeObject<PartialTemplateDto>(json);
templates.Add(template);
}
@ -168,18 +167,18 @@ namespace Volo.Docs.HtmlConverting
var afterJsonOpener = document.Substring(
document.IndexOf(jsonOpener, StringComparison.Ordinal) + jsonOpener.Length);
var json = afterJsonOpener.Substring(0,
var betweenJsonOpenerAndCloser = afterJsonOpener.Substring(0,
afterJsonOpener.IndexOf(jsonCloser, StringComparison.Ordinal));
if (!json.Contains(docs_templates))
if (!betweenJsonOpenerAndCloser.Contains(docs_templates))
{
document = afterJsonOpener.Substring(
afterJsonOpener.IndexOf(jsonCloser, StringComparison.Ordinal) + jsonCloser.Length);
newDocument.Append(beforeJson + json + jsonCloser);
newDocument.Append(beforeJson + betweenJsonOpenerAndCloser + jsonCloser);
continue;
}
json = json.Substring(json.IndexOf(docs_templates, StringComparison.Ordinal) + docs_templates.Length);
var json = betweenJsonOpenerAndCloser.Substring(betweenJsonOpenerAndCloser.IndexOf(docs_templates, StringComparison.Ordinal) + docs_templates.Length);
var templateName = JsonConvert.DeserializeObject<PartialTemplateDto>(json)?.Name;

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.Domain.Entities;
@ -60,7 +61,7 @@ namespace Volo.Docs.Pages.Documents.Project
public DocumentParametersDto DocumentPreferences { get; set; }
public DocumentRenderParameters UserPreferences { get; set; }
public DocumentRenderParameters UserPreferences { get; set; } = new DocumentRenderParameters();
private readonly IDocumentAppService _documentAppService;
private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory;
@ -419,7 +420,6 @@ namespace Volo.Docs.Pages.Documents.Project
private async Task<List<DocumentPartialTemplateContent>> GetDocumentPartialTemplatesAsync()
{
var contents = new List<DocumentPartialTemplateContent>();
var projectPartialTemplates = await _documentAppService.GetPartialTemplatesAsync(
new GetDocumentPartialTemplatesInput()
@ -431,14 +431,14 @@ namespace Volo.Docs.Pages.Documents.Project
if (!projectPartialTemplates?.Templates?.Any() ?? true)
{
return new List<DocumentPartialTemplateContent>();
return null;
}
var partialTemplatesInDocument = await _documentSectionRenderer.GetPartialTemplatesInDocumentAsync(Document.Content);
if (!partialTemplatesInDocument?.Any() ?? true)
if (!partialTemplatesInDocument?.Any(t => t.Parameters != null) ?? true)
{
return new List<DocumentPartialTemplateContent>();
return null;
}
foreach (var partialTemplates in partialTemplatesInDocument)
@ -447,11 +447,13 @@ namespace Volo.Docs.Pages.Documents.Project
{
if (!UserPreferences.ContainsKey(parameter.Key))
{
UserPreferences.Add(parameter.Key, parameter.Value);
UserPreferences.Add(parameter.Key, parameter.Value);
}
}
}
var contents = new List<DocumentPartialTemplateContent>();
foreach (var partialTemplate in projectPartialTemplates.Templates)
{
contents.Add(new DocumentPartialTemplateContent
@ -472,10 +474,8 @@ namespace Volo.Docs.Pages.Documents.Project
private void SetUserPreferences()
{
UserPreferences = new DocumentRenderParameters
{
{"Document_Language_Code", LanguageCode}, {"Document_Version", Version}
};
UserPreferences.Add("Document_Language_Code", LanguageCode);
UserPreferences.Add("Document_Version", Version);
var cookie = Request.Cookies["AbpDocsPreferences"];

Loading…
Cancel
Save