Browse Source

Implement widget auto initialize.

pull/5569/head
Halil İbrahim Kalkan 6 years ago
parent
commit
28ba0bd8a1
  1. 19
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/widget-manager.js
  2. 9
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/AbpViewComponentHelper.cs
  3. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs
  4. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs
  5. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs
  6. 272
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js
  7. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/RatingViewComponent.cs
  8. 151
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/default.js
  9. 3
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs
  10. 104
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js
  11. 6
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Reactions/ReactionPublicAppService_Tests.cs

19
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; 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); })(jQuery);

9
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}\""); wrapperAttributesBuilder.Append($" data-refresh-url=\"{widget.RefreshUrl}\"");
} }
if (widget.AutoInitialize)
{
wrapperAttributesBuilder.Append(" data-widget-auto-init=\"true\"");
}
return new HtmlContentBuilder() return new HtmlContentBuilder()
.AppendHtml($"<div {wrapperAttributesBuilder}>") .AppendHtml($"<div {wrapperAttributesBuilder}>")
.AppendHtml(await DefaultViewComponentHelper.InvokeAsync(widget.ViewComponentType, arguments)) .AppendHtml(await DefaultViewComponentHelper.InvokeAsync(widget.ViewComponentType, arguments))
.AppendHtml("</div>"); .AppendHtml("</div>");
} }
} }
} }

2
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 string RefreshUrl { get; set; }
public bool AutoInitialize { get; set; }
public static bool IsWidget(Type type) public static bool IsWidget(Type type)
{ {
return type.IsSubclassOf(typeof(ViewComponent)) && return type.IsSubclassOf(typeof(ViewComponent)) &&

3
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] [CanBeNull]
public string RefreshUrl { get; set; } public string RefreshUrl { get; set; }
public bool AutoInitialize { get; set; }
public WidgetDefinition( public WidgetDefinition(
[NotNull] Type viewComponentType, [NotNull] Type viewComponentType,
[CanBeNull] ILocalizableString displayName = null) [CanBeNull] ILocalizableString displayName = null)
@ -64,6 +66,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets
Styles = GetStyles(WidgetAttribute); Styles = GetStyles(WidgetAttribute);
Scripts = GetScripts(WidgetAttribute); Scripts = GetScripts(WidgetAttribute);
RefreshUrl = WidgetAttribute.RefreshUrl; RefreshUrl = WidgetAttribute.RefreshUrl;
AutoInitialize = WidgetAttribute.AutoInitialize;
} }
private static List<WidgetResourceItem> GetStyles(WidgetAttribute widgetAttribute) private static List<WidgetResourceItem> GetStyles(WidgetAttribute widgetAttribute)

4
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;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
using Volo.CmsKit.Public.Comments; using Volo.CmsKit.Public.Comments;
using Volo.CmsKit.Web;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting 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( [Widget(
ScriptTypes = new[] {typeof(CommentingScriptBundleContributor)}, ScriptTypes = new[] {typeof(CommentingScriptBundleContributor)},
StyleTypes = new[] {typeof(CommentingStyleBundleContributor)}, StyleTypes = new[] {typeof(CommentingStyleBundleContributor)},
RefreshUrl = "/CmsKitPublicWidgets/Commenting" RefreshUrl = "/CmsKitPublicWidgets/Commenting",
AutoInitialize = true
)] )]
public class CommentingViewComponent : AbpViewComponent public class CommentingViewComponent : AbpViewComponent
{ {

272
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'); 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) { function getFilters() {
var widgetManager = $widget.data('abp-widget-manager'); return {
var $commentArea = $widget.find('.cms-comment-area'); 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) { function registerEditLinks($container) {
$container.find('.comment-edit-link').each(function () { $container.find('.comment-edit-link').each(function () {
var $link = $(this); var $link = $(this);
$link.on('click', function (e) { $link.on('click', function (e) {
e.preventDefault(); e.preventDefault();
var commentId = $link.data('id'); var commentId = $link.data('id');
var $relatedCommentContentArea = $container.find('.cms-comment-content-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 + ']'); var $relatedCommentEditFormArea = $container.find('.cms-comment-edit-area[data-id=' + commentId + ']');
$relatedCommentContentArea.hide(); $relatedCommentContentArea.hide();
$relatedCommentEditFormArea.show(); $relatedCommentEditFormArea.show();
$link.removeAttr('href'); $link.removeAttr('href');
});
}); });
$container.find('.comment-edit-cancel-button').each(function () { });
var $button = $(this); $container.find('.comment-edit-cancel-button').each(function () {
$button.on('click', function (e) { var $button = $(this);
e.preventDefault(); $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 $relatedCommentContentArea = $container.find('.cms-comment-content-area[data-id=' + commentId + ']');
var $relatedCommentEditFormArea = $container.find('.cms-comment-edit-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 $link = $container.find('.comment-edit-link[data-id=' + commentId + ']');
$relatedCommentContentArea.show(); $relatedCommentContentArea.show();
$relatedCommentEditFormArea.hide(); $relatedCommentEditFormArea.hide();
$link.attr('href', '#'); $link.attr('href', '#');
});
}); });
} });
}
function registerReplyLinks($container) { function registerReplyLinks($container) {
$container.find('.comment-reply-link').each(function () { $container.find('.comment-reply-link').each(function () {
var $link = $(this); var $link = $(this);
$link.on('click', function (e) { $link.on('click', function (e) {
e.preventDefault(); 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 $relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id=' + replyCommentId + ']');
var $links = $container.find('.comment-reply-link[data-reply-id=' + replyCommentId + ']'); var $links = $container.find('.comment-reply-link[data-reply-id=' + replyCommentId + ']');
$relatedCommentArea.show(); $relatedCommentArea.show();
$relatedCommentArea.find('textarea').focus(); $relatedCommentArea.find('textarea').focus();
$links.addClass('disabled'); $links.addClass('disabled');
});
}); });
$container.find('.reply-cancel-button').each(function () { });
var $button = $(this); $container.find('.reply-cancel-button').each(function () {
$button.on('click', function (e) { var $button = $(this);
e.preventDefault(); $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 $relatedCommentArea = $container.find('.cms-comment-form-area[data-reply-id=' + replyCommentId + ']');
var $links = $container.find('.comment-reply-link[data-reply-id=' + replyCommentId + ']'); var $links = $container.find('.comment-reply-link[data-reply-id=' + replyCommentId + ']');
$relatedCommentArea.hide(); $relatedCommentArea.hide();
$links.removeClass('disabled'); $links.removeClass('disabled');
});
}); });
} });
}
function registerDeleteLinks($container) {
$container.find('.comment-delete-link').each(function () { function registerDeleteLinks($container) {
var $link = $(this); $container.find('.comment-delete-link').each(function () {
$link.on('click', '', function (e) { var $link = $(this);
e.preventDefault(); $link.on('click', '', function (e) {
e.preventDefault();
abp.message.confirm(l("MessageDeletionConfirmationMessage"), function (ok) {
if (ok) { abp.message.confirm(l("MessageDeletionConfirmationMessage"), function (ok) {
volo.cmsKit.public.comments.commentPublic.delete($link.data('id') if (ok) {
).then(function () { volo.cmsKit.public.comments.commentPublic.delete($link.data('id')
widgetManager.refresh($widget); ).then(function () {
}); widgetManager.refresh($widget);
} });
}); }
}); });
}); });
} });
}
function registerUpdateOfNewComment($container) {
$container.find('.cms-comment-update-form').each(function () { function registerUpdateOfNewComment($container) {
var $form = $(this); $container.find('.cms-comment-update-form').each(function () {
$form.submit(function (e) { var $form = $(this);
e.preventDefault(); $form.submit(function (e) {
var formAsObject = $form.serializeFormToObject(); e.preventDefault();
volo.cmsKit.public.comments.commentPublic.update( var formAsObject = $form.serializeFormToObject();
formAsObject.id, volo.cmsKit.public.comments.commentPublic.update(
{ formAsObject.id,
text: formAsObject.commentText {
} text: formAsObject.commentText
).then(function () { }
widgetManager.refresh($widget); ).then(function () {
}); widgetManager.refresh($widget);
}); });
}); });
} });
}
function registerSubmissionOfNewComment($container) {
$container.find('.cms-comment-form').each(function () { function registerSubmissionOfNewComment($container) {
var $form = $(this); $container.find('.cms-comment-form').each(function () {
$form.submit(function (e) { var $form = $(this);
e.preventDefault(); $form.submit(function (e) {
var formAsObject = $form.serializeFormToObject(); e.preventDefault();
volo.cmsKit.public.comments.commentPublic.create( var formAsObject = $form.serializeFormToObject();
$commentArea.attr('data-entity-type'), volo.cmsKit.public.comments.commentPublic.create(
$commentArea.attr('data-entity-id'), $commentArea.attr('data-entity-type'),
{ $commentArea.attr('data-entity-id'),
repliedCommentId: formAsObject.repliedCommentId, {
text: formAsObject.commentText repliedCommentId: formAsObject.repliedCommentId,
} text: formAsObject.commentText
).then(function () { }
widgetManager.refresh($widget); ).then(function () {
}); widgetManager.refresh($widget);
}); });
}); });
} });
}
function focusOnHash($container) { function focusOnHash($container) {
if (!location.hash.toLowerCase().startsWith('#cms-comment')) { if (!location.hash.toLowerCase().startsWith('#cms-comment')) {
return; return;
} }
var $link = $(location.hash + '_link'); var $link = $(location.hash + '_link');
if ($link.length > 0) { if ($link.length > 0) {
$link.click(); $link.click();
}
else {
$(location.hash).find('textarea').focus();
}
} }
else {
$(location.hash).find('textarea').focus();
}
}
function init() { function init() {
registerReplyLinks($widget); registerReplyLinks($widget);
registerEditLinks($widget); registerEditLinks($widget);
registerDeleteLinks($widget); registerDeleteLinks($widget);
registerUpdateOfNewComment($widget); registerUpdateOfNewComment($widget);
registerSubmissionOfNewComment($widget); registerSubmissionOfNewComment($widget);
focusOnHash($widget); focusOnHash($widget);
} }
return { return {
init: init, init: init,
getFilters: getFilters getFilters: getFilters
};
}; };
};
$('.abp-widget-wrapper[data-widget-name="CmsCommenting"]')
.each(function () {
var widgetManager = new abp.WidgetManager({
wrapper: $(this),
});
widgetManager.init($(this));
});
});
})(jQuery); })(jQuery);

11
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( [Widget(
StyleTypes = new[] {typeof(RatingStyleBundleContributor)}, StyleTypes = new[] {typeof(RatingStyleBundleContributor)},
ScriptTypes = new[] {typeof(RatingScriptBundleContributor)}, ScriptTypes = new[] {typeof(RatingScriptBundleContributor)},
RefreshUrl = "/CmsKitPublicWidgets/Rating" RefreshUrl = "/CmsKitPublicWidgets/Rating",
AutoInitialize = true
)] )]
public class RatingViewComponent : AbpViewComponent public class RatingViewComponent : AbpViewComponent
{ {
@ -29,7 +30,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating
AbpMvcUiOptions = options.Value; AbpMvcUiOptions = options.Value;
CurrentUser = currentUser; CurrentUser = currentUser;
} }
public virtual async Task<IViewComponentResult> InvokeAsync(string entityType, string entityId) public virtual async Task<IViewComponentResult> InvokeAsync(string entityType, string entityId)
{ {
var ratings = await RatingPublicAppService.GetGroupedStarCountsAsync(entityType, 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; currentUserRating = ratings.Find(x => x.IsSelectedByCurrentUser)?.StarCount;
} }
var loginUrl = var loginUrl =
$"{AbpMvcUiOptions.LoginUrl}?returnUrl={HttpContext.Request.Path.ToString()}&returnUrlHash=#cms-rating_{entityType}_{entityId}"; $"{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, CurrentRating = currentUserRating,
TotalRating = totalRating TotalRating = totalRating
}; };
return View("~/Pages/CmsKit/Shared/Components/Rating/Default.cshtml", viewModel); 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; } public int TotalRating { get; set; }
} }
} }

151
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/default.js

@ -1,93 +1,82 @@
(function () { (function () {
var l = abp.localization.getResource("CmsKit"); var l = abp.localization.getResource("CmsKit");
$(document).ready(function () { abp.widgets.CmsRating = function ($widget) {
abp.widgets.CmsRating = function ($widget) { var widgetManager = $widget.data("abp-widget-manager");
var widgetManager = $widget.data("abp-widget-manager"); var $ratingArea = $widget.find(".cms-rating-area");
var $ratingArea = $widget.find(".cms-rating-area");
function getFilters() { function getFilters() {
return { return {
entityType: $ratingArea.attr("data-entity-type"), entityType: $ratingArea.attr("data-entity-type"),
entityId: $ratingArea.attr("data-entity-id") 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 registerUndoLink() { function registerCreateOfNewRating() {
$widget.find(".rating-undo-link").each(function () { $widget.find(".my-rating").each(function () {
$(this).on('click', '', function (e) { var authenticated = $(this).attr("data-authenticated");
e.preventDefault();
abp.message.confirm(l("RatingUndoMessage"), function (ok) { $(this).starRating({
if (ok) { initialRating: 0,
volo.cmsKit.public.ratings.ratingPublic.delete( starSize: 16,
$ratingArea.attr("data-entity-type"), emptyColor: '#eee',
$ratingArea.attr("data-entity-id") hoverColor: '#ffc107',
).then(function () { activeColor: '#ffc107',
widgetManager.refresh($widget); 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() { function registerUndoLink() {
registerCreateOfNewRating(); $widget.find(".rating-undo-link").each(function () {
registerUndoLink(); $(this).on('click', '', function (e) {
} e.preventDefault();
return { abp.message.confirm(l("RatingUndoMessage"), function (ok) {
init: init, if (ok) {
getFilters: getFilters volo.cmsKit.public.ratings.ratingPublic.delete(
} $ratingArea.attr("data-entity-type"),
}; $ratingArea.attr("data-entity-id")
).then(function () {
$('.abp-widget-wrapper[data-widget-name="CmsRating"]') widgetManager.refresh($widget);
.each(function () { });
var widgetManager = new abp.WidgetManager({ }
wrapper: $(this), })
}); });
widgetManager.init($(this));
}); });
}); }
function init() {
registerCreateOfNewRating();
registerUndoLink();
}
return {
init: init,
getFilters: getFilters
}
};
}) })
(jQuery); (jQuery);

3
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( [Widget(
ScriptTypes = new[] {typeof(ReactionSelectionScriptBundleContributor)}, ScriptTypes = new[] {typeof(ReactionSelectionScriptBundleContributor)},
StyleTypes = new[] {typeof(ReactionSelectionStyleBundleContributor)}, StyleTypes = new[] {typeof(ReactionSelectionStyleBundleContributor)},
RefreshUrl = "/CmsKitPublicWidgets/ReactionSelection" RefreshUrl = "/CmsKitPublicWidgets/ReactionSelection",
AutoInitialize = true
)] )]
public class ReactionSelectionViewComponent : AbpViewComponent public class ReactionSelectionViewComponent : AbpViewComponent
{ {

104
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'); 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) { function getFilters() {
var widgetManager = $widget.data('abp-widget-manager'); return {
var $reactionArea = $widget.find('.cms-reaction-area'); entityType: $reactionArea.attr('data-entity-type'),
var $selectIcon = $widget.find('.cms-reaction-select-icon'); entityId: $reactionArea.attr('data-entity-id')
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 registerClickOfReactionIcons($container) { function registerClickOfReactionIcons($container) {
$container.find('.cms-reaction-icon').each(function () { $container.find('.cms-reaction-icon').each(function () {
var $icon = $(this); var $icon = $(this);
var reactionName = $icon.attr('data-reaction-name'); var reactionName = $icon.attr('data-reaction-name');
if ($icon.attr('data-click-action') === 'false'){ if ($icon.attr('data-click-action') === 'false') {
return; return;
} }
$icon.click(function () { $icon.click(function () {
var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create'; var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create';
volo.cmsKit.public.reactions.reactionPublic[methodName]( volo.cmsKit.public.reactions.reactionPublic[methodName](
$reactionArea.attr('data-entity-type'), $reactionArea.attr('data-entity-type'),
$reactionArea.attr('data-entity-id'), $reactionArea.attr('data-entity-id'),
reactionName reactionName
).then(function () { ).then(function () {
$selectIcon.popover('hide'); $selectIcon.popover('hide');
widgetManager.refresh($widget); widgetManager.refresh($widget);
});
}); });
}); });
} });
}
function init() { function init() {
$selectIcon.popover({ $selectIcon.popover({
placement: 'left', placement: 'left',
html: true, html: true,
trigger: 'focus', trigger: 'focus',
title: l('PickYourReaction'), title: l('PickYourReaction'),
content: $popoverContent.html() content: $popoverContent.html()
}).on('shown.bs.popover', function () { }).on('shown.bs.popover', function () {
var $popover = $('#' + $selectIcon.attr('aria-describedby')); var $popover = $('#' + $selectIcon.attr('aria-describedby'));
registerClickOfReactionIcons($popover); registerClickOfReactionIcons($popover);
}); });
registerClickOfReactionIcons($widget); registerClickOfReactionIcons($widget);
} }
return { return {
init: init, init: init,
getFilters: getFilters getFilters: getFilters
};
}; };
};
$('.abp-widget-wrapper[data-widget-name="CmsReactionSelection"]')
.each(function () {
var widgetManager = new abp.WidgetManager({
wrapper: $(this),
});
widgetManager.init();
});
});
})(jQuery); })(jQuery);

6
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Reactions/ReactionPublicAppService_Tests.cs

@ -65,13 +65,13 @@ namespace Volo.CmsKit.Reactions
UsingDbContext(context => UsingDbContext(context =>
{ {
var reaction = context.Set<UserReaction>().FirstOrDefault(x => var reaction = context.Set<UserReaction>().Where(x =>
x.CreatorId == _cmsKitTestData.User1Id && x.CreatorId == _cmsKitTestData.User1Id &&
x.ReactionName == StandardReactions.Eyes && x.ReactionName == StandardReactions.Eyes &&
x.EntityId == _cmsKitTestData.EntityId2 && x.EntityId == _cmsKitTestData.EntityId2 &&
x.EntityType == _cmsKitTestData.EntityType2); x.EntityType == _cmsKitTestData.EntityType2).ToList();
reaction.ShouldNotBeNull(); reaction.Count.ShouldBe(1);
}); });
} }

Loading…
Cancel
Save