Removed the unnecessary PageVC

pull/13082/head
malik masis 3 years ago
parent 31224b98d8
commit 0cdc2cf4b0

@ -1,44 +0,0 @@
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@using System.Dynamic
@using Volo.CmsKit.Public.Web.Renderers
@using Volo.Abp.Data
@using Volo.CmsKit.Contents
@inject IMarkdownToHtmlRenderer MarkdownRenderer
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages.PageViewModel
<abp-card>
<abp-card-body>
@foreach (ContentFragment contentFragment in Model.ContentFragments)
{
if (contentFragment.Type == "Markdown") //TODO: Constant
{
@Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty<string>("Content")))
}
else if (contentFragment.Type == "Widget") //TODO: Constant
{
@await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties))
}
}
</abp-card-body>
</abp-card>
@{
dynamic ConvertToDynamicObject(Dictionary<string, object> dict)
{
var eo = new ExpandoObject();
var eoColl = (ICollection<KeyValuePair<string, object>>)eo;
foreach (var kvp in dict)
{
eoColl.Add(kvp);
}
dynamic eoDynamic = eo;
return eoDynamic;
}
}

@ -1,42 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
using Volo.CmsKit.Contents;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
[Widget(
StyleTypes = new[]
{
typeof(HighlightJsStyleContributor)
},
ScriptTypes = new[]
{
typeof(HighlightJsScriptContributor)
},
ScriptFiles = new[]
{
"/Pages/Public/CmsKit/highlightOnLoad.js"
})]
public class DefaultPageViewComponent : AbpViewComponent //TODO: Remove component, directly render in the page
{
public virtual async Task<IViewComponentResult> InvokeAsync(
Guid pageId,
string title,
string content,
List<ContentFragment> contentFragments)
{
var model = new PageViewModel
{
Id = pageId,
Title = title,
ContentFragments = contentFragments
};
return View("~/Pages/CmsKit/Shared/Components/Pages/Default.cshtml", model);
}
}

@ -1,9 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
using Volo.CmsKit.Tags;

@ -1,33 +1,63 @@
@page
@using Microsoft.AspNetCore.Mvc.Localization

@page
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@using Volo.CmsKit.Contents
@using Volo.CmsKit.Localization
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@using System.Dynamic
@using Volo.CmsKit.Public.Web.Renderers
@using Volo.Abp.Data
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs;
@using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
@inject IMarkdownToHtmlRenderer MarkdownRenderer
@model Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Pages.IndexModel
@inject IHtmlLocalizer<CmsKitResource> L
@section styles{
<abp-style src="/Pages/Public/CmsKit/Pages/index.css" />
<style>
@Html.Raw(Model.Page.Style)
@Html.Raw(Model.PageDto.Style)
</style>
}
@section scripts{
<script>
@Html.Raw(Model.Page.Script)
@Html.Raw(Model.PageDto.Script)
</script>
}
@await Component.InvokeAsync(typeof(DefaultPageViewComponent),
new
<abp-card>
<abp-card-body>
@foreach (ContentFragment contentFragment in Model.PageDto.ContentFragments)
{
if (contentFragment.Type == "Markdown") //TODO: Constant
{
@Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty<string>("Content")))
}
else if (contentFragment.Type == "Widget") //TODO: Constant
{
@await Component.InvokeAsync(contentFragment.GetProperty<string>("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties))
}
}
</abp-card-body>
</abp-card>
@{
dynamic ConvertToDynamicObject(Dictionary<string, object> dict)
{
pageId = Model.Page.Id,
title = Model.Page.Title,
content = Model.Page.Content,
contentFragments = Model.Page.ContentFragments
})
var eo = new ExpandoObject();
var eoColl = (ICollection<KeyValuePair<string, object>>)eo;
foreach (var kvp in dict)
{
eoColl.Add(kvp);
}
dynamic eoDynamic = eo;
return eoDynamic;
}
}

@ -12,18 +12,18 @@ public class IndexModel : CommonPageModel
protected IPagePublicAppService PagePublicAppService { get; }
public PageDto Page;
public PageDto PageDto{ get; private set; }
public IndexModel(IPagePublicAppService pagePublicAppService)
public IndexModel(IPagePublicAppService pagePublicAppService)
{
PagePublicAppService = pagePublicAppService;
}
public async Task<IActionResult> OnGetAsync()
{
Page = await PagePublicAppService.FindBySlugAsync(Slug);
PageDto = await PagePublicAppService.FindBySlugAsync(Slug);
if (Page == null)
if (PageDto == null)
{
return NotFound();
}

@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using Volo.CmsKit.Contents;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Pages;
public class PageViewModel
{

@ -130,5 +130,5 @@ public class CmsKitTestData : ISingletonDependency
public string PollName { get; } = "Poll";
public string WidgetName { get; } = "CmsPollByName";
public string WidgetName { get; } = "CmsPollByCode";
}

Loading…
Cancel
Save