Browse Source

added markdown to comments

pull/19919/head
EmreKendirli 2 years ago
parent
commit
aac7ebc15f
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs
  2. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs
  3. 26
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/ClientProxies/Volo/CmsKit/Admin/Comments/CommentAdminClientProxy.Generated.cs
  4. 3547
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/ClientProxies/cms-kit-admin-generate-proxy.json
  5. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs
  6. 1
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/Index.cshtml
  7. 315
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Approve/index.js
  8. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs
  9. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js
  10. 7
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js
  11. 1
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Shared/Components/Comments/CommentSettingViewComponent.cs
  12. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js
  13. 19
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

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

@ -16,7 +16,7 @@ public interface ICommentAdminAppService : IApplicationService
Task SetSettings(SettingsDto settingsDto);
Task<SettingsDto> GetSettings();
Task<int> GetPendingCommentCount();
Task<int> GetWaitingCommentCount();
Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input);

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

@ -112,7 +112,7 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
}
return null;
}
public async Task<int> GetPendingCommentCount()
public async Task<int> GetWaitingCommentCount()
{
var count = await CommentRepository.GetCountAsync(commentApproveStateType: CommentApproveStateType.Waiting);
return (int)(count);

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

@ -49,4 +49,30 @@ public partial class CommentAdminClientProxy : ClientProxyBase<ICommentAdminAppS
{ typeof(CommentApprovalDto), commentApprovalDto }
});
}
public virtual void SetSettings(SettingsDto settingsDto)
{
//Client Proxy does not support the synchronization method, you should always use asynchronous methods as a best practice
throw new System.NotImplementedException();
}
public virtual SettingsDto GetSettings()
{
//Client Proxy does not support the synchronization method, you should always use asynchronous methods as a best practice
throw new System.NotImplementedException();
}
public virtual int GetWaitingCommentCount()
{
//Client Proxy does not support the synchronization method, you should always use asynchronous methods as a best practice
throw new System.NotImplementedException();
}
public virtual async Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input)
{
return await RequestAsync<PagedResultDto<CommentWithAuthorDto>>(nameof(GetWaitingCommentsWithRepliesAsync), new ClientProxyRequestTypeValue
{
{ typeof(CommentGetListInput), input }
});
}
}

3547
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/ClientProxies/cms-kit-admin-generate-proxy.json

File diff suppressed because it is too large

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

@ -77,9 +77,9 @@ public class CommentAdminController : CmsKitAdminController, ICommentAdminAppSer
[HttpGet]
[Route("waiting-count")]
[Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<int> GetPendingCommentCount()
public Task<int> GetWaitingCommentCount()
{
return CommentAdminAppService.GetPendingCommentCount();
return CommentAdminAppService.GetWaitingCommentCount();
}
[HttpGet]

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

@ -29,6 +29,7 @@
<abp-script src="/client-proxies/cms-kit-admin-proxy.js" />
<abp-script src="/Pages/CmsKit/Comments/Approve/index.js" />
</abp-script-bundle>
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js"></script>
}

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

@ -1,182 +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 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"
});
var detailsModal = new abp.ModalManager(abp.appPath + "CmsKit/Comments/DetailsModal");
moment()._locale.preparse = (string) => string;
moment()._locale.postformat = (string) => string;
$('.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.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);
});
}
},
{
text: function (data) {
return l('Disapproved') ;
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"
});
$('.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.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) {
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);
});
{
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
}
]
}
},
{
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 "";
}
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));
},
{
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 "";
}
return "";
}
},
{
title: l("Text"),
data: "text",
orderable: false,
render: function (data) {
//var markdownData = marked(data || "");
//var sanitizedData = DOMPurify.sanitize(markdownData);
data = $.fn.dataTable.render.text().display(data || "");
return (
'<span data-toggle="tooltip" title="' +
data +
'" style="white-space: normal; word-break: break-all;">' +
data +
"</span>"
);
},
{
title: l("Text"),
data: "text",
orderable: false,
render: function (data) {
var converter = new showdown.Converter();
var htmlContent = converter.makeHtml(data);
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) {
return '<span class="datatableCell" data-field="' + filterSelector + '" data-val="' + data + '">' + data + '</span>';
}
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');
$(document).on('click', '.datatableCell', function () {
var inputSelector = $(this).attr('data-field');
var value = $(this).attr('data-val');
$(inputSelector).val(value);
$(inputSelector).val(value);
_dataTable.ajax.reloadEx();
});
_dataTable.ajax.reloadEx();
});
filterForm.submit(function (e) {
e.preventDefault();
_dataTable.ajax.reloadEx();
filterForm.submit(function (e) {
e.preventDefault();
_dataTable.ajax.reloadEx();
});
});
});

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? CreationEndDate { get; set; }
public CommentApproveStateType commentApproveStateType { get; set; }
public CommentApproveStateType? commentApproveStateType { get; set; }
}

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

@ -32,7 +32,10 @@ $(function (){
});
var filterForm = $('#CmsKitCommentsFilterForm');
$('.singledatepicker').on('apply.daterangepicker', function (ev, picker) {
$(this).val(picker.startDate.format('l'));
$(this).data('date', picker.startDate.locale('en').format('YYYY-MM-DD'));
});
var getFilter = function () {
var filterObj = filterForm.serializeFormToObject();

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

@ -16,9 +16,6 @@ $(function (){
return momentDate.isValid() ? momentDate.toISOString() : null;
};
//var defaultStartDate = moment().add(-7, 'days');
//$("#CreationStartDate").val(defaultStartDate.format('L'));
$('.singledatepicker').daterangepicker({
"singleDatePicker": true,
@ -237,8 +234,8 @@ $(function (){
_dataTable.ajax.reloadEx();
});
// Get and display pending comment count
commentsService.getPendingCommentCount().then(function (count) {
// Get and display waiting comment count
commentsService.getWaitingCommentCount().then(function (count) {
if (count > 0) {
var alertMessage = l("CommentAlertMessage", count);
var alertElement = '<abp-alert alert-type="Warning">' + alertMessage + '</abp-alert>';

1
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Shared/Components/Comments/CommentSettingViewComponent.cs

@ -6,7 +6,6 @@ namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Shared.Components.Comments;
[ViewComponent(Name = "CmsCommentSetting")]
[Widget(
ScriptTypes = new[] { typeof(CommentSettingScriptBundleContributor) },
// RefreshUrl = "/CmsKitPublicWidgets/Commenting",
AutoInitialize = true
)]
public class CommentSettingViewComponent : AbpViewComponent

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

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

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

@ -125,19 +125,13 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
Author = user
};
if (CommentApproveStateType.Approved == commentApproveStateType)
query = commentApproveStateType switch
{
query = query.Where(c => c.Comment.IsApproved == true);
}
else if (CommentApproveStateType.Disapproved == commentApproveStateType)
{
query = query.Where(c => c.Comment.IsApproved == false);
}
else if (CommentApproveStateType.Waiting == commentApproveStateType)
{
query = query.Where(c => c.Comment.IsApproved == null);
}
CommentApproveStateType.Approved => query.Where(c => c.Comment.IsApproved == true),
CommentApproveStateType.Disapproved => query.Where(c => c.Comment.IsApproved == true || c.Comment.IsApproved == null),
_ => query
};
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
@ -198,6 +192,5 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
.WhereIf(CommentApproveStateType.Approved == commentApproveStateType, c => c.Comment.IsApproved == true)
.WhereIf(CommentApproveStateType.Disapproved == commentApproveStateType, c => c.Comment.IsApproved == false)
.WhereIf(CommentApproveStateType.Waiting == commentApproveStateType, c => c.Comment.IsApproved == null);
//.WhereIf(isApproved.HasValue, c => c.Comment.IsApproved == isApproved);
}
}

Loading…
Cancel
Save