Browse Source

First draft implementation for widgets

pull/13082/head
Halil İbrahim Kalkan 4 years ago
parent
commit
fad8890047
  1. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs
  2. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs
  3. 21
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs
  4. 14
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs
  5. 17
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml
  6. 36
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
  7. 9
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs
  8. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs
  9. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs
  10. 18
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs

8
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs

@ -0,0 +1,8 @@
using System.Collections.Generic;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class CmsKitContentWidgetOptions
{
public Dictionary<string, ContentWidgetConfig> WidgetConfigs { get; } = new();
}

6
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs

@ -0,0 +1,6 @@
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public abstract class ContentFragment
{
}

21
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs

@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class ContentParser : IContentParser, ITransientDependency
{
public async Task<List<ContentFragment>> ParseAsync(string content)
{
return new List<ContentFragment> {
new MarkdownContentFragment {
Content = "**ABP Framework** is completely open source and developed in a community-driven manner."
},
new WidgetContentFragment("CmsPoll") { Properties = { { "widgetName", "poll-right" } } },
new MarkdownContentFragment {
Content = "Thanks _for_ *your* feedback."
}
};
}
}

14
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs

@ -0,0 +1,14 @@
using System;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class ContentWidgetConfig
{
public string Name { get; }
public Type ViewComponentType { get; set; }
public ContentWidgetConfig(string name)
{
Name = name;
}
}

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

@ -2,6 +2,7 @@
@using Volo.CmsKit.Public.Web.Renderers @using Volo.CmsKit.Public.Web.Renderers
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs @using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@inject IMarkdownToHtmlRenderer MarkdownRenderer @inject IMarkdownToHtmlRenderer MarkdownRenderer
@ -9,9 +10,19 @@
<abp-card> <abp-card>
<abp-card-body> <abp-card-body>
@if (!Model.Content.IsNullOrEmpty()) @foreach (var contentFragment in Model.ContentFragments)
{ {
@Html.Raw(await MarkdownRenderer.RenderAsync(Model.Content)) if (contentFragment is MarkdownContentFragment markdownContentFragment)
{
@Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content))
}
else if(contentFragment is WidgetContentFragment widgetContentFragment)
{
@await Component.InvokeAsync(widgetContentFragment.Name, new
{
widgetName = "poll-right"
})
}
} }
</abp-card-body> </abp-card-body>
</abp-card> </abp-card>

36
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs

@ -2,8 +2,6 @@
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.CmsKit.Public.Pages;
using Volo.CmsKit.Public.Web.Renderers;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs; using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
@ -12,43 +10,39 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
[Widget( [Widget(
StyleTypes = new[] StyleTypes = new[]
{ {
typeof(HighlightJsStyleContributor) typeof(HighlightJsStyleContributor)
}, },
ScriptTypes = new[] ScriptTypes = new[]
{ {
typeof(HighlightJsScriptContributor) typeof(HighlightJsScriptContributor)
}, },
ScriptFiles = new[] ScriptFiles = new[]
{ {
"/Pages/Public/CmsKit/highlightOnLoad.js" "/Pages/Public/CmsKit/highlightOnLoad.js"
})] })]
public class DefaultPageViewComponent : AbpViewComponent public class DefaultPageViewComponent : AbpViewComponent
{ {
protected IPagePublicAppService PagePublicAppService { get; } private readonly IContentParser _contentParser;
public DefaultPageViewComponent(IPagePublicAppService pagePublicAppService) public DefaultPageViewComponent(IContentParser contentParser)
{ {
PagePublicAppService = pagePublicAppService; _contentParser = contentParser;
} }
public virtual async Task<IViewComponentResult> InvokeAsync(Guid pageId, string title, string content) public virtual async Task<IViewComponentResult> InvokeAsync(
Guid pageId,
string title,
string content)
{ {
var contentFragments = await _contentParser.ParseAsync(content);
var model = new PageViewModel var model = new PageViewModel
{ {
Id = pageId, Id = pageId,
Title = title, Title = title,
Content = content ContentFragments = contentFragments
}; };
return View("~/Pages/CmsKit/Shared/Components/Pages/Default.cshtml", model); return View("~/Pages/CmsKit/Shared/Components/Pages/Default.cshtml", model);
} }
} }
public class PageViewModel
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}

9
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs

@ -0,0 +1,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public interface IContentParser
{
Task<List<ContentFragment>> ParseAsync(string content);
}

6
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs

@ -0,0 +1,6 @@
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class MarkdownContentFragment : ContentFragment
{
public string Content { get; set; }
}

13
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class PageViewModel
{
public Guid Id { get; set; }
public string Title { get; set; }
public List<ContentFragment> ContentFragments { get; set; }
}

18
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs

@ -0,0 +1,18 @@
using System.Collections.Generic;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages;
public class WidgetContentFragment : ContentFragment
{
public string Name { get; }
public string ViewComponentName { get; set; }
public Dictionary<string, string> Properties { get; }
public WidgetContentFragment(string name)
{
Name = name;
Properties = new Dictionary<string, string>();
}
}
Loading…
Cancel
Save