From 9b0d16fefbf390ad0cc7c41e33d52d5d7fb1aa76 Mon Sep 17 00:00:00 2001 From: EmreKendirli Date: Tue, 21 May 2024 11:04:22 +0300 Subject: [PATCH] approve page was made --- .../CmsKitAdminWebModule.cs | 4 +- .../Components/CommentsSetting/Index.cshtml | 6 +-- .../{Waiting => Approve}/Index.cshtml | 2 +- .../{Waiting => Approve}/Index.cshtml.cs | 2 +- .../Comments/{Waiting => Approve}/index.js | 52 ++++++------------- .../Pages/CmsKit/Comments/Details.cshtml | 12 +++++ .../Pages/CmsKit/Comments/Details.cshtml.cs | 1 + .../Pages/CmsKit/Comments/Index.cshtml | 17 +++--- .../Pages/CmsKit/Comments/Index.cshtml.cs | 2 +- .../Pages/CmsKit/Comments/details.js | 24 ++++++++- .../Pages/CmsKit/Comments/index.js | 32 +++++++++--- ...or.cs => CommentSettingPageContributor.cs} | 9 +++- .../Volo.CmsKit.Admin.Web.csproj | 2 +- .../CmsKit/Localization/Resources/en.json | 22 ++++++-- .../CmsKit/Comments/ICommentRepository.cs | 2 +- .../Comments/MongoCommentRepository.cs | 21 +++----- .../Comments/CommentPublicAppService.cs | 6 +-- 17 files changed, 133 insertions(+), 83 deletions(-) rename modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/{Waiting => Approve}/Index.cshtml (97%) rename modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/{Waiting => Approve}/Index.cshtml.cs (85%) rename modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/{Waiting => Approve}/index.js (76%) rename modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/{BookStoreSettingPageContributor.cs => CommentSettingPageContributor.cs} (67%) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/CmsKitAdminWebModule.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/CmsKitAdminWebModule.cs index 50b9922af6..47e1f3a1ff 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/CmsKitAdminWebModule.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/CmsKitAdminWebModule.cs @@ -110,7 +110,7 @@ public class CmsKitAdminWebModule : AbpModule options.Conventions.AddPageRoute("/CmsKit/Comments/Details", "/Cms/Comments/{Id}"); options.Conventions.AddPageRoute("/CmsKit/Menus/MenuItems/Index", "/Cms/Menus/Items"); options.Conventions.AddPageRoute("/CmsKit/GlobalResources/Index", "/Cms/GlobalResources"); - options.Conventions.AddPageRoute("/CmsKit/Comments/Waiting/Index", "/Cms/Comments/Waiting"); + options.Conventions.AddPageRoute("/CmsKit/Comments/Approve/Index", "/Cms/Comments/Approve"); }); @@ -189,7 +189,7 @@ public class CmsKitAdminWebModule : AbpModule Configure(options => { - options.Contributors.Add(new BookStoreSettingPageContributor()); + options.Contributors.Add(new CommentSettingPageContributor()); }); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml index 77e164d6dc..cfb222f38d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml @@ -17,14 +17,14 @@ @inject IHtmlLocalizer L -

@L["CommentSettings:Title"].Value

+

@L["CmsKitCommentOptions:Title"].Value


- +
- @L["CommentSettings:RequireApprovementDescription"].Value + @L["CmsKitCommentOptions:RequireApprovementDescription"].Value
diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/Index.cshtml b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml similarity index 97% rename from modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/Index.cshtml rename to modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml index 24c64a2210..2c02778731 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/Index.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml @@ -27,7 +27,7 @@ - + } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/Index.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml.cs similarity index 85% rename from modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/Index.cshtml.cs rename to modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml.cs index cca3212629..ebc326997a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/Index.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml.cs @@ -2,7 +2,7 @@ using System; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments.Waiting; +namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments.Approve; public class IndexModel : CmsKitAdminPageModel { diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/index.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/index.js similarity index 76% rename from modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/index.js rename to modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/index.js index 7b6eb22bae..c9b9dbc4df 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/index.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/index.js @@ -17,8 +17,8 @@ }; - var defaultStartDate = moment().add(-7, 'days'); - $("#CreationStartDate").val(defaultStartDate.format('L')); + //var defaultStartDate = moment().add(-7, 'days'); + //$("#CreationStartDate").val(defaultStartDate.format('L')); $('.singledatepicker').daterangepicker({ "singleDatePicker": true, @@ -67,32 +67,31 @@ rowAction: { items: [ { - text: l('Details'), - action: function (data) { - location.href = 'Comments/' + data.record.id; - } - }, - { - text: l('Delete'), - visible: abp.auth.isGranted('CmsKit.Comments.Delete'), - confirmMessage: function (data) { - return l("CommentDeletionConfirmationMessage") + text: function (data) { + return l('Approve'); }, action: function (data) { + var newApprovalStatus = true; + commentsService - .delete(data.record.id) + .updateApprovalStatus(data.record.id, { IsApproved: newApprovalStatus }) .then(function () { _dataTable.ajax.reloadEx(); - abp.notify.success(l('DeletedSuccessfully')); + var message = newApprovalStatus ? l('ApprovedSuccessfully') : l('ApprovalRevokedSuccessfully'); + abp.notify.success(message); + }) + .catch(function (error) { + console.log("error", error) + abp.notify.error(error.message); }); } }, { text: function (data) { - return data.isApproved ? l('Revoke Approval') : l('Approve'); + return l('Revoke Approval') ; }, action: function (data) { - var newApprovalStatus = !data.record?.isApproved; + var newApprovalStatus = false; commentsService .updateApprovalStatus(data.record.id, { IsApproved: newApprovalStatus }) @@ -134,16 +133,6 @@ return ""; } }, - { - title: l("URL"), - data: "url", - render: function (data, type, row) { - if (data !== null) { - return ''; - } - return ""; - } - }, { title: l("Text"), data: "text", @@ -151,20 +140,13 @@ render: function (data) { data = $.fn.dataTable.render.text().display(data || ""); - var maxChars = 64; - - if (data.length > maxChars) { return ( '' + - data.substring(0, maxChars) + - "..." + + '" style="white-space: normal; word-break: break-all;">' + + data + "" ); - } else { - return data; - } } }, { diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml index 8e4cfbdb4e..9af37889fd 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml @@ -93,6 +93,18 @@ + +
+ + +
+
+
diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs index f1e793987f..27f1b04797 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs @@ -15,6 +15,7 @@ public class DetailsModel : CmsKitAdminPageModel public DateTime? CreationStartDate { get; set; } public DateTime? CreationEndDate { get; set; } + public string IsApproved { get; set; } public CommentWithAuthorDto CommentWithAuthorDto { get; protected set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml index 33fa9bf1eb..2bb31d8c38 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml @@ -42,7 +42,7 @@ - + @@ -59,12 +59,15 @@ - +
+ + +
diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs index 4fb5b46e4e..245937b45f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs @@ -8,7 +8,7 @@ public class IndexModel : CmsKitAdminPageModel public string Author { get; set; } - public DateTime? CreationStartDate { get; set; } + public DateTime? CreationStartDate { get; set; } = null; public DateTime? CreationEndDate { get; set; } public string IsApproved { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js index 33e1c2228c..ed85779569 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js @@ -81,7 +81,7 @@ $(function (){ }, { text: function (data) { - return data.isApproved ? l('Revoke Approval') : l('Approve'); + return data.isApproved ? l('Disapproved') : l('Approve'); }, action: function (data) { var newApprovalStatus = !data.record?.isApproved; @@ -94,7 +94,27 @@ $(function (){ abp.notify.success(message); }) .catch(function (error) { - console.log("error", error) + abp.notify.error(error.message); + }); + } + }, + { + text: function (data) { + if (data.isApproved == null) { + return l('Disapproved') + } + }, + action: function (data) { + var newApprovalStatus = false; + + commentsService + .updateApprovalStatus(data.record.id, { IsApproved: newApprovalStatus }) + .then(function () { + _dataTable.ajax.reloadEx(); + var message = newApprovalStatus ? l('ApprovedSuccessfully') : l('ApprovalRevokedSuccessfully'); + abp.notify.success(message); + }) + .catch(function (error) { abp.notify.error(error.message); }); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js index 447e6f2e17..f103f1c142 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js @@ -17,8 +17,8 @@ $(function (){ }; - var defaultStartDate = moment().add(-7, 'days'); - $("#CreationStartDate").val(defaultStartDate.format('L')); + //var defaultStartDate = moment().add(-7, 'days'); + //$("#CreationStartDate").val(defaultStartDate.format('L')); $('.singledatepicker').daterangepicker({ "singleDatePicker": true, @@ -89,7 +89,7 @@ $(function (){ }, { text: function (data) { - return data.isApproved ? l('Revoke Approval') : l('Approve'); + return data.isApproved ? l('Disapproved') : l('Approve'); }, action: function (data) { var newApprovalStatus = !data.record?.isApproved; @@ -102,7 +102,27 @@ $(function (){ abp.notify.success(message); }) .catch(function (error) { - console.log("error", error) + abp.notify.error(error.message); + }); + } + }, + { + text: function (data) { + if (data.isApproved == null) { + return l('Disapproved') + } + }, + action: function (data) { + var newApprovalStatus = false; + + commentsService + .updateApprovalStatus(data.record.id, { IsApproved: newApprovalStatus }) + .then(function () { + _dataTable.ajax.reloadEx(); + var message = newApprovalStatus ? l('ApprovedSuccessfully') : l('ApprovalRevokedSuccessfully'); + abp.notify.success(message); + }) + .catch(function (error) { abp.notify.error(error.message); }); } @@ -220,12 +240,12 @@ $(function (){ commentsService.getPendingCommentCount().then(function (count) { console.log(count) if (count > 0) { - var alertMessage = 'You have pending comments: ' + count; + var alertMessage = l("CommentAlertMessage") + count + ""; var alertElement = '' + alertMessage + ''; $('#commentsAlert').html(alertElement); $('#commentsAlert').show() $('#commentsAlert').click(function () { - window.location.href = '/Cms/Comments/Waiting' + window.location.href = '/Cms/Comments/Approve' }); } }); diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/BookStoreSettingPageContributor.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs similarity index 67% rename from modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/BookStoreSettingPageContributor.cs rename to modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs index 55e414f589..5ea7383087 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/BookStoreSettingPageContributor.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs @@ -1,17 +1,22 @@ using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; using Volo.Abp.SettingManagement.Web.Pages.SettingManagement; using Volo.CmsKit.Admin.Web.Components.MySettingGroup; +using Volo.CmsKit.Localization; namespace Volo.CmsKit.Admin.Web.Settings; -public class BookStoreSettingPageContributor : ISettingPageContributor +public class CommentSettingPageContributor : ISettingPageContributor { + public Task ConfigureAsync(SettingPageCreationContext context) { + var l = context.ServiceProvider.GetRequiredService>(); context.Groups.Add( new SettingPageGroup( "Volo.Abp.MySettingGroup", - "MySettingGroup", + l["Menu:CmsKitCommentOptions"], typeof(CommentSettingViewComponent), order: 1 ) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Volo.CmsKit.Admin.Web.csproj b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Volo.CmsKit.Admin.Web.csproj index 09f1b36a37..a822dafd02 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Volo.CmsKit.Admin.Web.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Volo.CmsKit.Admin.Web.csproj @@ -36,7 +36,7 @@ - + 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 2cc952f1bf..9bb12e6c7e 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 @@ -230,8 +230,24 @@ "DuplicateCommentAttemptMessage": "Duplicate comment post attempt detected. Your comment has already been submitted.", "NoBlogPostYet": "No blog post yet!", - "CommentSettings:Title": "Comment Settings.", - "CommentSettings:RequireApprovement": "Require approval for comments", - "CommentSettings:RequireApprovementDescription": "When enabled, comments will require approval before being published." + "CmsKitCommentOptions:Title": "Comment Settings.", + "CmsKitCommentOptions:RequireApprovement": "Require approval for comments", + "CmsKitCommentOptions:RequireApprovementDescription": "When enabled, comments will require approval before being published.", + + "CommentFilter:ApproveState":"Approve State", + "CommentFilter:All":"All", + "CommentFilter:Approved":"Approved", + "CommentFilter:Disapproved":"Disapproved", + "CommentFilter:Waiting":"Waiting", + + "ApprovedSuccessfully":"Approved Successfully", + "ApprovalRevokedSuccessfully":"Approval Revoked Successfully", + + "Approve":"Approve", + "Disapproved":"Disapproved", + + "CommentAlertMessage":"You have waiting comments: ", + + "Menu:CmsKitCommentOptions":"CmsKit Comment Options" } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs index 330076ea7e..512cefceda 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs @@ -39,7 +39,7 @@ public interface ICommentRepository : IBasicRepository Task> GetListWithAuthorsAsync( [NotNull] string entityType, [NotNull] string entityId, - bool? isApproved = null, + bool? isApproved, CancellationToken cancellationToken = default ); diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs index b2a11377c1..b26a9b1d26 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs @@ -117,7 +117,7 @@ public class MongoCommentRepository : MongoDbRepository> GetListWithAuthorsAsync( string entityType, string entityId, - bool? isApproved = null, + bool? isApproved, CancellationToken cancellationToken = default) { Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); @@ -134,20 +134,16 @@ public class MongoCommentRepository : MongoDbRepository c.EntityId == entityId && c.EntityType == entityType); - if (isApproved.HasValue) - { - commentsQuery = commentsQuery.Where(c => c.IsApproved == isApproved.Value); - } + + commentsQuery = isApproved.Value ? + commentsQuery.Where(c => c.IsApproved == true) : + commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null); + var comments = await commentsQuery .OrderBy(c => c.CreationTime) .ToListAsync(GetCancellationToken(cancellationToken)); - // var comments = await (await GetMongoQueryableAsync(cancellationToken)) - //.Where(c => c.EntityId == entityId && c.EntityType == entityType ) - // .OrderBy(c => c.CreationTime) - //.ToListAsync(GetCancellationToken(cancellationToken)); - return comments .Select( comment => @@ -213,8 +209,7 @@ public class MongoCommentRepository : MongoDbRepository c.RepliedCommentId == repliedCommentId) .WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate) .WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate); - //.WhereIf(isApproved.HasValue, c => c.IsApproved == isApproved.Value) - //.WhereIf(isApproved == null, c => c.IsApproved == null); + if (!string.IsNullOrWhiteSpace(isApproved)) { bool? isApprovedValue = ParseIsApproved(isApproved); @@ -229,10 +224,8 @@ public class MongoCommentRepository : MongoDbRepository> GetListAsync(string entityType, string entityId) { - string checkboxState = await SettingManager.GetOrNullGlobalAsync(AppSettings.RequireApprovement); + string state = await SettingManager.GetOrNullGlobalAsync(AppSettings.RequireApprovement); - var commentsWithAuthor = bool.Parse(checkboxState) ? - await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, true) : - await CommentRepository.GetListWithAuthorsAsync(entityType, entityId); + var commentsWithAuthor = await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, bool.Parse(state)); return new ListResultDto( ConvertCommentsToNestedStructure(commentsWithAuthor)