From a2d9f457fc3cbca52f17859ea4b7da8db8af05bc Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 7 Jun 2022 23:06:33 +0300 Subject: [PATCH] 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 }) } }