Browse Source

refactor

pull/19919/head
Berkan Sasmaz 2 years ago
parent
commit
662eb75cd1
  1. 0
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/wwwroot/libs/codemirror/mode/sas/sas.js
  2. 1392
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/yarn.lock
  3. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs
  4. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentSettingsDto.cs
  5. 11
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs
  6. 1
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/CmsKitAdminApplicationAutoMapperProfile.cs
  7. 41
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs
  8. 8
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/ClientProxies/Volo/CmsKit/Admin/Comments/CommentAdminClientProxy.Generated.cs
  9. 20
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs
  10. 26
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/CmsKitAdminWebModule.cs
  11. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml
  12. 1
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml.cs
  13. 17
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/PrismjsScriptBundleContributorDocsExtension.cs
  14. 306
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/index.js
  15. 10
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml
  16. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs
  17. 10
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml
  18. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs
  19. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js
  20. 12
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveState.cs
  21. 12
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs
  22. 7
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Settings/AppSettings.cs
  23. 8
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs
  24. 6
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  25. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Settings/CmsKitSettingDefinitionProvider.cs
  26. 25
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  27. 71
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
  28. 9
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

0
modules/cms-kit/host/Volo.CmsKit.Web.Unified/wwwroot/libs/codemirror/mode/sas/sas.js

1392
modules/cms-kit/host/Volo.CmsKit.Web.Unified/yarn.lock

File diff suppressed because it is too large

4
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs

@ -19,7 +19,5 @@ public class CommentGetListInput : PagedAndSortedResultRequestDto
public DateTime? CreationEndDate { get; set; } public DateTime? CreationEndDate { get; set; }
public CommentApproveStateType commentApproveStateType { get; set; } public CommentApproveState CommentApproveState { get; set; }
} }

4
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentSettingsDto.cs

@ -1,11 +1,9 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.CmsKit.Admin.Comments; namespace Volo.CmsKit.Admin.Comments;
[Serializable] [Serializable]
public class SettingsDto public class SettingsDto
{ {
public bool RequireApprovement { get; set; } public bool CommentRequireApprovement { get; set; }
} }

11
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs

@ -13,14 +13,13 @@ public interface ICommentAdminAppService : IApplicationService
Task DeleteAsync(Guid id); Task DeleteAsync(Guid id);
Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto commentApprovalDto); Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto input);
Task SetSettings(SettingsDto settingsDto); Task SetSettingsAsync(SettingsDto input);
Task<SettingsDto> GetSettings(); Task<SettingsDto> GetSettingsAsync();
Task<int> GetWaitingCommentCount(); Task<int> GetWaitingCountAsync();
Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input);
Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingWithRepliesAsync(CommentGetListInput input);
} }

1
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/CmsKitAdminApplicationAutoMapperProfile.cs

@ -34,6 +34,7 @@ public class CmsKitAdminApplicationAutoMapperProfile : Profile
CreateMap<BlogPost, BlogPostListDto>() CreateMap<BlogPost, BlogPostListDto>()
.Ignore(d => d.BlogName) .Ignore(d => d.BlogName)
.MapExtraProperties(); .MapExtraProperties();
CreateMap<CreateBlogPostDto, BlogPost>(MemberList.Source).MapExtraProperties(); CreateMap<CreateBlogPostDto, BlogPost>(MemberList.Source).MapExtraProperties();
CreateMap<UpdateBlogPostDto, BlogPost>(MemberList.Source).MapExtraProperties(); CreateMap<UpdateBlogPostDto, BlogPost>(MemberList.Source).MapExtraProperties();

41
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs

@ -38,7 +38,7 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Author, input.Author,
input.CreationStartDate, input.CreationStartDate,
input.CreationEndDate, input.CreationEndDate,
input.commentApproveStateType input.CommentApproveState
); );
@ -52,7 +52,7 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Sorting, input.Sorting,
input.MaxResultCount, input.MaxResultCount,
input.SkipCount, input.SkipCount,
input.commentApproveStateType input.CommentApproveState
); );
var dtos = comments.Select(queryResultItem => var dtos = comments.Select(queryResultItem =>
@ -85,41 +85,35 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
public async Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto commentApprovalDto) public async Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto input)
{ {
var comment = await CommentRepository.GetAsync(id); var comment = await CommentRepository.GetAsync(id);
comment.IsApproved = commentApprovalDto.IsApproved; comment.SetApprovalStatus(input.IsApproved);
await CommentRepository.UpdateAsync(comment); await CommentRepository.UpdateAsync(comment);
} }
public async Task SetSettings(SettingsDto settingsDto) public async Task SetSettingsAsync(SettingsDto input)
{ {
await _settingManager.SetGlobalAsync(AppSettings.RequireApprovement, settingsDto.RequireApprovement.ToString()); await _settingManager.SetGlobalAsync(AppSettings.CommentRequireApprovement, input.CommentRequireApprovement.ToString());
} }
public async Task<SettingsDto> GetSettings() public async Task<SettingsDto> GetSettingsAsync()
{ {
string approvalSettingValue = await _settingManager.GetOrNullGlobalAsync(AppSettings.RequireApprovement); var isRequireApprovementEnabled = bool.Parse(await _settingManager.GetOrNullGlobalAsync(AppSettings.CommentRequireApprovement));
if (bool.TryParse(approvalSettingValue, out bool isApprovalRequired)) return new SettingsDto
{ {
SettingsDto settings = new SettingsDto CommentRequireApprovement = isRequireApprovementEnabled
{ };
RequireApprovement = isApprovalRequired
};
return settings;
}
return null;
} }
public async Task<int> GetWaitingCommentCount()
{
var count = await CommentRepository.GetCountAsync(commentApproveStateType: CommentApproveStateType.Waiting);
return (int)(count);
public async Task<int> GetWaitingCountAsync()
{
return (int) await CommentRepository.GetCountAsync(commentApproveState: CommentApproveState.Waiting);
} }
public async Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input) public async Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingWithRepliesAsync(CommentGetListInput input)
{ {
var totalCount = await CommentRepository.GetCountAsync( var totalCount = await CommentRepository.GetCountAsync(
input.Text, input.Text,
@ -128,10 +122,9 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Author, input.Author,
input.CreationStartDate, input.CreationStartDate,
input.CreationEndDate, input.CreationEndDate,
CommentApproveStateType.Waiting CommentApproveState.Waiting
); );
var comments = await CommentRepository.GetListAsync( var comments = await CommentRepository.GetListAsync(
input.Text, input.Text,
input.EntityType, input.EntityType,
@ -142,7 +135,7 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Sorting, input.Sorting,
input.MaxResultCount, input.MaxResultCount,
input.SkipCount, input.SkipCount,
CommentApproveStateType.Waiting CommentApproveState.Waiting
); );
var dtos = comments.Select(queryResultItem => var dtos = comments.Select(queryResultItem =>

8
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/ClientProxies/Volo/CmsKit/Admin/Comments/CommentAdminClientProxy.Generated.cs

@ -41,12 +41,12 @@ public partial class CommentAdminClientProxy : ClientProxyBase<ICommentAdminAppS
}); });
} }
public virtual async Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto commentApprovalDto) public virtual async Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto input)
{ {
await RequestAsync(nameof(UpdateApprovalStatusAsync), new ClientProxyRequestTypeValue await RequestAsync(nameof(UpdateApprovalStatusAsync), new ClientProxyRequestTypeValue
{ {
{ typeof(Guid), id }, { typeof(Guid), id },
{ typeof(CommentApprovalDto), commentApprovalDto } { typeof(CommentApprovalDto), input }
}); });
} }
@ -68,9 +68,9 @@ public partial class CommentAdminClientProxy : ClientProxyBase<ICommentAdminAppS
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public virtual async Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input) public virtual async Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingWithRepliesAsync(CommentGetListInput input)
{ {
return await RequestAsync<PagedResultDto<CommentWithAuthorDto>>(nameof(GetWaitingCommentsWithRepliesAsync), new ClientProxyRequestTypeValue return await RequestAsync<PagedResultDto<CommentWithAuthorDto>>(nameof(GetWaitingWithRepliesAsync), new ClientProxyRequestTypeValue
{ {
{ typeof(CommentGetListInput), input } { typeof(CommentGetListInput), input }
}); });

20
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs

@ -52,41 +52,41 @@ public class CommentAdminController : CmsKitAdminController, ICommentAdminAppSer
[HttpPost] [HttpPost]
[Route("{id}")] [Route("{id}")]
[Authorize(CmsKitAdminPermissions.Comments.Update)] [Authorize(CmsKitAdminPermissions.Comments.Update)]
public Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto commentApprovalDto) public Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto input)
{ {
return CommentAdminAppService.UpdateApprovalStatusAsync(id, commentApprovalDto); return CommentAdminAppService.UpdateApprovalStatusAsync(id, input);
} }
[HttpPost] [HttpPost]
[Route("settings")] [Route("settings")]
[Authorize(CmsKitAdminPermissions.Comments.Default)] [Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task SetSettings(SettingsDto settingsDto) public Task SetSettingsAsync(SettingsDto input)
{ {
return CommentAdminAppService.SetSettings(settingsDto); return CommentAdminAppService.SetSettingsAsync(input);
} }
[HttpGet] [HttpGet]
[Route("settings")] [Route("settings")]
[Authorize(CmsKitAdminPermissions.Comments.Default)] [Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<SettingsDto> GetSettings() public Task<SettingsDto> GetSettingsAsync()
{ {
return CommentAdminAppService.GetSettings(); return CommentAdminAppService.GetSettingsAsync();
} }
[HttpGet] [HttpGet]
[Route("waiting-count")] [Route("waiting-count")]
[Authorize(CmsKitAdminPermissions.Comments.Default)] [Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<int> GetWaitingCommentCount() public Task<int> GetWaitingCountAsync()
{ {
return CommentAdminAppService.GetWaitingCommentCount(); return CommentAdminAppService.GetWaitingCountAsync();
} }
[HttpGet] [HttpGet]
[Route("waiting")] [Route("waiting")]
[Authorize(CmsKitAdminPermissions.Comments.Default)] [Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input) public Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingWithRepliesAsync(CommentGetListInput input)
{ {
return CommentAdminAppService.GetWaitingCommentsWithRepliesAsync(input); return CommentAdminAppService.GetWaitingWithRepliesAsync(input);
} }
} }

26
modules/cms-kit/src/Volo.CmsKit.Admin.Web/CmsKitAdminWebModule.cs

@ -3,7 +3,9 @@ using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.MarkdownIt;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.Prismjs; using Volo.Abp.AspNetCore.Mvc.UI.Packages.Prismjs;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.PageToolbars; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.PageToolbars;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
using Volo.Abp.Http.ProxyScripting.Generators.JQuery; using Volo.Abp.Http.ProxyScripting.Generators.JQuery;
@ -57,6 +59,7 @@ public class CmsKitAdminWebModule : AbpModule
{ {
options.MenuContributors.Add(new CmsKitAdminMenuContributor()); options.MenuContributors.Add(new CmsKitAdminMenuContributor());
}); });
Configure<AbpBundlingOptions>(options => Configure<AbpBundlingOptions>(options =>
{ {
options.ScriptBundles options.ScriptBundles
@ -64,8 +67,14 @@ public class CmsKitAdminWebModule : AbpModule
configuration => configuration =>
{ {
configuration.AddFiles("/client-proxies/cms-kit-admin-proxy.js"); configuration.AddFiles("/client-proxies/cms-kit-admin-proxy.js");
})
.Configure(StandardBundles.Scripts.Global,
configuration =>
{
configuration.AddContributors(typeof(MarkdownItScriptContributor));
}); });
}); });
Configure<AbpVirtualFileSystemOptions>(options => Configure<AbpVirtualFileSystemOptions>(options =>
{ {
options.FileSets.AddEmbedded<CmsKitAdminWebModule>("Volo.CmsKit.Admin.Web"); options.FileSets.AddEmbedded<CmsKitAdminWebModule>("Volo.CmsKit.Admin.Web");
@ -96,6 +105,7 @@ public class CmsKitAdminWebModule : AbpModule
options.Conventions.AuthorizePage("/CmsKit/Menus/MenuItems/UpdateModal", CmsKitAdminPermissions.Menus.Update); options.Conventions.AuthorizePage("/CmsKit/Menus/MenuItems/UpdateModal", CmsKitAdminPermissions.Menus.Update);
options.Conventions.AuthorizeFolder("/CmsKit/Menus/MenuItems", CmsKitAdminPermissions.Menus.Update); options.Conventions.AuthorizeFolder("/CmsKit/Menus/MenuItems", CmsKitAdminPermissions.Menus.Update);
options.Conventions.AuthorizeFolder("/CmsKit/GlobalResources", CmsKitAdminPermissions.GlobalResources.Default); options.Conventions.AuthorizeFolder("/CmsKit/GlobalResources", CmsKitAdminPermissions.GlobalResources.Default);
// TODO: Add /CmsKit/Comments/Approve/Index page
}); });
Configure<RazorPagesOptions>(options => Configure<RazorPagesOptions>(options =>
@ -179,21 +189,7 @@ public class CmsKitAdminWebModule : AbpModule
}); });
}); });
//Configure<AbpBundleContributorOptions>(options =>
//{
// options
// .Extensions<PrismjsScriptBundleContributor>()
// .Add<PrismjsScriptBundleContributorDocsExtension>();
//});
Configure<AbpBundlingOptions>(options =>
{
options.ScriptBundles.Configure(
"Volo.Abp.AspNetCore.Mvc.UI.Packages.MarkdownIt.MarkdownItScriptContributor",
bundle =>
{
bundle.AddFiles("/libs/markdown-it/markdown-it.min.js");
});
});
Configure<DynamicJavaScriptProxyOptions>(options => Configure<DynamicJavaScriptProxyOptions>(options =>
{ {
options.DisableModule(CmsKitAdminRemoteServiceConsts.ModuleName); options.DisableModule(CmsKitAdminRemoteServiceConsts.ModuleName);

5
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml

@ -29,13 +29,10 @@
<abp-script src="/client-proxies/cms-kit-common-proxy.js" /> <abp-script src="/client-proxies/cms-kit-common-proxy.js" />
<abp-script src="/client-proxies/cms-kit-admin-proxy.js" /> <abp-script src="/client-proxies/cms-kit-admin-proxy.js" />
<abp-script src="/Pages/CmsKit/Comments/Approve/index.js" /> <abp-script src="/Pages/CmsKit/Comments/Approve/index.js" />
<abp-script type="typeof(MarkdownItScriptContributor)" />
</abp-script-bundle> </abp-script-bundle>
<abp-script type="typeof(MarkdownItScriptContributor)" />
@* <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js"></script> *@
} }
<abp-card class="mb-4"> <abp-card class="mb-4">
<abp-card-body> <abp-card-body>
<div id="CmsKitCommentsWrapper"> <div id="CmsKitCommentsWrapper">

1
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml.cs

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments.Approve; namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments.Approve;
public class IndexModel : CmsKitAdminPageModel public class IndexModel : CmsKitAdminPageModel
{ {
public string EntityType { get; set; } public string EntityType { get; set; }

17
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/PrismjsScriptBundleContributorDocsExtension.cs

@ -1,17 +0,0 @@
using System.Collections.Generic;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments.Approve;
public class PrismjsScriptBundleContributorDocsExtension : BundleContributor
{
public override void ConfigureBundle(BundleConfigurationContext context)
{
//AddPlugins(context);
context.Files.Add("~/libs/markdown-it/markdown-it.min.js");
}
//private static void AddPlugins(IBundleConfigurationContext context)
//{
// context.Files.AddIfNotContains("/libs/markdown-it/markdown-it.min.js");
//}
}

306
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/index.js

@ -1,177 +1,173 @@
 $(function () {
var l = abp.localization.getResource("CmsKit");
$(function () { var commentsService = volo.cmsKit.admin.comments.commentAdmin;
var l = abp.localization.getResource("CmsKit"); var detailsModal = new abp.ModalManager(abp.appPath + "CmsKit/Comments/DetailsModal");
var commentsService = volo.cmsKit.admin.comments.commentAdmin; moment()._locale.preparse = (string) => string;
moment()._locale.postformat = (string) => string;
var detailsModal = new abp.ModalManager(abp.appPath + "CmsKit/Comments/DetailsModal"); var getFormattedDate = function ($datePicker) {
if (!$datePicker.val()) {
return null;
}
var momentDate = moment($datePicker.val(), $datePicker.data('daterangepicker').locale.format);
return momentDate.isValid() ? momentDate.toISOString() : null;
};
$('.singledatepicker').daterangepicker({
"singleDatePicker": true,
"showDropdowns": true,
"autoUpdateInput": false,
"autoApply": true,
"opens": "center",
"drops": "auto"
});
moment()._locale.preparse = (string) => string;
moment()._locale.postformat = (string) => string;
var getFormattedDate = function ($datePicker) { $('.singledatepicker').attr('autocomplete', 'off');
if (!$datePicker.val()) {
return null; $('.singledatepicker').on('apply.daterangepicker', function (ev, picker) {
} $(this).val(picker.startDate.format('l'));
var momentDate = moment($datePicker.val(), $datePicker.data('daterangepicker').locale.format); });
return momentDate.isValid() ? momentDate.toISOString() : null;
};
var filterForm = $('#CmsKitCommentsFilterForm');
$('.singledatepicker').daterangepicker({ var getFilter = function () {
"singleDatePicker": true, var filterObj = filterForm.serializeFormToObject();
"showDropdowns": true,
"autoUpdateInput": false, filterObj.creationStartDate = getFormattedDate($('#CreationStartDate'));
"autoApply": true, filterObj.creationEndDate = getFormattedDate($('#CreationEndDate'));
"opens": "center",
"drops": "auto" return filterObj;
}); };
var _dataTable = $('#CommentsTable').DataTable(abp.libs.datatables.normalizeConfiguration({
$('.singledatepicker').attr('autocomplete', 'off'); processing: true,
serverSide: true,
$('.singledatepicker').on('apply.daterangepicker', function (ev, picker) { paging: true,
$(this).val(picker.startDate.format('l')); scrollX: true,
}); searching: false,
scrollCollapse: true,
ajax: abp.libs.datatables.createAjax(commentsService.getWaitingCommentsWithReplies, getFilter),
var filterForm = $('#CmsKitCommentsFilterForm'); columnDefs: [
{
var getFilter = function () { width: "10%",
var filterObj = filterForm.serializeFormToObject(); title: l("Actions"),
targets: 0,
filterObj.creationStartDate = getFormattedDate($('#CreationStartDate')); orderable: false,
filterObj.creationEndDate = getFormattedDate($('#CreationEndDate')); rowAction: {
items: [
return filterObj; {
}; text: function (data) {
return l('Approve');
var _dataTable = $('#CommentsTable').DataTable(abp.libs.datatables.normalizeConfiguration({
processing: true,
serverSide: true,
paging: true,
scrollX: true,
searching: false,
scrollCollapse: true,
ajax: abp.libs.datatables.createAjax(commentsService.getWaitingCommentsWithReplies, getFilter),
columnDefs: [
{
width: "10%",
title: l("Actions"),
targets: 0,
orderable: false,
rowAction: {
items: [
{
text: function (data) {
return l('Approve');
},
action: function (data) {
var newApprovalStatus = true;
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);
});
}
}, },
{ action: function (data) {
text: function (data) { var newApprovalStatus = true;
return l('Disapproved');
}, commentsService
action: function (data) { .updateApprovalStatus(data.record.id, {IsApproved: newApprovalStatus})
var newApprovalStatus = false; .then(function () {
_dataTable.ajax.reloadEx();
commentsService var message = newApprovalStatus ? l('ApprovedSuccessfully') : l('ApprovalRevokedSuccessfully');
.updateApprovalStatus(data.record.id, { IsApproved: newApprovalStatus }) abp.notify.success(message);
.then(function () { })
_dataTable.ajax.reloadEx(); .catch(function (error) {
var message = newApprovalStatus ? l('ApprovedSuccessfully') : l('ApprovalRevokedSuccessfully'); abp.notify.error(error.message);
abp.notify.success(message); });
}) }
.catch(function (error) { },
abp.notify.error(error.message); {
}); text: function (data) {
} 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);
});
} }
]
}
},
{
width: "10%",
title: l("Username"),
orderable: false,
data: "author.userName",
render: function (data) {
if (data !== null) {
return GetFilterableDatatableContent('#Author', $.fn.dataTable.render.text().display(data)); //prevent against possible XSS
} }
return ""; ]
}
},
{
width: "10%",
title: l("Username"),
orderable: false,
data: "author.userName",
render: function (data) {
if (data !== null) {
return GetFilterableDatatableContent('#Author', $.fn.dataTable.render.text().display(data)); //prevent against possible XSS
} }
}, return "";
{ }
width: "15%", },
title: l("EntityType"), {
orderable: false, width: "15%",
data: "entityType", title: l("EntityType"),
render: function (data) { orderable: false,
if (data !== null) { data: "entityType",
return GetFilterableDatatableContent('#EntityType', $.fn.dataTable.render.text().display(data)); render: function (data) {
} if (data !== null) {
return ""; return GetFilterableDatatableContent('#EntityType', $.fn.dataTable.render.text().display(data));
} }
}, return "";
{ }
title: l("Text"), },
data: "text", {
orderable: false, title: l("Text"),
data: "text",
orderable: false,
render: function (data) { render: function (data) {
//var converter = new showdown.Converter(); //var converter = new showdown.Converter();
//var htmlContent = converter.makeHtml(data); //var htmlContent = converter.makeHtml(data);
var md = window.markdownit(); var md = window.markdownit();
var htmlContent = md.render(data); var htmlContent = md.render(data);
return (htmlContent); return (htmlContent);
}
},
{
width: "15%",
title: l("CreationTime"),
data: "creationTime",
orderable: true,
dataFormat: "datetime"
} }
] },
})); {
width: "15%",
title: l("CreationTime"),
data: "creationTime",
orderable: true,
dataFormat: "datetime"
}
]
}));
function GetFilterableDatatableContent(filterSelector, data) { function GetFilterableDatatableContent(filterSelector, data) {
return '<span class="datatableCell" data-field="' + filterSelector + '" data-val="' + data + '">' + data + '</span>'; return '<span class="datatableCell" data-field="' + filterSelector + '" data-val="' + data + '">' + data + '</span>';
} }
$(document).on('click', '.datatableCell', function () { $(document).on('click', '.datatableCell', function () {
var inputSelector = $(this).attr('data-field'); var inputSelector = $(this).attr('data-field');
var value = $(this).attr('data-val'); var value = $(this).attr('data-val');
$(inputSelector).val(value); $(inputSelector).val(value);
_dataTable.ajax.reloadEx(); _dataTable.ajax.reloadEx();
}); });
filterForm.submit(function (e) { filterForm.submit(function (e) {
e.preventDefault(); e.preventDefault();
_dataTable.ajax.reloadEx(); _dataTable.ajax.reloadEx();
});
}); });
});

10
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml

@ -97,11 +97,11 @@
<abp-column size-lg="_2" size-md="_12"> <abp-column size-lg="_2" size-md="_12">
<div class="mb-3" id="isApprovedColumn"> <div class="mb-3" id="isApprovedColumn">
<label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label> <label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label>
<select id="isApprovedSelect" asp-for="@Model.commentApproveStateType" class="form-control"> <select id="isApprovedSelect" asp-for="@Model.CommentApproveState" class="form-control">
<option value="@CommentApproveStateType.All">@L["CommentFilter:All"].Value</option> <option value="@CommentApproveState.All">@L["CommentFilter:All"].Value</option>
<option value="@CommentApproveStateType.Approved">@L["CommentFilter:Approved"].Value</option> <option value="@CommentApproveState.Approved">@L["CommentFilter:Approved"].Value</option>
<option value="@CommentApproveStateType.Disapproved">@L["CommentFilter:Disapproved"].Value</option> <option value="@CommentApproveState.Disapproved">@L["CommentFilter:Disapproved"].Value</option>
<option value="@CommentApproveStateType.Waiting">@L["CommentFilter:Waiting"].Value</option> <option value="@CommentApproveState.Waiting">@L["CommentFilter:Waiting"].Value</option>
</select> </select>
</div> </div>
</abp-column> </abp-column>

2
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs

@ -17,7 +17,7 @@ public class DetailsModel : CmsKitAdminPageModel
public DateTime? CreationEndDate { get; set; } public DateTime? CreationEndDate { get; set; }
public CommentApproveStateType commentApproveStateType { get; set; } public CommentApproveState CommentApproveState { get; set; }
public CommentWithAuthorDto CommentWithAuthorDto { get; protected set; } public CommentWithAuthorDto CommentWithAuthorDto { get; protected set; }

10
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml

@ -62,11 +62,11 @@
<abp-column size-lg="_2" size-md="_6"> <abp-column size-lg="_2" size-md="_6">
<div class="mb-3" id="isApprovedColumn"> <div class="mb-3" id="isApprovedColumn">
<label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label> <label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label>
<select id="isApprovedSelect" asp-for="@Model.commentApproveStateType" class="form-control"> <select id="isApprovedSelect" asp-for="@Model.CommentApproveStateType" class="form-control">
<option value="@CommentApproveStateType.All">@L["CommentFilter:All"].Value</option> <option value="@CommentApproveState.All">@L["CommentFilter:All"].Value</option>
<option value="@CommentApproveStateType.Approved">@L["CommentFilter:Approved"].Value</option> <option value="@CommentApproveState.Approved">@L["CommentFilter:Approved"].Value</option>
<option value="@CommentApproveStateType.Disapproved">@L["CommentFilter:Disapproved"].Value</option> <option value="@CommentApproveState.Disapproved">@L["CommentFilter:Disapproved"].Value</option>
<option value="@CommentApproveStateType.Waiting">@L["CommentFilter:Waiting"].Value</option> <option value="@CommentApproveState.Waiting">@L["CommentFilter:Waiting"].Value</option>
</select> </select>
</div> </div>
</abp-column> </abp-column>

2
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs

@ -12,6 +12,6 @@ public class IndexModel : CmsKitAdminPageModel
public DateTime? CreationStartDate { get; set; } = null; public DateTime? CreationStartDate { get; set; } = null;
public DateTime? CreationEndDate { get; set; } public DateTime? CreationEndDate { get; set; }
public CommentApproveStateType? commentApproveStateType { get; set; }
public CommentApproveState CommentApproveStateType { get; set; }
} }

5
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js

@ -234,7 +234,7 @@ $(function (){
_dataTable.ajax.reloadEx(); _dataTable.ajax.reloadEx();
}); });
// Get and display waiting comment count // TODO: Replace these methods because ther are replaced in appservice
commentsService.getWaitingCommentCount().then(function (count) { commentsService.getWaitingCommentCount().then(function (count) {
if (count > 0) { if (count > 0) {
var alertMessage = l("CommentAlertMessage", count); var alertMessage = l("CommentAlertMessage", count);
@ -247,7 +247,6 @@ $(function (){
} }
}); });
//
commentsService.getSettings().then(function (data) { commentsService.getSettings().then(function (data) {
if (data.requireApprovement) { if (data.requireApprovement) {
$('#CommentsTable').DataTable().column(6).visible(true); $('#CommentsTable').DataTable().column(6).visible(true);
@ -256,4 +255,6 @@ $(function (){
$('#isApprovedColumn').hide(); $('#isApprovedColumn').hide();
} }
}) })
// TODO: if I change the state of the comment, you should update the alert message
}); });

12
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveState.cs

@ -0,0 +1,12 @@
using System;
namespace Volo.CmsKit.Comments;
[Flags]
public enum CommentApproveState
{
All = 0,
Approved = 1,
Disapproved = 2,
Waiting = 4
}

12
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.CmsKit.Comments;
public enum CommentApproveStateType
{
All,
Approved,
Disapproved,
Waiting
}

7
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Settings/AppSettings.cs

@ -1,9 +1,6 @@
using System; namespace Volo.CmsKit.Settings;
using System.Collections.Generic;
using System.Text;
namespace Volo.CmsKit.Settings;
public static class AppSettings public static class AppSettings
{ {
public const string RequireApprovement = "Comments.RequireApprovement"; public const string CommentRequireApprovement = "Comments.RequireApprovement";
} }

8
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs

@ -27,7 +27,7 @@ public class Comment : AggregateRoot<Guid>, IHasCreationTime, IMustHaveCreator,
public virtual string IdempotencyToken { get; set; } public virtual string IdempotencyToken { get; set; }
public virtual bool? IsApproved { get; set; } public virtual bool? IsApproved { get; private set; }
protected Comment() protected Comment()
{ {
@ -64,4 +64,10 @@ public class Comment : AggregateRoot<Guid>, IHasCreationTime, IMustHaveCreator,
{ {
Text = Check.NotNullOrWhiteSpace(text, nameof(text), CommentConsts.MaxTextLength); Text = Check.NotNullOrWhiteSpace(text, nameof(text), CommentConsts.MaxTextLength);
} }
public virtual Comment SetApprovalStatus([NotNull] bool isApproved)
{
IsApproved = isApproved;
return this;
}
} }

6
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs

@ -21,7 +21,7 @@ public interface ICommentRepository : IBasicRepository<Comment, Guid>
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
@ -32,14 +32,14 @@ public interface ICommentRepository : IBasicRepository<Comment, Guid>
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync( Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
[NotNull] string entityType, [NotNull] string entityType,
[NotNull] string entityId, [NotNull] string entityId,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Settings/CmsKitSettingDefinitionProvider.cs

@ -10,7 +10,7 @@ public class CmsKitSettingDefinitionProvider : SettingDefinitionProvider
* Use names from CmsKitSettings class. * Use names from CmsKitSettings class.
*/ */
context.Add( context.Add(
new SettingDefinition(AppSettings.RequireApprovement, "true") new SettingDefinition(AppSettings.CommentRequireApprovement, "true")
) ; ) ;
} }
} }

25
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

@ -54,7 +54,7 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
@ -66,7 +66,7 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
commentApproveStateType, commentApproveState,
token); token);
if (!sorting.IsNullOrEmpty()) if (!sorting.IsNullOrEmpty())
@ -87,7 +87,7 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
@ -100,7 +100,7 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
commentApproveStateType, commentApproveState,
token); token);
return await query.LongCountAsync(token); return await query.LongCountAsync(token);
@ -109,7 +109,7 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync( public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType, string entityType,
string entityId, string entityId,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
@ -125,10 +125,10 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
Author = user Author = user
}; };
query = commentApproveStateType switch query = commentApproveState switch
{ {
CommentApproveStateType.Approved => query.Where(c => c.Comment.IsApproved == true), CommentApproveState.Approved => query.Where(c => c.Comment.IsApproved == true),
CommentApproveStateType.Disapproved => query.Where(c => c.Comment.IsApproved == true || c.Comment.IsApproved == null), CommentApproveState.Approved | CommentApproveState.Waiting => query.Where(c => c.Comment.IsApproved == true || c.Comment.IsApproved == null),
_ => query _ => query
}; };
@ -166,9 +166,8 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
var commentDbSet = await GetDbSetAsync(); var commentDbSet = await GetDbSetAsync();
@ -189,8 +188,8 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
.WhereIf(!authorUsername.IsNullOrWhiteSpace(), c => c.Author.UserName.Contains(authorUsername)) .WhereIf(!authorUsername.IsNullOrWhiteSpace(), c => c.Author.UserName.Contains(authorUsername))
.WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate) .WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate) .WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate)
.WhereIf(CommentApproveStateType.Approved == commentApproveStateType, c => c.Comment.IsApproved == true) .WhereIf(CommentApproveState.Approved == commentApproveState, c => c.Comment.IsApproved == true)
.WhereIf(CommentApproveStateType.Disapproved == commentApproveStateType, c => c.Comment.IsApproved == false) .WhereIf(CommentApproveState.Disapproved == commentApproveState, c => c.Comment.IsApproved == false)
.WhereIf(CommentApproveStateType.Waiting == commentApproveStateType, c => c.Comment.IsApproved == null); .WhereIf(CommentApproveState.Waiting == commentApproveState, c => c.Comment.IsApproved == null);
} }
} }

71
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

@ -1,5 +1,4 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
@ -46,11 +45,10 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
var token = GetCancellationToken(cancellationToken); var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync( var query = await GetListQueryAsync(
filter, filter,
@ -59,7 +57,7 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
commentApproveStateType, commentApproveState,
token); token);
var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting) var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
@ -70,20 +68,18 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
var commentIds = comments.Select(x => x.Id).ToList(); var commentIds = comments.Select(x => x.Id).ToList();
var authorsQuery = from comment in (await GetMongoQueryableAsync(token)) var authorsQuery = from comment in (await GetMongoQueryableAsync(token))
join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id
where commentIds.Contains(comment.Id) where commentIds.Contains(comment.Id)
orderby comment.CreationTime orderby comment.CreationTime
select user; select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(token); var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(token);
return comments return comments
.Select( .Select(
comment => comment =>
new CommentWithAuthorQueryResultItem new CommentWithAuthorQueryResultItem {
{ Comment = comment, Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
Comment = comment,
Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
}).ToList(); }).ToList();
} }
@ -94,7 +90,7 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
@ -105,7 +101,7 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
commentApproveStateType, commentApproveState,
cancellationToken); cancellationToken);
return await query.As<IMongoQueryable<Comment>>() return await query.As<IMongoQueryable<Comment>>()
@ -115,7 +111,7 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync( public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType, string entityType,
string entityId, string entityId,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
@ -132,10 +128,9 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
var commentsQuery = (await GetMongoQueryableAsync(cancellationToken)) var commentsQuery = (await GetMongoQueryableAsync(cancellationToken))
.Where(c => c.EntityId == entityId && c.EntityType == entityType); .Where(c => c.EntityId == entityId && c.EntityType == entityType);
commentsQuery = commentApproveStateType switch commentsQuery = commentApproveState switch {
{ CommentApproveState.Approved => commentsQuery.Where(c => c.IsApproved == true),
CommentApproveStateType.Approved => commentsQuery.Where(c => c.IsApproved == true), CommentApproveState.Approved | CommentApproveState.Waiting => commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null),
CommentApproveStateType.Disapproved => commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null),
_ => commentsQuery _ => commentsQuery
}; };
@ -182,15 +177,15 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
} }
protected virtual async Task<IQueryable<Comment>> GetListQueryAsync( protected virtual async Task<IQueryable<Comment>> GetListQueryAsync(
string filter = null, string filter = null,
string entityType = null, string entityType = null,
Guid? repliedCommentId = null, Guid? repliedCommentId = null,
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All, CommentApproveState commentApproveState = CommentApproveState.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
var queryable = await GetMongoQueryableAsync(cancellationToken); var queryable = await GetMongoQueryableAsync(cancellationToken);
@ -208,22 +203,8 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId) .WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
.WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate) .WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate) .WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate)
.WhereIf(CommentApproveStateType.Approved == commentApproveStateType, c => c.IsApproved == true) .WhereIf(CommentApproveState.Approved == commentApproveState, c => c.IsApproved == true)
.WhereIf(CommentApproveStateType.Disapproved == commentApproveStateType, c => c.IsApproved == false) .WhereIf(CommentApproveState.Disapproved == commentApproveState, c => c.IsApproved == false)
.WhereIf(CommentApproveStateType.Waiting == commentApproveStateType, c => c.IsApproved == null); .WhereIf(CommentApproveState.Waiting == commentApproveState, c => c.IsApproved == null);
} }
//public IQueryable<Comment> FilterCommentsByApprovalState(IQueryable<Comment> commentsQuery, CommentApproveStateType approveState)
//{
// switch (approveState)
// {
// case CommentApproveStateType.Approved:
// commentsQuery = commentsQuery.Where(c => c.IsApproved == true);
// break;
// case CommentApproveStateType.Disapproved:
// commentsQuery = commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null);
// break;
// }
// return commentsQuery;
//}
} }

9
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

@ -57,10 +57,11 @@ public class CommentPublicAppService : CmsKitPublicAppServiceBase, ICommentPubli
public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId) public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId)
{ {
string state = await SettingManager.GetOrNullGlobalAsync(AppSettings.RequireApprovement); var isRequireApprovementEnabled = bool.Parse(await SettingManager.GetOrNullGlobalAsync(AppSettings.CommentRequireApprovement));
var commentsWithAuthor = bool.Parse(state) ?
await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveStateType.Approved) : var commentsWithAuthor = isRequireApprovementEnabled
await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveStateType.Disapproved); ? await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveState.Approved)
: await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveState.Approved | CommentApproveState.Waiting);
return new ListResultDto<CommentWithDetailsDto>( return new ListResultDto<CommentWithDetailsDto>(

Loading…
Cancel
Save