Browse Source

code review and alert status added

pull/19919/head
EmreKendirli 2 years ago
parent
commit
ea435db7f3
  1. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs
  2. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs
  3. 52
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs
  4. 7
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs
  5. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/CmsKitAdminWebModule.cs
  6. 68
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml
  7. 16
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml
  8. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs
  9. 85
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/Index.cshtml
  10. 18
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/Index.cshtml.cs
  11. 230
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Waiting/index.js
  12. 11
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js
  13. 1
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Volo.CmsKit.Admin.Web.csproj
  14. 7
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js
  15. 6
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json
  16. 6
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  17. 83
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

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

@ -17,6 +17,7 @@ public class CommentGetListInput : PagedAndSortedResultRequestDto
public DateTime? CreationStartDate { get; set; }
public DateTime? CreationEndDate { get; set; }
public bool? IsApproved { get; set; }
public string IsApproved { get; set; }
}

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

@ -16,5 +16,7 @@ public interface ICommentAdminAppService : IApplicationService
Task SetSettings(SettingsDto settingsDto);
Task<SettingsDto> GetSettings();
Task<int> GetPendingCommentCount();
}

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

@ -31,27 +31,31 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
public virtual async Task<PagedResultDto<CommentWithAuthorDto>> GetListAsync(CommentGetListInput input)
{
var totalCount = await CommentRepository.GetCountAsync(
input.Text,
input.EntityType,
input.RepliedCommentId,
input.Author,
input.CreationStartDate,
input.CreationEndDate);
var comments = await CommentRepository.GetListAsync(
input.Text,
input.EntityType,
input.RepliedCommentId,
input.Author,
input.CreationStartDate,
input.CreationEndDate,
input.Sorting,
input.MaxResultCount,
input.SkipCount
);
var dtos = comments.Select(queryResultItem =>
var totalCount = await CommentRepository.GetCountAsync(
input.Text,
input.EntityType,
input.RepliedCommentId,
input.Author,
input.CreationStartDate,
input.CreationEndDate,
input.IsApproved
);
var comments = await CommentRepository.GetListAsync(
input.Text,
input.EntityType,
input.RepliedCommentId,
input.Author,
input.CreationStartDate,
input.CreationEndDate,
input.Sorting,
input.MaxResultCount,
input.SkipCount,
input.IsApproved
);
var dtos = comments.Select(queryResultItem =>
{
var dto = ObjectMapper.Map<Comment, CommentWithAuthorDto>(queryResultItem.Comment);
dto.Author = ObjectMapper.Map<CmsUser, CmsUserDto>(queryResultItem.Author);
@ -108,4 +112,10 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
}
return null;
}
public async Task<int> GetPendingCommentCount()
{
var count = await CommentRepository.GetCountAsync(isApproved: "null");
return (int)(count == null ? 0 : count);
}
}

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

@ -62,6 +62,7 @@ public class CommentAdminController : CmsKitAdminController, ICommentAdminAppSer
{
return CommentAdminAppService.SetSettings(settingsDto);
}
[HttpGet]
[Route("settings")]
@ -69,4 +70,10 @@ public class CommentAdminController : CmsKitAdminController, ICommentAdminAppSer
{
return CommentAdminAppService.GetSettings();
}
[HttpGet]
[Route("pending-count")]
public Task<int> GetPendingCommentCount()
{
return CommentAdminAppService.GetPendingCommentCount();
}
}

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

@ -110,6 +110,8 @@ 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");
});
Configure<AbpPageToolbarOptions>(options =>

68
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml

@ -1,6 +1,8 @@
@*
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.CmsKit.Localization
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@section scripts {
@ -12,23 +14,22 @@
</abp-script-bundle>
}
@{
// <p>sdf</p>
// <input type="checkbox" id="checkbox" />
// <button id="save">Save</button>
@inject IHtmlLocalizer<CmsKitResource> L
<abp-form #form="ngForm">
<h4>Checkbox Ayarları</h4>
<h4>@L["CommentSettings:Title"].Value</h4>
<hr />
<div class="form-group">
<div class="form-check">
<input type="checkbox" id="checkbox" class="form-check-input" name="checkbox" ngModel />
<label for="checkbox" class="form-check-label">Açıklama:</label>
<label for="checkbox" class="form-check-label">@L["CommentSettings:RequireApprovement"].Value</label>
</div>
<small id="checkboxHelp" class="form-text text-muted">Checkbox açıklama metni buraya gelecek.</small>
<small id="checkboxHelp" class="form-text text-muted">@L["CommentSettings:RequireApprovementDescription"].Value</small>
</div>
<div style="float:right" class="text-right mt-3">
<abp-button id="save" type="submit" class="btn btn-primary">
Kaydet
@L["SaveChanges"].Value
</abp-button>
</div>
</abp-form>
@ -36,54 +37,7 @@
}
@* <script>
var service = volo.cmsKit.admin.comments.commentAdmin;
$(document).ready(function () {
service.getSettings().done(function (response) {
var isChecked = response.requireApprovement
$('#checkbox').prop('checked', isChecked);
console.log('CheckBox durumu başarıyla güncellendi:', response.requireApprovement);
}).fail(function (error) {
console.error('CheckBox durumu alınırken bir hata oluştu:', error);
});
$('#save').click(function () {
var isChecked = $('#checkbox').prop('checked');
service.setSettings({ RequireApprovement: isChecked }).done(function (response) {
console.log('CheckBox durumu başarıyla güncellendi:', response);
alert('CheckBox durumu başarıyla kaydedildi.');
}).fail(function (error) {
console.error('CheckBox durumu güncellenirken bir hata oluştu:', error);
alert('CheckBox durumu kaydedilirken bir hata oluştu.');
});
});
});
</script> *@
@* <script>
var _service = volo.cmsKit.admin.comments.commentAdmin;
$(document).ready(function () {
_service.getSettings().done(function (response) {
var isChecked = response.requireApprovement;
$('#checkbox').prop('checked', isChecked);
console.log('CheckBox durumu başarıyla güncellendi:', response.requireApprovement);
}).fail(function (error) {
console.error('CheckBox durumu alınırken bir hata oluştu:', error);
});
$('#save').click(function () {
var isChecked = $('#checkbox').prop('checked');
_service.setSettings({ requireApprovement: isChecked }).done(function (response) {
console.log('CheckBox durumu başarıyla güncellendi:', response);
abp.notify.success('CheckBox durumu başarıyla kaydedildi.');
}).fail(function (error) {
console.error('CheckBox durumu güncellenirken bir hata oluştu:', error);
abp.notify.error('CheckBox durumu kaydedilirken bir hata oluştu.');
});
});
})
</script> *@
<script>
var app = app || {};
@ -99,7 +53,7 @@
_service.getSettings().done(function (response) {
var isChecked = response.requireApprovement;
$('#checkbox').prop('checked', isChecked);
console.log('CheckBox durumu başarıyla güncellendii:', response.requireApprovement);
console.log('CheckBox durumu başarıyla güncellendi:', response.requireApprovement);
}).fail(function (error) {
console.error('CheckBox durumu alınırken bir hata oluştu:', error);
});

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

@ -31,6 +31,9 @@
</abp-script-bundle>
}
<abp-alert id="commentsAlert" alert-type="Warning" style="display: none;">
</abp-alert>
<abp-card class="mb-4">
<abp-card-body>
<div id="CmsKitCommentsWrapper">
@ -47,14 +50,23 @@
</abp-row>
</abp-column>
<abp-column size-lg="_3" size-md="_6">
<abp-column size-lg="_2" size-md="_6">
<abp-input asp-for="@Model.Author" label="@L["Username"].Value" type="text" />
</abp-column>
<abp-column size-lg="_3" size-md="_6">
<abp-column size-lg="_2" size-md="_6">
<abp-input asp-for="@Model.EntityType" label="@L["EntityType"].Value" type="text" />
</abp-column>
<abp-column size-lg="_2" size-md="_6">
<select asp-for="@Model.IsApproved" label="@L["IsApproved"].Value">
<option value="">@L["All"].Value</option>
<option value="true">@L["Approved"].Value</option>
<option value="false">@L["Rejected"].Value</option>
<option value="null">@L["Pending"].Value</option>
</select>
</abp-column>
<abp-column size-lg="_2" size-md="_6">
<abp-button class="w-100 mb-3" button-type="Primary" type="submit">
<i class="fa fa-search" aria-hidden="true"></i>

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

@ -11,4 +11,6 @@ public class IndexModel : CmsKitAdminPageModel
public DateTime? CreationStartDate { get; set; }
public DateTime? CreationEndDate { get; set; }
public string IsApproved { get; set; }
}

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

@ -0,0 +1,85 @@
@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments
@using Volo.CmsKit.Admin.Web.Menus
@using Volo.CmsKit.Localization
@inject IPageLayout PageLayout
@inject IHtmlLocalizer<CmsKitResource> L
@model IndexModel
@{
PageLayout.Content.Title = L["Comments"].Value;
PageLayout.Content.BreadCrumb.Add(L["Menu:CMS"].Value);
PageLayout.Content.MenuItemName = CmsKitAdminMenus.Comments.CommentsMenu;
}
@section styles {
<abp-style-bundle>
<abp-style src="/Pages/CmsKit/Comments/index.css" />
</abp-style-bundle>
}
@section scripts {
<abp-script-bundle>
<abp-script src="/client-proxies/cms-kit-common-proxy.js" />
<abp-script src="/client-proxies/cms-kit-admin-proxy.js" />
<abp-script src="/Pages/CmsKit/Comments/index.js" />
</abp-script-bundle>
}
<abp-alert id="commentsAlert" alert-type="Warning" style="display: none;">
</abp-alert>
<abp-card class="mb-4">
<abp-card-body>
<div id="CmsKitCommentsWrapper">
<form id="CmsKitCommentsFilterForm" method="post">
<abp-row class="align-items-end">
<abp-column size-lg="_4" size-md="_12">
<abp-row>
<abp-column size-lg="_6" size-md="_6">
<abp-input asp-for="@Model.CreationStartDate" class="singledatepicker" label="@L["StartDate"].Value" type="text" />
</abp-column>
<abp-column size-lg="_6" size-md="_6">
<abp-input asp-for="@Model.CreationEndDate" class="singledatepicker" label="@L["EndDate"].Value" type="text" />
</abp-column>
</abp-row>
</abp-column>
<abp-column size-lg="_2" size-md="_6">
<abp-input asp-for="@Model.Author" label="@L["Username"].Value" type="text" />
</abp-column>
<abp-column size-lg="_2" size-md="_6">
<abp-input asp-for="@Model.EntityType" label="@L["EntityType"].Value" type="text" />
</abp-column>
<abp-column size-lg="_2" size-md="_6">
<select asp-for="@Model.IsApproved" label="@L["IsApproved"].Value">
<option value="">@L["All"].Value</option>
<option value="true">@L["Approved"].Value</option>
<option value="false">@L["Rejected"].Value</option>
<option value="null">@L["Pending"].Value</option>
</select>
</abp-column>
<abp-column size-lg="_2" size-md="_6">
<abp-button class="w-100 mb-3" button-type="Primary" type="submit">
<i class="fa fa-search" aria-hidden="true"></i>
</abp-button>
</abp-column>
</abp-row>
</form>
</div>
</abp-card-body>
</abp-card>
<abp-card>
<abp-card-body>
<abp-table id="CommentsTable" class="nowrap"></abp-table>
</abp-card-body>
</abp-card>

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

@ -0,0 +1,18 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments.Waiting;
public class IndexModel : CmsKitAdminPageModel
{
public string EntityType { get; set; }
public string Author { get; set; }
public DateTime? CreationStartDate { get; set; }
public DateTime? CreationEndDate { get; set; }
public string IsApproved { get; set; }
}

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

@ -0,0 +1,230 @@
$(function () {
var l = abp.localization.getResource("CmsKit");
var commentsService = volo.cmsKit.admin.comments.commentAdmin;
var detailsModal = new abp.ModalManager(abp.appPath + "CmsKit/Comments/DetailsModal");
moment()._locale.preparse = (string) => string;
moment()._locale.postformat = (string) => string;
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;
};
var defaultStartDate = moment().add(-7, 'days');
$("#CreationStartDate").val(defaultStartDate.format('L'));
$('.singledatepicker').daterangepicker({
"singleDatePicker": true,
"showDropdowns": true,
"autoUpdateInput": false,
"autoApply": true,
"opens": "center",
"drops": "auto"
});
$('.singledatepicker').attr('autocomplete', 'off');
$('.singledatepicker').on('apply.daterangepicker', function (ev, picker) {
$(this).val(picker.startDate.format('l'));
});
var filterForm = $('#CmsKitCommentsFilterForm');
var getFilter = function () {
var filterObj = filterForm.serializeFormToObject();
filterObj.creationStartDate = getFormattedDate($('#CreationStartDate'));
filterObj.creationEndDate = getFormattedDate($('#CreationEndDate'));
return filterObj;
};
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.getList, getFilter),
columnDefs: [
{
width: "10%",
title: l("Actions"),
targets: 0,
orderable: false,
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")
},
action: function (data) {
commentsService
.delete(data.record.id)
.then(function () {
_dataTable.ajax.reloadEx();
abp.notify.success(l('DeletedSuccessfully'));
});
}
},
{
text: function (data) {
return data.isApproved ? l('Revoke Approval') : l('Approve');
},
action: function (data) {
var newApprovalStatus = !data.record?.isApproved;
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) {
console.log("error", 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: "15%",
title: l("EntityType"),
orderable: false,
data: "entityType",
render: function (data) {
if (data !== null) {
return GetFilterableDatatableContent('#EntityType', $.fn.dataTable.render.text().display(data));
}
return "";
}
},
{
title: l("URL"),
data: "url",
render: function (data, type, row) {
if (data !== null) {
return '<a href="' + data + '#comment-' + row.id + '" target="_blank"><i class="fa fa-location-arrow"></i></a>';
}
return "";
}
},
{
title: l("Text"),
data: "text",
orderable: false,
render: function (data) {
data = $.fn.dataTable.render.text().display(data || "");
var maxChars = 64;
if (data.length > maxChars) {
return (
'<span data-toggle="tooltip" title="' +
data +
'">' +
data.substring(0, maxChars) +
"..." +
"</span>"
);
} else {
return data;
}
}
},
{
width: "15%",
title: l("CreationTime"),
data: "creationTime",
orderable: true,
dataFormat: "datetime"
},
{
width: "5%",
title: l("Status"),
orderable: false,
data: "isApproved",
render: function (data, type, row) {
var icons = ''
if (data === null) {
icons = '<i class="fa-solid fa-hourglass-start"></i>';
} else if (typeof data === "boolean") {
if (data) {
icons = '<i class="fa-solid fa-check" style="color: #63E6BE;"></i>';
} else {
icons = '<i class="fa-solid fa-x" style="color: #e0102f;"></i>';
}
}
return icons;
}
}
]
}));
function GetFilterableDatatableContent(filterSelector, data) {
return '<span class="datatableCell" data-field="' + filterSelector + '" data-val="' + data + '">' + data + '</span>';
}
$(document).on('click', '.datatableCell', function () {
var inputSelector = $(this).attr('data-field');
var value = $(this).attr('data-val');
$(inputSelector).val(value);
_dataTable.ajax.reloadEx();
});
filterForm.submit(function (e) {
e.preventDefault();
_dataTable.ajax.reloadEx();
});
// Get and display pending comment count
commentsService.getPendingCommentCount().then(function (count) {
console.log(count)
if (count > 0) {
var alertMessage = 'You have pending comments: ' + count;
var alertElement = '<abp-alert alert-type="Warning">' + alertMessage + '</abp-alert>';
console.log(count)
$('#commentsAlert').html(alertElement);
$('#commentsAlert').show()
}
});
});

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

@ -216,4 +216,15 @@ $(function (){
e.preventDefault();
_dataTable.ajax.reloadEx();
});
// Get and display pending comment count
commentsService.getPendingCommentCount().then(function (count) {
console.log(count)
if (count > 0) {
var alertMessage = 'You have pending comments: ' + count;
var alertElement = '<abp-alert alert-type="Warning">' + alertMessage + '</abp-alert>';
console.log(count)
$('#commentsAlert').html(alertElement);
$('#commentsAlert').show()
}
});
});

1
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Volo.CmsKit.Admin.Web.csproj

@ -36,6 +36,7 @@
<ItemGroup>
<None Remove="Components\CommentsSetting\Index.js" />
<None Remove="Pages\CmsKit\Comments\Waiting\index.js" />
</ItemGroup>
<ItemGroup>

7
modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js

@ -221,6 +221,13 @@
}, ajaxParams));
};
volo.cmsKit.admin.comments.commentAdmin.getPendingCommentCount = function(ajaxParams) {
return abp.ajax($.extend(true, {
url: abp.appPath + 'api/cms-kit-admin/comments/pending-count',
type: 'GET'
}, ajaxParams));
};
})();
// controller volo.cmsKit.admin.globalResources.globalResourceAdmin

6
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json

@ -228,6 +228,10 @@
"TagsHelpText": "Tags should be comma-separated (e.g.: tag1, tag2, tag3)",
"ThisPartOfContentCouldntBeLoaded": "This part of content couldn't be loaded.",
"DuplicateCommentAttemptMessage": "Duplicate comment post attempt detected. Your comment has already been submitted.",
"NoBlogPostYet": "No blog post yet!"
"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."
}
}

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

@ -21,10 +21,8 @@ public interface ICommentRepository : IBasicRepository<Comment, Guid>
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
bool? isApproved = null,
string isApproved = null,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
@ -34,7 +32,7 @@ public interface ICommentRepository : IBasicRepository<Comment, Guid>
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
bool? isApproved = null,
string isApproved = null,
CancellationToken cancellationToken = default
);

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

@ -45,10 +45,13 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
bool? isApproved = null,
string isApproved = null,
CancellationToken cancellationToken = default
)
{
//bool? isApprovedValue = ParseIsApproved(isApproved);
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(
filter,
@ -92,10 +95,11 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
bool? isApproved = null,
string isApproved = null,
CancellationToken cancellationToken = default
)
{
//bool? isApprovedValue = ParseIsApproved(isApproved);
var query = await GetListQueryAsync(
text,
entityType,
@ -127,22 +131,22 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken));
var commentsQuery = (await GetMongoQueryableAsync(cancellationToken))
.Where(c => c.EntityId == entityId && c.EntityType == entityType);
var commentsQuery = (await GetMongoQueryableAsync(cancellationToken))
.Where(c => c.EntityId == entityId && c.EntityType == entityType);
if (isApproved.HasValue)
{
commentsQuery = commentsQuery.Where(c => c.IsApproved == isApproved.Value);
}
if (isApproved.HasValue)
{
commentsQuery = commentsQuery.Where(c => c.IsApproved == isApproved.Value);
}
var comments = await commentsQuery
.OrderBy(c => c.CreationTime)
.ToListAsync(GetCancellationToken(cancellationToken));
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));
// var comments = await (await GetMongoQueryableAsync(cancellationToken))
//.Where(c => c.EntityId == entityId && c.EntityType == entityType )
// .OrderBy(c => c.CreationTime)
//.ToListAsync(GetCancellationToken(cancellationToken));
return comments
.Select(
@ -189,7 +193,7 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
bool? isApproved = null,
string isApproved = null,
CancellationToken cancellationToken = default
)
{
@ -204,11 +208,46 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
queryable = queryable.Where(x => x.CreatorId == authorId);
}
return queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
.WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate)
.WhereIf(isApproved.HasValue, c => c.IsApproved == isApproved);
queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
.WhereIf(repliedCommentId.HasValue, c => 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);
if (isApprovedValue.HasValue)
{
queryable = queryable.Where(c => c.IsApproved == isApprovedValue);
}
else if (isApprovedValue == null)
{
queryable = queryable.Where(c => c.IsApproved == null);
}
}
return queryable;
}
public static bool? ParseIsApproved(string isApproved)
{
if (string.IsNullOrWhiteSpace(isApproved))
{
return null;
}
return isApproved.ToLower() switch
{
"true" => true,
"false" => false,
"null" => (bool?)null,
_ => null
};
}
}

Loading…
Cancel
Save