Browse Source

Merge pull request #2297 from abpframework/Docs-module-conditional-section-feature

Docs module conditional section feature
pull/2318/head
Yunus Emre Kalkan 7 years ago
committed by GitHub
parent
commit
799d0697aa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs
  2. 2
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs
  3. 3
      modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs
  4. 3
      modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs
  5. 3
      modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs
  6. 13
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/DocumentParameterDto.cs
  7. 9
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/DocumentParametersDto.cs
  8. 19
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/GetParametersDocumentInput.cs
  9. 2
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs
  10. 38
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  11. 1
      modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/ProjectConsts.cs
  12. 3
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs
  13. 16
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs
  14. 1
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs
  15. 5
      modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs
  16. 8
      modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentParseParamaters.cs
  17. 12
      modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionConsts.cs
  18. 2
      modules/docs/src/Volo.Docs.Web/HtmlConverting/HtmlNormalizer.cs
  19. 15
      modules/docs/src/Volo.Docs.Web/HtmlConverting/IDocumentSectionRenderer.cs
  20. 120
      modules/docs/src/Volo.Docs.Web/HtmlConverting/ScribanDocumentSectionParser.cs
  21. 26
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml
  22. 120
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs
  23. 86
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js
  24. 1
      modules/docs/src/Volo.Docs.Web/Volo.Docs.Web.csproj
  25. 3
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestDataBuilder.cs

2
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs

@ -14,6 +14,8 @@ namespace Volo.Docs.Admin.Projects
public string NavigationDocumentName { get; set; }
public string ParametersDocumentName { get; set; }
public string MinimumVersion { get; set; }
public string MainWebsiteUrl { get; set; }

2
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs

@ -12,6 +12,8 @@ namespace Volo.Docs.Admin.Projects
public string NavigationDocumentName { get; set; }
public string ParametersDocumentName { get; set; }
public string MinimumVersion { get; set; }
public string MainWebsiteUrl { get; set; }

3
modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs

@ -53,7 +53,8 @@ namespace Volo.Docs.Admin.Projects
input.DocumentStoreType,
input.Format,
input.DefaultDocumentName,
input.NavigationDocumentName
input.NavigationDocumentName,
input.ParametersDocumentName
)
{
MinimumVersion = input.MinimumVersion,

3
modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs

@ -88,6 +88,9 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
[StringLength(ProjectConsts.MaxNavigationDocumentNameLength)]
public string NavigationDocumentName { get; set; } = "docs-nav.json";
[StringLength(ProjectConsts.MaxParametersDocumentNameLength)]
public string ParametersDocumentName { get; set; } = "docs-params.json";
[StringLength(ProjectConsts.MaxVersionNameLength)]
public string MinimumVersion { get; set; }

3
modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs

@ -96,6 +96,9 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
[StringLength(ProjectConsts.MaxNavigationDocumentNameLength)]
public string NavigationDocumentName { get; set; }
[StringLength(ProjectConsts.MaxParametersDocumentNameLength)]
public string ParametersDocumentName { get; set; }
[StringLength(ProjectConsts.MaxVersionNameLength)]
public string MinimumVersion { get; set; }

13
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/DocumentParameterDto.cs

@ -0,0 +1,13 @@
using System.Collections.Generic;
namespace Volo.Docs.Documents
{
public class DocumentParameterDto
{
public string Name { get; set; }
public string DisplayName { get; set; }
public Dictionary<string, string> Values { get; set; }
}
}

9
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/DocumentParametersDto.cs

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Volo.Docs.Documents
{
public class DocumentParametersDto
{
public List<DocumentParameterDto> Parameters {get;set;}
}
}

19
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/GetParametersDocumentInput.cs

@ -0,0 +1,19 @@
using System;
using System.ComponentModel.DataAnnotations;
using Volo.Docs.Language;
using Volo.Docs.Projects;
namespace Volo.Docs.Documents
{
public class GetParametersDocumentInput
{
public Guid ProjectId { get; set; }
[StringLength(ProjectConsts.MaxVersionNameLength)]
public string Version { get; set; }
[Required]
[StringLength(LanguageConsts.MaxLanguageCodeLength)]
public string LanguageCode { get; set; }
}
}

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

@ -11,6 +11,8 @@ namespace Volo.Docs.Documents
Task<DocumentWithDetailsDto> GetNavigationAsync(GetNavigationDocumentInput input);
Task<DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input);
Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input);
}
}

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

@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Volo.Abp.Application.Services;
using Newtonsoft.Json;
using Volo.Abp.Caching;
using Volo.Docs.Projects;
@ -18,19 +17,21 @@ namespace Volo.Docs.Documents
protected IDistributedCache<DocumentWithDetailsDto> DocumentCache { get; }
protected IDistributedCache<LanguageConfig> LanguageCache { get; }
protected IDistributedCache<DocumentResourceDto> ResourceCache { get; }
protected IHostEnvironment HostEnvironment { get; }
public DocumentAppService(
IProjectRepository projectRepository,
IDocumentStoreFactory documentStoreFactory,
IDistributedCache<DocumentWithDetailsDto> documentCache,
IDistributedCache<LanguageConfig> languageCache,
IDistributedCache<DocumentResourceDto> resourceCache)
IDistributedCache<DocumentResourceDto> resourceCache,
IHostEnvironment hostEnvironment)
{
_projectRepository = projectRepository;
_documentStoreFactory = documentStoreFactory;
DocumentCache = documentCache;
LanguageCache = languageCache;
ResourceCache = resourceCache;
HostEnvironment = hostEnvironment;
}
public virtual async Task<DocumentWithDetailsDto> GetAsync(GetDocumentInput input)
@ -83,7 +84,7 @@ namespace Volo.Docs.Documents
return ObjectMapper.Map<DocumentResource, DocumentResourceDto>(documentResource);
}
if (Debugger.IsAttached)
if (HostEnvironment.IsDevelopment())
{
return await GetResourceAsync();
}
@ -100,6 +101,28 @@ namespace Volo.Docs.Documents
);
}
public async Task<DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input)
{
var project = await _projectRepository.GetAsync(input.ProjectId);
try
{
var document = await GetDocumentWithDetailsDtoAsync(
project,
project.ParametersDocumentName,
input.LanguageCode,
input.Version
);
return JsonConvert.DeserializeObject<DocumentParametersDto>(document.Content);
}
catch (DocumentNotFoundException)
{
Logger.LogWarning($"Parameter file ({project.ParametersDocumentName}) not found.");
return new DocumentParametersDto();
}
}
protected virtual async Task<DocumentWithDetailsDto> GetDocumentWithDetailsDtoAsync(
Project project,
string documentName,
@ -119,7 +142,7 @@ namespace Volo.Docs.Documents
return CreateDocumentWithDetailsDto(project, document);
}
if (Debugger.IsAttached)
if (HostEnvironment.IsDevelopment())
{
return await GetDocumentAsync();
}
@ -143,5 +166,6 @@ namespace Volo.Docs.Documents
documentDto.Contributors = ObjectMapper.Map<List<DocumentContributor>, List<DocumentContributorDto>>(document.Contributors);
return documentDto;
}
}
}

1
modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/ProjectConsts.cs

@ -6,6 +6,7 @@
public const int MaxShortNameLength = 32;
public const int MaxDefaultDocumentNameLength = 128;
public const int MaxNavigationDocumentNameLength = 128;
public const int MaxParametersDocumentNameLength = 128;
public const int MaxLatestVersionBranchNameLength = 128;
public const int MaxVersionNameLength = 128;
}

3
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs

@ -36,6 +36,7 @@ namespace Volo.Docs.GitHub.Documents
var rawDocumentUrl = rawRootUrl + documentName;
var commitHistoryUrl = project.GetGitHubUrlForCommitHistory() + documentName;
var isNavigationDocument = documentName == project.NavigationDocumentName;
var isParameterDocument = documentName == project.ParametersDocumentName;
var editLink = rootUrl.ReplaceFirst("/tree/", "/blob/") + languageCode + "/" + documentName;
var localDirectory = "";
var fileName = documentName;
@ -56,7 +57,7 @@ namespace Volo.Docs.GitHub.Documents
LocalDirectory = localDirectory,
FileName = fileName,
Contributors = new List<DocumentContributor>(),
//Contributors = !isNavigationDocument ? await GetContributors(commitHistoryUrl, token, userAgent): new List<DocumentContributor>(),
//Contributors = !isNavigationDocument && !isParameterDocument ? await GetContributors(commitHistoryUrl, token, userAgent): new List<DocumentContributor>(),
Version = version,
Content = await DownloadWebContentAsStringAsync(rawDocumentUrl, token, userAgent)
};

16
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs

@ -34,6 +34,11 @@ namespace Volo.Docs.Projects
/// </summary>
public virtual string NavigationDocumentName { get; protected set; }
/// <summary>
/// The document to be used for the parameters file (index).
/// </summary>
public virtual string ParametersDocumentName { get; protected set; }
public virtual string MinimumVersion { get; set; }
/// <summary>
@ -56,8 +61,9 @@ namespace Volo.Docs.Projects
[NotNull] string shortName,
[NotNull] string documentStoreType,
[NotNull] string format,
[NotNull] string defaultDocumentName,
[NotNull] string navigationDocumentName)
[NotNull] string defaultDocumentName = "Index",
[NotNull] string navigationDocumentName = "docs-nav.json",
[NotNull] string parametersDocumentName = "docs-params.json")
{
Id = id;
@ -67,6 +73,7 @@ namespace Volo.Docs.Projects
Format = Check.NotNullOrWhiteSpace(format, nameof(format));
DefaultDocumentName = Check.NotNullOrWhiteSpace(defaultDocumentName, nameof(defaultDocumentName));
NavigationDocumentName = Check.NotNullOrWhiteSpace(navigationDocumentName, nameof(navigationDocumentName));
ParametersDocumentName = Check.NotNullOrWhiteSpace(parametersDocumentName, nameof(parametersDocumentName));
ExtraProperties = new Dictionary<string, object>();
}
@ -86,6 +93,11 @@ namespace Volo.Docs.Projects
NavigationDocumentName = Check.NotNullOrWhiteSpace(navigationDocumentName, nameof(navigationDocumentName));
}
public void SetParametersDocumentName(string parametersDocumentName)
{
ParametersDocumentName = Check.NotNullOrWhiteSpace(parametersDocumentName, nameof(parametersDocumentName));
}
public void SetDefaultDocumentName(string defaultDocumentName)
{
DefaultDocumentName = Check.NotNullOrWhiteSpace(defaultDocumentName, nameof(defaultDocumentName));

1
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs

@ -33,6 +33,7 @@ namespace Volo.Docs.EntityFrameworkCore
b.Property(x => x.ShortName).IsRequired().HasMaxLength(ProjectConsts.MaxShortNameLength);
b.Property(x => x.DefaultDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxDefaultDocumentNameLength);
b.Property(x => x.NavigationDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxNavigationDocumentNameLength);
b.Property(x => x.ParametersDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxParametersDocumentNameLength);
b.Property(x => x.LatestVersionBranchName).HasMaxLength(ProjectConsts.MaxLatestVersionBranchNameLength);
});
}

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

@ -45,5 +45,10 @@ namespace Volo.Docs.Documents
{
return DocumentAppService.GetResourceAsync(input);
}
public Task<DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input)
{
return DocumentAppService.GetParametersAsync(input);
}
}
}

8
modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentParseParamaters.cs

@ -0,0 +1,8 @@
using System.Collections.Generic;
namespace Volo.Docs.HtmlConverting
{
public class DocumentRenderParameters : Dictionary<string,string>
{
}
}

12
modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentSectionConsts.cs

@ -0,0 +1,12 @@
namespace Volo.Docs.HtmlConverting
{
public class DocumentSectionConsts
{
public const string SectionOpenerPrefix = "[doc-section:";
public const string SectionOpenerKeyValueSeparator = "=";
public const string SectionOpenerAndCondition = "&";
public const string SectionOpenerOrCondition = "|";
public const string SectionOpenerPostfix = "]";
public const string SectionCloser = "[/doc-section]";
}
}

2
modules/docs/src/Volo.Docs.Web/HtmlConverting/HtmlNormalizer.cs

@ -28,7 +28,6 @@ namespace Volo.Docs.HtmlConverting
}, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline);
return content;
}
@ -36,6 +35,5 @@ namespace Volo.Docs.HtmlConverting
{
return Regex.Replace(content, "<code class=\"" + currentLanguage + "\">", "<code class=\"" + newLanguage + "\">", RegexOptions.IgnoreCase);
}
}
}

15
modules/docs/src/Volo.Docs.Web/HtmlConverting/IDocumentSectionRenderer.cs

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.Docs.HtmlConverting
{
public interface IDocumentSectionRenderer: ITransientDependency
{
Task<string> RenderAsync(string doucment, DocumentRenderParameters parameters);
Task<Dictionary<string, List<string>>> GetAvailableParametersAsync(string document);
}
}

120
modules/docs/src/Volo.Docs.Web/HtmlConverting/ScribanDocumentSectionParser.cs

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Scriban;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Volo.Docs.HtmlConverting
{
public class ScribanDocumentSectionRenderer : IDocumentSectionRenderer
{
private const string jsonOpener = "````json";
private const string jsonCloser = "````";
private const string docs_param = "//[doc-params]";
public ILogger<ScribanDocumentSectionRenderer> Logger { get; set; }
public ScribanDocumentSectionRenderer()
{
Logger = NullLogger<ScribanDocumentSectionRenderer>.Instance;
}
public async Task<string> RenderAsync(string document, DocumentRenderParameters parameters = null)
{
Template scribanTemplate = Template.Parse(document);
if (parameters == null)
{
return await scribanTemplate.RenderAsync();
}
var result = await scribanTemplate.RenderAsync(parameters);
return RemoveOptionsJson(result);
}
public async Task<Dictionary<string, List<string>>> GetAvailableParametersAsync(string document)
{
try
{
if (!document.Contains(jsonOpener) || !document.Contains(docs_param))
{
return new Dictionary<string, List<string>>();
}
var (jsonBeginningIndex, JsonEndingIndex, insideJsonSection) = GetJsonBeginEndIndexesAndPureJson(document);
if (jsonBeginningIndex < 0 || JsonEndingIndex <= 0 || string.IsNullOrWhiteSpace(insideJsonSection))
{
return new Dictionary<string, List<string>>();
}
var pureJson = insideJsonSection.Replace(docs_param, "").Trim();
return JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(pureJson);
}
catch (Exception)
{
Logger.LogWarning("Unable to parse parameters of document.");
return new Dictionary<string, List<string>>();
}
}
private string RemoveOptionsJson(string document)
{
var orgDocument = document;
try
{
if (!document.Contains(jsonOpener) || !document.Contains(docs_param))
{
return orgDocument;
}
var (jsonBeginningIndex, JsonEndingIndex, insideJsonSection) = GetJsonBeginEndIndexesAndPureJson(document);
if (jsonBeginningIndex < 0 || JsonEndingIndex <= 0 || string.IsNullOrWhiteSpace(insideJsonSection))
{
return orgDocument;
}
return document.Remove(
jsonBeginningIndex - jsonOpener.Length, (JsonEndingIndex + jsonCloser.Length) - (jsonBeginningIndex - jsonOpener.Length)
);
}
catch (Exception)
{
return orgDocument;
}
}
private (int, int, string) GetJsonBeginEndIndexesAndPureJson(string document)
{
var searchedIndex = 0;
while (searchedIndex < document.Length)
{
var jsonBeginningIndex = document.Substring(searchedIndex).IndexOf(jsonOpener) + jsonOpener.Length + searchedIndex;
if (jsonBeginningIndex < 0)
{
return (-1,-1,"");
}
var JsonEndingIndex = document.Substring(jsonBeginningIndex).IndexOf(jsonCloser) + jsonBeginningIndex;
var insideJsonSection = document[jsonBeginningIndex..JsonEndingIndex];
if (insideJsonSection.IndexOf(docs_param) < 0)
{
searchedIndex = JsonEndingIndex + jsonCloser.Length;
continue;
}
return (jsonBeginningIndex, JsonEndingIndex, insideJsonSection);
}
return (-1, -1, "");
}
}
}

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

@ -207,10 +207,36 @@
}
</div>
}
<div class="alert alert-info" role="alert">
@if (Model.DocumentPreferences != null && Model.DocumentPreferences.Parameters != null && Model.DocumentPreferences.Parameters.Any())
{
foreach (var parameter in Model.DocumentPreferences.Parameters)
{
@(parameter.DisplayName + ":")
<select class="doc-section-combobox mr-4 mt-2" id="@("Section" + parameter.Name + "ComboboxId")" data-key="@parameter.Name">
@foreach (var value in parameter.Values)
{
@if (value.Key == (Model.UserPreferences.ContainsKey(parameter.Name) ? Model.UserPreferences[parameter.Name] : null))
{
<option value="@value.Key" selected="selected">@value.Value</option>
}
else
{
<option value="@value.Key">@value.Value</option>
}
}
</select>
}
}
</div>
</div>
<div class="docs-text-field">
<div data-spy="scroll" data-target="#docs-sticky-index" data-offset="0">
<article class="docs-body">
@if (Model.DocumentLanguageIsDifferent)
{
<abp-alert alert-type="Warning" dismissible="true" class="mb-0">

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

@ -56,22 +56,29 @@ namespace Volo.Docs.Pages.Documents.Project
public bool DocumentLanguageIsDifferent { get; set; }
public DocumentParametersDto DocumentPreferences { get; set; }
public DocumentRenderParameters UserPreferences { get; set; }
private readonly IDocumentAppService _documentAppService;
private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory;
private readonly IProjectAppService _projectAppService;
private readonly IDocumentSectionRenderer _documentSectionRenderer;
private readonly DocsUiOptions _uiOptions;
public IndexModel(
IDocumentAppService documentAppService,
IDocumentToHtmlConverterFactory documentToHtmlConverterFactory,
IProjectAppService projectAppService,
IOptions<DocsUiOptions> options)
IOptions<DocsUiOptions> options,
IDocumentSectionRenderer documentSectionRenderer)
{
ObjectMapperContext = typeof(DocsWebModule);
_documentAppService = documentAppService;
_documentToHtmlConverterFactory = documentToHtmlConverterFactory;
_projectAppService = projectAppService;
_documentSectionRenderer = documentSectionRenderer;
_uiOptions = options.Value;
}
@ -353,7 +360,7 @@ namespace Volo.Docs.Pages.Documents.Project
}
}
ConvertDocumentContentToHtml();
await ConvertDocumentContentToHtmlAsync();
}
private void SetLanguageSelectListItems()
@ -372,8 +379,13 @@ namespace Volo.Docs.Pages.Documents.Project
}
}
private void ConvertDocumentContentToHtml()
private async Task ConvertDocumentContentToHtmlAsync()
{
await SetDocumentPreferences();
SetUserPreferences();
Document.Content = await _documentSectionRenderer.RenderAsync(Document.Content, UserPreferences);
var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? Project.Format);
var content = converter.Convert(Project, Document, GetSpecificVersionOrLatest(), LanguageCode);
@ -392,5 +404,105 @@ namespace Volo.Docs.Pages.Documents.Project
Document.Content = content;
}
private void SetUserPreferences()
{
UserPreferences = new DocumentRenderParameters();
var cookie = Request.Cookies["AbpIoDocsPreferences"];
if (cookie != null)
{
var keyValues = cookie.Split("|");
foreach (var keyValue in keyValues)
{
if (keyValue.Split("=").Length < 2)
{
continue;
}
var key = keyValue.Split("=")[0];
var value = keyValue.Split("=")[1];
UserPreferences.Add(key, value);
}
}
var query = Request.Query;
foreach (var keyValue in query)
{
if (UserPreferences.ContainsKey(keyValue.Key))
{
UserPreferences.Remove(keyValue.Key);
}
UserPreferences.Add(keyValue.Key, keyValue.Value);
}
if (DocumentPreferences?.Parameters == null)
{
return;
}
foreach (var parameter in DocumentPreferences.Parameters)
{
if (!UserPreferences.ContainsKey(parameter.Name))
{
UserPreferences.Add(parameter.Name, parameter.Values.FirstOrDefault().Key);
}
}
}
public async Task SetDocumentPreferences()
{
var projectParameters = await _documentAppService.GetParametersAsync(
new GetParametersDocumentInput
{
ProjectId = Project.Id,
LanguageCode = LanguageCode,
Version = Version
});
if (projectParameters?.Parameters == null)
{
return;
}
var availableparameters = await _documentSectionRenderer.GetAvailableParametersAsync(Document.Content);
DocumentPreferences = new DocumentParametersDto
{
Parameters = new List<DocumentParameterDto>()
};
if (availableparameters == null || !availableparameters.Any())
{
return;
}
foreach (var parameter in projectParameters.Parameters)
{
var availableParameter = availableparameters.GetOrDefault(parameter.Name);
if (availableParameter != null)
{
var newParameter = new DocumentParameterDto
{
Name = parameter.Name,
DisplayName = parameter.DisplayName,
Values = new Dictionary<string, string>()
};
foreach (var value in parameter.Values)
{
if (availableParameter.Contains(value.Key))
{
newParameter.Values.Add(value.Key, value.Value);
}
}
DocumentPreferences.Parameters.Add(newParameter);
}
}
}
}
}
}

86
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js

@ -2,7 +2,7 @@
$(function () {
var initNavigationFilter = function (navigationContainerId) {
var $navigation = $("#" + navigationContainerId);
@ -102,12 +102,96 @@
);
};
var initSections = function () {
var clearQueryString = function () {
var uri = window.location.href.toString();
if (uri.indexOf("?") > 0) {
uri = uri.substring(0, uri.indexOf("?"));
}
window.history.replaceState({}, document.title, uri);
};
var setQueryString = function () {
clearQueryString();
var uri = window.location.href.toString();
var comboboxes = $(".doc-section-combobox");
if (comboboxes.length < 1) {
return;
}
var new_uri = uri + "?";
for (var i = 0; i < comboboxes.length; i++) {
var key = $(comboboxes[i]).data('key');
var value = comboboxes[i].value;
new_uri += key + "=" + value;
if (i !== comboboxes.length - 1) {
new_uri += "&";
}
}
window.history.replaceState({}, document.title, new_uri);
};
var setCookies = function () {
var cookie = abp.utils.getCookieValue("AbpIoDocsPreferences");
if (!cookie || cookie == null || cookie === null) {
cookie = "";
}
var keyValues = cookie.split("|");
var comboboxes = $(".doc-section-combobox");
for (var i = 0; i < comboboxes.length; i++) {
var key = $(comboboxes[i]).data('key');
var value = comboboxes[i].value;
var changed = false;
var keyValueslength = keyValues.length;
for (var k = 0; k < keyValueslength; k++) {
var splitted = keyValues[k].split("=");
if (splitted.length > 0 && splitted[0] === key) {
keyValues[k] = key + "=" + value;
console.log(keyValues[k]);
changed = true;
}
}
if (!changed) {
keyValues.push(key + "=" + value);
}
}
abp.utils.setCookieValue("AbpIoDocsPreferences", keyValues.join('|'));
};
$(".doc-section-combobox").change(function () {
setCookies();
clearQueryString();
location.reload();
});
setQueryString();
};
initNavigationFilter("sidebar-scroll");
initAnchorTags(".docs-page .docs-body");
initSocialShareLinks();
initSections();
});
})(jQuery);

1
modules/docs/src/Volo.Docs.Web/Volo.Docs.Web.csproj

@ -19,6 +19,7 @@
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Packages\Volo.Abp.AspNetCore.Mvc.UI.Packages.csproj" />
<ProjectReference Include="..\Volo.Docs.HttpApi\Volo.Docs.HttpApi.csproj" />
<PackageReference Include="Markdig.Signed" Version="0.15.6" />
<PackageReference Include="Scriban" Version="2.1.0" />
</ItemGroup>

3
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestDataBuilder.cs

@ -27,7 +27,8 @@ namespace Volo.Docs
GithubDocumentStore.Type,
"md",
"index",
"docs-nav.json"
"docs-nav.json",
"docs-params.json"
);
project

Loading…
Cancel
Save