Browse Source

Fix enum conversion method.

pull/20368/head
maliming 2 years ago
parent
commit
1c377800d9
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 2
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs
  2. 8
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs
  3. 18
      modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs
  4. 17
      modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs
  5. 8
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/ProjectDto.cs
  6. 39
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  7. 19
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs
  8. 7
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Projects/ProjectFileSystemExtensions.cs
  9. 17
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs
  10. 16
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Projects/ProjectGithubExtensions.cs
  11. 55
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs
  12. 19
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

2
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs

@ -47,7 +47,7 @@ public static class HasExtraPropertiesExtensions
if (conversionType.IsEnum)
{
return (TProperty)value;
return (TProperty)Enum.Parse(conversionType, value.ToString()!);
}
return (TProperty)Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture);

8
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
namespace Volo.Docs.Admin.Projects
{
[Serializable]
public class ProjectDto : EntityDto<Guid>, IHasConcurrencyStamp
public class ProjectDto : EntityDto<Guid>, IHasConcurrencyStamp, IHasExtraProperties
{
public string Name { get; set; }
@ -28,8 +28,8 @@ namespace Volo.Docs.Admin.Projects
public string DocumentStoreType { get; set; }
public Dictionary<string, object> ExtraProperties { get; set; }
public string ConcurrencyStamp { get; set; }
public ExtraPropertyDictionary ExtraProperties { get; set; } = new();
}
}

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

@ -81,7 +81,7 @@ namespace Volo.Docs.Admin.Projects
foreach (var extraProperty in input.ExtraProperties)
{
project.ExtraProperties.Add(extraProperty.Key, extraProperty.Value);
project.SetProperty(extraProperty.Key, extraProperty.Value);
}
project = await _projectRepository.InsertAsync(project);
@ -106,7 +106,7 @@ namespace Volo.Docs.Admin.Projects
foreach (var extraProperty in input.ExtraProperties)
{
project.ExtraProperties[extraProperty.Key] = extraProperty.Value;
project.SetProperty(extraProperty.Key, extraProperty.Value);
}
project = await _projectRepository.UpdateAsync(project);
@ -134,18 +134,18 @@ namespace Volo.Docs.Admin.Projects
{
throw new Exception("Cannot find the project with the Id " + projectId);
}
await _elasticSearchService.DeleteAllByProjectIdAsync(project.Id);
var docsCount = await _documentRepository.GetUniqueDocumentCountByProjectIdAsync(projectId);
if (docsCount == 0)
{
return;
}
const int maxResultCount = 1000;
var skipCount = 0;
while(skipCount < docsCount)
{
@ -164,13 +164,13 @@ namespace Volo.Docs.Admin.Projects
{
_elasticSearchService.ValidateElasticSearchEnabled();
var projects = await _projectRepository.GetListAsync();
foreach (var project in projects)
{
await ReindexProjectAsync(project.Id);
}
}
public virtual async Task<List<ProjectWithoutDetailsDto>> GetListWithoutDetailsAsync()
{
var projects = await _projectRepository.GetListWithoutDetailsAsync();

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

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc.Rendering;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Validation;
using Volo.Docs.Admin.Projects;
@ -34,7 +35,7 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
public virtual async Task<ActionResult> OnGetAsync(Guid id)
{
var project = await _projectAppService.GetAsync(id);
if (project.DocumentStoreType == "GitHub")
{
SetGithubProjectFromDto(project);
@ -75,18 +76,18 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
{
GithubProject = ObjectMapper.Map<ProjectDto,EditGithubProjectViewModel>(dto);
GithubProject.GitHubAccessToken = (string) dto.ExtraProperties[nameof(GithubProject.GitHubAccessToken)];
GithubProject.GitHubRootUrl = (string) dto.ExtraProperties[nameof(GithubProject.GitHubRootUrl)];
GithubProject.GitHubUserAgent = (string) dto.ExtraProperties[nameof(GithubProject.GitHubUserAgent)];
GithubProject.GitHubAccessToken = dto.GetProperty<string>(nameof(GithubProject.GitHubAccessToken));
GithubProject.GitHubRootUrl = dto.GetProperty<string>(nameof(GithubProject.GitHubRootUrl));
GithubProject.GitHubUserAgent = dto.GetProperty<string>(nameof(GithubProject.GitHubUserAgent));
if (dto.ExtraProperties.ContainsKey(nameof(GithubProject.GithubVersionProviderSource)))
if (dto.HasProperty(nameof(GithubProject.GithubVersionProviderSource)))
{
GithubProject.GithubVersionProviderSource = (GithubVersionProviderSource) (long) dto.ExtraProperties[nameof(GithubProject.GithubVersionProviderSource)];
GithubProject.GithubVersionProviderSource = dto.GetProperty<GithubVersionProviderSource>(nameof(GithubProject.GithubVersionProviderSource));
}
if (dto.ExtraProperties.ContainsKey(nameof(GithubProject.VersionBranchPrefix)))
if (dto.HasProperty(nameof(GithubProject.VersionBranchPrefix)))
{
GithubProject.VersionBranchPrefix = (string) dto.ExtraProperties[nameof(GithubProject.VersionBranchPrefix)];
GithubProject.VersionBranchPrefix = dto.GetProperty<string>(nameof(GithubProject.VersionBranchPrefix));
}
}

8
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/ProjectDto.cs

@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Data;
namespace Volo.Docs.Projects
{
[Serializable]
public class ProjectDto : EntityDto<Guid>
public class ProjectDto : EntityDto<Guid>, IHasExtraProperties
{
public string Name { get; set; }
@ -25,6 +25,6 @@ namespace Volo.Docs.Projects
public string DocumentStoreType { get; set; }
public Dictionary<string, object> ExtraProperties { get; set; }
public ExtraPropertyDictionary ExtraProperties { get; set; } = new();
}
}
}

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

@ -12,6 +12,7 @@ using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Docs.Caching;
using Volo.Docs.Documents.FullSearch.Elastic;
using Volo.Docs.Projects;
@ -69,7 +70,7 @@ namespace Volo.Docs.Documents
var inputVersionStringBuilder = new StringBuilder();
input.Version = inputVersionStringBuilder.Append(GetProjectVersionPrefixIfExist(project)).Append(input.Version).ToString();
return await GetDocumentWithDetailsDtoAsync(
project,
input.Name,
@ -84,9 +85,9 @@ namespace Volo.Docs.Documents
var sb = new StringBuilder();
input.Version = sb.Append(GetProjectVersionPrefixIfExist(project)).Append(input.Version).ToString();
sb.Clear();
return await GetDocumentWithDetailsDtoAsync(
project,
sb.Append(project.DefaultDocumentName).Append(".").Append(project.Format).ToString(),
@ -298,7 +299,7 @@ namespace Volo.Docs.Documents
private string NormalizePath(string prefix, string path, string shortName, DocumentWithoutDetails document)
{
var pathWithoutFileExtension = RemoveFileExtensionFromPath(path, document.Format);
var normalizedPathStringBuilder = new StringBuilder();
normalizedPathStringBuilder.Append(prefix).Append(document.LanguageCode).Append("/").Append(shortName)
.Append("/").Append(document.Version).Append("/").Append(pathWithoutFileExtension);
@ -377,7 +378,7 @@ namespace Volo.Docs.Documents
{
return await GetDocumentAsync(documentName, project, languageCode, version);
}
var document = await _documentRepository.FindAsync(project.Id, GetPossibleNames(documentName, project.Format), languageCode, version);
if (document == null)
{
@ -417,7 +418,7 @@ namespace Volo.Docs.Documents
string languageCode, string version, Document oldDocument = null)
{
Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the source...");
var sourceDocument = await GetSourceDocument(project, documentName, languageCode, version, oldDocument);
await _documentRepository.DeleteAsync(project.Id, sourceDocument.Name, sourceDocument.LanguageCode, sourceDocument.Version, autoSave: true);
@ -450,23 +451,23 @@ namespace Volo.Docs.Documents
{
return new List<string> {originalDocumentName};
}
var lowerCaseIndex = "index." + format;
var titleCaseIndex = "Index." + format;
var indexLength = lowerCaseIndex.Length;
var possibleNames = new List<string> {originalDocumentName};
if (originalDocumentName.EndsWith("/" + lowerCaseIndex, StringComparison.OrdinalIgnoreCase) || originalDocumentName.Equals(lowerCaseIndex, StringComparison.OrdinalIgnoreCase))
{
var indexPart = originalDocumentName.Right(indexLength);
var documentNameWithoutIndex = originalDocumentName.Left(originalDocumentName.Length - lowerCaseIndex.Length);
if(indexPart != lowerCaseIndex)
{
possibleNames.Add(documentNameWithoutIndex + lowerCaseIndex);
}
if(indexPart != titleCaseIndex)
{
possibleNames.Add(documentNameWithoutIndex + titleCaseIndex);
@ -481,14 +482,14 @@ namespace Volo.Docs.Documents
return possibleNames;
}
private async Task<Document> GetSourceDocument(Project project, string documentName,
string languageCode, string version, Document oldDocument)
{
var source = _documentStoreFactory.Create(project.DocumentStoreType);
Document sourceDocument = null;
Exception firstException = null;
foreach (var name in GetPossibleNames(documentName, project.Format))
{
@ -503,7 +504,7 @@ namespace Volo.Docs.Documents
firstException ??= ex;
}
}
if(sourceDocument == null)
{
throw firstException!;
@ -552,14 +553,14 @@ namespace Volo.Docs.Documents
return string.Empty;
}
return project.ExtraProperties["VersionBranchPrefix"].ToString();
return project.GetProperty<string>("VersionBranchPrefix");
}
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
return project.HasProperty("GithubVersionProviderSource")
? project.GetProperty<GithubVersionProviderSource>("GithubVersionProviderSource")
: GithubVersionProviderSource.Releases;
}
}
}
}

19
modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs

@ -6,6 +6,7 @@ using Microsoft.Extensions.Caching.Distributed;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Abp.Guids;
using Volo.Docs.Caching;
using Volo.Docs.Documents;
@ -41,7 +42,7 @@ namespace Volo.Docs.Projects
return new ListResultDto<ProjectDto>(
projectDtos.Select(p => HidePrivateProperties(p)).ToList()
);
);
}
public virtual async Task<ProjectDto> GetAsync(string shortName)
@ -136,30 +137,28 @@ namespace Volo.Docs.Projects
return string.Empty;
}
return project.ExtraProperties["VersionBranchPrefix"].ToString();
return project.GetProperty<string>("VersionBranchPrefix");
}
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
return project.HasProperty("GithubVersionProviderSource")
? project.GetProperty<GithubVersionProviderSource>("GithubVersionProviderSource")
: GithubVersionProviderSource.Releases;
}
private ProjectDto HidePrivateProperties(ProjectDto project)
{
if (project.ExtraProperties.ContainsKey("GitHubAccessToken"))
if (project.HasProperty("GitHubAccessToken"))
{
project.ExtraProperties["GitHubAccessToken"] = null;
project.SetProperty("GitHubAccessToken", null);
}
if (project.ExtraProperties.ContainsKey("GitHubUserAgent"))
if (project.HasProperty("GitHubUserAgent"))
{
project.ExtraProperties["GitHubUserAgent"] = null;
project.SetProperty("GitHubUserAgent", null);
}
return project;
}
}

7
modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Projects/ProjectFileSystemExtensions.cs

@ -1,6 +1,7 @@
using System;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Docs.FileSystem.Documents;
using Volo.Docs.Projects;
@ -11,13 +12,13 @@ namespace Volo.Docs.FileSystem.Projects
public static string GetFileSystemPath([NotNull] this Project project)
{
CheckFileSystemProject(project);
return project.ExtraProperties["Path"] as string;
return project.GetProperty<string>("Path");
}
public static void SetFileSystemPath([NotNull] this Project project, string value)
{
CheckFileSystemProject(project);
project.ExtraProperties["Path"] = value;
project.SetProperty("Path", value);
}
private static void CheckFileSystemProject(Project project)
@ -30,4 +31,4 @@ namespace Volo.Docs.FileSystem.Projects
}
}
}
}
}

17
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs

@ -11,6 +11,7 @@ using Volo.Docs.GitHub.Projects;
using Volo.Docs.Projects;
using Octokit;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Extensions;
using Project = Volo.Docs.Projects.Project;
@ -29,8 +30,8 @@ namespace Volo.Docs.GitHub.Documents
private readonly DocsGithubLanguageOptions _docsGithubLanguageOptions;
public GithubDocumentSource(
IGithubRepositoryManager githubRepositoryManager,
IGithubPatchAnalyzer githubPatchAnalyzer,
IGithubRepositoryManager githubRepositoryManager,
IGithubPatchAnalyzer githubPatchAnalyzer,
IDocumentRepository documentRepository,
IOptions<DocsGithubLanguageOptions> docsGithubLanguageOptions)
{
@ -275,7 +276,7 @@ namespace Volo.Docs.GitHub.Documents
if (githubVersionProviderSource == GithubVersionProviderSource.Branches && project.ExtraProperties.ContainsKey("VersionBranchPrefix"))
{
var prefix = (string) project.ExtraProperties["VersionBranchPrefix"];
var prefix = project.GetProperty<string>("VersionBranchPrefix");
if (!string.IsNullOrEmpty(prefix))
{
@ -307,8 +308,8 @@ namespace Volo.Docs.GitHub.Documents
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
return project.HasProperty("GithubVersionProviderSource")
? project.GetProperty<GithubVersionProviderSource>("GithubVersionProviderSource")
: GithubVersionProviderSource.Releases;
}
@ -344,9 +345,9 @@ namespace Volo.Docs.GitHub.Documents
}
catch
{
Logger.LogWarning("Could not retrieved language list from Github. Using the default language from DocsGithubLanguageOptions.");
return new LanguageConfig
Logger.LogWarning("Could not retrieved language list from Github. Using the default language from DocsGithubLanguageOptions.");
return new LanguageConfig
{
Languages = new List<LanguageConfigElement> { _docsGithubLanguageOptions.DefaultLanguage }
};

16
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Projects/ProjectGithubExtensions.cs

@ -1,6 +1,7 @@
using System;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Docs.GitHub.Documents;
using Volo.Docs.Projects;
@ -11,13 +12,12 @@ namespace Volo.Docs.GitHub.Projects
public static string GetGitHubUrl([NotNull] this Project project)
{
CheckGitHubProject(project);
return project.ExtraProperties["GitHubRootUrl"] as string;
return project.GetProperty<string>("GitHubRootUrl");
}
public static string GetGitHubInnerUrl([NotNull] this Project project, string languageCode, string documentName)
{
return project
.GetGitHubUrl().Split("{version}")[1].EnsureEndsWith('/').TrimStart('/') + languageCode + '/' + documentName;
return project.GetGitHubUrl().Split("{version}")[1].EnsureEndsWith('/').TrimStart('/') + languageCode + '/' + documentName;
}
public static string GetGitHubUrl([NotNull] this Project project, string version)
@ -30,25 +30,25 @@ namespace Volo.Docs.GitHub.Projects
public static void SetGitHubUrl([NotNull] this Project project, string value)
{
CheckGitHubProject(project);
project.ExtraProperties["GitHubRootUrl"] = value;
project.SetProperty("GitHubRootUrl", value);
}
public static string GetGitHubAccessTokenOrNull([NotNull] this Project project)
{
CheckGitHubProject(project);
return project.ExtraProperties["GitHubAccessToken"] as string;
return project.GetProperty<string>("GitHubAccessToken");
}
public static string GetGithubUserAgentOrNull([NotNull] this Project project)
{
CheckGitHubProject(project);
return project.ExtraProperties["GitHubUserAgent"] as string;
return project.GetProperty<string>("GitHubUserAgent");
}
public static void SetGitHubAccessToken([NotNull] this Project project, string value)
{
CheckGitHubProject(project);
project.ExtraProperties["GitHubAccessToken"] = value;
project.SetProperty("GitHubAccessToken", value);
}
private static void CheckGitHubProject(Project project)
@ -61,4 +61,4 @@ namespace Volo.Docs.GitHub.Projects
}
}
}
}
}

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

@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
using Volo.Docs.Documents;
using Volo.Docs.HtmlConverting;
@ -68,7 +69,7 @@ namespace Volo.Docs.Pages.Documents.Project
public string DocumentsUrlPrefix { get; set; }
public bool ShowProjectsCombobox { get; set; }
public bool ShowProjectsComboboxLabel { get; set; }
public bool IsVersionPreview { get; set; }
@ -83,8 +84,8 @@ namespace Volo.Docs.Pages.Documents.Project
public bool FullSearchEnabled { get; set; }
public bool IsLatestVersion { get; private set; }
public bool IsLatestVersion { get; private set; }
public DocumentNavigationsDto DocumentNavigationsDto { get; private set; }
private const int MaxDescriptionMetaTagLength = 200;
@ -93,7 +94,7 @@ namespace Volo.Docs.Pages.Documents.Project
private readonly IProjectAppService _projectAppService;
private readonly IDocumentSectionRenderer _documentSectionRenderer;
private readonly DocsUiOptions _uiOptions;
protected IDocsLinkGenerator DocsLinkGenerator => LazyServiceProvider.LazyGetRequiredService<IDocsLinkGenerator>();
public IndexModel(
@ -123,7 +124,7 @@ namespace Volo.Docs.Pages.Documents.Project
{
return Redirect(decodedUrl);
}
return await SetPageAsync();
}
@ -143,7 +144,7 @@ namespace Volo.Docs.Pages.Documents.Project
Response.StatusCode = 404;
return Page();
}
}
catch (EntityNotFoundException e)
{
@ -168,7 +169,7 @@ namespace Volo.Docs.Pages.Documents.Project
{
return RedirectToDefaultDocument();
}
var usingSingleLanguageMode = !_uiOptions.MultiLanguageMode && LanguageCode.IsNullOrWhiteSpace();
if (!usingSingleLanguageMode && !CheckLanguage())
@ -220,14 +221,14 @@ namespace Volo.Docs.Pages.Documents.Project
Project = await _projectAppService.GetAsync(ProjectName);
return;
}
var singleProjectName = ProjectName ?? _uiOptions.SingleProjectMode.ProjectName;
if (!singleProjectName.IsNullOrWhiteSpace())
{
Project = await _projectAppService.GetAsync(singleProjectName);
return;
}
var listResult = await _projectAppService.GetListAsync();
if (listResult.Items.Count == 1)
{
@ -265,12 +266,12 @@ namespace Volo.Docs.Pages.Documents.Project
{
return Request.Scheme + Uri.SchemeDelimiter + Request.Host.Value + Request.PathBase + DocsLinkGenerator.GenerateLink(ProjectName, LanguageCode, DocsAppConsts.Latest, DocumentName);
}
public string CreateDocumentLink(string documentName)
{
return DocsLinkGenerator.GenerateLink(ProjectName, LanguageCode, LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version, documentName);
}
public string BuildDocumentUrl(string projectName, string languageCode, string version, string documentName)
{
return DocsLinkGenerator.GenerateLink(projectName, languageCode, version, documentName);
@ -279,13 +280,13 @@ namespace Volo.Docs.Pages.Documents.Project
private IActionResult RedirectToDefaultLanguage()
{
return Redirect(DocsLinkGenerator.GenerateLink(
ProjectName,
DefaultLanguageCode,
ProjectName,
DefaultLanguageCode,
LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version,
DocumentName
));
}
private IActionResult RedirectToDefaultVersion()
{
return Redirect(DocsLinkGenerator.GenerateLink(
@ -301,7 +302,7 @@ namespace Volo.Docs.Pages.Documents.Project
return Redirect(DocsLinkGenerator.GenerateLink (
ProjectName,
DefaultLanguageCode,
LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version,
LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version,
""
));
}
@ -374,7 +375,7 @@ namespace Volo.Docs.Pages.Documents.Project
$"{DocsAppConsts.Latest}",
DocsAppConsts.Latest,
true);
if(string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
{
Version = RemoveVersionPrefix(Project.LatestVersionBranchName);
@ -387,16 +388,16 @@ namespace Volo.Docs.Pages.Documents.Project
Value = CreateVersionLink(LatestVersionInfo, v.Version, DocumentName),
Selected = v.IsSelected
}).ToList();
IsLatestVersion = Version == LatestVersionInfo.Version;
return true;
}
private VersionInfoViewModel GetLatestVersionInfo(List<VersionInfoViewModel> versions)
{
if (Project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
&& (GithubVersionProviderSource)(long)Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Branches)
if (Project.HasProperty("GithubVersionProviderSource")
&& Project.GetProperty<GithubVersionProviderSource>("GithubVersionProviderSource") == GithubVersionProviderSource.Branches)
{
var LatestVersionBranchNameWithoutPrefix = RemoveVersionPrefix(Project.LatestVersionBranchName);
@ -418,12 +419,12 @@ namespace Volo.Docs.Pages.Documents.Project
private string RemoveVersionPrefix(string version)
{
if (!Project.ExtraProperties.ContainsKey("VersionBranchPrefix"))
if (!Project.HasProperty("VersionBranchPrefix"))
{
return version;
}
var prefix = Project.ExtraProperties["VersionBranchPrefix"]?.ToString();
var prefix = Project.GetProperty<string>("VersionBranchPrefix");
if (string.IsNullOrWhiteSpace(version) || string.IsNullOrWhiteSpace(prefix) || !version.StartsWith(prefix) || version.Length <= prefix.Length)
{
@ -435,8 +436,8 @@ namespace Volo.Docs.Pages.Documents.Project
private void SetLatestVersionBranchName(List<VersionInfoViewModel> versions)
{
if (!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
|| (GithubVersionProviderSource)(long)Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Releases)
if (!Project.HasProperty("GithubVersionProviderSource")
|| Project.GetProperty<GithubVersionProviderSource>("GithubVersionProviderSource") == GithubVersionProviderSource.Releases)
{
versions.First(v => !SemanticVersionHelper.IsPreRelease(v.Version)).Version = Project.LatestVersionBranchName;
}
@ -467,7 +468,7 @@ namespace Volo.Docs.Pages.Documents.Project
{
version = DocsAppConsts.Latest;
}
return DocsLinkGenerator.GenerateLink(ProjectName, LanguageCode, version, documentName);
}
@ -536,7 +537,7 @@ namespace Volo.Docs.Pages.Documents.Project
SetUserPreferences();
var partialTemplates = await GetDocumentPartialTemplatesAsync();
DocumentNavigationsDto = await _documentSectionRenderer.GetDocumentNavigationsAsync(Document.Content);
Document.Content = await _documentSectionRenderer.RenderAsync(Document.Content, UserPreferences, partialTemplates);
@ -819,4 +820,4 @@ namespace Volo.Docs.Pages.Documents.Project
return description.Truncate(MaxDescriptionMetaTagLength);
}
}
}
}

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

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Pagination;
using Volo.Abp.Data;
using Volo.Docs.Documents;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.HtmlConverting;
@ -26,9 +27,9 @@ namespace Volo.Docs.Pages.Documents
[BindProperty(SupportsGet = true)] public string LanguageCode { get; set; }
[BindProperty(SupportsGet = true)] public string KeyWord { get; set; }
[BindProperty(SupportsGet = true)] public int CurrentPage { get; set; } = 1;
public PagerModel PagerModel { get; set; }
public ProjectDto Project { get; set; }
@ -73,8 +74,8 @@ namespace Volo.Docs.Pages.Documents
if (versions.Any() &&
string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
{
if ((!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") ||
(GithubVersionProviderSource) (long) Project.ExtraProperties["GithubVersionProviderSource"] ==GithubVersionProviderSource.Releases) &&
if ((!Project.HasProperty("GithubVersionProviderSource") ||
Project.GetProperty<GithubVersionProviderSource>("GithubVersionProviderSource") ==GithubVersionProviderSource.Releases) &&
!string.IsNullOrEmpty(Project.LatestVersionBranchName))
{
Version = Project.LatestVersionBranchName;
@ -94,9 +95,9 @@ namespace Volo.Docs.Pages.Documents
MaxResultCount = 10,
SkipCount = (CurrentPage - 1) * 10
});
SearchOutputs = pagedSearchOutputs.Items.ToList();
PagerModel = new PagerModel(pagedSearchOutputs.TotalCount, 10, CurrentPage, 10, Url.Page("Search", new
{
ProjectName,
@ -120,7 +121,7 @@ namespace Volo.Docs.Pages.Documents
return Page();
}
private async Task SetProjectAsync()
{
if (!_uiOptions.SingleProjectMode.Enable)
@ -128,14 +129,14 @@ namespace Volo.Docs.Pages.Documents
Project = await _projectAppService.GetAsync(ProjectName);
return;
}
var singleProjectName = ProjectName ?? _uiOptions.SingleProjectMode.ProjectName;
if (!singleProjectName.IsNullOrWhiteSpace())
{
Project = await _projectAppService.GetAsync(singleProjectName);
return;
}
var listResult = await _projectAppService.GetListAsync();
if (listResult.Items.Count == 1)
{

Loading…
Cancel
Save