Browse Source

docs module fixes

pull/4860/head
Yunus Emre Kalkan 6 years ago
parent
commit
ae6b5f34fd
  1. 2
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/cs.json
  2. 12
      modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs
  3. 34
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  4. 19
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs
  5. 9
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs
  6. 14
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs
  7. 2
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs
  8. 2
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

2
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/cs.json

@ -31,6 +31,8 @@
"DisplayName:GitHubRootUrl": "GitHub kořenové URL", "DisplayName:GitHubRootUrl": "GitHub kořenové URL",
"DisplayName:GitHubAccessToken": "GitHub přístupový token", "DisplayName:GitHubAccessToken": "GitHub přístupový token",
"DisplayName:GitHubUserAgent": "GitHub user agent", "DisplayName:GitHubUserAgent": "GitHub user agent",
"DisplayName:GithubVersionProviderSource": "GitHub version provider source",
"DisplayName:VersionBranchPrefix": "Version branch prefix",
"DisplayName:All": "Pull všeho", "DisplayName:All": "Pull všeho",
"DisplayName:LanguageCode": "Kód jazyka", "DisplayName:LanguageCode": "Kód jazyka",
"DisplayName:Version": "Verze", "DisplayName:Version": "Verze",

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

@ -77,8 +77,16 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
GithubProject.GitHubAccessToken = (string) dto.ExtraProperties[nameof(GithubProject.GitHubAccessToken)]; GithubProject.GitHubAccessToken = (string) dto.ExtraProperties[nameof(GithubProject.GitHubAccessToken)];
GithubProject.GitHubRootUrl = (string) dto.ExtraProperties[nameof(GithubProject.GitHubRootUrl)]; GithubProject.GitHubRootUrl = (string) dto.ExtraProperties[nameof(GithubProject.GitHubRootUrl)];
GithubProject.GitHubUserAgent = (string) dto.ExtraProperties[nameof(GithubProject.GitHubUserAgent)]; GithubProject.GitHubUserAgent = (string) dto.ExtraProperties[nameof(GithubProject.GitHubUserAgent)];
GithubProject.GithubVersionProviderSource = (GithubVersionProviderSource) dto.ExtraProperties[nameof(GithubProject.GithubVersionProviderSource)];
GithubProject.VersionBranchPrefix = (string) dto.ExtraProperties[nameof(GithubProject.VersionBranchPrefix)]; if (dto.ExtraProperties.ContainsKey(nameof(GithubProject.GithubVersionProviderSource)))
{
GithubProject.GithubVersionProviderSource = (GithubVersionProviderSource) (long) dto.ExtraProperties[nameof(GithubProject.GithubVersionProviderSource)];
}
if (dto.ExtraProperties.ContainsKey(nameof(GithubProject.VersionBranchPrefix)))
{
GithubProject.VersionBranchPrefix = (string) dto.ExtraProperties[nameof(GithubProject.VersionBranchPrefix)];
}
} }
public abstract class EditProjectViewModelBase public abstract class EditProjectViewModelBase

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

@ -64,6 +64,8 @@ namespace Volo.Docs.Documents
{ {
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
return await GetDocumentWithDetailsDtoAsync( return await GetDocumentWithDetailsDtoAsync(
project, project,
input.Name, input.Name,
@ -76,6 +78,8 @@ namespace Volo.Docs.Documents
{ {
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
return await GetDocumentWithDetailsDtoAsync( return await GetDocumentWithDetailsDtoAsync(
project, project,
project.DefaultDocumentName + "." + project.Format, project.DefaultDocumentName + "." + project.Format,
@ -88,6 +92,8 @@ namespace Volo.Docs.Documents
{ {
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
var navigationDocument = await GetDocumentWithDetailsDtoAsync( var navigationDocument = await GetDocumentWithDetailsDtoAsync(
project, project,
project.NavigationDocumentName, project.NavigationDocumentName,
@ -133,10 +139,11 @@ namespace Volo.Docs.Documents
public async Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input) public async Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input)
{ {
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);
var cacheKey =
CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode,
input.Version);
input.Version = string.IsNullOrWhiteSpace(input.Version) ? project.LatestVersionBranchName : input.Version; input.Version = string.IsNullOrWhiteSpace(input.Version) ? project.LatestVersionBranchName : input.Version;
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
var cacheKey = CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode,input.Version);
async Task<DocumentResource> GetResourceAsync() async Task<DocumentResource> GetResourceAsync()
{ {
@ -166,6 +173,8 @@ namespace Volo.Docs.Documents
{ {
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
var esDocs = var esDocs =
await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version); await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version);
@ -188,6 +197,8 @@ namespace Volo.Docs.Documents
{ {
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
try try
{ {
if (string.IsNullOrWhiteSpace(project.ParametersDocumentName)) if (string.IsNullOrWhiteSpace(project.ParametersDocumentName))
@ -337,5 +348,22 @@ namespace Volo.Docs.Documents
return TimeSpan.Parse(value); return TimeSpan.Parse(value);
} }
private string GetProjectVersionPrefixIfExist(Project project)
{
if (GetGithubVersionProviderSource(project) == GithubVersionProviderSource.Branches)
{
return project.ExtraProperties["VersionBranchPrefix"].ToString();
}
return "";
}
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
: GithubVersionProviderSource.Releases;
}
} }
} }

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

@ -106,6 +106,8 @@ namespace Volo.Docs.Projects
var project = await _projectRepository.GetByShortNameAsync(shortName); var project = await _projectRepository.GetByShortNameAsync(shortName);
var store = _documentSource.Create(project.DocumentStoreType); var store = _documentSource.Create(project.DocumentStoreType);
version = GetProjectVersionPrefixIfExist(project) + version;
async Task<LanguageConfig> GetLanguagesAsync() async Task<LanguageConfig> GetLanguagesAsync()
{ {
return await store.GetLanguageListAsync(project, version); return await store.GetLanguageListAsync(project, version);
@ -120,5 +122,22 @@ namespace Volo.Docs.Projects
} }
); );
} }
private string GetProjectVersionPrefixIfExist(Project project)
{
if (GetGithubVersionProviderSource(project) == GithubVersionProviderSource.Branches)
{
return project.ExtraProperties["VersionBranchPrefix"].ToString();
}
return "";
}
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
: GithubVersionProviderSource.Releases;
}
} }
} }

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

@ -253,8 +253,11 @@ namespace Volo.Docs.GitHub.Documents
if (!string.IsNullOrEmpty(prefix)) if (!string.IsNullOrEmpty(prefix))
{ {
versions = versions.Where(v => v.Name.StartsWith(prefix)).ToList(); versions = versions.Where(v => v.Name.StartsWith(prefix)).ToList();
versions.ForEach(v=> v.Name.Substring(prefix.Length)); foreach (var v in versions)
versions.ForEach(v=> v.DisplayName.Substring(prefix.Length)); {
v.Name = v.Name.Substring(prefix.Length);
v.DisplayName = v.DisplayName.Substring(prefix.Length);
}
} }
versions = _versionHelper.OrderByDescending(versions); versions = _versionHelper.OrderByDescending(versions);
@ -278,7 +281,7 @@ namespace Volo.Docs.GitHub.Documents
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project) private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{ {
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource") return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) project.ExtraProperties["GithubVersionProviderSource"] ? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
: GithubVersionProviderSource.Releases; : GithubVersionProviderSource.Releases;
} }

14
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs

@ -32,9 +32,19 @@ namespace Volo.Docs.GitHub.Documents.Version
var versionParts = version.Split("-"); var versionParts = version.Split("-");
if (versionParts[0].Split(".").Length > 3) var firstVersionPartSplitted = versionParts[0].Split(".");
if (firstVersionPartSplitted.Length > 3)
{
normalizedVersion = string.Join(".",firstVersionPartSplitted.Take(3));
}
else if (firstVersionPartSplitted.Length < 3)
{ {
normalizedVersion = string.Join(".",versionParts[0].Split(".").Take(3)); normalizedVersion = versionParts[0];
for (int i = firstVersionPartSplitted.Length; i < 3; i++)
{
normalizedVersion += ".0";
}
} }
else else
{ {

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

@ -307,7 +307,7 @@ namespace Volo.Docs.Pages.Documents.Project
private void SetLatestVersionBranchName(List<VersionInfoViewModel> versions) private void SetLatestVersionBranchName(List<VersionInfoViewModel> versions)
{ {
if (!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") if (!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
|| (GithubVersionProviderSource) Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Releases) || (GithubVersionProviderSource) (long) Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Releases)
{ {
versions.First(v=> !_versionHelper.IsPreRelease(v.Version)).Version = Project.LatestVersionBranchName; versions.First(v=> !_versionHelper.IsPreRelease(v.Version)).Version = Project.LatestVersionBranchName;
} }

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

@ -64,7 +64,7 @@ namespace Volo.Docs.Pages.Documents
string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase)) string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
{ {
if ((!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") || if ((!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") ||
(GithubVersionProviderSource) Project.ExtraProperties["GithubVersionProviderSource"] ==GithubVersionProviderSource.Releases) && (GithubVersionProviderSource) (long) Project.ExtraProperties["GithubVersionProviderSource"] ==GithubVersionProviderSource.Releases) &&
!string.IsNullOrEmpty(Project.LatestVersionBranchName)) !string.IsNullOrEmpty(Project.LatestVersionBranchName))
{ {
Version = Project.LatestVersionBranchName; Version = Project.LatestVersionBranchName;

Loading…
Cancel
Save