From 28ba0bd8a1f00cd5e192be6e00fdec8ccf2ef433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 22 Sep 2020 14:47:49 +0300 Subject: [PATCH] Implement widget auto initialize. --- .../jquery/widget-manager.js | 19 ++ .../Mvc/UI/Widgets/AbpViewComponentHelper.cs | 9 +- .../Mvc/UI/Widgets/WidgetAttribute.cs | 2 + .../Mvc/UI/Widgets/WidgetDefinition.cs | 3 + .../Commenting/CommentingViewComponent.cs | 4 +- .../Shared/Components/Commenting/default.js | 272 +++++++++--------- .../Components/Rating/RatingViewComponent.cs | 11 +- .../Shared/Components/Rating/default.js | 151 +++++----- .../ReactionSelectionViewComponent.cs | 3 +- .../Components/ReactionSelection/default.js | 104 +++---- .../ReactionPublicAppService_Tests.cs | 6 +- 11 files changed, 290 insertions(+), 294 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/widget-manager.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/widget-manager.js index 1dd7717070..55b6162e78 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/widget-manager.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/widget-manager.js @@ -115,4 +115,23 @@ return publicApi; }; + function autoInitWidgets($wrapper){ + $wrapper.findWithSelf('.abp-widget-wrapper[data-widget-auto-init="true"]') + .each(function(){ + var widgetManager = new abp.WidgetManager({ + wrapper: $(this), + }); + + widgetManager.init(); + }); + } + + abp.dom.onNodeAdded(function(args){ + autoInitWidgets(args.$el); + }) + + $(function(){ + autoInitWidgets($('body')); + }); + })(jQuery); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/AbpViewComponentHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/AbpViewComponentHelper.cs index 826c7635cf..346d28a526 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/AbpViewComponentHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/AbpViewComponentHelper.cs @@ -65,11 +65,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets { wrapperAttributesBuilder.Append($" data-refresh-url=\"{widget.RefreshUrl}\""); } - + + if (widget.AutoInitialize) + { + wrapperAttributesBuilder.Append(" data-widget-auto-init=\"true\""); + } + return new HtmlContentBuilder() .AppendHtml($"
") .AppendHtml(await DefaultViewComponentHelper.InvokeAsync(widget.ViewComponentType, arguments)) .AppendHtml("
"); } } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs index 002d981df3..7d0848e3fd 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs @@ -33,6 +33,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets public string RefreshUrl { get; set; } + public bool AutoInitialize { get; set; } + public static bool IsWidget(Type type) { return type.IsSubclassOf(typeof(ViewComponent)) && diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs index b33950abb3..c1a08ee07a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs @@ -50,6 +50,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets [CanBeNull] public string RefreshUrl { get; set; } + public bool AutoInitialize { get; set; } + public WidgetDefinition( [NotNull] Type viewComponentType, [CanBeNull] ILocalizableString displayName = null) @@ -64,6 +66,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets Styles = GetStyles(WidgetAttribute); Scripts = GetScripts(WidgetAttribute); RefreshUrl = WidgetAttribute.RefreshUrl; + AutoInitialize = WidgetAttribute.AutoInitialize; } private static List GetStyles(WidgetAttribute widgetAttribute) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs index 47944d71c8..bbe3bbeebf 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs @@ -8,7 +8,6 @@ using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.CmsKit.Public.Comments; -using Volo.CmsKit.Web; namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting { @@ -16,7 +15,8 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting [Widget( ScriptTypes = new[] {typeof(CommentingScriptBundleContributor)}, StyleTypes = new[] {typeof(CommentingStyleBundleContributor)}, - RefreshUrl = "/CmsKitPublicWidgets/Commenting" + RefreshUrl = "/CmsKitPublicWidgets/Commenting", + AutoInitialize = true )] public class CommentingViewComponent : AbpViewComponent { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js index 99e6167b49..b853a9c186 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js @@ -2,181 +2,169 @@ var l = abp.localization.getResource('CmsKit'); - $(document).ready(function () { + abp.widgets.CmsCommenting = function ($widget) { + var widgetManager = $widget.data('abp-widget-manager'); + var $commentArea = $widget.find('.cms-comment-area'); - abp.widgets.CmsCommenting = function ($widget) { - var widgetManager = $widget.data('abp-widget-manager'); - var $commentArea = $widget.find('.cms-comment-area'); - - function getFilters() { - return { - entityType: $commentArea.attr('data-entity-type'), - entityId: $commentArea.attr('data-entity-id') - }; - } + function getFilters() { + return { + entityType: $commentArea.attr('data-entity-type'), + entityId: $commentArea.attr('data-entity-id') + }; + } - function registerEditLinks($container) { - $container.find('.comment-edit-link').each(function () { - var $link = $(this); - $link.on('click', function (e) { - e.preventDefault(); + function registerEditLinks($container) { + $container.find('.comment-edit-link').each(function () { + var $link = $(this); + $link.on('click', function (e) { + e.preventDefault(); - var commentId = $link.data('id'); + var commentId = $link.data('id'); - var $relatedCommentContentArea = $container.find('.cms-comment-content-area[data-id=' + commentId + ']'); - var $relatedCommentEditFormArea = $container.find('.cms-comment-edit-area[data-id=' + commentId + ']'); + var $relatedCommentContentArea = $container.find('.cms-comment-content-area[data-id=' + commentId + ']'); + var $relatedCommentEditFormArea = $container.find('.cms-comment-edit-area[data-id=' + commentId + ']'); - $relatedCommentContentArea.hide(); - $relatedCommentEditFormArea.show(); - $link.removeAttr('href'); - }); + $relatedCommentContentArea.hide(); + $relatedCommentEditFormArea.show(); + $link.removeAttr('href'); }); - $container.find('.comment-edit-cancel-button').each(function () { - var $button = $(this); - $button.on('click', function (e) { - e.preventDefault(); + }); + $container.find('.comment-edit-cancel-button').each(function () { + var $button = $(this); + $button.on('click', function (e) { + e.preventDefault(); - var commentId = $button.data('id'); + var commentId = $button.data('id'); - var $relatedCommentContentArea = $container.find('.cms-comment-content-area[data-id=' + commentId + ']'); - var $relatedCommentEditFormArea = $container.find('.cms-comment-edit-area[data-id=' + commentId + ']'); - var $link = $container.find('.comment-edit-link[data-id=' + commentId + ']'); + var $relatedCommentContentArea = $container.find('.cms-comment-content-area[data-id=' + commentId + ']'); + var $relatedCommentEditFormArea = $container.find('.cms-comment-edit-area[data-id=' + commentId + ']'); + var $link = $container.find('.comment-edit-link[data-id=' + commentId + ']'); - $relatedCommentContentArea.show(); - $relatedCommentEditFormArea.hide(); - $link.attr('href', '#'); - }); + $relatedCommentContentArea.show(); + $relatedCommentEditFormArea.hide(); + $link.attr('href', '#'); }); - } + }); + } - function registerReplyLinks($container) { - $container.find('.comment-reply-link').each(function () { - var $link = $(this); - $link.on('click', function (e) { - e.preventDefault(); + function registerReplyLinks($container) { + $container.find('.comment-reply-link').each(function () { + var $link = $(this); + $link.on('click', function (e) { + e.preventDefault(); - var replyCommentId = $link.data('reply-id'); + var replyCommentId = $link.data('reply-id'); - var $relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id=' + replyCommentId + ']'); - var $links = $container.find('.comment-reply-link[data-reply-id=' + replyCommentId + ']'); + var $relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id=' + replyCommentId + ']'); + var $links = $container.find('.comment-reply-link[data-reply-id=' + replyCommentId + ']'); - $relatedCommentArea.show(); - $relatedCommentArea.find('textarea').focus(); - $links.addClass('disabled'); - }); + $relatedCommentArea.show(); + $relatedCommentArea.find('textarea').focus(); + $links.addClass('disabled'); }); - $container.find('.reply-cancel-button').each(function () { - var $button = $(this); - $button.on('click', function (e) { - e.preventDefault(); + }); + $container.find('.reply-cancel-button').each(function () { + var $button = $(this); + $button.on('click', function (e) { + e.preventDefault(); - var replyCommentId = $button.data('reply-id'); + var replyCommentId = $button.data('reply-id'); - var $relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id=' + replyCommentId + ']'); - var $links = $container.find('.comment-reply-link[data-reply-id=' + replyCommentId + ']'); + var $relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id=' + replyCommentId + ']'); + var $links = $container.find('.comment-reply-link[data-reply-id=' + replyCommentId + ']'); - $relatedCommentArea.hide(); - $links.removeClass('disabled'); - }); + $relatedCommentArea.hide(); + $links.removeClass('disabled'); }); - } - - function registerDeleteLinks($container) { - $container.find('.comment-delete-link').each(function () { - var $link = $(this); - $link.on('click', '', function (e) { - e.preventDefault(); - - abp.message.confirm(l("MessageDeletionConfirmationMessage"), function (ok) { - if (ok) { - volo.cmsKit.public.comments.commentPublic.delete($link.data('id') - ).then(function () { - widgetManager.refresh($widget); - }); - } - }); + }); + } + + function registerDeleteLinks($container) { + $container.find('.comment-delete-link').each(function () { + var $link = $(this); + $link.on('click', '', function (e) { + e.preventDefault(); + + abp.message.confirm(l("MessageDeletionConfirmationMessage"), function (ok) { + if (ok) { + volo.cmsKit.public.comments.commentPublic.delete($link.data('id') + ).then(function () { + widgetManager.refresh($widget); + }); + } }); }); - } - - function registerUpdateOfNewComment($container) { - $container.find('.cms-comment-update-form').each(function () { - var $form = $(this); - $form.submit(function (e) { - e.preventDefault(); - var formAsObject = $form.serializeFormToObject(); - volo.cmsKit.public.comments.commentPublic.update( - formAsObject.id, - { - text: formAsObject.commentText - } - ).then(function () { - widgetManager.refresh($widget); - }); + }); + } + + function registerUpdateOfNewComment($container) { + $container.find('.cms-comment-update-form').each(function () { + var $form = $(this); + $form.submit(function (e) { + e.preventDefault(); + var formAsObject = $form.serializeFormToObject(); + volo.cmsKit.public.comments.commentPublic.update( + formAsObject.id, + { + text: formAsObject.commentText + } + ).then(function () { + widgetManager.refresh($widget); }); }); - } - - function registerSubmissionOfNewComment($container) { - $container.find('.cms-comment-form').each(function () { - var $form = $(this); - $form.submit(function (e) { - e.preventDefault(); - var formAsObject = $form.serializeFormToObject(); - volo.cmsKit.public.comments.commentPublic.create( - $commentArea.attr('data-entity-type'), - $commentArea.attr('data-entity-id'), - { - repliedCommentId: formAsObject.repliedCommentId, - text: formAsObject.commentText - } - ).then(function () { - widgetManager.refresh($widget); - }); + }); + } + + function registerSubmissionOfNewComment($container) { + $container.find('.cms-comment-form').each(function () { + var $form = $(this); + $form.submit(function (e) { + e.preventDefault(); + var formAsObject = $form.serializeFormToObject(); + volo.cmsKit.public.comments.commentPublic.create( + $commentArea.attr('data-entity-type'), + $commentArea.attr('data-entity-id'), + { + repliedCommentId: formAsObject.repliedCommentId, + text: formAsObject.commentText + } + ).then(function () { + widgetManager.refresh($widget); }); }); - } + }); + } - function focusOnHash($container) { - if (!location.hash.toLowerCase().startsWith('#cms-comment')) { - return; - } + function focusOnHash($container) { + if (!location.hash.toLowerCase().startsWith('#cms-comment')) { + return; + } - var $link = $(location.hash + '_link'); + var $link = $(location.hash + '_link'); - if ($link.length > 0) { - $link.click(); - } - else { - $(location.hash).find('textarea').focus(); - } + if ($link.length > 0) { + $link.click(); } + else { + $(location.hash).find('textarea').focus(); + } + } - function init() { - registerReplyLinks($widget); - registerEditLinks($widget); - registerDeleteLinks($widget); + function init() { + registerReplyLinks($widget); + registerEditLinks($widget); + registerDeleteLinks($widget); - registerUpdateOfNewComment($widget); - registerSubmissionOfNewComment($widget); + registerUpdateOfNewComment($widget); + registerSubmissionOfNewComment($widget); - focusOnHash($widget); - } + focusOnHash($widget); + } - return { - init: init, - getFilters: getFilters - }; + return { + init: init, + getFilters: getFilters }; - - $('.abp-widget-wrapper[data-widget-name="CmsCommenting"]') - .each(function () { - var widgetManager = new abp.WidgetManager({ - wrapper: $(this), - }); - - widgetManager.init($(this)); - }); - }); + }; })(jQuery); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/RatingViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/RatingViewComponent.cs index cae050ea40..9a4613d003 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/RatingViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/RatingViewComponent.cs @@ -15,7 +15,8 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating [Widget( StyleTypes = new[] {typeof(RatingStyleBundleContributor)}, ScriptTypes = new[] {typeof(RatingScriptBundleContributor)}, - RefreshUrl = "/CmsKitPublicWidgets/Rating" + RefreshUrl = "/CmsKitPublicWidgets/Rating", + AutoInitialize = true )] public class RatingViewComponent : AbpViewComponent { @@ -29,7 +30,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating AbpMvcUiOptions = options.Value; CurrentUser = currentUser; } - + public virtual async Task InvokeAsync(string entityType, string entityId) { var ratings = await RatingPublicAppService.GetGroupedStarCountsAsync(entityType, entityId); @@ -40,7 +41,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating { currentUserRating = ratings.Find(x => x.IsSelectedByCurrentUser)?.StarCount; } - + var loginUrl = $"{AbpMvcUiOptions.LoginUrl}?returnUrl={HttpContext.Request.Path.ToString()}&returnUrlHash=#cms-rating_{entityType}_{entityId}"; @@ -53,7 +54,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating CurrentRating = currentUserRating, TotalRating = totalRating }; - + return View("~/Pages/CmsKit/Shared/Components/Rating/Default.cshtml", viewModel); } } @@ -72,4 +73,4 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating public int TotalRating { get; set; } } -} \ No newline at end of file +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/default.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/default.js index 4c7d9bed72..3db58f01c6 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/default.js @@ -1,93 +1,82 @@ (function () { var l = abp.localization.getResource("CmsKit"); - $(document).ready(function () { - abp.widgets.CmsRating = function ($widget) { - var widgetManager = $widget.data("abp-widget-manager"); - var $ratingArea = $widget.find(".cms-rating-area"); + abp.widgets.CmsRating = function ($widget) { + var widgetManager = $widget.data("abp-widget-manager"); + var $ratingArea = $widget.find(".cms-rating-area"); - function getFilters() { - return { - entityType: $ratingArea.attr("data-entity-type"), - entityId: $ratingArea.attr("data-entity-id") - }; - } - - function registerCreateOfNewRating() { - $widget.find(".my-rating").each(function () { - var authenticated = $(this).attr("data-authenticated"); - - $(this).starRating({ - initialRating: 0, - starSize: 16, - emptyColor: '#eee', - hoverColor: '#ffc107', - activeColor: '#ffc107', - useGradient: false, - strokeWidth: 0, - disableAfterRate: true, - useFullStars: true, - readOnly: authenticated === "True", - onHover: function (currentIndex, currentRating, $el) { - $widget.find(".live-rating").text(currentIndex); - }, - onLeave: function (currentIndex, currentRating, $el) { - $widget.find(".live-rating").text(currentRating); - }, - callback: function (currentRating, $el) { - volo.cmsKit.public.ratings.ratingPublic.create( - $ratingArea.attr("data-entity-type"), - $ratingArea.attr("data-entity-id"), - { - starCount: parseInt(currentRating) - } - ).then(function () { - widgetManager.refresh($widget); - }) - } - }); - } - ); - } + function getFilters() { + return { + entityType: $ratingArea.attr("data-entity-type"), + entityId: $ratingArea.attr("data-entity-id") + }; + } - function registerUndoLink() { - $widget.find(".rating-undo-link").each(function () { - $(this).on('click', '', function (e) { - e.preventDefault(); + function registerCreateOfNewRating() { + $widget.find(".my-rating").each(function () { + var authenticated = $(this).attr("data-authenticated"); - abp.message.confirm(l("RatingUndoMessage"), function (ok) { - if (ok) { - volo.cmsKit.public.ratings.ratingPublic.delete( - $ratingArea.attr("data-entity-type"), - $ratingArea.attr("data-entity-id") - ).then(function () { - widgetManager.refresh($widget); - }); - } - }) + $(this).starRating({ + initialRating: 0, + starSize: 16, + emptyColor: '#eee', + hoverColor: '#ffc107', + activeColor: '#ffc107', + useGradient: false, + strokeWidth: 0, + disableAfterRate: true, + useFullStars: true, + readOnly: authenticated === "True", + onHover: function (currentIndex, currentRating, $el) { + $widget.find(".live-rating").text(currentIndex); + }, + onLeave: function (currentIndex, currentRating, $el) { + $widget.find(".live-rating").text(currentRating); + }, + callback: function (currentRating, $el) { + volo.cmsKit.public.ratings.ratingPublic.create( + $ratingArea.attr("data-entity-type"), + $ratingArea.attr("data-entity-id"), + { + starCount: parseInt(currentRating) + } + ).then(function () { + widgetManager.refresh($widget); + }) + } }); - }); - } + } + ); + } - function init() { - registerCreateOfNewRating(); - registerUndoLink(); - } + function registerUndoLink() { + $widget.find(".rating-undo-link").each(function () { + $(this).on('click', '', function (e) { + e.preventDefault(); - return { - init: init, - getFilters: getFilters - } - }; - - $('.abp-widget-wrapper[data-widget-name="CmsRating"]') - .each(function () { - var widgetManager = new abp.WidgetManager({ - wrapper: $(this), + abp.message.confirm(l("RatingUndoMessage"), function (ok) { + if (ok) { + volo.cmsKit.public.ratings.ratingPublic.delete( + $ratingArea.attr("data-entity-type"), + $ratingArea.attr("data-entity-id") + ).then(function () { + widgetManager.refresh($widget); + }); + } + }) }); - - widgetManager.init($(this)); }); - }); + } + + function init() { + registerCreateOfNewRating(); + registerUndoLink(); + } + + return { + init: init, + getFilters: getFilters + } + }; }) -(jQuery); \ No newline at end of file +(jQuery); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs index 0af928e0f0..ff10ea662c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs @@ -14,7 +14,8 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.ReactionSelectio [Widget( ScriptTypes = new[] {typeof(ReactionSelectionScriptBundleContributor)}, StyleTypes = new[] {typeof(ReactionSelectionStyleBundleContributor)}, - RefreshUrl = "/CmsKitPublicWidgets/ReactionSelection" + RefreshUrl = "/CmsKitPublicWidgets/ReactionSelection", + AutoInitialize = true )] public class ReactionSelectionViewComponent : AbpViewComponent { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js index 7107fd5a81..b8b16c031e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js @@ -8,71 +8,59 @@ myDefaultWhiteList.span.push('data-reaction-name'); } - $(document).ready(function () { + abp.widgets.CmsReactionSelection = function ($widget) { + var widgetManager = $widget.data('abp-widget-manager'); + var $reactionArea = $widget.find('.cms-reaction-area'); + var $selectIcon = $widget.find('.cms-reaction-select-icon'); + var $popoverContent = $widget.find('.cms-reaction-selection-popover-content'); - abp.widgets.CmsReactionSelection = function ($widget) { - var widgetManager = $widget.data('abp-widget-manager'); - var $reactionArea = $widget.find('.cms-reaction-area'); - var $selectIcon = $widget.find('.cms-reaction-select-icon'); - var $popoverContent = $widget.find('.cms-reaction-selection-popover-content'); - - function getFilters() { - return { - entityType: $reactionArea.attr('data-entity-type'), - entityId: $reactionArea.attr('data-entity-id') - }; - } + function getFilters() { + return { + entityType: $reactionArea.attr('data-entity-type'), + entityId: $reactionArea.attr('data-entity-id') + }; + } - function registerClickOfReactionIcons($container) { - $container.find('.cms-reaction-icon').each(function () { - var $icon = $(this); - var reactionName = $icon.attr('data-reaction-name'); - if ($icon.attr('data-click-action') === 'false'){ - return; - } - $icon.click(function () { - var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create'; - volo.cmsKit.public.reactions.reactionPublic[methodName]( - $reactionArea.attr('data-entity-type'), - $reactionArea.attr('data-entity-id'), - reactionName - ).then(function () { - $selectIcon.popover('hide'); - widgetManager.refresh($widget); - }); + function registerClickOfReactionIcons($container) { + $container.find('.cms-reaction-icon').each(function () { + var $icon = $(this); + var reactionName = $icon.attr('data-reaction-name'); + if ($icon.attr('data-click-action') === 'false') { + return; + } + $icon.click(function () { + var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create'; + volo.cmsKit.public.reactions.reactionPublic[methodName]( + $reactionArea.attr('data-entity-type'), + $reactionArea.attr('data-entity-id'), + reactionName + ).then(function () { + $selectIcon.popover('hide'); + widgetManager.refresh($widget); }); }); - } + }); + } - function init() { + function init() { - $selectIcon.popover({ - placement: 'left', - html: true, - trigger: 'focus', - title: l('PickYourReaction'), - content: $popoverContent.html() - }).on('shown.bs.popover', function () { - var $popover = $('#' + $selectIcon.attr('aria-describedby')); - registerClickOfReactionIcons($popover); - }); + $selectIcon.popover({ + placement: 'left', + html: true, + trigger: 'focus', + title: l('PickYourReaction'), + content: $popoverContent.html() + }).on('shown.bs.popover', function () { + var $popover = $('#' + $selectIcon.attr('aria-describedby')); + registerClickOfReactionIcons($popover); + }); - registerClickOfReactionIcons($widget); - } + registerClickOfReactionIcons($widget); + } - return { - init: init, - getFilters: getFilters - }; + return { + init: init, + getFilters: getFilters }; - - $('.abp-widget-wrapper[data-widget-name="CmsReactionSelection"]') - .each(function () { - var widgetManager = new abp.WidgetManager({ - wrapper: $(this), - }); - - widgetManager.init(); - }); - }); + }; })(jQuery); diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Reactions/ReactionPublicAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Reactions/ReactionPublicAppService_Tests.cs index 9bf0e0b881..bbb928e99e 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Reactions/ReactionPublicAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Reactions/ReactionPublicAppService_Tests.cs @@ -65,13 +65,13 @@ namespace Volo.CmsKit.Reactions UsingDbContext(context => { - var reaction = context.Set().FirstOrDefault(x => + var reaction = context.Set().Where(x => x.CreatorId == _cmsKitTestData.User1Id && x.ReactionName == StandardReactions.Eyes && x.EntityId == _cmsKitTestData.EntityId2 && - x.EntityType == _cmsKitTestData.EntityType2); + x.EntityType == _cmsKitTestData.EntityType2).ToList(); - reaction.ShouldNotBeNull(); + reaction.Count.ShouldBe(1); }); }