diff --git a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs index 25a1debd00..277a97810a 100644 --- a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs +++ b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs @@ -13,7 +13,7 @@ namespace Volo.Docs.Documents Task GetNavigationDocumentAsync(string projectShortName, string version, bool normalize); - Task> GetVersions(string projectShortName, string defaultDocumentName, + Task> GetVersions(string projectShortName, string defaultDocumentName, Dictionary projectExtraProperties, string documentStoreType, string documentName); diff --git a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/VersionInfoDto.cs b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/VersionInfoDto.cs new file mode 100644 index 0000000000..4cd34bc082 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/VersionInfoDto.cs @@ -0,0 +1,12 @@ +using System; + +namespace Volo.Docs.Documents +{ + [Serializable] + public class VersionInfoDto + { + public string DisplayName { get; set; } + + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs index 7199e6d06d..bb48a9a575 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; using Volo.Abp.Application.Services; @@ -11,12 +12,12 @@ namespace Volo.Docs.Documents public class DocumentAppService : ApplicationService, IDocumentAppService { private readonly IProjectRepository _projectRepository; - private readonly IDistributedCache> _distributedCache; + private readonly IDistributedCache> _distributedCache; private readonly IDocumentStoreFactory _documentStoreFactory; public DocumentAppService( IProjectRepository projectRepository, - IDistributedCache> distributedCache, + IDistributedCache> distributedCache, IDocumentStoreFactory documentStoreFactory) { _projectRepository = projectRepository; @@ -64,7 +65,7 @@ namespace Volo.Docs.Documents } //TODO: Application service never gets such a parameter: Dictionary projectExtraProperties !!! - public async Task> GetVersions(string projectShortName, string defaultDocumentName, Dictionary projectExtraProperties, + public async Task> GetVersions(string projectShortName, string defaultDocumentName, Dictionary projectExtraProperties, string documentStoreType, string documentName) { var project = await _projectRepository.FindByShortNameAsync(projectShortName); @@ -86,22 +87,27 @@ namespace Volo.Docs.Documents if (!project.MinimumVersion.IsNullOrEmpty()) { - var minVersionIndex = versions.IndexOf(project.MinimumVersion); + var minVersionIndex = versions.FindIndex(v => v.Name == project.MinimumVersion); if (minVersionIndex > -1) { versions = versions.GetRange(0, minVersionIndex + 1); } } + if (!string.IsNullOrEmpty(project.LatestVersionBranchName)) + { + versions.First().Name = project.LatestVersionBranchName; + } + return versions; } - private async Task> GetVersionsFromCache(string projectShortName) + private async Task> GetVersionsFromCache(string projectShortName) { return await _distributedCache.GetAsync(projectShortName); } - private async Task SetVersionsToCache(string projectShortName, List versions) + private async Task SetVersionsToCache(string projectShortName, List versions) { var options = new DistributedCacheEntryOptions() { SlidingExpiration = TimeSpan.FromDays(1) }; await _distributedCache.SetAsync(projectShortName, versions, options); diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/GithubDocumentStore.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/GithubDocumentStore.cs index 38c933bf2c..de48edd87e 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/GithubDocumentStore.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/GithubDocumentStore.cs @@ -1,3 +1,6 @@ +using Microsoft.Extensions.Logging; +using Octokit; +using Octokit.Internal; using System; using System.Collections.Generic; using System.IO; @@ -6,9 +9,6 @@ using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using Octokit; -using Octokit.Internal; using Volo.Abp; using Volo.Abp.Domain.Services; using ProductHeaderValue = Octokit.ProductHeaderValue; @@ -80,7 +80,7 @@ namespace Volo.Docs.Documents } } - public async Task> GetVersions(Dictionary projectExtraProperties, string documentName) + public async Task> GetVersions(Dictionary projectExtraProperties, string documentName) { try { @@ -96,12 +96,12 @@ namespace Volo.Docs.Documents GetGithubRepositoryNameFromUrl(url) ); - return releases.OrderByDescending(r => r.PublishedAt).Select(r => r.TagName).ToList(); + return releases.OrderByDescending(r => r.PublishedAt).Select(r => new VersionInfoDto { Name = r.TagName, DisplayName = r.TagName }).ToList(); } catch (Exception ex) { Logger.LogError(ex.Message, ex); - return new List(); + return new List(); } } diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/IDocumentStore.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/IDocumentStore.cs index 3523774b0d..47039cd57a 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/IDocumentStore.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/IDocumentStore.cs @@ -9,6 +9,6 @@ namespace Volo.Docs.Documents Task FindDocumentByNameAsync(Dictionary projectExtraProperties, string projectFormat, string documentName, string version); - Task> GetVersions(Dictionary projectExtraProperties, string documentName); + Task> GetVersions(Dictionary projectExtraProperties, string documentName); } } \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/ProjectConsts.cs b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/ProjectConsts.cs index e2b4a10246..717158a166 100644 --- a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/ProjectConsts.cs +++ b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/ProjectConsts.cs @@ -6,5 +6,6 @@ public const int MaxShortNameLength = 32; public const int MaxDefaultDocumentNameLength = 128; public const int MaxNavigationDocumentNameLength = 128; + public const int MaxLatestVersionBranchNameLength = 128; } } diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs index 7b50528ef2..7dd8b9c185 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs @@ -47,6 +47,8 @@ namespace Volo.Docs.Projects public virtual string MainWebsiteUrl { get; protected set; } + public virtual string LatestVersionBranchName { get; set; } + protected Project() { ExtraProperties = new Dictionary(); diff --git a/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs b/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs index 57719c6e91..75fc26421c 100644 --- a/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs +++ b/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs @@ -26,6 +26,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.LatestVersionBranchName).HasMaxLength(ProjectConsts.MaxLatestVersionBranchNameLength); b.ConfigureExtraProperties(); }); diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs index 060c558f51..9e05c28655 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs @@ -89,7 +89,7 @@ namespace Volo.Docs.Pages.Documents.Project Versions = (await _documentAppService .GetVersions(project.ShortName, project.DefaultDocumentName, project.ExtraProperties, project.DocumentStoreType, DocumentNameWithExtension)) - .Select(v => new VersionInfo(v, v)).ToList(); + .Select(v => new VersionInfo(v.DisplayName, v.Name)).ToList(); LatestVersionInfo = GetLatestVersion();