From 4c95f9a059408c845c4e50fa58ac0e5d4b19102a Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Sat, 29 Sep 2018 01:58:03 +0300 Subject: [PATCH] Project index refactored. --- .../Pages/Documents/Project/Index.cshtml.cs | 77 ++++++++++++------- 1 file changed, 49 insertions(+), 28 deletions(-) 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 0e01442890..cfcc0a0f60 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 @@ -22,7 +22,7 @@ namespace Volo.Docs.Pages.Documents.Project [BindProperty(SupportsGet = true)] public string DocumentName { get; set; } - public string ProjectFormat { get; set; } + public string ProjectFormat { get; private set; } public string DocumentNameWithExtension { get; private set; } @@ -30,15 +30,12 @@ namespace Volo.Docs.Pages.Documents.Project public List Versions { get; private set; } - public List VersionSelectItems => Versions.Select(v => new SelectListItem - { - Text = v.DisplayText, - Value = "/documents/" + ProjectName + "/" + v.Version + "/" + DocumentName, - Selected = v.IsSelected - }).ToList(); + public List VersionSelectItems { get; private set; } public NavigationWithDetailsDto Navigation { get; private set; } + public VersionInfo LatestVersionInfo { get; private set; } + private readonly IDocumentAppService _documentAppService; private readonly IDocumentConverterFactory _documentConverterFactory; private readonly IProjectAppService _projectAppService; @@ -50,37 +47,53 @@ namespace Volo.Docs.Pages.Documents.Project _projectAppService = projectAppService; } - public VersionInfo LatestVersionInfo + public async Task OnGet() { - get - { - var latestVersion = Versions.First(); + var project = await _projectAppService.FindByShortNameAsync(ProjectName); - latestVersion.DisplayText = $"{latestVersion.Version} - " + DocsAppConsts.LatestVersion; - latestVersion.Version = latestVersion.Version; + SetPageParams(project); - return latestVersion; - } + await SetVersionAsync(project); + + await SetDocumentAsync(); + + await SetNavigationAsync(); } - public async Task OnGet() + private async Task SetNavigationAsync() { - var projectDto = await _projectAppService.FindByShortNameAsync(ProjectName); + Navigation = await _documentAppService.GetNavigationDocumentAsync(ProjectName, Version, false); + Navigation.ConvertItems(); + } - ProjectFormat = projectDto.Format; + private void SetPageParams(ProjectDto project) + { + ProjectFormat = project.Format; if (DocumentName.IsNullOrWhiteSpace()) { - DocumentName = projectDto.DefaultDocumentName; + DocumentName = project.DefaultDocumentName; } - DocumentNameWithExtension = DocumentName + "." + projectDto.Format; + DocumentNameWithExtension = DocumentName + "." + project.Format; + } - var versions = await _documentAppService.GetVersions(projectDto.ShortName, projectDto.DefaultDocumentName, - projectDto.ExtraProperties, projectDto.DocumentStoreType, DocumentNameWithExtension); + private async Task SetVersionAsync(ProjectDto project) + { + var versions = await _documentAppService.GetVersions(project.ShortName, project.DefaultDocumentName, + project.ExtraProperties, project.DocumentStoreType, DocumentNameWithExtension); + + VersionSelectItems = Versions.Select(v => new SelectListItem + { + Text = v.DisplayText, + Value = "/documents/" + ProjectName + "/" + v.Version + "/" + DocumentName, + Selected = v.IsSelected + }).ToList(); Versions = versions.Select(v => new VersionInfo(v, v)).ToList(); + LatestVersionInfo = GetLatestVersion(); + if (string.Equals(Version, DocsAppConsts.LatestVersion, StringComparison.OrdinalIgnoreCase)) { LatestVersionInfo.IsSelected = true; @@ -100,20 +113,28 @@ namespace Volo.Docs.Pages.Documents.Project Version = Versions.First().Version; } } + } + + private VersionInfo GetLatestVersion() + { + var latestVersion = Versions.First(); + + latestVersion.DisplayText = $"{latestVersion.Version} - " + DocsAppConsts.LatestVersion; + latestVersion.Version = latestVersion.Version; + + return latestVersion; + } + private async Task SetDocumentAsync() + { Document = await _documentAppService.GetByNameAsync(ProjectName, DocumentNameWithExtension, Version, true); - var converter = _documentConverterFactory.Create(Document.Format ?? projectDto.Format); + var converter = _documentConverterFactory.Create(Document.Format ?? ProjectFormat); var content = converter.NormalizeLinks(Document.Content, Document.Project.ShortName, Document.Version, Document.LocalDirectory); content = converter.Convert(content); content = HtmlNormalizer.ReplaceImageSources(content, Document.RawRootUrl, Document.LocalDirectory); content = HtmlNormalizer.ReplaceCodeBlocksLanguage(content, "language-C#", "language-csharp"); //todo find a way to make it on client in prismJS configuration (eg: map C# => csharp) Document.Content = content; - - Navigation = await _documentAppService.GetNavigationDocumentAsync(ProjectName, Version, false); - Navigation.ConvertItems(); - } - } } \ No newline at end of file