Merge pull request #3641 from liangshiw/liangshiwei/docs-module

Redirect to home page when an invalid URL or missing document
pull/3760/head
Alper Ebicoglu 5 years ago committed by GitHub
commit f0efccf877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -87,6 +87,11 @@ namespace Volo.Docs.FileSystem.Documents
{
throw new SecurityException("Can not get a resource file out of the project folder!");
}
if (!File.Exists(path))
{
throw new DocumentNotFoundException(path);
}
}
}
}

@ -16,6 +16,7 @@
"Projects": "Project(s)",
"NoProjectWarning": "There are no projects yet!",
"DocumentNotFound": "Oops, the requested document was not found!",
"ProjectNotFound": "Oops, the requested project was not found!",
"NavigationDocumentNotFound": "This version does not have a navigation document!",
"DocumentNotFoundInSelectedLanguage": "Document in the language you wanted is not found. Document in the default language is shown.",
"FilterTopics": "Filter topics",

@ -14,6 +14,7 @@
"Projects": "项目",
"NoProjectWarning": "还没有项目!",
"DocumentNotFound": "找不到请求的文档!",
"ProjectNotFound": "找不到请求的项目!",
"NavigationDocumentNotFound": "这个版本没有导航文件!",
"DocumentNotFoundInSelectedLanguage": "本文档不适用于所选语言, 将以默认语言显示文档.",
"FilterTopics": "过滤主题",

@ -14,6 +14,7 @@
"Projects": "專案",
"NoProjectWarning": "沒有專案!",
"DocumentNotFound": "找不到要求的文件!",
"ProjectNotFound": "找不到請求的項目!",
"NavigationDocumentNotFound": "這個版本沒有導覽文件!",
"DocumentNotFoundInSelectedLanguage": "本文件不適用於所選語系,將以預設語系顯示.",
"FilterTopics": "過濾主題",

@ -5,12 +5,12 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Clipboard
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.MalihuCustomScrollbar
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Popper
@using Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Prismjs
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@using Volo.Docs
@using Volo.Docs.Localization
@using Volo.Docs.Pages.Documents.Project
@using Volo.Docs.Pages.Documents.Shared.ErrorComponent
@inject IThemeManager ThemeManager
@inject IPageLayout PageLayout
@inject IHtmlLocalizer<DocsResource> L
@ -39,9 +39,10 @@
<abp-script src="/Pages/Documents/Project/bootstrap-toc.js" />
<abp-script src="/Pages/Documents/Shared/Scripts/vs.js" />
<abp-script src="/Pages/Documents/Project/index.js" />
<abp-script src="/Pages/Documents/Shared/ErrorComponent/error.js" />
</abp-script-bundle>
}
@if (Model.DocumentFound)
@if (Model.LoadSuccess)
{
<div class="docs-page" data-spy="scroll" data-target="#docs-sticky-index">
<div class="row justify-content-end">
@ -348,14 +349,31 @@
}
else
{
@(await Component.InvokeAsync<DocumentNotFoundViewComponent>(new
{
model = new DocumentNotFoundPageModel
if (!Model.ProjectFound)
{
@(await Component.InvokeAsync<ErrorViewComponent>(new
{
model = new ErrorPageModel
{
RedirectUrl = Model.DocumentsUrlPrefix,
ErrorCode = "404",
ErrorMessage = L.GetString("ProjectNotFound")
}
}))
}
if (!Model.DocumentFound)
{
@(await Component.InvokeAsync<ErrorViewComponent>(new
{
ProjectName = Model.ProjectName,
DocumentName = Model.DocumentName,
LanguageCode = Model.LanguageCode,
Version = Model.Version,
}
}))
model = new ErrorPageModel
{
RedirectUrl = Model.DocumentsUrlPrefix + Model.LanguageCode + "/" + Model.ProjectName + "/"
+ (Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version),
ErrorCode = "404",
ErrorMessage = L.GetString("DocumentNotFound"),
AutoRedirect = !Model.DocumentName.IsNullOrWhiteSpace()
}
}))
}
}

@ -7,13 +7,11 @@ using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Localization;
using Volo.Docs.Documents;
using Volo.Docs.HtmlConverting;
using Volo.Docs.Models;
@ -37,6 +35,10 @@ namespace Volo.Docs.Pages.Documents.Project
public bool DocumentFound { get; set; } = true;
public bool ProjectFound { get; set; } = true;
public bool LoadSuccess => DocumentFound && ProjectFound;
public string DefaultLanguageCode { get; set; }
public ProjectDto Project { get; set; }
@ -120,7 +122,8 @@ namespace Volo.Docs.Pages.Documents.Project
catch (EntityNotFoundException e)
{
Logger.LogWarning(e.Message);
return NotFound();
ProjectFound = false;
return Page();
}
if (ShowProjectsCombobox)
@ -344,43 +347,13 @@ namespace Volo.Docs.Pages.Documents.Project
try
{
if (DocumentName.IsNullOrWhiteSpace())
{
Document = await _documentAppService.GetDefaultAsync(
new GetDefaultDocumentInput
{
ProjectId = Project.Id,
LanguageCode = LanguageCode,
Version = Version
}
);
}
else
{
Document = await _documentAppService.GetAsync(
new GetDocumentInput
{
ProjectId = Project.Id,
Name = DocumentNameWithExtension,
LanguageCode = LanguageCode,
Version = Version
}
);
}
Document = await GetSpecificDocumentOrDefaultAsync(LanguageCode);
}
catch (DocumentNotFoundException)
{
if (LanguageCode != DefaultLanguageCode)
{
Document = await _documentAppService.GetAsync(
new GetDocumentInput
{
ProjectId = Project.Id,
Name = DocumentNameWithExtension,
LanguageCode = DefaultLanguageCode,
Version = Version
}
);
Document = await GetSpecificDocumentOrDefaultAsync(DefaultLanguageCode);
DocumentLanguageIsDifferent = true;
}
@ -542,6 +515,33 @@ namespace Volo.Docs.Pages.Documents.Project
}
private async Task<DocumentWithDetailsDto> GetSpecificDocumentOrDefaultAsync(string languageCode)
{
if (DocumentName.IsNullOrWhiteSpace())
{
return await _documentAppService.GetDefaultAsync(
new GetDefaultDocumentInput
{
ProjectId = Project.Id,
LanguageCode = languageCode,
Version = Version
}
);
}
else
{
return await _documentAppService.GetAsync(
new GetDocumentInput
{
ProjectId = Project.Id,
Name = DocumentNameWithExtension,
LanguageCode = languageCode,
Version = Version
}
);
}
}
public async Task SetDocumentPreferencesAsync()
{
var projectParameters = await _documentAppService.GetParametersAsync(

@ -226,7 +226,7 @@
'VoilaBot',
'ExaLead',
'Search Dog',
'MSN Bot' ,
'MSN Bot',
'BingBot'
];
@ -277,8 +277,7 @@
if (queryStrings.length <= 0) {
returnList.push(key + "=" + $(this).val());
}
else {
} else {
for (var k = 0; k < queryStrings.length; k++) {
returnList.push(key + "=" + $(this).val() + "&" + queryStrings[k]);
}
@ -291,7 +290,7 @@
var queryStrings = getQueryStringsFromComboboxes(0);
for (var i = 0; i < queryStrings.length; i++) {
html += "<a href=\"" + currentUrl + "?" + queryStrings[i] +"\">" + queryStrings[i]+"</a> "
html += "<a href=\"" + currentUrl + "?" + queryStrings[i] + "\">" + queryStrings[i] + "</a> "
}
$("#crawler_link").html(html);
@ -310,4 +309,3 @@
});
})(jQuery);

@ -1,15 +0,0 @@
namespace Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent
{
public class DocumentNotFoundPageModel
{
public string ProjectName { get; set; }
public string LanguageCode { get; set; }
public string Version { get; set; }
public string DocumentName { get; set; }
public string DocumentsUrlPrefix { get; set; }
}
}

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc;
namespace Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent
{
public class DocumentNotFoundViewComponent : AbpViewComponent
{
private readonly DocsUiOptions _options;
public DocumentNotFoundViewComponent(IOptions<DocsUiOptions> options)
{
_options = options.Value;
}
public IViewComponentResult Invoke(DocumentNotFoundPageModel model, string defaultErrorMessageKey)
{
model.DocumentsUrlPrefix = _options.RoutePrefix;
return View("~/Pages/Documents/Shared/DocumentNotFoundComponent/Default.cshtml", model);
}
}
}

@ -1,17 +1,19 @@
@using Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent
@model DocumentNotFoundPageModel
@model Volo.Docs.Pages.Documents.Shared.ErrorComponent.ErrorPageModel
@{
}
<div class="row position-relative vh-100" style="background: #e8e8e8;">
<div class="center">
<span class="notfound-404">404</span>
<div class="center" id="DocumentErrorContainer">
<span class="notfound-@Model.ErrorCode">@Model.ErrorCode</span>
<h1>
<strong>"@Model.DocumentName"</strong> not found in <strong>@Model.ProjectName</strong> documents, with <strong>@Model.Version</strong> version and <strong>@Model.LanguageCode</strong> language.
@Model.ErrorMessage
</h1>
<br />
<a href="@(Model.DocumentsUrlPrefix + Model.LanguageCode + "/" +Model.ProjectName + "/" + Model.Version)" class="btn btn-primary px-4">
Go Back
</a>
<br/>
@if (Model.AutoRedirect)
{
<a href="@(Model.RedirectUrl)" class="btn btn-primary px-4" id="ErrorRedirect">
Go Back <span id="ErrorRedirectSeconds">(3)</span>
</a>
}
</div>
</div>

@ -0,0 +1,13 @@
namespace Volo.Docs.Pages.Documents.Shared.ErrorComponent
{
public class ErrorPageModel
{
public string ErrorMessage { get; set; }
public string ErrorCode { get; set; }
public string RedirectUrl { get; set; }
public bool AutoRedirect { get; set; } = true;
}
}

@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc;
namespace Volo.Docs.Pages.Documents.Shared.ErrorComponent
{
public class ErrorViewComponent : AbpViewComponent
{
public IViewComponentResult Invoke(ErrorPageModel model)
{
return View("~/Pages/Documents/Shared/ErrorComponent/Default.cshtml", model);
}
}
}

@ -0,0 +1,20 @@
(function ($) {
$(function () {
var errorPageRedirect = function () {
var second = 3;
var close = setInterval(() => {
$("#ErrorRedirectSeconds").text(`(${--second})`);
if (second === 0) {
clearInterval(close);
$("#ErrorRedirect")[0].click();
}
}, 1000);
}
if (document.getElementById("ErrorRedirect")) {
errorPageRedirect();
}
});
})(jQuery);
Loading…
Cancel
Save