Browse Source

docs redirect improvements

pull/1192/head
Yunus Emre Kalkan 7 years ago
parent
commit
7309ccd6f2
  1. 52
      modules/docs/app/VoloDocs.Web/Pages/Index.cshtml
  2. 24
      modules/docs/app/VoloDocs.Web/Pages/Index.cshtml.cs
  3. 4
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml
  4. 19
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml.cs
  5. 9
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

52
modules/docs/app/VoloDocs.Web/Pages/Index.cshtml

@ -1,55 +1,5 @@
@page @page
@using System.Linq
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Docs
@using Volo.Docs.Localization
@using Volo.Docs.Pages.Documents
@model VoloDocs.Web.Pages.IndexModel @model VoloDocs.Web.Pages.IndexModel
@inject IHtmlLocalizer<DocsResource> L @{
@section styles {
<abp-style-bundle name="@typeof(IndexModel).FullName">
<abp-style src="/Pages/Documents/Shared/Styles/vs.css" />
</abp-style-bundle>
} }
<div class="p-5">
<h1 class="text-center mb-5">
@L["WelcomeVoloDocs"]
</h1>
@if (!Model.Projects.Any())
{
<div class="d-flex justify-content-center">
<div class="alert alert-secondary col-md-6 text-center" role="alert">
<p>@L["NoProjectWarning"]</p>
<hr />
<a href="/Docs/Admin/Projects">@L["CreateYourFirstProject"] <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
}
else if (Model.Projects.Count > 1)
{
<h2>@L["Projects"]</h2>
<p>
<ul style="list-style-type: upper-roman;">
@foreach (var project in Model.Projects)
{
<li>
<h3>
<a asp-page="./Documents/Project/Index"
asp-route-projectName="@project.ShortName"
asp-route-version="@DocsAppConsts.Latest">
@project.Name
</a>
</h3>
</li>
}
</ul>
</p>
}
</div>

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

@ -9,31 +9,15 @@ namespace VoloDocs.Web.Pages
{ {
public class IndexModel : PageModel public class IndexModel : PageModel
{ {
public IReadOnlyList<ProjectDto> Projects { get; set; }
private readonly IProjectAppService _projectAppService; public IndexModel()
public IndexModel(IProjectAppService projectAppService)
{ {
_projectAppService = projectAppService;
} }
public async Task<IActionResult> OnGetAsync() public IActionResult OnGet()
{ {
Projects = (await _projectAppService.GetListAsync()).Items; return Redirect("./documents");
//if (Projects.Count == 1)
//{
// return RedirectToPage("./Documents/Project/Index", new
// {
// projectName = Projects[0].ShortName,
// version = DocsAppConsts.Latest,
// languageCode = "",
// documentName = Projects[0].DefaultDocumentName
// });
//}
return Page();
} }
} }
} }

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

@ -29,9 +29,7 @@
{ {
<li> <li>
<h3> <h3>
<a asp-page="./Project/Index" <a href="./@Model.DocumentsUrlPrefix@project.ShortName">
asp-route-projectName="@project.ShortName"
asp-route-version="@DocsAppConsts.Latest">
@project.Name @project.Name
</a> </a>
</h3> </h3>

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

@ -1,35 +1,38 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
using Volo.Abp.Configuration;
using Volo.Docs.Projects; using Volo.Docs.Projects;
namespace Volo.Docs.Pages.Documents namespace Volo.Docs.Pages.Documents
{ {
public class IndexModel : PageModel public class IndexModel : PageModel
{ {
public string DocumentsUrlPrefix { get; set; }
public IReadOnlyList<ProjectDto> Projects { get; set; } public IReadOnlyList<ProjectDto> Projects { get; set; }
private readonly IProjectAppService _projectAppService; private readonly IProjectAppService _projectAppService;
private readonly IConfigurationRoot _configuration;
public IndexModel(IProjectAppService projectAppService) public IndexModel(IProjectAppService projectAppService, IConfigurationAccessor configurationAccessor)
{ {
_configuration = configurationAccessor.Configuration;
_projectAppService = projectAppService; _projectAppService = projectAppService;
} }
public async Task<IActionResult> OnGetAsync() public async Task<IActionResult> OnGetAsync()
{ {
DocumentsUrlPrefix = Convert.ToBoolean(_configuration["IncludeDocumentPrefixInUrl"]) ? "documents/" : "";
var listResult = await _projectAppService.GetListAsync(); var listResult = await _projectAppService.GetListAsync();
if (listResult.Items.Count == 1) if (listResult.Items.Count == 1)
{ {
return RedirectToPage("./Project/Index", new return Redirect("./" + DocumentsUrlPrefix + listResult.Items[0].ShortName);
{
projectName = listResult.Items[0].ShortName,
version = DocsAppConsts.Latest,
languageCode = "",
documentName = listResult.Items[0].DefaultDocumentName
});
} }
Projects = listResult.Items; Projects = listResult.Items;

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

@ -49,6 +49,8 @@ namespace Volo.Docs.Pages.Documents.Project
public VersionInfoViewModel LatestVersionInfo { get; private set; } public VersionInfoViewModel LatestVersionInfo { get; private set; }
public string DocumentsUrlPrefix { get; set; }
public bool DocumentLanguageIsDifferent { get; set; } public bool DocumentLanguageIsDifferent { get; set; }
private readonly IDocumentAppService _documentAppService; private readonly IDocumentAppService _documentAppService;
@ -70,6 +72,8 @@ namespace Volo.Docs.Pages.Documents.Project
public async Task<IActionResult> OnGetAsync() public async Task<IActionResult> OnGetAsync()
{ {
DocumentsUrlPrefix = Convert.ToBoolean(_configuration["IncludeDocumentPrefixInUrl"]) ? "documents/" : "";
await SetProjectAsync(); await SetProjectAsync();
await SetProjectsAsync(); await SetProjectsAsync();
await SetVersionAsync(); await SetVersionAsync();
@ -316,7 +320,7 @@ namespace Volo.Docs.Pages.Documents.Project
LanguageSelectListItems.Add( LanguageSelectListItems.Add(
new SelectListItem( new SelectListItem(
language.DisplayName, language.DisplayName,
"/documents/" + language.Code + "/" + Project.ShortName + "/" + Version + "/" + DocumentName, "/" + DocumentsUrlPrefix + language.Code + "/" + Project.ShortName + "/" + Version + "/" + DocumentName,
language.Code == LanguageCode language.Code == LanguageCode
) )
); );
@ -346,8 +350,7 @@ namespace Volo.Docs.Pages.Documents.Project
private void AddLanguageCodePrefixToLinks() private void AddLanguageCodePrefixToLinks()
{ {
var prefix = Convert.ToBoolean(_configuration["IncludeDocumentPrefixInUrl"]) ? "documents/" : ""; Document.Content = Document.Content.Replace("href=\"/documents", "href=\"/" + DocumentsUrlPrefix + LanguageCode);
Document.Content = Document.Content.Replace("href=\"/documents", "href=\"/" + prefix + LanguageCode);
} }
} }
} }
Loading…
Cancel
Save