Resolved #564: docs module should support reading documents from a branch for the latest version

pull/570/head
Halil ibrahim Kalkan 6 years ago
parent fef395033d
commit 8ef7435163

@ -13,7 +13,7 @@ namespace Volo.Docs.Documents
Task<NavigationWithDetailsDto> GetNavigationDocumentAsync(string projectShortName, string version,
bool normalize);
Task<List<string>> GetVersions(string projectShortName, string defaultDocumentName,
Task<List<VersionInfoDto>> GetVersions(string projectShortName, string defaultDocumentName,
Dictionary<string, object> projectExtraProperties,
string documentStoreType, string documentName);

@ -0,0 +1,12 @@
using System;
namespace Volo.Docs.Documents
{
[Serializable]
public class VersionInfoDto
{
public string DisplayName { get; set; }
public string Name { get; set; }
}
}

@ -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<List<string>> _distributedCache;
private readonly IDistributedCache<List<VersionInfoDto>> _distributedCache;
private readonly IDocumentStoreFactory _documentStoreFactory;
public DocumentAppService(
IProjectRepository projectRepository,
IDistributedCache<List<string>> distributedCache,
IDistributedCache<List<VersionInfoDto>> distributedCache,
IDocumentStoreFactory documentStoreFactory)
{
_projectRepository = projectRepository;
@ -64,7 +65,7 @@ namespace Volo.Docs.Documents
}
//TODO: Application service never gets such a parameter: Dictionary<string, object> projectExtraProperties !!!
public async Task<List<string>> GetVersions(string projectShortName, string defaultDocumentName, Dictionary<string, object> projectExtraProperties,
public async Task<List<VersionInfoDto>> GetVersions(string projectShortName, string defaultDocumentName, Dictionary<string, object> 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<List<string>> GetVersionsFromCache(string projectShortName)
private async Task<List<VersionInfoDto>> GetVersionsFromCache(string projectShortName)
{
return await _distributedCache.GetAsync(projectShortName);
}
private async Task SetVersionsToCache(string projectShortName, List<string> versions)
private async Task SetVersionsToCache(string projectShortName, List<VersionInfoDto> versions)
{
var options = new DistributedCacheEntryOptions() { SlidingExpiration = TimeSpan.FromDays(1) };
await _distributedCache.SetAsync(projectShortName, versions, options);

@ -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<List<string>> GetVersions(Dictionary<string, object> projectExtraProperties, string documentName)
public async Task<List<VersionInfoDto>> GetVersions(Dictionary<string, object> 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<string>();
return new List<VersionInfoDto>();
}
}

@ -9,6 +9,6 @@ namespace Volo.Docs.Documents
Task<Document> FindDocumentByNameAsync(Dictionary<string, object> projectExtraProperties, string projectFormat,
string documentName, string version);
Task<List<string>> GetVersions(Dictionary<string, object> projectExtraProperties, string documentName);
Task<List<VersionInfoDto>> GetVersions(Dictionary<string, object> projectExtraProperties, string documentName);
}
}

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

@ -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<string, object>();

@ -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();
});

@ -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();

Loading…
Cancel
Save