From 44c4fa784c32626b7b13263e7c60db452352c9dd Mon Sep 17 00:00:00 2001 From: Alperen Samurlu Date: Mon, 17 Nov 2025 13:48:04 +0300 Subject: [PATCH 1/2] Display average rating and total ratings in UI Added 'Average Rating' and 'Total Ratings' labels to localization and updated the rating component to show average rating and total ratings in the modal and main view. Calculated average rating in the view component and passed it to the view model. Removed undo rating functionality and related UI/JS code for a simplified rating experience. --- .../CmsKit/Localization/Resources/en.json | 2 ++ .../Shared/Components/Rating/Default.cshtml | 18 +++++----- .../Components/Rating/RatingViewComponent.cs | 4 +++ .../Shared/Components/Rating/default.js | 34 ++++--------------- 4 files changed, 21 insertions(+), 37 deletions(-) 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 { From fce9165a2c279a7be188b0b13310c6e2c8c90642 Mon Sep 17 00:00:00 2001 From: Alperen Samurlu Date: Thu, 20 Nov 2025 14:54:20 +0300 Subject: [PATCH 2/2] Make rating modal IDs unique per entity Generates unique modal and label IDs for the rating detail modal based on entity type and ID, preventing conflicts when multiple rating components are rendered on the same page. --- .../CmsKit/Shared/Components/Rating/Default.cshtml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 9ce4632856..0c0a1dc8f5 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 @@ -5,6 +5,12 @@ @model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating.RatingViewModel @inject IHtmlLocalizer L +@{ + var modalId = "ratingDetail_" + Model.EntityType + "_" + Model.EntityId; + modalId = modalId.Replace(".", "-").Replace(":", "-").Replace("/", "-").Replace(" ", "-"); + var modalLabelId = modalId + "_label"; +} +