Browse Source

Refactor Project\Index.cshtml.cs

pull/625/head
Halil ibrahim Kalkan 8 years ago
parent
commit
90f4df42fc
  1. 7
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml
  2. 84
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

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

@ -10,7 +10,6 @@
@{
ViewBag.FluidLayout = true;
Layout = ThemeManager.CurrentTheme.GetEmptyLayout();
var projectDisplayName = Model.ProjectDisplayName ?? Model.ProjectName;
}
@section styles {
<abp-style-bundle name="@typeof(IndexModel).FullName">
@ -46,10 +45,10 @@
<div class="docs-top">
<nav class="navbar navbar-logo">
@if (!projectDisplayName.IsNullOrWhiteSpace())
@if (!Model.Project.Name.IsNullOrWhiteSpace())
{
<a class="navbar-brand w-100" href="@Model.CreateLink(Model.LatestVersionInfo, Model.GetSpecificVersionOrLatest())">
@projectDisplayName<br>
@Model.Project.Name<br>
<strong class="display-block">
@L["Documents"]
</strong>
@ -108,7 +107,7 @@
<ul root-node="@Model.Navigation.RootNode"
version="@(Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)"
project-name="@Model.ProjectName"
project-format="@Model.ProjectFormat"
project-format="@Model.Project.Format"
selected-document-name="@Model.DocumentNameWithExtension"
id="sidebar-scroll"
class="nav nav-list"></ul>

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

@ -23,9 +23,7 @@ namespace Volo.Docs.Pages.Documents.Project
[BindProperty(SupportsGet = true)]
public string DocumentName { get; set; }
public string ProjectDisplayName { get; set; }
public string ProjectFormat { get; private set; }
public ProjectDto Project { get; set; }
public string DocumentNameWithExtension { get; private set; }
@ -53,55 +51,29 @@ namespace Volo.Docs.Pages.Documents.Project
_projectAppService = projectAppService;
}
public async Task OnGet()
public async Task OnGetAsync()
{
var project = await _projectAppService.GetByShortNameAsync(ProjectName);
SetPageParams(project);
Project = await _projectAppService.GetByShortNameAsync(ProjectName);
await SetVersionAsync(project);
await SetDocumentAsync(project);
await SetNavigationAsync(project);
SetDocumentNames();
await SetVersionAsync();
await SetDocumentAsync();
await SetNavigationAsync();
}
private async Task SetNavigationAsync(ProjectDto project)
private void SetDocumentNames()
{
try
{
var document = await _documentAppService.GetNavigationDocumentAsync(
new GetNavigationDocumentInput
{
ProjectId = project.Id,
Version = Version
}
);
Navigation = ObjectMapper.Map<DocumentWithDetailsDto, NavigationWithDetailsDto>(document);
}
catch (DocumentNotFoundException) //TODO: What if called on a remote service which may return 404
{
return;
}
Navigation.ConvertItems();
}
private void SetPageParams(ProjectDto project)
{
ProjectFormat = project.Format;
ProjectDisplayName = project.Name;
if (DocumentName.IsNullOrWhiteSpace())
{
DocumentName = project.DefaultDocumentName;
DocumentName = Project.DefaultDocumentName;
}
DocumentNameWithExtension = DocumentName + "." + project.Format;
DocumentNameWithExtension = DocumentName + "." + Project.Format;
}
private async Task SetVersionAsync(ProjectDto project)
private async Task SetVersionAsync()
{
var versionInfoDtos = await _projectAppService.GetVersionsAsync(project.Id);
var versionInfoDtos = await _projectAppService.GetVersionsAsync(Project.Id);
Versions = versionInfoDtos.Select(v => new VersionInfo(v.DisplayName, v.Name)).ToList();
@ -135,6 +107,30 @@ namespace Volo.Docs.Pages.Documents.Project
}).ToList();
}
private async Task SetNavigationAsync()
{
try
{
var document = await _documentAppService.GetNavigationDocumentAsync(
new GetNavigationDocumentInput
{
ProjectId = Project.Id,
Version = Version
}
);
Navigation = ObjectMapper.Map<DocumentWithDetailsDto, NavigationWithDetailsDto>(document);
}
catch (DocumentNotFoundException) //TODO: What if called on a remote service which may return 404
{
return;
}
Navigation.ConvertItems();
}
public string CreateLink(VersionInfo latestVersion, string version, string documentName = null)
{
if (latestVersion.Version == version)
@ -174,7 +170,7 @@ namespace Volo.Docs.Pages.Documents.Project
Document.Version;
}
private async Task SetDocumentAsync(ProjectDto project)
private async Task SetDocumentAsync()
{
try
{
@ -183,7 +179,7 @@ namespace Volo.Docs.Pages.Documents.Project
Document = await _documentAppService.GetDefaultAsync(
new GetDefaultDocumentInput
{
ProjectId = project.Id,
ProjectId = Project.Id,
Version = Version
}
);
@ -193,7 +189,7 @@ namespace Volo.Docs.Pages.Documents.Project
Document = await _documentAppService.GetAsync(
new GetDocumentInput
{
ProjectId = project.Id,
ProjectId = Project.Id,
Name = DocumentNameWithExtension,
Version = Version
}
@ -205,7 +201,7 @@ namespace Volo.Docs.Pages.Documents.Project
return;
}
var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? ProjectFormat);
var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? Project.Format);
var content = converter.NormalizeLinks(Document.Content, Document.Project.ShortName, GetSpecificVersionOrLatest(), Document.LocalDirectory);
content = converter.Convert(content);

Loading…
Cancel
Save