Merge pull request #1650 from abpframework/Docs-option-for-projects-combobox

Docs option for projects combobox
pull/1725/head
Halil İbrahim Kalkan 6 years ago committed by GitHub
commit 9d7e3e1359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,19 +8,19 @@ namespace VoloDocs.Web.Pages
{ {
public class IndexModel : PageModel public class IndexModel : PageModel
{ {
private readonly DocsUrlOptions _urlOptions; private readonly DocsUiOptions _urlUiOptions;
public IndexModel(IOptions<DocsUrlOptions> urlOptions) public IndexModel(IOptions<DocsUiOptions> urlOptions)
{ {
_urlOptions = urlOptions.Value; _urlUiOptions = urlOptions.Value;
} }
public IActionResult OnGet() public IActionResult OnGet()
{ {
//TODO: Create HomeController & Index instead of Page. Otherwise, we have an empty Index.cshtml file. //TODO: Create HomeController & Index instead of Page. Otherwise, we have an empty Index.cshtml file.
if (!_urlOptions.RoutePrefix.IsNullOrWhiteSpace()) if (!_urlUiOptions.RoutePrefix.IsNullOrWhiteSpace())
{ {
return Redirect("." + _urlOptions.RoutePrefix); return Redirect("." + _urlUiOptions.RoutePrefix);
} }
return Page(); return Page();

@ -62,7 +62,7 @@ namespace VoloDocs.Web
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
Configure<DocsUrlOptions>(options => Configure<DocsUiOptions>(options =>
{ {
options.RoutePrefix = null; options.RoutePrefix = null;
}); });

@ -13,7 +13,7 @@ namespace Volo.Docs.Areas.Documents.TagHelpers
[HtmlTargetElement("ul", Attributes = "root-node")] [HtmlTargetElement("ul", Attributes = "root-node")]
public class TreeTagHelper : TagHelper public class TreeTagHelper : TagHelper
{ {
private readonly DocsUrlOptions _urlOptions; private readonly DocsUiOptions _uiOptions;
private const string LiItemTemplateWithLink = @"<li class='{0}'><span class='plus-icon'><i class='fa fa-{1}'></i></span>{2}{3}</li>"; private const string LiItemTemplateWithLink = @"<li class='{0}'><span class='plus-icon'><i class='fa fa-{1}'></i></span>{2}{3}</li>";
@ -41,9 +41,9 @@ namespace Volo.Docs.Areas.Documents.TagHelpers
[HtmlAttributeName("language")] [HtmlAttributeName("language")]
public string LanguageCode { get; set; } public string LanguageCode { get; set; }
public TreeTagHelper(IOptions<DocsUrlOptions> urlOptions) public TreeTagHelper(IOptions<DocsUiOptions> urlOptions)
{ {
_urlOptions = urlOptions.Value; _uiOptions = urlOptions.Value;
} }
public override void Process(TagHelperContext context, TagHelperOutput output) public override void Process(TagHelperContext context, TagHelperOutput output)
@ -142,7 +142,7 @@ namespace Volo.Docs.Areas.Documents.TagHelpers
return "javascript:;"; return "javascript:;";
} }
var prefix = _urlOptions.RoutePrefix; var prefix = _uiOptions.RoutePrefix;
return prefix + LanguageCode + "/" + ProjectName + "/" + Version + "/" + pathWithoutFileExtension; return prefix + LanguageCode + "/" + ProjectName + "/" + Version + "/" + pathWithoutFileExtension;
} }

@ -2,7 +2,7 @@
namespace Volo.Docs namespace Volo.Docs
{ {
public class DocsUrlOptions public class DocsUiOptions
{ {
private string _routePrefix = "documents"; private string _routePrefix = "documents";
@ -15,6 +15,12 @@ namespace Volo.Docs
set => _routePrefix = value; set => _routePrefix = value;
} }
/// <summary>
/// Allows user to see a combobox in user interface for swapping across projects
/// Default value: True;
/// </summary>
public bool ShowProjectsCombobox = true;
private string GetFormattedRoutePrefix() private string GetFormattedRoutePrefix()
{ {
if (string.IsNullOrWhiteSpace(_routePrefix)) if (string.IsNullOrWhiteSpace(_routePrefix))

@ -41,11 +41,11 @@ namespace Volo.Docs
Configure<RazorPagesOptions>(options => Configure<RazorPagesOptions>(options =>
{ {
var urlOptions = context.Services var docsOptions = context.Services
.GetRequiredServiceLazy<IOptions<DocsUrlOptions>>() .GetRequiredServiceLazy<IOptions<DocsUiOptions>>()
.Value.Value; .Value.Value;
var routePrefix = urlOptions.RoutePrefix; var routePrefix = docsOptions.RoutePrefix;
options.Conventions.AddPageRoute("/Documents/Project/Index", routePrefix + "{projectName}"); options.Conventions.AddPageRoute("/Documents/Project/Index", routePrefix + "{projectName}");
options.Conventions.AddPageRoute("/Documents/Project/Index", routePrefix + "{languageCode}/{projectName}"); options.Conventions.AddPageRoute("/Documents/Project/Index", routePrefix + "{languageCode}/{projectName}");

@ -14,13 +14,13 @@ namespace Volo.Docs.Markdown
public const string Type = "md"; public const string Type = "md";
private readonly IMarkdownConverter _markdownConverter; private readonly IMarkdownConverter _markdownConverter;
private readonly DocsUrlOptions _urlOptions; private readonly DocsUiOptions _uiOptions;
public MarkdownDocumentToHtmlConverter(IMarkdownConverter markdownConverter, public MarkdownDocumentToHtmlConverter(IMarkdownConverter markdownConverter,
IOptions<DocsUrlOptions> urlOptions) IOptions<DocsUiOptions> urlOptions)
{ {
_markdownConverter = markdownConverter; _markdownConverter = markdownConverter;
_urlOptions = urlOptions.Value; _uiOptions = urlOptions.Value;
} }
private const string MdLinkFormat = "[{0}]({1}{2}/{3}/{4}{5}/{6})"; private const string MdLinkFormat = "[{0}]({1}{2}/{3}/{4}{5}/{6})";
@ -73,7 +73,7 @@ namespace Volo.Docs.Markdown
return string.Format( return string.Format(
MdLinkFormat, MdLinkFormat,
displayText, displayText,
_urlOptions.RoutePrefix, _uiOptions.RoutePrefix,
languageCode, languageCode,
projectShortName, projectShortName,
version, version,
@ -101,7 +101,7 @@ namespace Volo.Docs.Markdown
return string.Format( return string.Format(
MdLinkFormat, MdLinkFormat,
displayText, displayText,
_urlOptions.RoutePrefix, _uiOptions.RoutePrefix,
languageCode, languageCode,
projectShortName, projectShortName,
version, version,

@ -15,19 +15,19 @@ namespace Volo.Docs.Pages.Documents
public IReadOnlyList<ProjectDto> Projects { get; set; } public IReadOnlyList<ProjectDto> Projects { get; set; }
private readonly IProjectAppService _projectAppService; private readonly IProjectAppService _projectAppService;
private readonly DocsUrlOptions _urlOptions; private readonly DocsUiOptions _uiOptions;
public IndexModel( public IndexModel(
IProjectAppService projectAppService, IProjectAppService projectAppService,
IOptions<DocsUrlOptions> urlOptions) IOptions<DocsUiOptions> urlOptions)
{ {
_projectAppService = projectAppService; _projectAppService = projectAppService;
_urlOptions = urlOptions.Value; _uiOptions = urlOptions.Value;
} }
public async Task<IActionResult> OnGetAsync() public async Task<IActionResult> OnGetAsync()
{ {
DocumentsUrlPrefix = _urlOptions.RoutePrefix; DocumentsUrlPrefix = _uiOptions.RoutePrefix;
var listResult = await _projectAppService.GetListAsync(); var listResult = await _projectAppService.GetListAsync();

@ -76,7 +76,7 @@
<div class="docs-tree-list"> <div class="docs-tree-list">
@if (Model.ProjectSelectItems.Count > 1) @if (Model.ShowProjectsCombobox && Model.ProjectSelectItems.Count > 1)
{ {
<div class="docs-version"> <div class="docs-version">
<div class="version-select"> <div class="version-select">

@ -52,28 +52,31 @@ namespace Volo.Docs.Pages.Documents.Project
public string DocumentsUrlPrefix { get; set; } public string DocumentsUrlPrefix { get; set; }
public bool ShowProjectsCombobox { get; set; }
public bool DocumentLanguageIsDifferent { get; set; } public bool DocumentLanguageIsDifferent { get; set; }
private readonly IDocumentAppService _documentAppService; private readonly IDocumentAppService _documentAppService;
private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory; private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory;
private readonly IProjectAppService _projectAppService; private readonly IProjectAppService _projectAppService;
private readonly DocsUrlOptions _options; private readonly DocsUiOptions _uiOptions;
public IndexModel( public IndexModel(
IDocumentAppService documentAppService, IDocumentAppService documentAppService,
IDocumentToHtmlConverterFactory documentToHtmlConverterFactory, IDocumentToHtmlConverterFactory documentToHtmlConverterFactory,
IProjectAppService projectAppService, IProjectAppService projectAppService,
IOptions<DocsUrlOptions> options) IOptions<DocsUiOptions> options)
{ {
_documentAppService = documentAppService; _documentAppService = documentAppService;
_documentToHtmlConverterFactory = documentToHtmlConverterFactory; _documentToHtmlConverterFactory = documentToHtmlConverterFactory;
_projectAppService = projectAppService; _projectAppService = projectAppService;
_options = options.Value; _uiOptions = options.Value;
} }
public async Task<IActionResult> OnGetAsync() public async Task<IActionResult> OnGetAsync()
{ {
DocumentsUrlPrefix = _options.RoutePrefix; DocumentsUrlPrefix = _uiOptions.RoutePrefix;
ShowProjectsCombobox = _uiOptions.ShowProjectsCombobox;
if (IsDocumentCultureDifferentThanCurrent()) if (IsDocumentCultureDifferentThanCurrent())
{ {
@ -81,7 +84,12 @@ namespace Volo.Docs.Pages.Documents.Project
} }
await SetProjectAsync(); await SetProjectAsync();
await SetProjectsAsync();
if (ShowProjectsCombobox)
{
await SetProjectsAsync();
}
await SetVersionAsync(); await SetVersionAsync();
await SetLanguageList(); await SetLanguageList();

Loading…
Cancel
Save