diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json index e3c3600eb0..364df5ab2d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json @@ -3,6 +3,7 @@ "texts": { "AddSubMenuItem": "Add Sub Menu Item", "AreYouSure": "Are You Sure?", + "AverageRating": "Average Rating", "BlogDeletionConfirmationMessage": "The blog '{0}' will be deleted. Are you sure?", "BlogFeatureNotAvailable": "This feature is not available now. Enable with 'GlobalFeatureManager' to use it.", "BlogId": "Blog", @@ -168,6 +169,7 @@ "Text": "Text", "ThankYou": "Thank you", "Title": "Title", + "TotalRatings": "Total Ratings", "Undo": "Undo", "Update": "Update", "UpdatePreferenceSuccessMessage": "Your preferences have been saved.", diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/Default.cshtml index 95879128a7..9ce4632856 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/Default.cshtml @@ -11,13 +11,7 @@ @if (CurrentUser.IsAuthenticated) { - @if (!Model.IsReadOnly && Model.CurrentRating != null) - { - - @L["Undo"] - - } - if (Model.Ratings != null) + @if (Model.Ratings != null) { @@ -31,6 +25,11 @@ "> } 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 7ab1df47b8..75308d105f 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 @@ -35,6 +35,7 @@ public class RatingViewComponent : AbpViewComponent { var ratings = await RatingPublicAppService.GetGroupedStarCountsAsync(entityType, entityId); var totalRating = ratings.Sum(x => x.Count); + var averageRating = totalRating > 0 ? (double)ratings.Sum(x => x.StarCount * x.Count) / totalRating : 0; short? currentUserRating = null; if (CurrentUser.IsAuthenticated) @@ -53,6 +54,7 @@ public class RatingViewComponent : AbpViewComponent Ratings = ratings, CurrentRating = currentUserRating, TotalRating = totalRating, + AverageRating = averageRating, IsReadOnly = isReadOnly }; @@ -74,5 +76,7 @@ public class RatingViewModel public int TotalRating { get; set; } + public double AverageRating { get; set; } + public bool IsReadOnly { get; set; } } 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 69bb1bac4f..4647d55c70 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 @@ -16,24 +16,22 @@ $widget.find(".my-rating").each(function () { var authenticated = $(this).attr("data-authenticated"); var readonly = $(this).attr("data-readonly"); + var currentRating = parseInt($(this).attr("data-rating")) || 0; + var $liveRating = $widget.find(".live-rating"); + var averageRating = $liveRating.text(); $(this).starRating({ - initialRating: 0, + initialRating: currentRating, starSize: 16, emptyColor: '#eee', hoverColor: '#ffc107', activeColor: '#ffc107', useGradient: false, strokeWidth: 0, - disableAfterRate: true, + disableAfterRate: false, useFullStars: true, readOnly: authenticated === "True" || readonly === "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"), @@ -50,28 +48,8 @@ ); } - function registerUndoLink() { - $widget.find(".rating-undo-link").each(function () { - $(this).on('click', '', function (e) { - e.preventDefault(); - - 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); - }); - } - }) - }); - }); - } - function init() { registerCreateOfNewRating(); - registerUndoLink(); } return {