Browse Source

docs redirect improvements

pull/1192/head
Yunus Emre Kalkan 7 years ago
parent
commit
bbe6710d93
  1. 20
      modules/docs/app/VoloDocs.Web/Pages/Index.cshtml.cs
  2. 2
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  3. 28
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

20
modules/docs/app/VoloDocs.Web/Pages/Index.cshtml.cs

@ -22,16 +22,16 @@ namespace VoloDocs.Web.Pages
{ {
Projects = (await _projectAppService.GetListAsync()).Items; Projects = (await _projectAppService.GetListAsync()).Items;
if (Projects.Count == 1) //if (Projects.Count == 1)
{ //{
return RedirectToPage("./Documents/Project/Index", new // return RedirectToPage("./Documents/Project/Index", new
{ // {
projectName = Projects[0].ShortName, // projectName = Projects[0].ShortName,
version = DocsAppConsts.Latest, // version = DocsAppConsts.Latest,
languageCode = "", // languageCode = "",
documentName = Projects[0].DefaultDocumentName // documentName = Projects[0].DefaultDocumentName
}); // });
} //}
return Page(); return Page();
} }

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

@ -51,7 +51,7 @@ namespace Volo.Docs.Documents
return await GetDocumentWithDetailsDtoAsync( return await GetDocumentWithDetailsDtoAsync(
project, project,
project.DefaultDocumentName, project.DefaultDocumentName + "." + project.Format,
input.LanguageCode, input.LanguageCode,
input.Version input.Version
); );

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

@ -70,6 +70,11 @@ namespace Volo.Docs.Pages.Documents.Project
await SetVersionAsync(); await SetVersionAsync();
await SetLanguageList(); await SetLanguageList();
if (IsDefaultDocument())
{
return RedirectToDefaultDocument();
}
if (!CheckLanguage()) if (!CheckLanguage())
{ {
return RedirectToDefaultLanguage(); return RedirectToDefaultLanguage();
@ -83,6 +88,11 @@ namespace Volo.Docs.Pages.Documents.Project
return Page(); return Page();
} }
private bool IsDefaultDocument()
{
return DocumentName == Project.DefaultDocumentName;
}
private async Task SetProjectAsync() private async Task SetProjectAsync()
{ {
Project = await _projectAppService.GetAsync(ProjectName); Project = await _projectAppService.GetAsync(ProjectName);
@ -114,6 +124,17 @@ namespace Volo.Docs.Pages.Documents.Project
}); });
} }
private IActionResult RedirectToDefaultDocument()
{
return RedirectToPage(new
{
projectName = ProjectName,
version = Version,
documentName = "",
languageCode = DefaultLanguageCode
});
}
private async Task SetProjectsAsync() private async Task SetProjectsAsync()
{ {
var projects = await _projectAppService.GetListAsync(); var projects = await _projectAppService.GetListAsync();
@ -228,16 +249,11 @@ namespace Volo.Docs.Pages.Documents.Project
private async Task SetDocumentAsync() private async Task SetDocumentAsync()
{ {
if (DocumentName.IsNullOrWhiteSpace())
{
DocumentName = Project.DefaultDocumentName;
}
DocumentNameWithExtension = DocumentName + "." + Project.Format; DocumentNameWithExtension = DocumentName + "." + Project.Format;
try try
{ {
if (DocumentNameWithExtension.IsNullOrWhiteSpace()) if (DocumentName.IsNullOrWhiteSpace())
{ {
Document = await _documentAppService.GetDefaultAsync( Document = await _documentAppService.GetDefaultAsync(
new GetDefaultDocumentInput new GetDefaultDocumentInput

Loading…
Cancel
Save