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; ViewBag.FluidLayout = true;
Layout = ThemeManager.CurrentTheme.GetEmptyLayout(); Layout = ThemeManager.CurrentTheme.GetEmptyLayout();
var projectDisplayName = Model.ProjectDisplayName ?? Model.ProjectName;
} }
@section styles { @section styles {
<abp-style-bundle name="@typeof(IndexModel).FullName"> <abp-style-bundle name="@typeof(IndexModel).FullName">
@ -46,10 +45,10 @@
<div class="docs-top"> <div class="docs-top">
<nav class="navbar navbar-logo"> <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())"> <a class="navbar-brand w-100" href="@Model.CreateLink(Model.LatestVersionInfo, Model.GetSpecificVersionOrLatest())">
@projectDisplayName<br> @Model.Project.Name<br>
<strong class="display-block"> <strong class="display-block">
@L["Documents"] @L["Documents"]
</strong> </strong>
@ -108,7 +107,7 @@
<ul root-node="@Model.Navigation.RootNode" <ul root-node="@Model.Navigation.RootNode"
version="@(Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)" version="@(Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)"
project-name="@Model.ProjectName" project-name="@Model.ProjectName"
project-format="@Model.ProjectFormat" project-format="@Model.Project.Format"
selected-document-name="@Model.DocumentNameWithExtension" selected-document-name="@Model.DocumentNameWithExtension"
id="sidebar-scroll" id="sidebar-scroll"
class="nav nav-list"></ul> 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)] [BindProperty(SupportsGet = true)]
public string DocumentName { get; set; } public string DocumentName { get; set; }
public string ProjectDisplayName { get; set; } public ProjectDto Project { get; set; }
public string ProjectFormat { get; private set; }
public string DocumentNameWithExtension { get; private set; } public string DocumentNameWithExtension { get; private set; }
@ -53,55 +51,29 @@ namespace Volo.Docs.Pages.Documents.Project
_projectAppService = projectAppService; _projectAppService = projectAppService;
} }
public async Task OnGet() public async Task OnGetAsync()
{ {
var project = await _projectAppService.GetByShortNameAsync(ProjectName); Project = await _projectAppService.GetByShortNameAsync(ProjectName);
SetPageParams(project);
await SetVersionAsync(project); SetDocumentNames();
await SetDocumentAsync(project); await SetVersionAsync();
await SetNavigationAsync(project); 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()) 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(); Versions = versionInfoDtos.Select(v => new VersionInfo(v.DisplayName, v.Name)).ToList();
@ -135,6 +107,30 @@ namespace Volo.Docs.Pages.Documents.Project
}).ToList(); }).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) public string CreateLink(VersionInfo latestVersion, string version, string documentName = null)
{ {
if (latestVersion.Version == version) if (latestVersion.Version == version)
@ -174,7 +170,7 @@ namespace Volo.Docs.Pages.Documents.Project
Document.Version; Document.Version;
} }
private async Task SetDocumentAsync(ProjectDto project) private async Task SetDocumentAsync()
{ {
try try
{ {
@ -183,7 +179,7 @@ namespace Volo.Docs.Pages.Documents.Project
Document = await _documentAppService.GetDefaultAsync( Document = await _documentAppService.GetDefaultAsync(
new GetDefaultDocumentInput new GetDefaultDocumentInput
{ {
ProjectId = project.Id, ProjectId = Project.Id,
Version = Version Version = Version
} }
); );
@ -193,7 +189,7 @@ namespace Volo.Docs.Pages.Documents.Project
Document = await _documentAppService.GetAsync( Document = await _documentAppService.GetAsync(
new GetDocumentInput new GetDocumentInput
{ {
ProjectId = project.Id, ProjectId = Project.Id,
Name = DocumentNameWithExtension, Name = DocumentNameWithExtension,
Version = Version Version = Version
} }
@ -205,7 +201,7 @@ namespace Volo.Docs.Pages.Documents.Project
return; 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); var content = converter.NormalizeLinks(Document.Content, Document.Project.ShortName, GetSpecificVersionOrLatest(), Document.LocalDirectory);
content = converter.Convert(content); content = converter.Convert(content);

Loading…
Cancel
Save