Browse Source

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

pull/570/head
Halil ibrahim Kalkan 8 years ago
parent
commit
8ef7435163
  1. 2
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs
  2. 12
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/VersionInfoDto.cs
  3. 18
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  4. 12
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/GithubDocumentStore.cs
  5. 2
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/IDocumentStore.cs
  6. 1
      modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/ProjectConsts.cs
  7. 2
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs
  8. 1
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs
  9. 2
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

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

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

12
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; }
}
}

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

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Distributed;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
@ -11,12 +12,12 @@ namespace Volo.Docs.Documents
public class DocumentAppService : ApplicationService, IDocumentAppService public class DocumentAppService : ApplicationService, IDocumentAppService
{ {
private readonly IProjectRepository _projectRepository; private readonly IProjectRepository _projectRepository;
private readonly IDistributedCache<List<string>> _distributedCache; private readonly IDistributedCache<List<VersionInfoDto>> _distributedCache;
private readonly IDocumentStoreFactory _documentStoreFactory; private readonly IDocumentStoreFactory _documentStoreFactory;
public DocumentAppService( public DocumentAppService(
IProjectRepository projectRepository, IProjectRepository projectRepository,
IDistributedCache<List<string>> distributedCache, IDistributedCache<List<VersionInfoDto>> distributedCache,
IDocumentStoreFactory documentStoreFactory) IDocumentStoreFactory documentStoreFactory)
{ {
_projectRepository = projectRepository; _projectRepository = projectRepository;
@ -64,7 +65,7 @@ namespace Volo.Docs.Documents
} }
//TODO: Application service never gets such a parameter: Dictionary<string, object> projectExtraProperties !!! //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) string documentStoreType, string documentName)
{ {
var project = await _projectRepository.FindByShortNameAsync(projectShortName); var project = await _projectRepository.FindByShortNameAsync(projectShortName);
@ -86,22 +87,27 @@ namespace Volo.Docs.Documents
if (!project.MinimumVersion.IsNullOrEmpty()) if (!project.MinimumVersion.IsNullOrEmpty())
{ {
var minVersionIndex = versions.IndexOf(project.MinimumVersion); var minVersionIndex = versions.FindIndex(v => v.Name == project.MinimumVersion);
if (minVersionIndex > -1) if (minVersionIndex > -1)
{ {
versions = versions.GetRange(0, minVersionIndex + 1); versions = versions.GetRange(0, minVersionIndex + 1);
} }
} }
if (!string.IsNullOrEmpty(project.LatestVersionBranchName))
{
versions.First().Name = project.LatestVersionBranchName;
}
return versions; return versions;
} }
private async Task<List<string>> GetVersionsFromCache(string projectShortName) private async Task<List<VersionInfoDto>> GetVersionsFromCache(string projectShortName)
{ {
return await _distributedCache.GetAsync(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) }; var options = new DistributedCacheEntryOptions() { SlidingExpiration = TimeSpan.FromDays(1) };
await _distributedCache.SetAsync(projectShortName, versions, options); await _distributedCache.SetAsync(projectShortName, versions, options);

12
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;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -6,9 +9,6 @@ using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Octokit;
using Octokit.Internal;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Domain.Services; using Volo.Abp.Domain.Services;
using ProductHeaderValue = Octokit.ProductHeaderValue; 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 try
{ {
@ -96,12 +96,12 @@ namespace Volo.Docs.Documents
GetGithubRepositoryNameFromUrl(url) 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) catch (Exception ex)
{ {
Logger.LogError(ex.Message, ex); Logger.LogError(ex.Message, ex);
return new List<string>(); return new List<VersionInfoDto>();
} }
} }

2
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/IDocumentStore.cs

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

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

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

2
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 MainWebsiteUrl { get; protected set; }
public virtual string LatestVersionBranchName { get; set; }
protected Project() protected Project()
{ {
ExtraProperties = new Dictionary<string, object>(); ExtraProperties = new Dictionary<string, object>();

1
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.ShortName).IsRequired().HasMaxLength(ProjectConsts.MaxShortNameLength);
b.Property(x => x.DefaultDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxDefaultDocumentNameLength); b.Property(x => x.DefaultDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxDefaultDocumentNameLength);
b.Property(x => x.NavigationDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxNavigationDocumentNameLength); b.Property(x => x.NavigationDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxNavigationDocumentNameLength);
b.Property(x => x.LatestVersionBranchName).HasMaxLength(ProjectConsts.MaxLatestVersionBranchNameLength);
b.ConfigureExtraProperties(); b.ConfigureExtraProperties();
}); });

2
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 Versions = (await _documentAppService
.GetVersions(project.ShortName, project.DefaultDocumentName, project.ExtraProperties, .GetVersions(project.ShortName, project.DefaultDocumentName, project.ExtraProperties,
project.DocumentStoreType, DocumentNameWithExtension)) project.DocumentStoreType, DocumentNameWithExtension))
.Select(v => new VersionInfo(v, v)).ToList(); .Select(v => new VersionInfo(v.DisplayName, v.Name)).ToList();
LatestVersionInfo = GetLatestVersion(); LatestVersionInfo = GetLatestVersion();

Loading…
Cancel
Save