From ebc1170b9eebf18aa71961a7e3319d2ef101884e Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 14 Jul 2022 10:12:26 +0300 Subject: [PATCH 1/3] Added some example widgets for doc --- .../CmsKitWebUnifiedModule.cs | 6 +++++ .../ViewComponents/CommentDate.cshtml | 11 ++++++++ .../CommentDateViewComponent.cs | 25 +++++++++++++++++++ .../ViewComponents/DecisionCommentDate.cshtml | 6 +++++ .../DecisionCommentDateViewComponent.cs | 23 +++++++++++++++++ .../Pages/CmsKit/Contents/addWidgetModal.js | 6 +++++ .../Pages/Public/CmsKit/Pages/Index.cshtml | 1 + 7 files changed, 78 insertions(+) create mode 100644 modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/CommentDate.cshtml create mode 100644 modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/CommentDateViewComponent.cs create mode 100644 modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDate.cshtml create mode 100644 modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDateViewComponent.cs diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs index 9a6be48e5f..5e953e82d6 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs @@ -46,6 +46,7 @@ using Volo.CmsKit.Comments; using Volo.CmsKit.MediaDescriptors; using Volo.CmsKit.Reactions; using Volo.CmsKit.Ratings; +using Volo.CmsKit.Contents; namespace Volo.CmsKit; @@ -152,6 +153,11 @@ public class CmsKitWebUnifiedModule : AbpModule { options.IsEnabled = MultiTenancyConsts.IsEnabled; }); + + Configure(options => + { + options.AddWidget("ExComment", "CommentDate", "DecisionCommentDate"); + }); } private void ConfigureCmsKit(ServiceConfigurationContext context) diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/CommentDate.cshtml b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/CommentDate.cshtml new file mode 100644 index 0000000000..7921c0ecbd --- /dev/null +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/CommentDate.cshtml @@ -0,0 +1,11 @@ +@model Volo.CmsKit.ViewComponents.CommentDateViewComponent + +

Welcome Comment Date Component

+@if (Model.IsShow) +{ +

@DateTime.Today.ToLongDateString()

+} +else +{ +

Without date

+} \ No newline at end of file diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/CommentDateViewComponent.cs b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/CommentDateViewComponent.cs new file mode 100644 index 0000000000..4122bb1481 --- /dev/null +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/CommentDateViewComponent.cs @@ -0,0 +1,25 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.UI.Widgets; + +namespace Volo.CmsKit.ViewComponents; + +[Widget( + AutoInitialize = true +)] + +[ViewComponent(Name = "CommentDate")] +public class CommentDateViewComponent : AbpViewComponent +{ + public bool IsShow { get; set; } + + public CommentDateViewComponent() + { + } + + public virtual async Task InvokeAsync(string isShow) + { + return View("~/ViewComponents/CommentDate.cshtml", new CommentDateViewComponent() { IsShow = bool.Parse(isShow) }); + } +} diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDate.cshtml b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDate.cshtml new file mode 100644 index 0000000000..7464d52bc4 --- /dev/null +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDate.cshtml @@ -0,0 +1,6 @@ +
+ + +
\ No newline at end of file diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDateViewComponent.cs b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDateViewComponent.cs new file mode 100644 index 0000000000..d0586b17a2 --- /dev/null +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDateViewComponent.cs @@ -0,0 +1,23 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.UI.Widgets; + +namespace Volo.CmsKit.ViewComponents; + +[Widget( + AutoInitialize = true +)] + +[ViewComponent(Name = "DecisionCommentDate")] +public class DecisionCommentDateViewComponent : AbpViewComponent +{ + public DecisionCommentDateViewComponent() + { + } + + public virtual async Task InvokeAsync() + { + return View("~/ViewComponents/DecisionCommentDate.cshtml"); + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js index 2c307c8faf..cae289bd1f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js @@ -20,6 +20,12 @@ $(function () { let html = " " $("#PropertySideId").append(html); } + else { + + var val = $('#NewOption').is(":checked"); + let html = " " + $("#PropertySideId").append(html); + } var keys = []; var values = []; 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 5a92ae2b04..2aa3c0ce8b 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 @@ -40,6 +40,7 @@ { @await Component.InvokeAsync(contentFragment.GetProperty("Type"), contentFragment.ExtraProperties.ConvertToDynamicObject()) } + } From e90c6df8a9e1b88993b4260eaca60065f5a40ec4 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 14 Jul 2022 12:00:14 +0300 Subject: [PATCH 2/3] Add dynamic parameters to dynamic widget --- .../ViewComponents/DecisionCommentDate.cshtml | 12 ++--- .../DecisionCommentDateViewComponent.cs | 13 ++++- .../{Pages => }/_ViewImports.cshtml | 0 .../Pages/CmsKit/BlogPosts/create.js | 6 +-- .../CmsKit/Contents/AddWidgetModal.cshtml | 14 ++++-- .../Pages/CmsKit/Contents/addWidgetModal.js | 47 ++++++------------- 6 files changed, 45 insertions(+), 47 deletions(-) rename modules/cms-kit/host/Volo.CmsKit.Web.Unified/{Pages => }/_ViewImports.cshtml (100%) diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDate.cshtml b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDate.cshtml index 7464d52bc4..0622000bb7 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDate.cshtml +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDate.cshtml @@ -1,6 +1,6 @@ -
- - -
\ No newline at end of file +@using Volo.CmsKit.ViewComponents +@model DecisionCommentDateViewModel + +
+ +
diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDateViewComponent.cs b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDateViewComponent.cs index d0586b17a2..c4f52d508a 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDateViewComponent.cs +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/ViewComponents/DecisionCommentDateViewComponent.cs @@ -1,7 +1,10 @@ -using System.Threading.Tasks; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; +using Volo.Abp.Localization; namespace Volo.CmsKit.ViewComponents; @@ -18,6 +21,12 @@ public class DecisionCommentDateViewComponent : AbpViewComponent public virtual async Task InvokeAsync() { - return View("~/ViewComponents/DecisionCommentDate.cshtml"); + return View("~/ViewComponents/DecisionCommentDate.cshtml", new DecisionCommentDateViewModel()); } } + +public class DecisionCommentDateViewModel +{ + [DisplayName("Show date in the component")] + public bool IsShow { get; set; } = true; +} diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/_ViewImports.cshtml b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/_ViewImports.cshtml similarity index 100% rename from modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/_ViewImports.cshtml rename to modules/cms-kit/host/Volo.CmsKit.Web.Unified/_ViewImports.cshtml diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js index 375b7ad41b..086f44e67a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js @@ -329,9 +329,9 @@ $(function () { }); } - $('#GeneratedWidgetText').on('change', function () { - var txt = $('#GeneratedWidgetText').val(); - editor.insertText(txt); + $('#GeneratedWidgetText').on('change', function (text) { + + editor.insertText(text); }); function createAddWidgetButton() { diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/AddWidgetModal.cshtml b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/AddWidgetModal.cshtml index 3219538d46..87831e4e1d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/AddWidgetModal.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/AddWidgetModal.cshtml @@ -1,5 +1,6 @@ @page @using Microsoft.AspNetCore.Mvc.Localization +@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal @using Volo.CmsKit.Admin.Web.Pages @using Volo.CmsKit.Localization @using Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents; @@ -20,15 +21,17 @@
@if (Model.Widgets.Count() > 1) { + foreach (var item in Model.ViewModel.Details) { - + } -
-
- } else { @@ -36,4 +39,7 @@ }
+ + + diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js index cae289bd1f..2f625fe2fa 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js @@ -3,6 +3,8 @@ $(function () { abp.modals.addWidgetModal = function () { var initModal = function () { + var activeEditor; + var activeForm; let widgetName, widgetType; $("#ViewModel_Widget").change(function () { @@ -11,47 +13,28 @@ $(function () { $('.widget-detail').attr('hidden', 'true'); - $('#editor-' + widgetName).removeAttr('hidden'); - }); + activeEditor = $('#editor-' + widgetName); + activeEditor.removeAttr('hidden'); - $("#save-changes").click(function () { - var widgetKey = $("#WidgetCode").val(); - if (widgetKey != undefined) { - let html = " " - $("#PropertySideId").append(html); - } - else { - - var val = $('#NewOption').is(":checked"); - let html = " " - $("#PropertySideId").append(html); - } + activeForm = $('#editor-' + widgetName + ' form'); + }); - var keys = []; - var values = []; - $(".properties").each(function () { - if (($.trim($(this).val()).length > 0)) { - keys.push(this.id); - values.push($(this).val()); - } - }); + $(".save-changes").click(function () { - let updatedText = ''; - if (widgetType != undefined) { + let properties = activeForm.serializeFormToObject(); - updatedText = "[Widget Type=\"" + widgetType + "\" "; + let widgetText = "[Widget Type=\"" + widgetType + "\" "; - for (var i = 0; i < keys.length; i++) { - updatedText += keys[i] + "=\"" + values[i]; - updatedText += i == (keys.length - 1) ? "\"" : "\" "; + for (var propertyName in properties) { + if (!propertyName.includes(']') && !propertyName.includes('[')) { + widgetText += propertyName + "=\"" + properties[propertyName] + "\" "; } - - updatedText += "]"; } - $('#GeneratedWidgetText').val(updatedText); - $("#GeneratedWidgetText").trigger("change"); + widgetText = widgetText.trim() + "]"; + $('#GeneratedWidgetText').val(widgetText); + $("#GeneratedWidgetText").trigger("change"); $('#addWidgetModal').modal('hide'); }); }; From ac36705b5f2346c719f6b6d84e8423ff60852f51 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 14 Jul 2022 12:03:30 +0300 Subject: [PATCH 3/3] revert BlogPost/create.js changes --- .../Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js index 086f44e67a..375b7ad41b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/BlogPosts/create.js @@ -329,9 +329,9 @@ $(function () { }); } - $('#GeneratedWidgetText').on('change', function (text) { - - editor.insertText(text); + $('#GeneratedWidgetText').on('change', function () { + var txt = $('#GeneratedWidgetText').val(); + editor.insertText(txt); }); function createAddWidgetButton() {