From fad8890047eab7ca5df7e1cb3fe77fe352644cb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 30 May 2022 11:57:21 +0300 Subject: [PATCH 01/36] First draft implementation for widgets --- .../Pages/CmsKitContentWidgetOptions.cs | 8 +++++ .../Components/Pages/ContentFragment.cs | 6 ++++ .../Shared/Components/Pages/ContentParser.cs | 21 +++++++++++ .../Components/Pages/ContentWidgetConfig.cs | 14 ++++++++ .../Shared/Components/Pages/Default.cshtml | 17 +++++++-- .../Pages/DefaultPageViewComponent.cs | 36 ++++++++----------- .../Shared/Components/Pages/IContentParser.cs | 9 +++++ .../Pages/MarkdownContentFragment.cs | 6 ++++ .../Shared/Components/Pages/PageViewModel.cs | 13 +++++++ .../Components/Pages/WidgetContentFragment.cs | 18 ++++++++++ 10 files changed, 124 insertions(+), 24 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs new file mode 100644 index 0000000000..a4aedbc158 --- /dev/null +++ b/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 WidgetConfigs { get; } = new(); +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs new file mode 100644 index 0000000000..c5486903dd --- /dev/null +++ b/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 +{ + +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs new file mode 100644 index 0000000000..bfc0828821 --- /dev/null +++ b/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> ParseAsync(string content) + { + return new List { + 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." + } + }; + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs new file mode 100644 index 0000000000..647427b330 --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index 50104515c9..3ca57d6a05 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/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.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs +@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages @inject IMarkdownToHtmlRenderer MarkdownRenderer @@ -9,9 +10,19 @@ - @if (!Model.Content.IsNullOrEmpty()) - { - @Html.Raw(await MarkdownRenderer.RenderAsync(Model.Content)) + @foreach (var contentFragment in Model.ContentFragments) + { + 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" + }) + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs index c5427af114..914001b073 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs @@ -2,8 +2,6 @@ using System.Threading.Tasks; using Microsoft.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.Widgets; @@ -12,43 +10,39 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; [Widget( StyleTypes = new[] { - typeof(HighlightJsStyleContributor) + typeof(HighlightJsStyleContributor) }, ScriptTypes = new[] { - typeof(HighlightJsScriptContributor) + typeof(HighlightJsScriptContributor) }, ScriptFiles = new[] { - "/Pages/Public/CmsKit/highlightOnLoad.js" + "/Pages/Public/CmsKit/highlightOnLoad.js" })] 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 InvokeAsync(Guid pageId, string title, string content) + + public virtual async Task InvokeAsync( + Guid pageId, + string title, + string content) { + var contentFragments = await _contentParser.ParseAsync(content); + var model = new PageViewModel { Id = pageId, Title = title, - Content = content + ContentFragments = contentFragments }; 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; } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs new file mode 100644 index 0000000000..03e54ea4bb --- /dev/null +++ b/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> ParseAsync(string content); +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs new file mode 100644 index 0000000000..361a4b3973 --- /dev/null +++ b/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; } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs new file mode 100644 index 0000000000..eae24aeae4 --- /dev/null +++ b/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 ContentFragments { get; set; } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs new file mode 100644 index 0000000000..125c48a72e --- /dev/null +++ b/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 Properties { get; } + + public WidgetContentFragment(string name) + { + Name = name; + Properties = new Dictionary(); + } +} \ No newline at end of file From c86db705397afb526eaf1f5f16cd24b37149c8b0 Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 2 Jun 2022 16:46:58 +0300 Subject: [PATCH 02/36] Improved example --- .../Shared/Components/Pages/ContentParser.cs | 1 + .../Shared/Components/Pages/Default.cshtml | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs index bfc0828821..ebea7cfa7e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs @@ -13,6 +13,7 @@ public class ContentParser : IContentParser, ITransientDependency Content = "**ABP Framework** is completely open source and developed in a community-driven manner." }, new WidgetContentFragment("CmsPoll") { Properties = { { "widgetName", "poll-right" } } }, + new WidgetContentFragment("CmsPollByName") { Properties = { { "name", "poll-name" } } }, new MarkdownContentFragment { Content = "Thanks _for_ *your* feedback." } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index 3ca57d6a05..17ac619aa3 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -16,12 +16,23 @@ { @Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content)) } - else if(contentFragment is WidgetContentFragment widgetContentFragment) + else if (contentFragment is WidgetContentFragment widgetContentFragment) { - @await Component.InvokeAsync(widgetContentFragment.Name, new + //TODO + if (widgetContentFragment.Name == "CmsPoll") { - widgetName = "poll-right" - }) + @await Component.InvokeAsync(widgetContentFragment.Name, new + { + widgetName = "poll-right" + }) + } + else + { + @await Component.InvokeAsync(widgetContentFragment.Name,new + { + name = "poll-name" + }) + } } } From 200ec20190c1eb1c1e0be9fa9b7760c9ebe6e0ab Mon Sep 17 00:00:00 2001 From: malik masis Date: Sat, 4 Jun 2022 18:41:16 +0300 Subject: [PATCH 03/36] Implemented widget options --- .../Components/Pages/CmsKitContentWidgetOptions.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs index a4aedbc158..d782299026 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs @@ -4,5 +4,15 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; public class CmsKitContentWidgetOptions { - public Dictionary WidgetConfigs { get; } = new(); + public Dictionary WidgetConfigs { get; } + + public CmsKitContentWidgetOptions() + { + WidgetConfigs = new(); + } + + public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig) + { + WidgetConfigs.Add(name, contentWidgetConfig); + } } \ No newline at end of file From 6057f2a12d272c6eec13588eb525256139e02337 Mon Sep 17 00:00:00 2001 From: malik masis Date: Mon, 6 Jun 2022 12:04:16 +0300 Subject: [PATCH 04/36] Converted widget name to the actual vc --- .../Shared/Components/Pages/ContentParser.cs | 16 ++++++++++++++-- .../Shared/Components/Pages/Default.cshtml | 17 +++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs index ebea7cfa7e..d9156e5a58 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs @@ -1,19 +1,31 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; public class ContentParser : IContentParser, ITransientDependency { + private readonly CmsKitContentWidgetOptions _options; + public ContentParser(IOptions options) + { + _options = options.Value; + } + public async Task> ParseAsync(string content) { + var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name; return new List { new MarkdownContentFragment { Content = "**ABP Framework** is completely open source and developed in a community-driven manner." }, - new WidgetContentFragment("CmsPoll") { Properties = { { "widgetName", "poll-right" } } }, - new WidgetContentFragment("CmsPollByName") { Properties = { { "name", "poll-name" } } }, + new WidgetContentFragment(name) { + Properties = { + { "name", "poll-name" } + } + }, new MarkdownContentFragment { Content = "Thanks _for_ *your* feedback." } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index 17ac619aa3..ece75e5422 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -18,21 +18,10 @@ } else if (contentFragment is WidgetContentFragment widgetContentFragment) { - //TODO - if (widgetContentFragment.Name == "CmsPoll") + @await Component.InvokeAsync(widgetContentFragment.Name, new { - @await Component.InvokeAsync(widgetContentFragment.Name, new - { - widgetName = "poll-right" - }) - } - else - { - @await Component.InvokeAsync(widgetContentFragment.Name,new - { - name = "poll-name" - }) - } + name = "poll-name" + }) } } From 53b8669d3dad837ee883757486bc349af66d9936 Mon Sep 17 00:00:00 2001 From: malik masis Date: Mon, 6 Jun 2022 13:20:20 +0300 Subject: [PATCH 05/36] Added missed fact attribute --- .../Pages/PageManager_Test.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Pages/PageManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Pages/PageManager_Test.cs index 92dac10caf..208de3817f 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Pages/PageManager_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Pages/PageManager_Test.cs @@ -1,9 +1,6 @@ -using Shouldly; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; +using Shouldly; +using Xunit; namespace Volo.CmsKit.Pages; @@ -20,6 +17,7 @@ public class PageManager_Test : CmsKitDomainTestBase pageRepository = GetRequiredService(); } + [Fact] public async Task CreateAsync_ShouldWorkProperly_WithNonExistingSlug() { var title = "My awesome page"; @@ -34,6 +32,7 @@ public class PageManager_Test : CmsKitDomainTestBase page.Content.ShouldBe(content); } + [Fact] public async Task CreateAsync_ShouldThrowException_WithExistingSlug() { var title = "My awesome page"; @@ -46,6 +45,7 @@ public class PageManager_Test : CmsKitDomainTestBase exception.ShouldNotBeNull(); } + [Fact] public async Task SetSlugAsync_ShouldWorkProperly_WithNonExistingSlug() { var newSlug = "freshly-generated-new-slug"; @@ -56,6 +56,7 @@ public class PageManager_Test : CmsKitDomainTestBase page.Slug.ShouldBe(newSlug); } + [Fact] public async Task SetSlugAsync_ShouldThrowException_WithExistingSlug() { var newSlug = testData.Page_2_Slug; From c3eef7a06a9495d5d0c860911ea0e916faafbcd2 Mon Sep 17 00:00:00 2001 From: malik masis Date: Mon, 6 Jun 2022 18:34:40 +0300 Subject: [PATCH 06/36] Splitted MarkdownContentFragment still need development --- .../Shared/Components/Pages/ContentParser.cs | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs index d9156e5a58..f91e6d22b7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs @@ -1,5 +1,7 @@ +using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -16,19 +18,44 @@ public class ContentParser : IContentParser, ITransientDependency public async Task> ParseAsync(string content) { + if (!_options.WidgetConfigs.Any()) + { + return new List() + { + new MarkdownContentFragment() { Content = content } + }; + } + + MatchCollection mc = Regex.Matches(content, @"(?<=\[Wid)(.*?)(?=\])");//(?<=X)(.*?)(?=Y) + + string split = "-----"; + + var polls = new List(); + foreach (Match m in mc) + { + polls.Add("[Wid" + m + "]"); + content = content.Replace("[Wid" + m + "]", split); + } + + var splittedContent = content.Split(split, StringSplitOptions.RemoveEmptyEntries); + + var contentFragments = new List(); var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name; - return new List { - new MarkdownContentFragment { - Content = "**ABP Framework** is completely open source and developed in a community-driven manner." - }, - new WidgetContentFragment(name) { - Properties = { - { "name", "poll-name" } - } - }, - new MarkdownContentFragment { - Content = "Thanks _for_ *your* feedback." + for (int b = 0; b < splittedContent.Length; b++) + { + contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[b] }); + if (b != splittedContent.Length - 1) + { + contentFragments.Add(new WidgetContentFragment(name) + { + Properties = + { + { "name", "poll-name" } + } + }); } - }; + } + + return contentFragments; } } \ No newline at end of file From a2d9f457fc3cbca52f17859ea4b7da8db8af05bc Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 7 Jun 2022 23:06:33 +0300 Subject: [PATCH 07/36] created the first dynamic poll --- .../CmsKit/Shared/Components/Pages/ContentParser.cs | 11 +++++++---- .../CmsKit/Shared/Components/Pages/Default.cshtml | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs index f91e6d22b7..7c84b75917 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs @@ -28,6 +28,9 @@ public class ContentParser : IContentParser, ITransientDependency MatchCollection mc = Regex.Matches(content, @"(?<=\[Wid)(.*?)(?=\])");//(?<=X)(.*?)(?=Y) + MatchCollection mcPollName = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")"); + var pollNames = mcPollName.Select(p => p.Value).ToList(); + string split = "-----"; var polls = new List(); @@ -41,16 +44,16 @@ public class ContentParser : IContentParser, ITransientDependency var contentFragments = new List(); var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name; - for (int b = 0; b < splittedContent.Length; b++) + for (int i = 0; i < splittedContent.Length; i++) { - contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[b] }); - if (b != splittedContent.Length - 1) + contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[i] }); + if (i != splittedContent.Length - 1) { contentFragments.Add(new WidgetContentFragment(name) { Properties = { - { "name", "poll-name" } + { "name", pollNames[i] } } }); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index ece75e5422..45720013b6 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -20,7 +20,7 @@ { @await Component.InvokeAsync(widgetContentFragment.Name, new { - name = "poll-name" + name = widgetContentFragment.Properties.FirstOrDefault().Value }) } } From 6edfcdf0e0931e131f97fdb4bc21b3aa78e20dc2 Mon Sep 17 00:00:00 2001 From: malik masis Date: Wed, 8 Jun 2022 10:39:44 +0300 Subject: [PATCH 08/36] Improved parsing the poll widget for the different cases --- .../Shared/Components/Pages/ContentParser.cs | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs index 7c84b75917..8019ae3ac2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs @@ -26,37 +26,65 @@ public class ContentParser : IContentParser, ITransientDependency }; } - MatchCollection mc = Regex.Matches(content, @"(?<=\[Wid)(.*?)(?=\])");//(?<=X)(.*?)(?=Y) + string delimeter = "----"; + var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter); - MatchCollection mcPollName = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")"); - var pollNames = mcPollName.Select(p => p.Value).ToList(); + var parsedList = new List(); - string split = "-----"; + if (!replacedText.Contains(delimeter)) + { + parsedList.Add(replacedText); + } - var polls = new List(); - foreach (Match m in mc) + while (replacedText.Contains(delimeter)) { - polls.Add("[Wid" + m + "]"); - content = content.Replace("[Wid" + m + "]", split); + //For parsing delimeter + var index = replacedText.IndexOf(delimeter); + if (index != 0) + { + parsedList.Add(replacedText.Substring(0, index)); + replacedText = replacedText.Substring(index, replacedText.Length - index); + index = 0; + } + + parsedList.Add(replacedText.Substring(index, delimeter.Length)); + replacedText = replacedText.Substring(delimeter.Length, replacedText.Length - delimeter.Length); + + //for parsing the other side + index = replacedText.IndexOf(delimeter); + if (index != -1) + { + parsedList.Add(replacedText.Substring(0, index)); + replacedText = replacedText.Substring(index, replacedText.Length - index); + + } + else + { + parsedList.Add(replacedText); + } } - var splittedContent = content.Split(split, StringSplitOptions.RemoveEmptyEntries); + var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name; + + var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList(); var contentFragments = new List(); - var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name; - for (int i = 0; i < splittedContent.Length; i++) + for (int i = 0, k = 0; i < parsedList.Count; i++) { - contentFragments.Add(new MarkdownContentFragment() { Content = splittedContent[i] }); - if (i != splittedContent.Length - 1) + if (parsedList[i] == delimeter) { contentFragments.Add(new WidgetContentFragment(name) { Properties = { - { "name", pollNames[i] } + { "name", pollNames[k++] } } }); } + else + { + contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] }); + } } return contentFragments; From d48a0715310b99aab44d19fb5cd36edebd05b7dc Mon Sep 17 00:00:00 2001 From: malik masis Date: Wed, 8 Jun 2022 16:04:17 +0300 Subject: [PATCH 09/36] set properties dynamically --- .../Shared/Components/Pages/ContentParser.cs | 23 +++++++++++-------- .../Shared/Components/Pages/Default.cshtml | 5 +--- .../Components/Pages/WidgetContentFragment.cs | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs index 8019ae3ac2..e0d53e1b6e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -10,6 +9,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; public class ContentParser : IContentParser, ITransientDependency { + private const string delimeter = "----"; private readonly CmsKitContentWidgetOptions _options; public ContentParser(IOptions options) { @@ -26,7 +26,6 @@ public class ContentParser : IContentParser, ITransientDependency }; } - string delimeter = "----"; var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter); var parsedList = new List(); @@ -56,7 +55,6 @@ public class ContentParser : IContentParser, ITransientDependency { parsedList.Add(replacedText.Substring(0, index)); replacedText = replacedText.Substring(index, replacedText.Length - index); - } else { @@ -64,22 +62,27 @@ public class ContentParser : IContentParser, ITransientDependency } } - var name = _options.WidgetConfigs.FirstOrDefault(p => p.Key == "Poll").Value?.Name; - var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList(); + var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList(); var contentFragments = new List(); + for (int i = 0, k = 0; i < parsedList.Count; i++) { if (parsedList[i] == delimeter) { - contentFragments.Add(new WidgetContentFragment(name) + var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault(); + if (name is not null) { - Properties = + contentFragments.Add(new WidgetContentFragment(name) { - { "name", pollNames[k++] } - } - }); + Properties = + { + { "Name", pollNames[k]} + } + }); + } + k++; } else { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index 45720013b6..3b6e6f0f8c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -18,10 +18,7 @@ } else if (contentFragment is WidgetContentFragment widgetContentFragment) { - @await Component.InvokeAsync(widgetContentFragment.Name, new - { - name = widgetContentFragment.Properties.FirstOrDefault().Value - }) + @await Component.InvokeAsync(widgetContentFragment.Name, widgetContentFragment.Properties) } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs index 125c48a72e..8dea303b0e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs @@ -8,11 +8,11 @@ public class WidgetContentFragment : ContentFragment public string ViewComponentName { get; set; } - public Dictionary Properties { get; } + public IDictionary Properties { get; } public WidgetContentFragment(string name) { Name = name; - Properties = new Dictionary(); + Properties = new Dictionary(); } } \ No newline at end of file From 349471af5eed33320eac502c4cf6bdbe5dd261d0 Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 9 Jun 2022 13:39:08 +0300 Subject: [PATCH 10/36] Added poll for blogpost as well It will be made refactor --- .../CmsKit/Public/Blogs/BlogPostPublicDto.cs | 3 + .../CmsKit/Public/Blogs/ContentFragment.cs | 6 ++ .../Public/Blogs/MarkdownContentFragment.cs | 6 ++ .../Public/Blogs/WidgetContentFragment.cs | 18 ++++ .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 14 ++- .../Public/CmsKit/Blogs/BlogPost.cshtml.cs | 17 ++-- .../Blogs/CmsKitContentWidgetOptions.cs | 18 ++++ .../Public/CmsKit/Blogs/ContentParser.cs | 96 +++++++++++++++++++ .../CmsKit/Blogs/ContentWidgetConfig.cs | 15 +++ .../Public/CmsKit/Blogs/IContentParser.cs | 10 ++ 10 files changed, 192 insertions(+), 11 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs index 8c6a6a01e9..3ce3c3457a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Volo.Abp.Application.Dtos; using Volo.CmsKit.Users; @@ -15,6 +16,8 @@ public class BlogPostPublicDto : AuditedEntityDto public string ShortDescription { get; set; } + public List ContentFragments { get; set; } + public string Content { get; set; } public Guid? CoverImageMediaId { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs new file mode 100644 index 0000000000..e46316399c --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs @@ -0,0 +1,6 @@ +namespace Volo.CmsKit.Public.Blogs; + +public abstract class ContentFragment +{ + +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs new file mode 100644 index 0000000000..79cacf4575 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs @@ -0,0 +1,6 @@ +namespace Volo.CmsKit.Public.Blogs; + +public class MarkdownContentFragment : ContentFragment +{ + public string Content { get; set; } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs new file mode 100644 index 0000000000..11acbf4324 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Volo.CmsKit.Public.Blogs; + +public class WidgetContentFragment : ContentFragment +{ + public string Name { get; } + + public string ViewComponentName { get; set; } + + public IDictionary Properties { get; } + + public WidgetContentFragment(string name) + { + Name = name; + Properties = new Dictionary(); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index 9d8680e96c..2347e1cfc4 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -1,5 +1,6 @@ @page +@using Volo.CmsKit.Public.Blogs @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment @using Volo.CmsKit.Public.Web.Pages @using Volo.Abp.GlobalFeatures @@ -65,11 +66,18 @@ @Model.BlogPost.CreationTime

- @if (!Model.BlogPost.Content.IsNullOrEmpty()) + @foreach (var contentFragment in Model.BlogPost.ContentFragments) { - @Html.Raw(await MarkdownRenderer.RenderAsync(Model.BlogPost.Content)) + if (contentFragment is MarkdownContentFragment markdownContentFragment) + { + @Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content)) + } + else if (contentFragment is WidgetContentFragment widgetContentFragment) + { + @await Component.InvokeAsync(widgetContentFragment.Name, widgetContentFragment.Properties) + } } - +

@if (Model.BlogPost.LastModificationTime != null) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs index dcefb976a4..e1eda83bb7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs @@ -1,11 +1,5 @@ -using Markdig; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Blogs; using Volo.CmsKit.GlobalFeatures; @@ -37,17 +31,24 @@ public class BlogPostModel : CmsKitPublicPageModelBase protected IBlogFeatureAppService BlogFeatureAppService { get; } + private readonly IContentParser _contentParser; + + public BlogPostModel( IBlogPostPublicAppService blogPostPublicAppService, - IBlogFeatureAppService blogFeaturePublicAppService) + IBlogFeatureAppService blogFeaturePublicAppService +, + IContentParser contentParser) { BlogPostPublicAppService = blogPostPublicAppService; BlogFeatureAppService = blogFeaturePublicAppService; + _contentParser = contentParser; } public virtual async Task OnGetAsync() { BlogPost = await BlogPostPublicAppService.GetAsync(BlogSlug, BlogPostSlug); + BlogPost.ContentFragments = await _contentParser.ParseAsync(BlogPost.Content); if (GlobalFeatureManager.Instance.IsEnabled()) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs new file mode 100644 index 0000000000..7a8cc195be --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; + +public class CmsKitContentWidgetOptions +{ + public Dictionary WidgetConfigs { get; } + + public CmsKitContentWidgetOptions() + { + WidgetConfigs = new(); + } + + public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig) + { + WidgetConfigs.Add(name, contentWidgetConfig); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs new file mode 100644 index 0000000000..56439d9d7b --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs @@ -0,0 +1,96 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; +using Volo.CmsKit.Public.Blogs; + +namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; + +public class ContentParser : IContentParser, ITransientDependency +{ + private const string delimeter = "----"; + private readonly CmsKitContentWidgetOptions _options; + public ContentParser(IOptions options) + { + _options = options.Value; + } + + public async Task> ParseAsync(string content) + { + if (!_options.WidgetConfigs.Any()) + { + return new List() + { + new MarkdownContentFragment() { Content = content } + }; + } + + var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter); + + var parsedList = new List(); + + if (!replacedText.Contains(delimeter)) + { + parsedList.Add(replacedText); + } + + while (replacedText.Contains(delimeter)) + { + //For parsing delimeter + var index = replacedText.IndexOf(delimeter); + if (index != 0) + { + parsedList.Add(replacedText.Substring(0, index)); + replacedText = replacedText.Substring(index, replacedText.Length - index); + index = 0; + } + + parsedList.Add(replacedText.Substring(index, delimeter.Length)); + replacedText = replacedText.Substring(delimeter.Length, replacedText.Length - delimeter.Length); + + //for parsing the other side + index = replacedText.IndexOf(delimeter); + if (index != -1) + { + parsedList.Add(replacedText.Substring(0, index)); + replacedText = replacedText.Substring(index, replacedText.Length - index); + } + else + { + parsedList.Add(replacedText); + } + } + + var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList(); + var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList(); + + var contentFragments = new List(); + + for (int i = 0, k = 0; i < parsedList.Count; i++) + { + if (parsedList[i] == delimeter) + { + var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault(); + if (name is not null) + { + contentFragments.Add(new WidgetContentFragment(name) + { + Properties = + { + { "Name", pollNames[k]} + } + }); + } + k++; + } + else + { + contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] }); + } + } + + return contentFragments; + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs new file mode 100644 index 0000000000..7f3e40eac4 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs @@ -0,0 +1,15 @@ +using System; + + +namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; + +public class ContentWidgetConfig +{ + public string Name { get; } + public Type ViewComponentType { get; set; } + + public ContentWidgetConfig(string name) + { + Name = name; + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs new file mode 100644 index 0000000000..6ea786f70f --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.CmsKit.Public.Blogs; + +namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; + +public interface IContentParser +{ + Task> ParseAsync(string content); +} \ No newline at end of file From 7b3442ae5fb4a5c591d5e4b542c31c4cca25c33b Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 9 Jun 2022 17:43:48 +0300 Subject: [PATCH 11/36] Removed duplication and moved to the domain --- .../Volo/CmsKit/Blogs/BlogPostConsts.cs | 4 +- .../Volo/CmsKit/Polls/ContentFragment.cs | 5 + .../Volo/CmsKit/Polls}/IContentParser.cs | 4 +- .../CmsKit/Polls}/MarkdownContentFragment.cs | 4 +- .../Volo/CmsKit/Polls/PollConsts.cs | 5 + .../CmsKit/Polls}/WidgetContentFragment.cs | 9 +- .../Polls}/CmsKitContentWidgetOptions.cs | 4 +- .../Volo/CmsKit/Polls}/ContentParser.cs | 8 +- .../Volo/CmsKit/Polls}/ContentWidgetConfig.cs | 7 +- .../CmsKit/Polls/PollViewComponentManager.cs | 19 ++++ .../CmsKit/Public/Blogs/BlogPostPublicDto.cs | 1 + .../CmsKit/Public/Blogs/ContentFragment.cs | 6 -- .../Polls/IPollViewComponentAppService.cs | 11 +++ .../Polls/PollViewComponentAppService.cs | 20 ++++ .../PollViewComponentClientProxy.Generated.cs | 27 ++++++ .../PollViewComponentClientProxy.cs | 7 ++ .../ClientProxies/cms-kit-generate-proxy.json | 63 ++++++++++++ .../Polls/PollViewComponentController.cs | 27 ++++++ .../Pages/CmsKitContentWidgetOptions.cs | 18 ---- .../Components/Pages/ContentFragment.cs | 6 -- .../Components/Pages/ContentWidgetConfig.cs | 14 --- .../Shared/Components/Pages/Default.cshtml | 2 +- .../Pages/DefaultPageViewComponent.cs | 13 +-- .../Pages/MarkdownContentFragment.cs | 6 -- .../Shared/Components/Pages/PageViewModel.cs | 1 + .../Components/Pages/WidgetContentFragment.cs | 18 ---- .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 1 + .../Public/CmsKit/Blogs/BlogPost.cshtml.cs | 12 +-- .../Public/CmsKit/Blogs/ContentParser.cs | 96 ------------------- .../Public/CmsKit/Blogs/IContentParser.cs | 10 -- 30 files changed, 219 insertions(+), 209 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs rename modules/cms-kit/src/{Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages => Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls}/IContentParser.cs (54%) rename modules/cms-kit/src/{Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs => Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls}/MarkdownContentFragment.cs (72%) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs rename modules/cms-kit/src/{Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs => Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls}/WidgetContentFragment.cs (81%) rename modules/cms-kit/src/{Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs => Volo.CmsKit.Domain/Volo/CmsKit/Polls}/CmsKitContentWidgetOptions.cs (84%) rename modules/cms-kit/src/{Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages => Volo.CmsKit.Domain/Volo/CmsKit/Polls}/ContentParser.cs (93%) rename modules/cms-kit/src/{Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs => Volo.CmsKit.Domain/Volo/CmsKit/Polls}/ContentWidgetConfig.cs (70%) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs index 94a0456c66..99e6ed5b34 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs @@ -1,6 +1,4 @@ -using Volo.CmsKit.GlobalFeatures; - -namespace Volo.CmsKit.Blogs; +namespace Volo.CmsKit.Blogs; public static class BlogPostConsts { diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs new file mode 100644 index 0000000000..403bff4f64 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs @@ -0,0 +1,5 @@ +namespace Volo.CmsKit.Polls; +public abstract class ContentFragment +{ + +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs similarity index 54% rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs rename to modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs index 03e54ea4bb..25bc2e8f64 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/IContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; -namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; +namespace Volo.CmsKit.Polls; public interface IContentParser { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs similarity index 72% rename from modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs rename to modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs index 79cacf4575..0768f325f2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/MarkdownContentFragment.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs @@ -1,6 +1,6 @@ -namespace Volo.CmsKit.Public.Blogs; +namespace Volo.CmsKit.Polls; public class MarkdownContentFragment : ContentFragment { public string Content { get; set; } -} \ No newline at end of file +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs new file mode 100644 index 0000000000..8f8ab97073 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs @@ -0,0 +1,5 @@ +namespace Volo.CmsKit.Polls; +public static class PollConsts +{ + public static string Delimeter { get; } = "----"; +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs similarity index 81% rename from modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs rename to modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs index 11acbf4324..9d0d8c9761 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/WidgetContentFragment.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs @@ -1,11 +1,10 @@ -using System.Collections.Generic; - -namespace Volo.CmsKit.Public.Blogs; +using System.Collections.Generic; +namespace Volo.CmsKit.Polls; public class WidgetContentFragment : ContentFragment { public string Name { get; } - + public string ViewComponentName { get; set; } public IDictionary Properties { get; } @@ -15,4 +14,4 @@ public class WidgetContentFragment : ContentFragment Name = name; Properties = new Dictionary(); } -} \ No newline at end of file +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs similarity index 84% rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs rename to modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs index 7a8cc195be..251cbe463c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/CmsKitContentWidgetOptions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; -namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; +namespace Volo.CmsKit.Polls; public class CmsKitContentWidgetOptions { - public Dictionary WidgetConfigs { get; } + public Dictionary WidgetConfigs { get; } public CmsKitContentWidgetOptions() { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs similarity index 93% rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs rename to modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs index e0d53e1b6e..09bc778021 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; +namespace Volo.CmsKit.Polls; public class ContentParser : IContentParser, ITransientDependency { @@ -62,8 +62,8 @@ public class ContentParser : IContentParser, ITransientDependency } } - var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList(); - var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList(); + var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); + var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); var contentFragments = new List(); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs similarity index 70% rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs rename to modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs index 7f3e40eac4..eb9c6a0656 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentWidgetConfig.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs @@ -1,13 +1,12 @@ -using System; +using System; - -namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; +namespace Volo.CmsKit.Polls; public class ContentWidgetConfig { public string Name { get; } public Type ViewComponentType { get; set; } - + public ContentWidgetConfig(string name) { Name = name; diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs new file mode 100644 index 0000000000..f110597702 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Domain.Services; + +namespace Volo.CmsKit.Polls; +public class PollViewComponentManager : DomainService +{ + protected IContentParser ContentParser { get; set; } + public PollViewComponentManager(IContentParser contentParser) + { + ContentParser = contentParser; + } + + public virtual async Task> ParseAsync(string content) + { + return await ContentParser.ParseAsync(content); + } + +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs index 3ce3c3457a..22fb257d62 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Volo.Abp.Application.Dtos; +using Volo.CmsKit.Polls; using Volo.CmsKit.Users; namespace Volo.CmsKit.Public.Blogs; diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs deleted file mode 100644 index e46316399c..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/ContentFragment.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.CmsKit.Public.Blogs; - -public abstract class ContentFragment -{ - -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs new file mode 100644 index 0000000000..994158e008 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.CmsKit.Polls; + +namespace Volo.CmsKit.Public.Polls; + +public interface IPollViewComponentAppService : IApplicationService +{ + Task> ParseAsync(string content); +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs new file mode 100644 index 0000000000..24f30d6173 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.CmsKit.Polls; + +namespace Volo.CmsKit.Public.Polls; + +public class PollViewComponentAppService : CmsKitPublicAppServiceBase, IPollViewComponentAppService +{ + protected PollViewComponentManager PollViewComponentManager { get; set; } + + public PollViewComponentAppService(PollViewComponentManager pollViewComponentManager) + { + PollViewComponentManager = pollViewComponentManager; + } + + public virtual async Task> ParseAsync(string content) + { + return await PollViewComponentManager.ParseAsync(content); + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs new file mode 100644 index 0000000000..cb841663e7 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs @@ -0,0 +1,27 @@ +// This file is automatically generated by ABP framework to use MVC Controllers from CSharp +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Http.Client; +using Volo.Abp.Http.Modeling; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.ClientProxying; +using Volo.CmsKit.Public.Polls; +using System.Collections.Generic; +using Volo.CmsKit.Polls; + +// ReSharper disable once CheckNamespace +namespace Volo.CmsKit.Public.Polls.ClientProxies; + +[Dependency(ReplaceServices = true)] +[ExposeServices(typeof(IPollViewComponentAppService), typeof(PollViewComponentClientProxy))] +public partial class PollViewComponentClientProxy : ClientProxyBase, IPollViewComponentAppService +{ + public virtual async Task> ParseAsync(string content) + { + return await RequestAsync>(nameof(ParseAsync), new ClientProxyRequestTypeValue + { + { typeof(string), content } + }); + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs new file mode 100644 index 0000000000..b3ba894b58 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs @@ -0,0 +1,7 @@ +// This file is part of PollViewComponentClientProxy, you can customize it here +// ReSharper disable once CheckNamespace +namespace Volo.CmsKit.Public.Polls.ClientProxies; + +public partial class PollViewComponentClientProxy +{ +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json index d39e795845..626dce7ff2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json @@ -505,6 +505,57 @@ } } }, + "Volo.CmsKit.Public.Polls.PollViewComponentController": { + "controllerName": "PollViewComponent", + "controllerGroupName": "PollViewComponent", + "isRemoteService": true, + "apiVersion": null, + "type": "Volo.CmsKit.Public.Polls.PollViewComponentController", + "interfaces": [ + { + "type": "Volo.CmsKit.Public.Polls.IPollViewComponentAppService" + } + ], + "actions": { + "ParseAsyncByContent": { + "uniqueName": "ParseAsyncByContent", + "name": "ParseAsync", + "httpMethod": "GET", + "url": "api/cms-kit-public/polls/{content}", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "content", + "typeAsString": "System.String, System.Private.CoreLib", + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "content", + "name": "content", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "System.Collections.Generic.List", + "typeSimple": "[Volo.CmsKit.Polls.ContentFragment]" + }, + "allowAnonymous": null, + "implementFrom": "Volo.CmsKit.Public.Polls.IPollViewComponentAppService" + } + } + }, "Volo.CmsKit.Public.Pages.PagesPublicController": { "controllerName": "PagesPublic", "controllerGroupName": "PagesPublic", @@ -989,6 +1040,18 @@ "bindingSourceId": "ModelBinding", "descriptorName": "input" }, + { + "nameOnMethod": "input", + "name": "TagId", + "jsonName": null, + "type": "System.Guid?", + "typeSimple": "string?", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "input" + }, { "nameOnMethod": "input", "name": "Sorting", diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs new file mode 100644 index 0000000000..021040fee6 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp; +using Volo.CmsKit.Polls; + +namespace Volo.CmsKit.Public.Polls; + +[RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)] +[Area(CmsKitPublicRemoteServiceConsts.ModuleName)] +[Route("api/cms-kit-public/polls")] +public class PollViewComponentController : CmsKitPublicControllerBase, IPollViewComponentAppService +{ + protected IPollViewComponentAppService PollViewComponentAppService { get; } + + public PollViewComponentController(IPollViewComponentAppService pollViewComponentAppService) + { + PollViewComponentAppService = pollViewComponentAppService; + } + + [HttpGet] + [Route("{content}")] + public virtual Task> ParseAsync(string content) + { + return PollViewComponentAppService.ParseAsync(content); + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs deleted file mode 100644 index d782299026..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/CmsKitContentWidgetOptions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; - -namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; - -public class CmsKitContentWidgetOptions -{ - public Dictionary WidgetConfigs { get; } - - public CmsKitContentWidgetOptions() - { - WidgetConfigs = new(); - } - - public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig) - { - WidgetConfigs.Add(name, contentWidgetConfig); - } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs deleted file mode 100644 index c5486903dd..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentFragment.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; - -public abstract class ContentFragment -{ - -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs deleted file mode 100644 index 647427b330..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/ContentWidgetConfig.cs +++ /dev/null @@ -1,14 +0,0 @@ -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; - } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index 3b6e6f0f8c..2a437dd8fb 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -1,8 +1,8 @@ @addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap +@using Volo.CmsKit.Polls @using Volo.CmsKit.Public.Web.Renderers @using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs -@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages @inject IMarkdownToHtmlRenderer MarkdownRenderer diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs index 914001b073..7449d0329e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs @@ -4,6 +4,7 @@ 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.Public.Polls; namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; @@ -22,20 +23,20 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; })] public class DefaultPageViewComponent : AbpViewComponent { - private readonly IContentParser _contentParser; + protected IPollViewComponentAppService PollViewComponentAppService { get; set; } - public DefaultPageViewComponent(IContentParser contentParser) + public DefaultPageViewComponent(IPollViewComponentAppService pollViewComponentAppService) { - _contentParser = contentParser; + PollViewComponentAppService = pollViewComponentAppService; } - + public virtual async Task InvokeAsync( Guid pageId, string title, string content) { - var contentFragments = await _contentParser.ParseAsync(content); - + var contentFragments = await PollViewComponentAppService.ParseAsync(content); + var model = new PageViewModel { Id = pageId, diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs deleted file mode 100644 index 361a4b3973..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/MarkdownContentFragment.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; - -public class MarkdownContentFragment : ContentFragment -{ - public string Content { get; set; } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs index eae24aeae4..a8dfd40458 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Volo.CmsKit.Polls; namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs deleted file mode 100644 index 8dea303b0e..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/WidgetContentFragment.cs +++ /dev/null @@ -1,18 +0,0 @@ -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 IDictionary Properties { get; } - - public WidgetContentFragment(string name) - { - Name = name; - Properties = new Dictionary(); - } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index 2347e1cfc4..6115f33676 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -1,5 +1,6 @@ @page +@using Volo.CmsKit.Polls @using Volo.CmsKit.Public.Blogs @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment @using Volo.CmsKit.Public.Web.Pages diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs index e1eda83bb7..beea823f79 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs @@ -4,6 +4,7 @@ using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Blogs; using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Public.Blogs; +using Volo.CmsKit.Public.Polls; namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; @@ -31,24 +32,23 @@ public class BlogPostModel : CmsKitPublicPageModelBase protected IBlogFeatureAppService BlogFeatureAppService { get; } - private readonly IContentParser _contentParser; + protected IPollViewComponentAppService PollViewComponentAppService { get; } public BlogPostModel( IBlogPostPublicAppService blogPostPublicAppService, - IBlogFeatureAppService blogFeaturePublicAppService -, - IContentParser contentParser) + IBlogFeatureAppService blogFeaturePublicAppService, + IPollViewComponentAppService pollViewComponentAppService) { BlogPostPublicAppService = blogPostPublicAppService; BlogFeatureAppService = blogFeaturePublicAppService; - _contentParser = contentParser; + PollViewComponentAppService = pollViewComponentAppService; } public virtual async Task OnGetAsync() { BlogPost = await BlogPostPublicAppService.GetAsync(BlogSlug, BlogPostSlug); - BlogPost.ContentFragments = await _contentParser.ParseAsync(BlogPost.Content); + BlogPost.ContentFragments = await PollViewComponentAppService.ParseAsync(BlogPost.Content); if (GlobalFeatureManager.Instance.IsEnabled()) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs deleted file mode 100644 index 56439d9d7b..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/ContentParser.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using Microsoft.Extensions.Options; -using Volo.Abp.DependencyInjection; -using Volo.CmsKit.Public.Blogs; - -namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; - -public class ContentParser : IContentParser, ITransientDependency -{ - private const string delimeter = "----"; - private readonly CmsKitContentWidgetOptions _options; - public ContentParser(IOptions options) - { - _options = options.Value; - } - - public async Task> ParseAsync(string content) - { - if (!_options.WidgetConfigs.Any()) - { - return new List() - { - new MarkdownContentFragment() { Content = content } - }; - } - - var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter); - - var parsedList = new List(); - - if (!replacedText.Contains(delimeter)) - { - parsedList.Add(replacedText); - } - - while (replacedText.Contains(delimeter)) - { - //For parsing delimeter - var index = replacedText.IndexOf(delimeter); - if (index != 0) - { - parsedList.Add(replacedText.Substring(0, index)); - replacedText = replacedText.Substring(index, replacedText.Length - index); - index = 0; - } - - parsedList.Add(replacedText.Substring(index, delimeter.Length)); - replacedText = replacedText.Substring(delimeter.Length, replacedText.Length - delimeter.Length); - - //for parsing the other side - index = replacedText.IndexOf(delimeter); - if (index != -1) - { - parsedList.Add(replacedText.Substring(0, index)); - replacedText = replacedText.Substring(index, replacedText.Length - index); - } - else - { - parsedList.Add(replacedText); - } - } - - var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Select(p => p.Value).ToList(); - var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Select(p => p.Value).ToList(); - - var contentFragments = new List(); - - for (int i = 0, k = 0; i < parsedList.Count; i++) - { - if (parsedList[i] == delimeter) - { - var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault(); - if (name is not null) - { - contentFragments.Add(new WidgetContentFragment(name) - { - Properties = - { - { "Name", pollNames[k]} - } - }); - } - k++; - } - else - { - contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] }); - } - } - - return contentFragments; - } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs deleted file mode 100644 index 6ea786f70f..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/IContentParser.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Volo.CmsKit.Public.Blogs; - -namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; - -public interface IContentParser -{ - Task> ParseAsync(string content); -} \ No newline at end of file From 4ad65e239af718c2712ebd87867847927e1f0953 Mon Sep 17 00:00:00 2001 From: malik masis Date: Fri, 10 Jun 2022 09:56:18 +0300 Subject: [PATCH 12/36] Fixed optional whitespace char issue --- .../src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs index 09bc778021..b586ff80fa 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs @@ -62,8 +62,8 @@ public class ContentParser : IContentParser, ITransientDependency } } - var pollNames = Regex.Matches(content, @"(?<=PollName="")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); - var polls = Regex.Matches(content, @"(?<=Widget Type="")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); + var pollNames = Regex.Matches(content, @"(?<=PollName\s*=\s*"")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); + var polls = Regex.Matches(content, @"(?<=Widget Type\s*=\s*"")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); var contentFragments = new List(); From f727afaa093c4b6dae4a192c20e3539cee8562b9 Mon Sep 17 00:00:00 2001 From: malik masis Date: Fri, 10 Jun 2022 14:36:24 +0300 Subject: [PATCH 13/36] Checked string length --- .../src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs index b586ff80fa..5bbd5a9b24 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs @@ -56,7 +56,7 @@ public class ContentParser : IContentParser, ITransientDependency parsedList.Add(replacedText.Substring(0, index)); replacedText = replacedText.Substring(index, replacedText.Length - index); } - else + else if (replacedText.Length > 0) { parsedList.Add(replacedText); } From 47c809885dcc14c248f74b256a4f89f0132caeec Mon Sep 17 00:00:00 2001 From: malik masis Date: Fri, 10 Jun 2022 14:56:19 +0300 Subject: [PATCH 14/36] Checked range of arrays --- .../Volo/CmsKit/Polls/ContentParser.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs index 5bbd5a9b24..38c0737012 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs @@ -71,16 +71,19 @@ public class ContentParser : IContentParser, ITransientDependency { if (parsedList[i] == delimeter) { - var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault(); - if (name is not null) + if (polls.Count > k) { - contentFragments.Add(new WidgetContentFragment(name) + var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault(); + if (name is not null && pollNames.Count > k) { - Properties = + contentFragments.Add(new WidgetContentFragment(name) { - { "Name", pollNames[k]} - } - }); + Properties = + { + { "Name", pollNames[k]} + } + }); + } } k++; } From 5aca43a2b58ca441c7ff8e568786c8c9c7efb151 Mon Sep 17 00:00:00 2001 From: malik masis Date: Fri, 10 Jun 2022 14:58:51 +0300 Subject: [PATCH 15/36] Added PollViewComponentManager_Test --- .../Polls/PollViewComponentManager_Test.cs | 123 ++++++++++++++++++ .../Volo.CmsKit.TestBase/CmsKitTestData.cs | 4 + 2 files changed, 127 insertions(+) create mode 100644 modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs new file mode 100644 index 0000000000..67ae5982f1 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using Shouldly; +using Xunit; + +namespace Volo.CmsKit.Polls; + +public class PollViewComponentManager_Test : CmsKitDomainTestBase +{ + private readonly PollViewComponentManager pollManager; + private readonly CmsKitTestData testData; + private readonly IOptions _options; + + public PollViewComponentManager_Test() + { + pollManager = GetRequiredService(); + testData = GetRequiredService(); + _options = GetRequiredService>(); + } + + [Fact] + public async Task ParseAsync_ShouldWorkWithoutConfigOptions() + { + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type= ""Poll"" PollName =""poll-name""] + Thanks _for_ *your * feedback."; + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(1);//Ignored Widget + } + + [Fact] + public async Task ParseAsync_ShouldWorkWithWrongConfigOptions() + { + _options.Value.AddWidgetConfig(testData.WidgetName, new ContentWidgetConfig(testData.PollName)); + + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type= ""Poll"" PollName =""poll-name""] + Thanks _for_ *your * feedback."; + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(2); + } + + [Fact] + public async Task ParseAsync_ShouldWorkWithWrongWidgetType() + { + _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Wrong Type= ""Poll"" PollName =""poll-name""] + Thanks _for_ *your * feedback."; + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(2); + } + + [Fact] + public async Task ParseAsync_ShouldWorkWithWrongPollName() + { + _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type= ""Poll"" PollWrongName =""poll-name""] + Thanks _for_ *your * feedback."; + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(2); + } + + [Theory] + [MemberData(nameof(ExampleData))] + public async Task ParseAsync_ShouldWorkProperlyWithCorrectInputs(string content, int expectedLine) + { + _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(expectedLine); + } + + public static IEnumerable ExampleData => + new List + { + new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type=""Poll"" PollName=""poll-name""] + Thanks _for_ *your * feedback.", 3}, + + new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type=""Poll"" PollName=""poll-name""] + Thanks _for_ *your * feedback. + [Widget Type=""Poll"" PollName=""poll-name1""]", 4 }, + + new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. + Thanks _for_ *your * feedback. + [Widget Type=""Poll"" PollName=""poll-name""]", 2 }, + + new object[] { @"[Widget Type=""Poll"" PollName=""poll-name""] gg [Widget Type=""Poll"" PollName=""poll-name1""]**ABP Framework** is completely open source and developed in a community-driven manner. + Thanks _for_ *your * feedback. + Thanks _for_ *your * feedback.", 4}, + + new object[] { @"Thanks _for_ *your * feedback. + Thanks _for_ *your * feedback.", 1} + }; + +} + + + + + + diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs index d47f139560..6445fb86f4 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs @@ -127,4 +127,8 @@ public class CmsKitTestData : ISingletonDependency public string MenuItem_3_Name { get; } = "Products"; public string MenuItem_3_Url { get; } = "/products"; + + public string PollName { get; } = "Poll"; + + public string WidgetName { get; } = "CmsPollByName"; } From 4c7e4c8e2e578b3e5fafb0b23620b4701f9aa8bc Mon Sep 17 00:00:00 2001 From: malik masis Date: Sun, 12 Jun 2022 00:22:53 +0300 Subject: [PATCH 16/36] Fixed typo of the variable name --- .../Polls/PollViewComponentManager_Test.cs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs index 67ae5982f1..dbe91f2f14 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Options; using Shouldly; @@ -27,10 +26,10 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase [Widget Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var page = await pollManager.ParseAsync(content); + var poll = await pollManager.ParseAsync(content); - page.ShouldNotBeNull(); - page.Count.ShouldBe(1);//Ignored Widget + poll.ShouldNotBeNull(); + poll.Count.ShouldBe(1);//Ignored Widget } [Fact] @@ -42,10 +41,10 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase [Widget Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var page = await pollManager.ParseAsync(content); + var poll = await pollManager.ParseAsync(content); - page.ShouldNotBeNull(); - page.Count.ShouldBe(2); + poll.ShouldNotBeNull(); + poll.Count.ShouldBe(2); } [Fact] @@ -57,10 +56,10 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase [Widget Wrong Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var page = await pollManager.ParseAsync(content); + var poll = await pollManager.ParseAsync(content); - page.ShouldNotBeNull(); - page.Count.ShouldBe(2); + poll.ShouldNotBeNull(); + poll.Count.ShouldBe(2); } [Fact] @@ -72,22 +71,22 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase [Widget Type= ""Poll"" PollWrongName =""poll-name""] Thanks _for_ *your * feedback."; - var page = await pollManager.ParseAsync(content); + var poll = await pollManager.ParseAsync(content); - page.ShouldNotBeNull(); - page.Count.ShouldBe(2); + poll.ShouldNotBeNull(); + poll.Count.ShouldBe(2); } [Theory] - [MemberData(nameof(ExampleData))] + [MemberData(nameof(ExampleData))] public async Task ParseAsync_ShouldWorkProperlyWithCorrectInputs(string content, int expectedLine) { _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); - var page = await pollManager.ParseAsync(content); + var poll = await pollManager.ParseAsync(content); - page.ShouldNotBeNull(); - page.Count.ShouldBe(expectedLine); + poll.ShouldNotBeNull(); + poll.Count.ShouldBe(expectedLine); } public static IEnumerable ExampleData => From 57ec03370a2fdf22d0cb43f93904b1895de4ba84 Mon Sep 17 00:00:00 2001 From: malik masis Date: Mon, 13 Jun 2022 15:20:49 +0300 Subject: [PATCH 17/36] Changed the widget structure --- .../CmsKit/Polls/WidgetContentFragment.cs | 2 +- .../Volo/CmsKit/Polls/ContentParser.cs | 43 +++++++++++++++---- .../Polls/PollViewComponentManager_Test.cs | 17 ++++++++ 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs index 9d0d8c9761..115e69e134 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs @@ -7,7 +7,7 @@ public class WidgetContentFragment : ContentFragment public string ViewComponentName { get; set; } - public IDictionary Properties { get; } + public IDictionary Properties { get; set; } public WidgetContentFragment(string name) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs index 38c0737012..b207a4731a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs @@ -62,8 +62,9 @@ public class ContentParser : IContentParser, ITransientDependency } } - var pollNames = Regex.Matches(content, @"(?<=PollName\s*=\s*"")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); - var polls = Regex.Matches(content, @"(?<=Widget Type\s*=\s*"")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); + + Dictionary>> parsedWidgets = new(); + ParseWidgets(content, parsedWidgets); var contentFragments = new List(); @@ -71,17 +72,23 @@ public class ContentParser : IContentParser, ITransientDependency { if (parsedList[i] == delimeter) { - if (polls.Count > k) + var values = parsedWidgets.GetOrDefault($"{k}.Widget").Select(p => p.Value).ToList(); + var keys = parsedWidgets.GetOrDefault($"{k}.Widget").Select(p => p.Key).ToList(); + + if (parsedWidgets.Count > k) { - var name = _options.WidgetConfigs.Where(p => p.Key == polls[k]).Select(p => p.Value.Name).FirstOrDefault(); - if (name is not null && pollNames.Count > k) + var name = _options.WidgetConfigs.Where(p => p.Key == values[0]).Select(p => p.Value.Name).FirstOrDefault(); + if (name is not null && parsedWidgets.Count > k) { + var properties = new Dictionary(); + for (int kv = 0; kv < values.Count; kv++) + { + properties.Add(keys[kv], values[kv]); + } + contentFragments.Add(new WidgetContentFragment(name) { - Properties = - { - { "Name", pollNames[k]} - } + Properties = properties }); } } @@ -95,4 +102,22 @@ public class ContentParser : IContentParser, ITransientDependency return contentFragments; } + + private void ParseWidgets(string content, Dictionary>> parsedWidgets) + { + var widgets = Regex.Matches(content, @"(?<=\[Widget)(.*?)(?=\])").Cast().Select(p => p.Value).ToList(); + for (int p = 0; p < widgets.Count; p++) + { + var preparedContent = string.Join("", widgets[p]); + var keys = Regex.Matches(preparedContent, @"(?<=[\[Widget]?\s)(.*?)(?=="")").Cast().Select(p => p.Value).Where(p => p != string.Empty).ToList(); + var values = Regex.Matches(preparedContent, @"(?<=\s*[a-zA-Z]*=\s*"")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); + + var list = new List>(); + for (int kv = 0; kv < keys.Count; kv++) + { + list.Add(new KeyValuePair(keys[kv], values[kv])); + } + parsedWidgets.Add($"{p}.Widget", list); + } + } } \ No newline at end of file diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs index dbe91f2f14..3b0c4aee14 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs @@ -19,6 +19,23 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase _options = GetRequiredService>(); } + [Fact] + public async Task AA_ParseAsync_ShouldWorkMoreDynamically() + { + _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + _options.Value.AddWidgetConfig("ImageGallery", new ContentWidgetConfig("ImageGallery"));//test + + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type=""Poll"" PollName =""poll-name""] + Thanks _for_ *your * feedback. + [Widget Type=""ImageGallery"" GalleryName=""Xyz"" Source=""GoogleDrive""]"; + + var poll = await pollManager.ParseAsync(content); + + poll.ShouldNotBeNull(); + poll.Count.ShouldBe(4); + } + [Fact] public async Task ParseAsync_ShouldWorkWithoutConfigOptions() { From 16f753270cdbebc6e96ee64052bbcf14d4740101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 13 Jun 2022 16:07:06 +0300 Subject: [PATCH 18/36] Revised content fragments --- .../Volo/CmsKit/Contents/ContentFragment.cs | 10 +++++++ .../Volo/CmsKit/Contents}/ContentParser.cs | 22 ++++++++++++--- .../Contents}/MarkdownContentFragment.cs | 2 +- .../CmsKit/Contents}/WidgetContentFragment.cs | 2 +- .../Volo/CmsKit/Polls/ContentFragment.cs | 5 ---- .../Volo/CmsKit/Polls/IContentParser.cs | 9 ------- .../CmsKit/Polls/PollViewComponentManager.cs | 19 ------------- .../CmsKit/Public/Blogs/BlogPostPublicDto.cs | 1 + .../Volo/CmsKit/Public/Pages/PageDto.cs | 4 +++ .../Polls/IPollViewComponentAppService.cs | 11 -------- .../Public/Blogs/BlogPostPublicAppService.cs | 14 +++++++--- .../Public/Pages/PagePublicAppService.cs | 9 +++++-- .../Polls/PollViewComponentAppService.cs | 20 -------------- .../PublicApplicationAutoMapperProfile.cs | 3 ++- .../PollViewComponentClientProxy.Generated.cs | 27 ------------------- .../PollViewComponentClientProxy.cs | 7 ----- .../Polls/PollViewComponentController.cs | 27 ------------------- .../Shared/Components/Pages/Default.cshtml | 14 +++++----- .../Pages/DefaultPageViewComponent.cs | 17 ++++-------- .../Shared/Components/Pages/PageViewModel.cs | 1 + .../Public/CmsKit/Blogs/BlogPost.cshtml.cs | 9 +------ .../Pages/Public/CmsKit/Pages/Index.cshtml | 4 ++- .../Polls/PollViewComponentManager_Test.cs | 5 ++-- 23 files changed, 74 insertions(+), 168 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentFragment.cs rename modules/cms-kit/src/{Volo.CmsKit.Domain/Volo/CmsKit/Polls => Volo.CmsKit.Common.Application/Volo/CmsKit/Contents}/ContentParser.cs (84%) rename modules/cms-kit/src/{Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls => Volo.CmsKit.Common.Application/Volo/CmsKit/Contents}/MarkdownContentFragment.cs (74%) rename modules/cms-kit/src/{Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls => Volo.CmsKit.Common.Application/Volo/CmsKit/Contents}/WidgetContentFragment.cs (92%) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentFragment.cs new file mode 100644 index 0000000000..20574f830c --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentFragment.cs @@ -0,0 +1,10 @@ +using System; +using Volo.Abp.ObjectExtending; + +namespace Volo.CmsKit.Contents; + +[Serializable] +public class ContentFragment : ExtensibleObject +{ + public string Type { get; set; } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs similarity index 84% rename from modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs index b207a4731a..c4da64a986 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs @@ -3,14 +3,17 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Options; +using Volo.Abp.Data; using Volo.Abp.DependencyInjection; +using Volo.CmsKit.Polls; -namespace Volo.CmsKit.Polls; +namespace Volo.CmsKit.Contents; -public class ContentParser : IContentParser, ITransientDependency +public class ContentParser : ITransientDependency { private const string delimeter = "----"; private readonly CmsKitContentWidgetOptions _options; + public ContentParser(IOptions options) { _options = options.Value; @@ -18,6 +21,13 @@ public class ContentParser : IContentParser, ITransientDependency public async Task> ParseAsync(string content) { + return new List { + new ContentFragment() { Type = "Markdown" }.SetProperty("Content", "This is *a markdown* text."), + new ContentFragment() { Type = "Widget" }.SetProperty("Type", "Poll").SetProperty("Code", "6dhah8dd"), + new ContentFragment() { Type = "Markdown" }.SetProperty("Content", "This is *another markdown* text.") + }; + + /* if (!_options.WidgetConfigs.Any()) { return new List() @@ -101,6 +111,7 @@ public class ContentParser : IContentParser, ITransientDependency } return contentFragments; + */ } private void ParseWidgets(string content, Dictionary>> parsedWidgets) @@ -109,14 +120,17 @@ public class ContentParser : IContentParser, ITransientDependency for (int p = 0; p < widgets.Count; p++) { var preparedContent = string.Join("", widgets[p]); - var keys = Regex.Matches(preparedContent, @"(?<=[\[Widget]?\s)(.*?)(?=="")").Cast().Select(p => p.Value).Where(p => p != string.Empty).ToList(); - var values = Regex.Matches(preparedContent, @"(?<=\s*[a-zA-Z]*=\s*"")(.*?)(?="")").Cast().Select(p => p.Value).ToList(); + var keys = Regex.Matches(preparedContent, @"(?<=[\[Widget]?\s)(.*?)(?=="")").Cast() + .Select(p => p.Value).Where(p => p != string.Empty).ToList(); + var values = Regex.Matches(preparedContent, @"(?<=\s*[a-zA-Z]*=\s*"")(.*?)(?="")").Cast() + .Select(p => p.Value).ToList(); var list = new List>(); for (int kv = 0; kv < keys.Count; kv++) { list.Add(new KeyValuePair(keys[kv], values[kv])); } + parsedWidgets.Add($"{p}.Widget", list); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/MarkdownContentFragment.cs similarity index 74% rename from modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/MarkdownContentFragment.cs index 0768f325f2..6aeaa323ba 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/MarkdownContentFragment.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/MarkdownContentFragment.cs @@ -1,4 +1,4 @@ -namespace Volo.CmsKit.Polls; +namespace Volo.CmsKit.Contents; public class MarkdownContentFragment : ContentFragment { diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/WidgetContentFragment.cs similarity index 92% rename from modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/WidgetContentFragment.cs index 115e69e134..8b5e697418 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/WidgetContentFragment.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/WidgetContentFragment.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Volo.CmsKit.Polls; +namespace Volo.CmsKit.Contents; public class WidgetContentFragment : ContentFragment { public string Name { get; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs deleted file mode 100644 index 403bff4f64..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/ContentFragment.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Volo.CmsKit.Polls; -public abstract class ContentFragment -{ - -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs deleted file mode 100644 index 25bc2e8f64..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/IContentParser.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Volo.CmsKit.Polls; - -public interface IContentParser -{ - Task> ParseAsync(string content); -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs deleted file mode 100644 index f110597702..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/PollViewComponentManager.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Volo.Abp.Domain.Services; - -namespace Volo.CmsKit.Polls; -public class PollViewComponentManager : DomainService -{ - protected IContentParser ContentParser { get; set; } - public PollViewComponentManager(IContentParser contentParser) - { - ContentParser = contentParser; - } - - public virtual async Task> ParseAsync(string content) - { - return await ContentParser.ParseAsync(content); - } - -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs index 22fb257d62..06e7eec7a5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Volo.Abp.Application.Dtos; +using Volo.CmsKit.Contents; using Volo.CmsKit.Polls; using Volo.CmsKit.Users; diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/PageDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/PageDto.cs index 64175d0f18..a336844289 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/PageDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/PageDto.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using Volo.Abp.Application.Dtos; +using Volo.CmsKit.Contents; namespace Volo.CmsKit.Public.Pages; @@ -11,6 +13,8 @@ public class PageDto : EntityDto public string Slug { get; set; } public string Content { get; set; } + + public List ContentFragments { get; set; } public string Script { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs deleted file mode 100644 index 994158e008..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Polls/IPollViewComponentAppService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Volo.Abp.Application.Services; -using Volo.CmsKit.Polls; - -namespace Volo.CmsKit.Public.Polls; - -public interface IPollViewComponentAppService : IApplicationService -{ - Task> ParseAsync(string content); -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs index 65e6c6fa20..ebdda3d293 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Blogs; +using Volo.CmsKit.Contents; using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Users; @@ -16,22 +17,29 @@ public class BlogPostPublicAppService : CmsKitPublicAppServiceBase, IBlogPostPub protected IBlogRepository BlogRepository { get; } protected IBlogPostRepository BlogPostRepository { get; } + protected ContentParser ContentParser { get; } public BlogPostPublicAppService( IBlogRepository blogRepository, - IBlogPostRepository blogPostRepository) + IBlogPostRepository blogPostRepository, + ContentParser contentParser) { BlogRepository = blogRepository; BlogPostRepository = blogPostRepository; + ContentParser = contentParser; } - public virtual async Task GetAsync([NotNull] string blogSlug, [NotNull] string blogPostSlug) + public virtual async Task GetAsync( + [NotNull] string blogSlug, [NotNull] string blogPostSlug) { var blog = await BlogRepository.GetBySlugAsync(blogSlug); var blogPost = await BlogPostRepository.GetBySlugAsync(blog.Id, blogPostSlug); - return ObjectMapper.Map(blogPost); + var blogPostDto = ObjectMapper.Map(blogPost); + blogPostDto.ContentFragments = await ContentParser.ParseAsync(blogPost.Content); + + return blogPostDto; } public virtual async Task> GetListAsync([NotNull] string blogSlug, BlogPostGetListInput input) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs index 258ef935ed..2bae7c350f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Volo.Abp.GlobalFeatures; +using Volo.CmsKit.Contents; using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Pages; @@ -9,10 +10,12 @@ namespace Volo.CmsKit.Public.Pages; public class PagePublicAppService : CmsKitPublicAppServiceBase, IPagePublicAppService { protected IPageRepository PageRepository { get; } + protected ContentParser ContentParser { get; } - public PagePublicAppService(IPageRepository pageRepository) + public PagePublicAppService(IPageRepository pageRepository, ContentParser contentParser) { PageRepository = pageRepository; + ContentParser = contentParser; } public virtual async Task FindBySlugAsync(string slug) @@ -24,6 +27,8 @@ public class PagePublicAppService : CmsKitPublicAppServiceBase, IPagePublicAppSe return null; } - return ObjectMapper.Map(page); + var pageDto = ObjectMapper.Map(page); + pageDto.ContentFragments = await ContentParser.ParseAsync(page.Content); + return pageDto; } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs deleted file mode 100644 index 24f30d6173..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Polls/PollViewComponentAppService.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Volo.CmsKit.Polls; - -namespace Volo.CmsKit.Public.Polls; - -public class PollViewComponentAppService : CmsKitPublicAppServiceBase, IPollViewComponentAppService -{ - protected PollViewComponentManager PollViewComponentManager { get; set; } - - public PollViewComponentAppService(PollViewComponentManager pollViewComponentManager) - { - PollViewComponentManager = pollViewComponentManager; - } - - public virtual async Task> ParseAsync(string content) - { - return await PollViewComponentManager.ParseAsync(content); - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs index a6b7e497ac..a242e28c3b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs @@ -32,7 +32,8 @@ public class PublicApplicationAutoMapperProfile : Profile CreateMap(); - CreateMap(MemberList.None); + CreateMap(MemberList.None) //TODO: Remove MemberList.None (enable validation) + .Ignore(x => x.ContentFragments); CreateMap(); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs deleted file mode 100644 index cb841663e7..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.Generated.cs +++ /dev/null @@ -1,27 +0,0 @@ -// This file is automatically generated by ABP framework to use MVC Controllers from CSharp -using System; -using System.Threading.Tasks; -using Volo.Abp.Application.Dtos; -using Volo.Abp.Http.Client; -using Volo.Abp.Http.Modeling; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Http.Client.ClientProxying; -using Volo.CmsKit.Public.Polls; -using System.Collections.Generic; -using Volo.CmsKit.Polls; - -// ReSharper disable once CheckNamespace -namespace Volo.CmsKit.Public.Polls.ClientProxies; - -[Dependency(ReplaceServices = true)] -[ExposeServices(typeof(IPollViewComponentAppService), typeof(PollViewComponentClientProxy))] -public partial class PollViewComponentClientProxy : ClientProxyBase, IPollViewComponentAppService -{ - public virtual async Task> ParseAsync(string content) - { - return await RequestAsync>(nameof(ParseAsync), new ClientProxyRequestTypeValue - { - { typeof(string), content } - }); - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs deleted file mode 100644 index b3ba894b58..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/PollViewComponentClientProxy.cs +++ /dev/null @@ -1,7 +0,0 @@ -// This file is part of PollViewComponentClientProxy, you can customize it here -// ReSharper disable once CheckNamespace -namespace Volo.CmsKit.Public.Polls.ClientProxies; - -public partial class PollViewComponentClientProxy -{ -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs deleted file mode 100644 index 021040fee6..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Polls/PollViewComponentController.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Volo.Abp; -using Volo.CmsKit.Polls; - -namespace Volo.CmsKit.Public.Polls; - -[RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)] -[Area(CmsKitPublicRemoteServiceConsts.ModuleName)] -[Route("api/cms-kit-public/polls")] -public class PollViewComponentController : CmsKitPublicControllerBase, IPollViewComponentAppService -{ - protected IPollViewComponentAppService PollViewComponentAppService { get; } - - public PollViewComponentController(IPollViewComponentAppService pollViewComponentAppService) - { - PollViewComponentAppService = pollViewComponentAppService; - } - - [HttpGet] - [Route("{content}")] - public virtual Task> ParseAsync(string content) - { - return PollViewComponentAppService.ParseAsync(content); - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index 2a437dd8fb..a7a6d70766 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -1,8 +1,8 @@ @addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap -@using Volo.CmsKit.Polls @using Volo.CmsKit.Public.Web.Renderers -@using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs +@using Volo.Abp.Data +@using Volo.CmsKit.Contents @inject IMarkdownToHtmlRenderer MarkdownRenderer @@ -10,15 +10,15 @@ - @foreach (var contentFragment in Model.ContentFragments) + @foreach (ContentFragment contentFragment in Model.ContentFragments) { - if (contentFragment is MarkdownContentFragment markdownContentFragment) + if (contentFragment.Type == "Markdown") //TODO: Constant { - @Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content)) + @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) } - else if (contentFragment is WidgetContentFragment widgetContentFragment) + else if (contentFragment.Type == "Widget") //TODO: Constant { - @await Component.InvokeAsync(widgetContentFragment.Name, widgetContentFragment.Properties) + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties) } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs index 7449d0329e..43706cee56 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs @@ -1,10 +1,11 @@ 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.Public.Polls; +using Volo.CmsKit.Contents; namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; @@ -21,22 +22,14 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; { "/Pages/Public/CmsKit/highlightOnLoad.js" })] -public class DefaultPageViewComponent : AbpViewComponent +public class DefaultPageViewComponent : AbpViewComponent //TODO: Remove component, directly render in the page { - protected IPollViewComponentAppService PollViewComponentAppService { get; set; } - - public DefaultPageViewComponent(IPollViewComponentAppService pollViewComponentAppService) - { - PollViewComponentAppService = pollViewComponentAppService; - } - public virtual async Task InvokeAsync( Guid pageId, string title, - string content) + string content, + List contentFragments) { - var contentFragments = await PollViewComponentAppService.ParseAsync(content); - var model = new PageViewModel { Id = pageId, diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs index a8dfd40458..acd5ed2447 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Volo.CmsKit.Contents; using Volo.CmsKit.Polls; namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs index beea823f79..6227190ab8 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml.cs @@ -4,7 +4,6 @@ using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Blogs; using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Public.Blogs; -using Volo.CmsKit.Public.Polls; namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; @@ -32,23 +31,17 @@ public class BlogPostModel : CmsKitPublicPageModelBase protected IBlogFeatureAppService BlogFeatureAppService { get; } - protected IPollViewComponentAppService PollViewComponentAppService { get; } - - public BlogPostModel( IBlogPostPublicAppService blogPostPublicAppService, - IBlogFeatureAppService blogFeaturePublicAppService, - IPollViewComponentAppService pollViewComponentAppService) + IBlogFeatureAppService blogFeaturePublicAppService) { BlogPostPublicAppService = blogPostPublicAppService; BlogFeatureAppService = blogFeaturePublicAppService; - PollViewComponentAppService = pollViewComponentAppService; } public virtual async Task OnGetAsync() { BlogPost = await BlogPostPublicAppService.GetAsync(BlogSlug, BlogPostSlug); - BlogPost.ContentFragments = await PollViewComponentAppService.ParseAsync(BlogPost.Content); if (GlobalFeatureManager.Instance.IsEnabled()) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml index a3f1d0c95e..5296315e1c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml @@ -1,5 +1,6 @@ @page @using Microsoft.AspNetCore.Mvc.Localization +@using Volo.CmsKit.Contents @using Volo.CmsKit.Localization @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages @@ -27,5 +28,6 @@ { pageId = Model.Page.Id, title = Model.Page.Title, - content = Model.Page.Content + content = Model.Page.Content, + contentFragments = Model.Page.ContentFragments }) \ No newline at end of file diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs index 3b0c4aee14..272821cb9e 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs @@ -8,17 +8,16 @@ namespace Volo.CmsKit.Polls; public class PollViewComponentManager_Test : CmsKitDomainTestBase { - private readonly PollViewComponentManager pollManager; private readonly CmsKitTestData testData; private readonly IOptions _options; public PollViewComponentManager_Test() { - pollManager = GetRequiredService(); testData = GetRequiredService(); _options = GetRequiredService>(); } + /* TODO: Enable again [Fact] public async Task AA_ParseAsync_ShouldWorkMoreDynamically() { @@ -129,7 +128,7 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase new object[] { @"Thanks _for_ *your * feedback. Thanks _for_ *your * feedback.", 1} }; - +*/ } From 0fc407f723db73149fd06a6badc3133fba38797d Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 10:18:51 +0300 Subject: [PATCH 19/36] Moved unit test to app layer --- .../Contents/ContentParser_Test.cs} | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) rename modules/cms-kit/test/{Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs => Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs} (87%) diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs similarity index 87% rename from modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs rename to modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs index 272821cb9e..f1b877bac8 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs @@ -2,22 +2,23 @@ using System.Threading.Tasks; using Microsoft.Extensions.Options; using Shouldly; +using Volo.CmsKit.Polls; using Xunit; -namespace Volo.CmsKit.Polls; - -public class PollViewComponentManager_Test : CmsKitDomainTestBase +namespace Volo.CmsKit.Contents; +public class ContentParser_Test : CmsKitDomainTestBase { private readonly CmsKitTestData testData; private readonly IOptions _options; + private readonly ContentParser contentParser; - public PollViewComponentManager_Test() + public ContentParser_Test() { testData = GetRequiredService(); _options = GetRequiredService>(); + contentParser = GetRequiredService(); } - /* TODO: Enable again [Fact] public async Task AA_ParseAsync_ShouldWorkMoreDynamically() { @@ -29,10 +30,10 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase Thanks _for_ *your * feedback. [Widget Type=""ImageGallery"" GalleryName=""Xyz"" Source=""GoogleDrive""]"; - var poll = await pollManager.ParseAsync(content); + var widgets = await contentParser.ParseAsync(content); - poll.ShouldNotBeNull(); - poll.Count.ShouldBe(4); + widgets.ShouldNotBeNull(); + widgets.Count.ShouldBe(4); } [Fact] @@ -42,7 +43,7 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase [Widget Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var poll = await pollManager.ParseAsync(content); + var poll = await contentParser.ParseAsync(content); poll.ShouldNotBeNull(); poll.Count.ShouldBe(1);//Ignored Widget @@ -57,7 +58,7 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase [Widget Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var poll = await pollManager.ParseAsync(content); + var poll = await contentParser.ParseAsync(content); poll.ShouldNotBeNull(); poll.Count.ShouldBe(2); @@ -72,7 +73,7 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase [Widget Wrong Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var poll = await pollManager.ParseAsync(content); + var poll = await contentParser.ParseAsync(content); poll.ShouldNotBeNull(); poll.Count.ShouldBe(2); @@ -87,7 +88,7 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase [Widget Type= ""Poll"" PollWrongName =""poll-name""] Thanks _for_ *your * feedback."; - var poll = await pollManager.ParseAsync(content); + var poll = await contentParser.ParseAsync(content); poll.ShouldNotBeNull(); poll.Count.ShouldBe(2); @@ -99,7 +100,7 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase { _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); - var poll = await pollManager.ParseAsync(content); + var poll = await contentParser.ParseAsync(content); poll.ShouldNotBeNull(); poll.Count.ShouldBe(expectedLine); @@ -128,11 +129,4 @@ public class PollViewComponentManager_Test : CmsKitDomainTestBase new object[] { @"Thanks _for_ *your * feedback. Thanks _for_ *your * feedback.", 1} }; -*/ } - - - - - - From 69c0a539a20aaad3093a70e59cb501e53b112622 Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 10:19:58 +0300 Subject: [PATCH 20/36] Fixed unbuildable code --- .../Volo/CmsKit/Polls/PollConsts.cs | 5 ----- .../Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs | 1 - .../CmsKit/Shared/Components/Pages/PageViewModel.cs | 1 - .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 10 +++++----- 4 files changed, 5 insertions(+), 12 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs deleted file mode 100644 index 8f8ab97073..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Polls/PollConsts.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Volo.CmsKit.Polls; -public static class PollConsts -{ - public static string Delimeter { get; } = "----"; -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs index 06e7eec7a5..695f50836e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostPublicDto.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using Volo.Abp.Application.Dtos; using Volo.CmsKit.Contents; -using Volo.CmsKit.Polls; using Volo.CmsKit.Users; namespace Volo.CmsKit.Public.Blogs; diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs index acd5ed2447..8dcc71c3b2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Volo.CmsKit.Contents; -using Volo.CmsKit.Polls; namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages; diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index 6115f33676..c6fabf0f81 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -1,6 +1,6 @@ @page -@using Volo.CmsKit.Polls +@using Volo.Abp.Data @using Volo.CmsKit.Public.Blogs @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment @using Volo.CmsKit.Public.Web.Pages @@ -69,13 +69,13 @@

@foreach (var contentFragment in Model.BlogPost.ContentFragments) { - if (contentFragment is MarkdownContentFragment markdownContentFragment) + if (contentFragment.Type == "Markdown") //TODO: Constant { - @Html.Raw(await MarkdownRenderer.RenderAsync(markdownContentFragment.Content)) + @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) } - else if (contentFragment is WidgetContentFragment widgetContentFragment) + else if (contentFragment.Type == "Widget") //TODO: Constant { - @await Component.InvokeAsync(widgetContentFragment.Name, widgetContentFragment.Properties) + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties) } } From 9fba0fa717ee98839c13a6a6bb860f091eb0383b Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 10:28:20 +0300 Subject: [PATCH 21/36] Fixed creating instance wrongly --- .../Contents/ContentParser_Test.cs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs index f1b877bac8..00dc4c184e 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs @@ -10,13 +10,12 @@ public class ContentParser_Test : CmsKitDomainTestBase { private readonly CmsKitTestData testData; private readonly IOptions _options; - private readonly ContentParser contentParser; + private ContentParser contentParser; public ContentParser_Test() { testData = GetRequiredService(); _options = GetRequiredService>(); - contentParser = GetRequiredService(); } [Fact] @@ -24,6 +23,7 @@ public class ContentParser_Test : CmsKitDomainTestBase { _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); _options.Value.AddWidgetConfig("ImageGallery", new ContentWidgetConfig("ImageGallery"));//test + contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. [Widget Type=""Poll"" PollName =""poll-name""] @@ -43,55 +43,58 @@ public class ContentParser_Test : CmsKitDomainTestBase [Widget Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var poll = await contentParser.ParseAsync(content); + var widgets = await contentParser.ParseAsync(content); - poll.ShouldNotBeNull(); - poll.Count.ShouldBe(1);//Ignored Widget + widgets.ShouldNotBeNull(); + widgets.Count.ShouldBe(1);//Ignored Widget } [Fact] public async Task ParseAsync_ShouldWorkWithWrongConfigOptions() { _options.Value.AddWidgetConfig(testData.WidgetName, new ContentWidgetConfig(testData.PollName)); + contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. [Widget Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var poll = await contentParser.ParseAsync(content); + var widgets = await contentParser.ParseAsync(content); - poll.ShouldNotBeNull(); - poll.Count.ShouldBe(2); + widgets.ShouldNotBeNull(); + widgets.Count.ShouldBe(2); } [Fact] public async Task ParseAsync_ShouldWorkWithWrongWidgetType() { _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. [Widget Wrong Type= ""Poll"" PollName =""poll-name""] Thanks _for_ *your * feedback."; - var poll = await contentParser.ParseAsync(content); + var widgets = await contentParser.ParseAsync(content); - poll.ShouldNotBeNull(); - poll.Count.ShouldBe(2); + widgets.ShouldNotBeNull(); + widgets.Count.ShouldBe(2); } [Fact] public async Task ParseAsync_ShouldWorkWithWrongPollName() { _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. [Widget Type= ""Poll"" PollWrongName =""poll-name""] Thanks _for_ *your * feedback."; - var poll = await contentParser.ParseAsync(content); + var widgets = await contentParser.ParseAsync(content); - poll.ShouldNotBeNull(); - poll.Count.ShouldBe(2); + widgets.ShouldNotBeNull(); + widgets.Count.ShouldBe(2); } [Theory] @@ -99,11 +102,12 @@ public class ContentParser_Test : CmsKitDomainTestBase public async Task ParseAsync_ShouldWorkProperlyWithCorrectInputs(string content, int expectedLine) { _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + contentParser = new ContentParser(_options); - var poll = await contentParser.ParseAsync(content); + var widgets = await contentParser.ParseAsync(content); - poll.ShouldNotBeNull(); - poll.Count.ShouldBe(expectedLine); + widgets.ShouldNotBeNull(); + widgets.Count.ShouldBe(expectedLine); } public static IEnumerable ExampleData => From 5058d57ec3839b99b127680b540671dd25ad56c8 Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 10:37:45 +0300 Subject: [PATCH 22/36] Fixed the auto mapper issue --- .../CmsKit/Public/PublicApplicationAutoMapperProfile.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs index a242e28c3b..704a03778c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs @@ -30,10 +30,11 @@ public class PublicApplicationAutoMapperProfile : Profile CreateMap(); - CreateMap(); + CreateMap() + .Ignore(x => x.ContentFragments); - CreateMap(MemberList.None) //TODO: Remove MemberList.None (enable validation) - .Ignore(x => x.ContentFragments); + CreateMap() + .Ignore(x => x.ContentFragments); CreateMap(); From c056c4918e86e63accc9bb56ef3465e909128617 Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 13:02:15 +0300 Subject: [PATCH 23/36] Removed unnecessary classes --- .../CmsKit/Contents/MarkdownContentFragment.cs | 6 ------ .../CmsKit/Contents/WidgetContentFragment.cs | 17 ----------------- 2 files changed, 23 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/MarkdownContentFragment.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/WidgetContentFragment.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/MarkdownContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/MarkdownContentFragment.cs deleted file mode 100644 index 6aeaa323ba..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/MarkdownContentFragment.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Volo.CmsKit.Contents; - -public class MarkdownContentFragment : ContentFragment -{ - public string Content { get; set; } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/WidgetContentFragment.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/WidgetContentFragment.cs deleted file mode 100644 index 8b5e697418..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/WidgetContentFragment.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; - -namespace Volo.CmsKit.Contents; -public class WidgetContentFragment : ContentFragment -{ - public string Name { get; } - - public string ViewComponentName { get; set; } - - public IDictionary Properties { get; set; } - - public WidgetContentFragment(string name) - { - Name = name; - Properties = new Dictionary(); - } -} From 0ea5554fb7187a7bce9ac0e43f6e7cbd6372558b Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 13:02:59 +0300 Subject: [PATCH 24/36] Worked properly with hard-coded content parser --- .../CmsKit/Shared/Components/Pages/Default.cshtml | 10 +++++++--- .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index a7a6d70766..edb6f1dbec 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -17,9 +17,13 @@ @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) } else if (contentFragment.Type == "Widget") //TODO: Constant - { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties) + { + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), new + { + extraProperties = contentFragment.ExtraProperties + } + ) + } } - } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index c6fabf0f81..eac43e41fc 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -75,10 +75,13 @@ } else if (contentFragment.Type == "Widget") //TODO: Constant { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties) + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), new + { + extraProperties = contentFragment.ExtraProperties + } + ) } } -

@if (Model.BlogPost.LastModificationTime != null) { From a07eaf4c4536b23e37a3692990d27acbec80e1bd Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 14:45:42 +0300 Subject: [PATCH 25/36] Used dynamic values instead of hard-coded in ContentParser --- .../Volo/CmsKit/Contents/ContentParser.cs | 31 +++++++------------ .../Shared/Components/Pages/Default.cshtml | 14 ++++----- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs index c4da64a986..3b34c66346 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs @@ -21,18 +21,11 @@ public class ContentParser : ITransientDependency public async Task> ParseAsync(string content) { - return new List { - new ContentFragment() { Type = "Markdown" }.SetProperty("Content", "This is *a markdown* text."), - new ContentFragment() { Type = "Widget" }.SetProperty("Type", "Poll").SetProperty("Code", "6dhah8dd"), - new ContentFragment() { Type = "Markdown" }.SetProperty("Content", "This is *another markdown* text.") - }; - - /* if (!_options.WidgetConfigs.Any()) { - return new List() + return new List { - new MarkdownContentFragment() { Content = content } + new ContentFragment() { Type = "Markdown" }.SetProperty("Content", content), }; } @@ -87,31 +80,31 @@ public class ContentParser : ITransientDependency if (parsedWidgets.Count > k) { - var name = _options.WidgetConfigs.Where(p => p.Key == values[0]).Select(p => p.Value.Name).FirstOrDefault(); + var widgetType = values[0]; + var name = _options.WidgetConfigs.Where(p => p.Key == widgetType).Select(p => p.Value.Name).FirstOrDefault(); if (name is not null && parsedWidgets.Count > k) { - var properties = new Dictionary(); + values[0] = name; + var contentFragment = new ContentFragment() { Type = "Widget" }; + contentFragments.Add(contentFragment); for (int kv = 0; kv < values.Count; kv++) { - properties.Add(keys[kv], values[kv]); + + contentFragments.FindLast(p=>p == contentFragment) + .SetProperty(keys[kv], values[kv]); } - - contentFragments.Add(new WidgetContentFragment(name) - { - Properties = properties - }); } } k++; } else { - contentFragments.Add(new MarkdownContentFragment() { Content = parsedList[i] }); + contentFragments.Add(new ContentFragment() { Type = "Markdown" } + .SetProperty("Content", parsedList[i])); } } return contentFragments; - */ } private void ParseWidgets(string content, Dictionary>> parsedWidgets) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index edb6f1dbec..396628ae66 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -17,13 +17,13 @@ @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) } else if (contentFragment.Type == "Widget") //TODO: Constant - { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), new - { - extraProperties = contentFragment.ExtraProperties - } - ) - } + { + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), new + { + extraProperties = contentFragment.ExtraProperties + } + ) } + } From 09b59e220ae64f315350f45c6a94f8a2b92d158b Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 16:47:46 +0300 Subject: [PATCH 26/36] Refactored ContentParser --- .../Volo/CmsKit/Contents/ContentParser.cs | 86 +++++++++---------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs index 3b34c66346..9badeab8d3 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs @@ -19,20 +19,28 @@ public class ContentParser : ITransientDependency _options = options.Value; } - public async Task> ParseAsync(string content) + public Task> ParseAsync(string content) { if (!_options.WidgetConfigs.Any()) { - return new List + return Task.FromResult(new List { new ContentFragment() { Type = "Markdown" }.SetProperty("Content", content), - }; + }); } - var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter); - var parsedList = new List(); + ParseContent(content, parsedList); + + var contentFragments = new List(); + FillContentFragment(content, parsedList, contentFragments); + return Task.FromResult(contentFragments); + } + + private void ParseContent(string content, List parsedList) + { + var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter); if (!replacedText.Contains(delimeter)) { parsedList.Add(replacedText); @@ -64,34 +72,40 @@ public class ContentParser : ITransientDependency parsedList.Add(replacedText); } } + } - - Dictionary>> parsedWidgets = new(); - ParseWidgets(content, parsedWidgets); - - var contentFragments = new List(); - + private void FillContentFragment(string content, List parsedList, List contentFragments) + { + content = Regex.Replace(content, @"=\s*""", @"="""); + content = Regex.Replace(content, @"""\s*=", @"""="); + var widgets = Regex.Matches(content, @"(?<=\[Widget)(.*?)(?=\])").Cast().Select(p => p.Value).ToList(); for (int i = 0, k = 0; i < parsedList.Count; i++) { if (parsedList[i] == delimeter) { - var values = parsedWidgets.GetOrDefault($"{k}.Widget").Select(p => p.Value).ToList(); - var keys = parsedWidgets.GetOrDefault($"{k}.Widget").Select(p => p.Key).ToList(); - - if (parsedWidgets.Count > k) + if (widgets.Count > k) { - var widgetType = values[0]; - var name = _options.WidgetConfigs.Where(p => p.Key == widgetType).Select(p => p.Value.Name).FirstOrDefault(); - if (name is not null && parsedWidgets.Count > k) + var preparedContent = string.Join("", widgets[k]); + var keys = Regex.Matches(preparedContent, @"(?<=\s)(.*?)(?==\s*"")").Cast() + .Select(p => p.Value).Where(p => p != string.Empty).ToList(); + var values = Regex.Matches(preparedContent, @"(?<=\s*[a-zA-Z]*=\s*"")(.*?)(?="")").Cast() + .Select(p => p.Value).ToList(); + + var widgetTypeIndex = keys.IndexOf("Type"); + if (widgetTypeIndex != -1) { - values[0] = name; - var contentFragment = new ContentFragment() { Type = "Widget" }; - contentFragments.Add(contentFragment); - for (int kv = 0; kv < values.Count; kv++) + var widgetType = values[widgetTypeIndex]; + var name = _options.WidgetConfigs.Where(p => p.Key == widgetType).Select(p => p.Value.Name).FirstOrDefault(); + if (name is not null && widgets.Count > k) { - - contentFragments.FindLast(p=>p == contentFragment) - .SetProperty(keys[kv], values[kv]); + values[0] = name; + var contentFragment = new ContentFragment() { Type = "Widget" }; + contentFragments.Add(contentFragment); + for (int kv = 0; kv < values.Count; kv++) + { + contentFragments.FindLast(p => p == contentFragment) + .SetProperty(keys[kv], values[kv]); + } } } } @@ -103,28 +117,6 @@ public class ContentParser : ITransientDependency .SetProperty("Content", parsedList[i])); } } - - return contentFragments; } - private void ParseWidgets(string content, Dictionary>> parsedWidgets) - { - var widgets = Regex.Matches(content, @"(?<=\[Widget)(.*?)(?=\])").Cast().Select(p => p.Value).ToList(); - for (int p = 0; p < widgets.Count; p++) - { - var preparedContent = string.Join("", widgets[p]); - var keys = Regex.Matches(preparedContent, @"(?<=[\[Widget]?\s)(.*?)(?=="")").Cast() - .Select(p => p.Value).Where(p => p != string.Empty).ToList(); - var values = Regex.Matches(preparedContent, @"(?<=\s*[a-zA-Z]*=\s*"")(.*?)(?="")").Cast() - .Select(p => p.Value).ToList(); - - var list = new List>(); - for (int kv = 0; kv < keys.Count; kv++) - { - list.Add(new KeyValuePair(keys[kv], values[kv])); - } - - parsedWidgets.Add($"{p}.Widget", list); - } - } } \ No newline at end of file From 05ef73658f1bb6cccb9152ccae797d951a6f5069 Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 14 Jun 2022 16:48:34 +0300 Subject: [PATCH 27/36] Run all cases of the unit tests successfully --- .../Contents/ContentParser_Test.cs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs index 00dc4c184e..4a51206a15 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs @@ -19,30 +19,33 @@ public class ContentParser_Test : CmsKitDomainTestBase } [Fact] - public async Task AA_ParseAsync_ShouldWorkMoreDynamically() + public async Task ParseAsync_ShouldWorkWithDifferentWidgetTypes() { _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); _options.Value.AddWidgetConfig("ImageGallery", new ContentWidgetConfig("ImageGallery"));//test contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. - [Widget Type=""Poll"" PollName =""poll-name""] + [Widget Type=""Poll"" Code=""poll-name""] Thanks _for_ *your * feedback. - [Widget Type=""ImageGallery"" GalleryName=""Xyz"" Source=""GoogleDrive""]"; + [Widget GalleryName=""Xyz"" Type=""ImageGallery"" Source=""GoogleDrive""]"; var widgets = await contentParser.ParseAsync(content); widgets.ShouldNotBeNull(); widgets.Count.ShouldBe(4); + widgets[1].ExtraProperties.Count.ShouldBe(2); + widgets[3].ExtraProperties.Count.ShouldBe(3); } [Fact] public async Task ParseAsync_ShouldWorkWithoutConfigOptions() { var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. - [Widget Type= ""Poll"" PollName =""poll-name""] + [Widget Type= ""Poll"" Code =""poll-name""] Thanks _for_ *your * feedback."; + contentParser = new ContentParser(_options); var widgets = await contentParser.ParseAsync(content); widgets.ShouldNotBeNull(); @@ -56,7 +59,7 @@ public class ContentParser_Test : CmsKitDomainTestBase contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. - [Widget Type= ""Poll"" PollName =""poll-name""] + [Widget Type= ""Poll"" Code =""poll-name""] Thanks _for_ *your * feedback."; var widgets = await contentParser.ParseAsync(content); @@ -72,7 +75,7 @@ public class ContentParser_Test : CmsKitDomainTestBase contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. - [Widget Wrong Type= ""Poll"" PollName =""poll-name""] + [Widget Wrong Type= ""Poll"" Code =""poll-name""] Thanks _for_ *your * feedback."; var widgets = await contentParser.ParseAsync(content); @@ -88,13 +91,13 @@ public class ContentParser_Test : CmsKitDomainTestBase contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. - [Widget Type= ""Poll"" PollWrongName =""poll-name""] + [Widget Type= ""Poll"" PollWrongName =""poll-name""] Thanks _for_ *your * feedback."; var widgets = await contentParser.ParseAsync(content); widgets.ShouldNotBeNull(); - widgets.Count.ShouldBe(2); + widgets.Count.ShouldBe(3); } [Theory] @@ -114,19 +117,19 @@ public class ContentParser_Test : CmsKitDomainTestBase new List { new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. - [Widget Type=""Poll"" PollName=""poll-name""] + [Widget Type=""Poll"" Code=""poll-name""] Thanks _for_ *your * feedback.", 3}, new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. - [Widget Type=""Poll"" PollName=""poll-name""] + [Widget Type=""Poll"" Code=""poll-name""] Thanks _for_ *your * feedback. - [Widget Type=""Poll"" PollName=""poll-name1""]", 4 }, + [Widget Type=""Poll"" Code=""poll-name1""]", 4 }, new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. Thanks _for_ *your * feedback. - [Widget Type=""Poll"" PollName=""poll-name""]", 2 }, + [Widget Type=""Poll"" Code=""poll-name""]", 2 }, - new object[] { @"[Widget Type=""Poll"" PollName=""poll-name""] gg [Widget Type=""Poll"" PollName=""poll-name1""]**ABP Framework** is completely open source and developed in a community-driven manner. + new object[] { @"[Widget Type=""Poll"" Code=""poll-name""] gg [Widget Type=""Poll"" Code=""poll-name1""]**ABP Framework** is completely open source and developed in a community-driven manner. Thanks _for_ *your * feedback. Thanks _for_ *your * feedback.", 4}, From 237fa5756650601605ffa44f3027a8e375e4a2f0 Mon Sep 17 00:00:00 2001 From: malik masis Date: Wed, 15 Jun 2022 11:49:21 +0300 Subject: [PATCH 28/36] Moved options from domain to application layer --- .../Volo/CmsKit/Contents}/CmsKitContentWidgetOptions.cs | 2 +- .../Volo/CmsKit/Contents/ContentParser.cs | 1 - .../Volo/CmsKit/Contents}/ContentWidgetConfig.cs | 2 +- .../Contents/ContentParser_Test.cs | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) rename modules/cms-kit/src/{Volo.CmsKit.Domain/Volo/CmsKit/Polls => Volo.CmsKit.Common.Application/Volo/CmsKit/Contents}/CmsKitContentWidgetOptions.cs (92%) rename modules/cms-kit/src/{Volo.CmsKit.Domain/Volo/CmsKit/Polls => Volo.CmsKit.Common.Application/Volo/CmsKit/Contents}/ContentWidgetConfig.cs (86%) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs similarity index 92% rename from modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs index 251cbe463c..2d2ed68302 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/CmsKitContentWidgetOptions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Volo.CmsKit.Polls; +namespace Volo.CmsKit.Contents; public class CmsKitContentWidgetOptions { diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs index 9badeab8d3..3c239207cd 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Microsoft.Extensions.Options; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; -using Volo.CmsKit.Polls; namespace Volo.CmsKit.Contents; diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs similarity index 86% rename from modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs index eb9c6a0656..634b44fde2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Polls/ContentWidgetConfig.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs @@ -1,6 +1,6 @@ using System; -namespace Volo.CmsKit.Polls; +namespace Volo.CmsKit.Contents; public class ContentWidgetConfig { diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs index 4a51206a15..7deeff2a80 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using Microsoft.Extensions.Options; using Shouldly; -using Volo.CmsKit.Polls; using Xunit; namespace Volo.CmsKit.Contents; From f751f89d89fd618d02b3c1be5af1341e3f0225bf Mon Sep 17 00:00:00 2001 From: malik masis Date: Wed, 15 Jun 2022 13:19:11 +0300 Subject: [PATCH 29/36] Converted ExtraProperties to a dynamic object --- .../Shared/Components/Pages/Default.cshtml | 25 +++++++++++++++---- .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 24 ++++++++++++++---- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml index 396628ae66..d79e809c47 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml @@ -1,5 +1,6 @@ @addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap +@using System.Dynamic @using Volo.CmsKit.Public.Web.Renderers @using Volo.Abp.Data @using Volo.CmsKit.Contents @@ -18,12 +19,26 @@ } else if (contentFragment.Type == "Widget") //TODO: Constant { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), new - { - extraProperties = contentFragment.ExtraProperties - } - ) + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties)) } } + + +@{ + dynamic ConvertToDynamicObject(Dictionary dict) + { + var eo = new ExpandoObject(); + var eoColl = (ICollection>)eo; + + foreach (var kvp in dict) + { + eoColl.Add(kvp); + } + + dynamic eoDynamic = eo; + + return eoDynamic; + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index eac43e41fc..b7ead0592a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -1,5 +1,6 @@ @page +@using System.Dynamic @using Volo.Abp.Data @using Volo.CmsKit.Public.Blogs @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment @@ -75,11 +76,7 @@ } else if (contentFragment.Type == "Widget") //TODO: Constant { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), new - { - extraProperties = contentFragment.ExtraProperties - } - ) + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties)) } }

@@ -167,4 +164,21 @@ entityId = Model.BlogPost.Id.ToString() }) } +} + +@{ + dynamic ConvertToDynamicObject(Dictionary dict) + { + var eo = new ExpandoObject(); + var eoColl = (ICollection>)eo; + + foreach (var kvp in dict) + { + eoColl.Add(kvp); + } + + dynamic eoDynamic = eo; + + return eoDynamic; + } } \ No newline at end of file From 0cdc2cf4b06847396eaf5a1ea172715c848b6423 Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 16 Jun 2022 15:12:01 +0300 Subject: [PATCH 30/36] Removed the unnecessary PageVC --- .../Shared/Components/Pages/Default.cshtml | 44 -------------- .../Pages/DefaultPageViewComponent.cs | 42 -------------- .../Components/Tags/TagViewComponent.cs | 7 +-- .../Pages/Public/CmsKit/Pages/Index.cshtml | 58 ++++++++++++++----- .../Pages/Public/CmsKit/Pages/Index.cshtml.cs | 8 +-- .../CmsKit}/Pages/PageViewModel.cs | 2 +- .../Volo.CmsKit.TestBase/CmsKitTestData.cs | 2 +- 7 files changed, 52 insertions(+), 111 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs rename modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/{CmsKit/Shared/Components => Public/CmsKit}/Pages/PageViewModel.cs (77%) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml deleted file mode 100644 index d79e809c47..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml +++ /dev/null @@ -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 - - - - @foreach (ContentFragment contentFragment in Model.ContentFragments) - { - if (contentFragment.Type == "Markdown") //TODO: Constant - { - @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) - } - else if (contentFragment.Type == "Widget") //TODO: Constant - { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties)) - } - } - - - - -@{ - dynamic ConvertToDynamicObject(Dictionary dict) - { - var eo = new ExpandoObject(); - var eoColl = (ICollection>)eo; - - foreach (var kvp in dict) - { - eoColl.Add(kvp); - } - - dynamic eoDynamic = eo; - - return eoDynamic; - } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs deleted file mode 100644 index 43706cee56..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs +++ /dev/null @@ -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 InvokeAsync( - Guid pageId, - string title, - string content, - List contentFragments) - { - var model = new PageViewModel - { - Id = pageId, - Title = title, - ContentFragments = contentFragments - }; - - return View("~/Pages/CmsKit/Shared/Components/Pages/Default.cshtml", model); - } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs index a3dc23c61a..0e550a6ade 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs @@ -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; diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml index 5296315e1c..498569c222 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml @@ -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 L @section styles{ } @section scripts{ } -@await Component.InvokeAsync(typeof(DefaultPageViewComponent), - new + + + @foreach (ContentFragment contentFragment in Model.PageDto.ContentFragments) + { + if (contentFragment.Type == "Markdown") //TODO: Constant + { + @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) + } + else if (contentFragment.Type == "Widget") //TODO: Constant + { + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties)) + } + } + + + +@{ + dynamic ConvertToDynamicObject(Dictionary dict) { - pageId = Model.Page.Id, - title = Model.Page.Title, - content = Model.Page.Content, - contentFragments = Model.Page.ContentFragments - }) \ No newline at end of file + var eo = new ExpandoObject(); + var eoColl = (ICollection>)eo; + + foreach (var kvp in dict) + { + eoColl.Add(kvp); + } + + dynamic eoDynamic = eo; + + return eoDynamic; + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml.cs index 6eeac638cf..1434eccb4b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml.cs @@ -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 OnGetAsync() { - Page = await PagePublicAppService.FindBySlugAsync(Slug); + PageDto = await PagePublicAppService.FindBySlugAsync(Slug); - if (Page == null) + if (PageDto == null) { return NotFound(); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/PageViewModel.cs similarity index 77% rename from modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs rename to modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/PageViewModel.cs index 8dcc71c3b2..5e5df3e917 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/PageViewModel.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/PageViewModel.cs @@ -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 { diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs index 6445fb86f4..cfa54d2e55 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs @@ -130,5 +130,5 @@ public class CmsKitTestData : ISingletonDependency public string PollName { get; } = "Poll"; - public string WidgetName { get; } = "CmsPollByName"; + public string WidgetName { get; } = "CmsPollByCode"; } From 591fa1b6ab31dda52307f0aaaf980dcb4cda6e1d Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 16 Jun 2022 15:49:10 +0300 Subject: [PATCH 31/36] Moved values into the const file --- .../Volo/CmsKit/Contents/ContentConsts.cs | 7 ++++++ .../Volo/CmsKit/Contents/ContentParser.cs | 22 +++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentConsts.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentConsts.cs new file mode 100644 index 0000000000..bf58fb8f99 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentConsts.cs @@ -0,0 +1,7 @@ +namespace Volo.CmsKit.Contents; +public static class ContentConsts +{ + public static string Delimeter { get; set; } = "----"; + public static string Widget { get; set; } = "Widget"; + public static string Markdown { get; set; } = "Markdown"; +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs index 3c239207cd..369f6aef84 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs @@ -5,12 +5,12 @@ using System.Threading.Tasks; using Microsoft.Extensions.Options; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; +using static Volo.CmsKit.Contents.ContentConsts; namespace Volo.CmsKit.Contents; public class ContentParser : ITransientDependency { - private const string delimeter = "----"; private readonly CmsKitContentWidgetOptions _options; public ContentParser(IOptions options) @@ -39,16 +39,16 @@ public class ContentParser : ITransientDependency private void ParseContent(string content, List parsedList) { - var replacedText = Regex.Replace(content, @"\[.*?\]", delimeter); - if (!replacedText.Contains(delimeter)) + var replacedText = Regex.Replace(content, @"\[.*?\]", Delimeter); + if (!replacedText.Contains(Delimeter)) { parsedList.Add(replacedText); } - while (replacedText.Contains(delimeter)) + while (replacedText.Contains(Delimeter)) { //For parsing delimeter - var index = replacedText.IndexOf(delimeter); + var index = replacedText.IndexOf(Delimeter); if (index != 0) { parsedList.Add(replacedText.Substring(0, index)); @@ -56,11 +56,11 @@ public class ContentParser : ITransientDependency index = 0; } - parsedList.Add(replacedText.Substring(index, delimeter.Length)); - replacedText = replacedText.Substring(delimeter.Length, replacedText.Length - delimeter.Length); + parsedList.Add(replacedText.Substring(index, Delimeter.Length)); + replacedText = replacedText.Substring(Delimeter.Length, replacedText.Length - Delimeter.Length); //for parsing the other side - index = replacedText.IndexOf(delimeter); + index = replacedText.IndexOf(Delimeter); if (index != -1) { parsedList.Add(replacedText.Substring(0, index)); @@ -80,7 +80,7 @@ public class ContentParser : ITransientDependency var widgets = Regex.Matches(content, @"(?<=\[Widget)(.*?)(?=\])").Cast().Select(p => p.Value).ToList(); for (int i = 0, k = 0; i < parsedList.Count; i++) { - if (parsedList[i] == delimeter) + if (parsedList[i] == Delimeter) { if (widgets.Count > k) { @@ -98,7 +98,7 @@ public class ContentParser : ITransientDependency if (name is not null && widgets.Count > k) { values[0] = name; - var contentFragment = new ContentFragment() { Type = "Widget" }; + var contentFragment = new ContentFragment() { Type = Widget }; contentFragments.Add(contentFragment); for (int kv = 0; kv < values.Count; kv++) { @@ -112,7 +112,7 @@ public class ContentParser : ITransientDependency } else { - contentFragments.Add(new ContentFragment() { Type = "Markdown" } + contentFragments.Add(new ContentFragment() { Type = Markdown } .SetProperty("Content", parsedList[i])); } } From 3de1f919d8b4a0daafc5f6fa69bfa76311cb9aa1 Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 16 Jun 2022 15:49:56 +0300 Subject: [PATCH 32/36] Removed duplication --- .../Volo.CmsKit.Common.Web/Contents/Helper.cs | 23 ++++ .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 109 ++++++++---------- .../Pages/Public/CmsKit/Pages/Index.cshtml | 24 +--- 3 files changed, 75 insertions(+), 81 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs new file mode 100644 index 0000000000..3d653e2351 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using System.Dynamic; + +namespace Volo.CmsKit.Web.Contents; + +public static class Helper +{ + public static dynamic ConvertToDynamicObject(this Dictionary dict) + { + var eo = new ExpandoObject(); + var eoColl = (ICollection>)eo; + + foreach (var kvp in dict) + { + eoColl.Add(kvp); + } + + dynamic eoDynamic = eo; + + return eoDynamic; + } +} + diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index b7ead0592a..f104551911 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -12,6 +12,8 @@ @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Tags @using Volo.CmsKit.Public.Web.Renderers @using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs +@using Volo.CmsKit.Contents +@using Volo.CmsKit.Web.Contents; @inherits CmsKitPublicPageBase @@ -26,57 +28,57 @@ } @section styles{ - @if (isScrollIndexEnabled) - { - - - - } + @if (isScrollIndexEnabled) + { + + + + } - - + + } -@section scripts{ + @section scripts{ @if (isScrollIndexEnabled) { - - + + } - - + + } -

-
- - - - -
-

@Model.BlogPost.Title

-

- - @@@Model.BlogPost.Author?.UserName - - @Model.BlogPost.CreationTime -

- @foreach (var contentFragment in Model.BlogPost.ContentFragments) +
+
+ + + + +
+

@Model.BlogPost.Title

+

+ + @@@Model.BlogPost.Author?.UserName + + @Model.BlogPost.CreationTime +

+ @foreach (var contentFragment in Model.BlogPost.ContentFragments) { - if (contentFragment.Type == "Markdown") //TODO: Constant + if (contentFragment.Type == ContentConsts.Markdown) { @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) } - else if (contentFragment.Type == "Widget") //TODO: Constant + else if (contentFragment.Type == ContentConsts.Widget) { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties)) + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties.ConvertToDynamicObject()) } }

@@ -85,18 +87,18 @@ @L["LastModification"].Value : @Model.BlogPost.LastModificationTime }

-
+
@if (GlobalFeatureManager.Instance.IsEnabled()) { if (Model.TagsFeature?.IsEnabled == true) { @await Component.InvokeAsync(typeof(TagViewComponent), new - { - entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, - entityId = Model.BlogPost.Id.ToString(), - urlFormat = $"/blogs/{Model.BlogSlug}?tagId={{TagId}}" - }) + { + entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, + entityId = Model.BlogPost.Id.ToString(), + urlFormat = $"/blogs/{Model.BlogSlug}?tagId={{TagId}}" + }) } }
@@ -109,10 +111,10 @@ if (Model.ReactionsFeature?.IsEnabled == true) { @await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new - { - entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, - entityId = Model.BlogPost.Id.ToString() - }) + { + entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, + entityId = Model.BlogPost.Id.ToString() + }) } } @@ -122,10 +124,10 @@ if (Model.RatingsFeature?.IsEnabled == true) { @await Component.InvokeAsync(typeof(RatingViewComponent), new - { - entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, - entityId = Model.BlogPost.Id.ToString() - }) + { + entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, + entityId = Model.BlogPost.Id.ToString() + }) } } @@ -164,21 +166,4 @@ entityId = Model.BlogPost.Id.ToString() }) } -} - -@{ - dynamic ConvertToDynamicObject(Dictionary dict) - { - var eo = new ExpandoObject(); - var eoColl = (ICollection>)eo; - - foreach (var kvp in dict) - { - eoColl.Add(kvp); - } - - dynamic eoDynamic = eo; - - return eoDynamic; - } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml index 498569c222..17045c4575 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml @@ -7,6 +7,8 @@ @using Volo.Abp.Data @using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs; @using Volo.Abp.AspNetCore.Mvc.UI.Widgets; +@using Volo.CmsKit.Web.Contents; + @inject IMarkdownToHtmlRenderer MarkdownRenderer @@ -33,31 +35,15 @@ @foreach (ContentFragment contentFragment in Model.PageDto.ContentFragments) { - if (contentFragment.Type == "Markdown") //TODO: Constant + if (contentFragment.Type == ContentConsts.Markdown) { @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) } - else if (contentFragment.Type == "Widget") //TODO: Constant + else if (contentFragment.Type == ContentConsts.Widget) { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), ConvertToDynamicObject(contentFragment.ExtraProperties)) + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties.ConvertToDynamicObject()) } }
-@{ - dynamic ConvertToDynamicObject(Dictionary dict) - { - var eo = new ExpandoObject(); - var eoColl = (ICollection>)eo; - - foreach (var kvp in dict) - { - eoColl.Add(kvp); - } - - dynamic eoDynamic = eo; - - return eoDynamic; - } -} \ No newline at end of file From e5d0521e2a1497663778004e25223facf51ff0ca Mon Sep 17 00:00:00 2001 From: malik masis Date: Fri, 17 Jun 2022 10:57:01 +0300 Subject: [PATCH 33/36] Removed the missed hard-coded --- .../Volo/CmsKit/Contents/ContentConsts.cs | 1 + .../Volo/CmsKit/Contents/ContentParser.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentConsts.cs index bf58fb8f99..8caaa7a03a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentConsts.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/ContentConsts.cs @@ -4,4 +4,5 @@ public static class ContentConsts public static string Delimeter { get; set; } = "----"; public static string Widget { get; set; } = "Widget"; public static string Markdown { get; set; } = "Markdown"; + public static string Content { get; set; } = "Content"; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs index 369f6aef84..b5716be9df 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs @@ -24,7 +24,7 @@ public class ContentParser : ITransientDependency { return Task.FromResult(new List { - new ContentFragment() { Type = "Markdown" }.SetProperty("Content", content), + new ContentFragment() { Type = Markdown }.SetProperty(Content, content), }); } @@ -113,7 +113,7 @@ public class ContentParser : ITransientDependency else { contentFragments.Add(new ContentFragment() { Type = Markdown } - .SetProperty("Content", parsedList[i])); + .SetProperty(Content, parsedList[i])); } } } From 14966dfc5d6e71643de0f508e8924faa813d575f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 20 Jun 2022 15:03:00 +0300 Subject: [PATCH 34/36] Review notes --- .../Volo.CmsKit.Web.Unified/appsettings.json | 2 +- .../Volo/CmsKit/Contents/ContentParser.cs | 3 +- .../CmsKit/Contents/ContentWidgetConfig.cs | 4 +- .../Volo.CmsKit.Common.Web/Contents/Helper.cs | 12 ++--- .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 48 +++++++++---------- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/appsettings.json b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/appsettings.json index 3c872decbe..fcf428bab3 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/appsettings.json +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/appsettings.json @@ -1,5 +1,5 @@ { "ConnectionStrings": { - "Default": "Server=(localdb)\\.\\MSSQLLocalDB;Database=CmsKit_Unified;Trusted_Connection=True" + "Default": "Server=(localdb)\\MSSQLLocalDB;Database=CmsKit_Unified;Trusted_Connection=True" } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs index b5716be9df..7fe9fe5b60 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentParser.cs @@ -24,7 +24,7 @@ public class ContentParser : ITransientDependency { return Task.FromResult(new List { - new ContentFragment() { Type = Markdown }.SetProperty(Content, content), + new ContentFragment { Type = Markdown }.SetProperty(Content, content), }); } @@ -117,5 +117,4 @@ public class ContentParser : ITransientDependency } } } - } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs index 634b44fde2..8dc1f5d29f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs @@ -5,9 +5,9 @@ namespace Volo.CmsKit.Contents; public class ContentWidgetConfig { public string Name { get; } - public Type ViewComponentType { get; set; } + public Type ViewComponentType { get; set; } //TODO: Remove this - public ContentWidgetConfig(string name) + public ContentWidgetConfig(string name) //TODO: widgetName { Name = name; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs index 3d653e2351..d61c5f418a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs @@ -3,21 +3,19 @@ using System.Dynamic; namespace Volo.CmsKit.Web.Contents; -public static class Helper +public static class DictionaryDynamicExtensions { - public static dynamic ConvertToDynamicObject(this Dictionary dict) + public static dynamic ConvertToDynamicObject(this Dictionary dict) //TODO: Move to AbpDictionaryExtensions { - var eo = new ExpandoObject(); - var eoColl = (ICollection>)eo; + var expandoObject = new ExpandoObject(); + var eoColl = (ICollection>)expandoObject; foreach (var kvp in dict) { eoColl.Add(kvp); } - dynamic eoDynamic = eo; - - return eoDynamic; + return expandoObject; } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index f104551911..d9211ed04c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -71,34 +71,34 @@ @Model.BlogPost.CreationTime

@foreach (var contentFragment in Model.BlogPost.ContentFragments) - { - if (contentFragment.Type == ContentConsts.Markdown) - { - @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) - } - else if (contentFragment.Type == ContentConsts.Widget) - { - @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties.ConvertToDynamicObject()) - } - } -

- @if (Model.BlogPost.LastModificationTime != null) { - @L["LastModification"].Value : @Model.BlogPost.LastModificationTime + if (contentFragment.Type == ContentConsts.Markdown) + { + @Html.Raw(await MarkdownRenderer.RenderAsync(contentFragment.GetProperty("Content"))) + } + else if (contentFragment.Type == ContentConsts.Widget) + { + @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties.ConvertToDynamicObject()) + } } -

-
+

+ @if (Model.BlogPost.LastModificationTime != null) + { + @L["LastModification"].Value : @Model.BlogPost.LastModificationTime + } +

+
- @if (GlobalFeatureManager.Instance.IsEnabled()) - { - if (Model.TagsFeature?.IsEnabled == true) + @if (GlobalFeatureManager.Instance.IsEnabled()) { - @await Component.InvokeAsync(typeof(TagViewComponent), new - { - entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, - entityId = Model.BlogPost.Id.ToString(), - urlFormat = $"/blogs/{Model.BlogSlug}?tagId={{TagId}}" - }) + if (Model.TagsFeature?.IsEnabled == true) + { + @await Component.InvokeAsync(typeof(TagViewComponent), new + { + entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType, + entityId = Model.BlogPost.Id.ToString(), + urlFormat = $"/blogs/{Model.BlogSlug}?tagId={{TagId}}" + }) } }
From 0b3319b8d9b861a4ae08cde74d6b03b327797323 Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 21 Jun 2022 10:04:07 +0300 Subject: [PATCH 35/36] Removed ViewComponentType --- .../CmsKit/Contents/CmsKitContentWidgetOptions.cs | 4 ++-- .../Volo/CmsKit/Contents/ContentWidgetConfig.cs | 9 +++------ .../Contents/ContentParser_Test.cs | 12 ++++++------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs index 2d2ed68302..1f9dae60ab 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs @@ -11,8 +11,8 @@ public class CmsKitContentWidgetOptions WidgetConfigs = new(); } - public void AddWidgetConfig(string name, ContentWidgetConfig contentWidgetConfig) + public void AddWidget(string widgetName, string widgetKey) { - WidgetConfigs.Add(name, contentWidgetConfig); + WidgetConfigs.Add(widgetName, new ContentWidgetConfig(widgetKey)); } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs index 8dc1f5d29f..a5eab5930a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs @@ -1,14 +1,11 @@ -using System; - -namespace Volo.CmsKit.Contents; +namespace Volo.CmsKit.Contents; public class ContentWidgetConfig { public string Name { get; } - public Type ViewComponentType { get; set; } //TODO: Remove this - public ContentWidgetConfig(string name) //TODO: widgetName + public ContentWidgetConfig(string widgetName) { - Name = name; + Name = widgetName; } } \ No newline at end of file diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs index 7deeff2a80..108d883a70 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentParser_Test.cs @@ -20,8 +20,8 @@ public class ContentParser_Test : CmsKitDomainTestBase [Fact] public async Task ParseAsync_ShouldWorkWithDifferentWidgetTypes() { - _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); - _options.Value.AddWidgetConfig("ImageGallery", new ContentWidgetConfig("ImageGallery"));//test + _options.Value.AddWidget(testData.PollName, testData.WidgetName); + _options.Value.AddWidget("ImageGallery", "ImageGallery"); contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. @@ -54,7 +54,7 @@ public class ContentParser_Test : CmsKitDomainTestBase [Fact] public async Task ParseAsync_ShouldWorkWithWrongConfigOptions() { - _options.Value.AddWidgetConfig(testData.WidgetName, new ContentWidgetConfig(testData.PollName)); + _options.Value.AddWidget(testData.WidgetName, testData.PollName); contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. @@ -70,7 +70,7 @@ public class ContentParser_Test : CmsKitDomainTestBase [Fact] public async Task ParseAsync_ShouldWorkWithWrongWidgetType() { - _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + _options.Value.AddWidget(testData.PollName, testData.WidgetName); contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. @@ -86,7 +86,7 @@ public class ContentParser_Test : CmsKitDomainTestBase [Fact] public async Task ParseAsync_ShouldWorkWithWrongPollName() { - _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + _options.Value.AddWidget(testData.PollName, testData.WidgetName); contentParser = new ContentParser(_options); var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. @@ -103,7 +103,7 @@ public class ContentParser_Test : CmsKitDomainTestBase [MemberData(nameof(ExampleData))] public async Task ParseAsync_ShouldWorkProperlyWithCorrectInputs(string content, int expectedLine) { - _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + _options.Value.AddWidget(testData.PollName, testData.WidgetName); contentParser = new ContentParser(_options); var widgets = await contentParser.ParseAsync(content); From 62529edbf8081e5786141ff0520526d777c80a2b Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 21 Jun 2022 18:34:15 +0300 Subject: [PATCH 36/36] Moved ConvertToDynamicObject to framework --- .../Generic/AbpDictionaryExtensions.cs | 19 +++++++++++++++++ .../Volo.CmsKit.Common.Web/Contents/Helper.cs | 21 ------------------- .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 2 -- .../Pages/Public/CmsKit/Pages/Index.cshtml | 5 +---- 4 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs diff --git a/framework/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs b/framework/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs index 1e6dd0288c..6ac5601f7d 100644 --- a/framework/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs +++ b/framework/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Dynamic; namespace System.Collections.Generic; @@ -128,4 +129,22 @@ public static class AbpDictionaryExtensions { return dictionary.GetOrAdd(key, k => factory()); } + + /// + /// Converts a dictionary to dynamic object so added and removed at run + /// + /// The collection object + /// If value is correct, return ExpandoObject that represents an object + public static dynamic ConvertToDynamicObject(this Dictionary dictionary) + { + var expandoObject = new ExpandoObject(); + var expendObjectCollection = (ICollection>)expandoObject; + + foreach (var keyValuePair in dictionary) + { + expendObjectCollection.Add(keyValuePair); + } + + return expandoObject; + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs deleted file mode 100644 index d61c5f418a..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/Helper.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Dynamic; - -namespace Volo.CmsKit.Web.Contents; - -public static class DictionaryDynamicExtensions -{ - public static dynamic ConvertToDynamicObject(this Dictionary dict) //TODO: Move to AbpDictionaryExtensions - { - var expandoObject = new ExpandoObject(); - var eoColl = (ICollection>)expandoObject; - - foreach (var kvp in dict) - { - eoColl.Add(kvp); - } - - return expandoObject; - } -} - diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index d9211ed04c..2cff5c9072 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -1,6 +1,5 @@ @page -@using System.Dynamic @using Volo.Abp.Data @using Volo.CmsKit.Public.Blogs @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Blogs.BlogPostComment @@ -13,7 +12,6 @@ @using Volo.CmsKit.Public.Web.Renderers @using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs @using Volo.CmsKit.Contents -@using Volo.CmsKit.Web.Contents; @inherits CmsKitPublicPageBase diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml index 17045c4575..5a92ae2b04 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml @@ -1,5 +1,4 @@ - -@page +@page @addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap @using Volo.CmsKit.Contents @using System.Dynamic @@ -7,8 +6,6 @@ @using Volo.Abp.Data @using Volo.Abp.AspNetCore.Mvc.UI.Packages.HighlightJs; @using Volo.Abp.AspNetCore.Mvc.UI.Widgets; -@using Volo.CmsKit.Web.Contents; - @inject IMarkdownToHtmlRenderer MarkdownRenderer