Browse Source

Merge pull request #7335 from abpframework/cotur/cms-kit/page

Added Routing to Cms-Kit Page
pull/7363/head
İlkay İlknur 6 years ago
committed by GitHub
parent
commit
3741d3557d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPageAppService.cs
  2. 9
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PageAppService.cs
  3. 6
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs
  4. 5
      modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs
  5. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Pages/Index.cshtml
  6. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Pages/Index.cshtml.cs
  7. 32
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Contents/ContentViewComponent.cs
  8. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Contents/Default.cshtml
  9. 12
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml
  10. 11
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PagePublicAppService_Tests.cs

2
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPageAppService.cs

@ -5,6 +5,6 @@ namespace Volo.CmsKit.Public.Pages
{ {
public interface IPageAppService public interface IPageAppService
{ {
Task<PageDto> GetByUrlAsync([NotNull] string url); Task<PageDto> FindByUrlAsync([NotNull] string url);
} }
} }

9
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PageAppService.cs

@ -12,9 +12,14 @@ namespace Volo.CmsKit.Public.Pages
PageRepository = pageRepository; PageRepository = pageRepository;
} }
public virtual async Task<PageDto> GetByUrlAsync(string url) public virtual async Task<PageDto> FindByUrlAsync(string url)
{ {
var page = await PageRepository.GetByUrlAsync(url); var page = await PageRepository.FindByUrlAsync(url);
if (page == null)
{
return null;
}
return ObjectMapper.Map<Page, PageDto>(page); return ObjectMapper.Map<Page, PageDto>(page);
} }

6
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs

@ -7,7 +7,7 @@ namespace Volo.CmsKit.Public.Pages
[RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)] [RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)]
[Area("cms-kit")] [Area("cms-kit")]
[Route("api/cms-kit-public/comments")] [Route("api/cms-kit-public/comments")]
public class PagesPublicController public class PagesPublicController : IPageAppService
{ {
protected readonly IPageAppService PageAppService; protected readonly IPageAppService PageAppService;
@ -18,9 +18,9 @@ namespace Volo.CmsKit.Public.Pages
[HttpGet] [HttpGet]
[Route("url/{url}")] [Route("url/{url}")]
public Task<PageDto> GetByUrlAsync(string url) public Task<PageDto> FindByUrlAsync(string url)
{ {
return PageAppService.GetByUrlAsync(url); return PageAppService.FindByUrlAsync(url);
} }
} }
} }

5
modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.RazorPages; using System.Linq;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
@ -56,7 +57,7 @@ namespace Volo.CmsKit.Public.Web
Configure<RazorPagesOptions>(options => Configure<RazorPagesOptions>(options =>
{ {
//... options.Conventions.AddPageRoute("/CmsKit/Pages/Index", "/{*pageUrl}");
}); });
} }
} }

2
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Pages/Index.cshtml

@ -1,4 +1,4 @@
@page "{pageUrl}" @page "{*pageUrl}"
@using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.AspNetCore.Mvc.Localization
@using Volo.CmsKit.Localization @using Volo.CmsKit.Localization
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages

11
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Pages/Index.cshtml.cs

@ -19,9 +19,16 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Pages
PageAppService = pageAppService; PageAppService = pageAppService;
} }
public async Task OnGetAsync() public async Task<IActionResult> OnGetAsync()
{ {
Page = await PageAppService.GetByUrlAsync(PageUrl); Page = await PageAppService.FindByUrlAsync(PageUrl);
if (Page == null)
{
return NotFound();
}
return Page();
} }
} }
} }

32
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Contents/ContentViewComponent.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Domain.Entities;
using Volo.CmsKit.Public.Contents; using Volo.CmsKit.Public.Contents;
using Volo.CmsKit.Web.Contents; using Volo.CmsKit.Web.Contents;
@ -25,18 +26,26 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents
string entityType, string entityType,
string entityId) string entityId)
{ {
var content = await contentAppService.GetAsync(new GetContentInput var content = string.Empty;
try
{ {
EntityId = entityId, var contentDto = await contentAppService.GetAsync(new GetContentInput
EntityType = entityType {
}); EntityId = entityId,
EntityType = entityType
});
content = contentDto.Value;
}
catch (EntityNotFoundException e)
{
// ContentDto can be null, we will render empty content.
}
var viewModel = new ContentViewModel var viewModel = new ContentViewModel
{ {
EntityId = entityId, Value = await contentRenderer.RenderAsync(content)
EntityType = entityType,
ContentId = content.Id,
Rendered = await contentRenderer.RenderAsync(content.Value)
}; };
return View("~/Pages/CmsKit/Shared/Components/Contents/Default.cshtml", viewModel); return View("~/Pages/CmsKit/Shared/Components/Contents/Default.cshtml", viewModel);
@ -44,12 +53,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents
public class ContentViewModel public class ContentViewModel
{ {
public Guid ContentId { get; set; } public string Value { get; set; }
public string EntityType { get; set; }
public string EntityId { get; set; }
public string Rendered { get; set; }
} }
} }
} }

2
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Contents/Default.cshtml

@ -1,3 +1,3 @@
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents.ContentViewComponent.ContentViewModel @model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents.ContentViewComponent.ContentViewModel
@Html.Raw(Model.Rendered) @Html.Raw(Model.Value)

12
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml

@ -1,16 +1,16 @@
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap @addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@using Microsoft.AspNetCore.Mvc.RazorPages @using Microsoft.AspNetCore.Mvc.RazorPages
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages.PageViewModel @model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages.PageViewModel
@inject IPageLayout PageLayout
@{
PageLayout.Content.Title = Model.Title;
}
<abp-card> <abp-card>
<abp-card-header>
<h3>
@Model.Title
</h3>
</abp-card-header>
<abp-card-body> <abp-card-body>
@await Component.InvokeAsync(typeof(ContentViewComponent), @await Component.InvokeAsync(typeof(ContentViewComponent),
new new

11
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PagePublicAppService_Tests.cs

@ -18,15 +18,20 @@ namespace Volo.CmsKit.Pages
} }
[Fact] [Fact]
public async Task ShouldGetByUrlAsync() public async Task ShouldFindByUrlAsync()
{ {
await Should.NotThrowAsync(async () => await _pageAppService.GetByUrlAsync(_data.Page_1_Url)); var page = await _pageAppService.FindByUrlAsync(_data.Page_1_Url);
page.ShouldNotBeNull();
page.Title.ShouldBe(_data.Page_1_Title);
} }
[Fact] [Fact]
public async Task ShouldNotGetByUrlAsync() public async Task ShouldNotGetByUrlAsync()
{ {
await Should.ThrowAsync<Exception>(async () => await _pageAppService.GetByUrlAsync("not-exist-url")); var page = await _pageAppService.FindByUrlAsync("not-exist-url");
page.ShouldBeNull();
} }
} }
} }
Loading…
Cancel
Save