From 0289e15a8f4fd51624e01ce3e3b744bb13de6642 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 19 Oct 2023 11:31:22 +0300 Subject: [PATCH] Add readonly support to CommentingViewComponent --- .../Pages/Index.cshtml | 8 +- .../Commenting/CommentingViewComponent.cs | 6 +- .../Components/Commenting/Default.cshtml | 176 +++++++++--------- 3 files changed, 103 insertions(+), 87 deletions(-) diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml index 860c2350ac..5302289fb3 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml @@ -65,7 +65,13 @@ @if (GlobalFeatureManager.Instance.IsEnabled()) { - @await Component.InvokeAsync(typeof(CommentingViewComponent), new {entityType = "quote", entityId = "1", referralLinks = new [] {"nofollow"}}) + @await Component.InvokeAsync(typeof(CommentingViewComponent), new + { + entityType = "quote", + entityId = "1", + isReadOnly = false, + referralLinks = new [] {"nofollow"} + }) } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs index 5810103ea9..32503ceab7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs @@ -60,6 +60,7 @@ public class CommentingViewComponent : AbpViewComponent public virtual async Task InvokeAsync( string entityType, string entityId, + bool isReadOnly, IEnumerable referralLinks = null) { referralLinks ??= Enumerable.Empty(); @@ -74,7 +75,8 @@ public class CommentingViewComponent : AbpViewComponent EntityType = entityType, ReferralLinks = referralLinks, LoginUrl = loginUrl, - Comments = comments.OrderByDescending(i => i.CreationTime).ToList() + IsReadOnly = isReadOnly, + Comments = comments.OrderByDescending(i => i.CreationTime).ToList(), }; await ConvertMarkdownTextsToHtml(viewModel); @@ -144,6 +146,8 @@ public class CommentingViewComponent : AbpViewComponent public string Captcha { get; set; } public string CaptchaImageBase64 { get; set; } + + public bool IsReadOnly { get; set; } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml index 8829df73c5..29ab21223c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml @@ -20,16 +20,16 @@ @ @((string.IsNullOrWhiteSpace(author.Name) - ? author.UserName - : author.Name + " " + author.Surname).Trim()) + ? author.UserName + : author.Name + " " + author.Surname).Trim()) @creationTime.ToString() ; } @{ Func GetCommentArea(Guid? repliedCommentId, bool cancelButton = false) => @
+ data-reply-id="@(repliedCommentId?.ToString() ?? "")" + style="@(string.IsNullOrEmpty(repliedCommentId?.ToString() ?? "") ? "" : "display:none")">
@@ -43,31 +43,31 @@
@if (CmsKitCommentOptions.Value.IsRecaptchaEnabled) - { -
- -
-
- -
-
- -
- + { +
+ +
+
+ +
+
+
+
- } +
+ }
@L["Send"] @if (cancelButton) - { - - @L["Cancel"] - - } + { + + @L["Cancel"] + + }
@@ -86,32 +86,32 @@ Func GetCommentActionArea(Guid id, Guid authorId, bool isReply) => @
@if (!isReply) - { - @if (CurrentUser.IsAuthenticated) - { - - @L["Reply"] - + { + @if (CurrentUser.IsAuthenticated) + { + + @L["Reply"] + + + + @L["Delete"] + + } + else + { + + @L["LoginToReply"] + + } + } + - - @L["Delete"] - - } - else - { - - @L["LoginToReply"] - - } - } - - @if (authorId == CurrentUser.Id) - { - - @L["Edit"] - - } + { + + @L["Edit"] + + }
; } @{ @@ -128,26 +128,26 @@
- @L["MarkdownSupported"] + @L["MarkdownSupported"]
@if (CmsKitCommentOptions.Value.IsRecaptchaEnabled) - { - var output = await Model.GenerateCaptchaAsync(); + { + var output = await Model.GenerateCaptchaAsync(); -
- -
-
- -
-
- -
- +
+ +
+
+ +
+
+
+
- } +
+ }
@L["Update"] @@ -183,22 +183,25 @@ @GetCommentContentArea(comment.Id, comment.Text).Invoke(null) -
-
-
- @GetCommentActionArea(comment.Id, comment.Author.Id, false).Invoke(null) + @if (!Model.Input.IsReadOnly) + { +
+
+
+ @GetCommentActionArea(comment.Id, comment.Author.Id, false).Invoke(null) +
-
-
-
- @if (cmsKitUiOptions.Value.CommentsOptions.IsReactionsEnabled && GlobalFeatureManager.Instance.IsEnabled()) - { - @await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new { entityType = "comment", entityId = comment.Id.ToString() }) - } +
+
+ @if (cmsKitUiOptions.Value.CommentsOptions.IsReactionsEnabled && GlobalFeatureManager.Instance.IsEnabled()) + { + @await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new { entityType = "comment", entityId = comment.Id.ToString() }) + } +
-
- @GetEditArea(comment.Id, Model.Input.RawCommentTexts[comment.Id], comment.ConcurrencyStamp).Invoke(null) + @GetEditArea(comment.Id, Model.Input.RawCommentTexts[comment.Id], comment.ConcurrencyStamp).Invoke(null) + } @if (comment.Replies.Any()) { @@ -212,23 +215,26 @@ @GetCommentContentArea(reply.Id, reply.Text).Invoke(null) -
-
-
- @GetCommentActionArea(reply.Id, reply.Author.Id, true).Invoke(null) + @if (!Model.Input.IsReadOnly) + { +
+
+
+ @GetCommentActionArea(reply.Id, reply.Author.Id, true).Invoke(null) +
-
-
-
- @if (cmsKitUiOptions.Value.CommentsOptions.IsReactionsEnabled && GlobalFeatureManager.Instance.IsEnabled()) - { - @await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new { entityType = "comment", entityId = reply.Id.ToString() }) - } +
+
+ @if (cmsKitUiOptions.Value.CommentsOptions.IsReactionsEnabled && GlobalFeatureManager.Instance.IsEnabled()) + { + @await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new { entityType = "comment", entityId = reply.Id.ToString() }) + } +
-
- @GetEditArea(reply.Id, Model.Input.RawCommentTexts[reply.Id], reply.ConcurrencyStamp).Invoke(null) + @GetEditArea(reply.Id, Model.Input.RawCommentTexts[reply.Id], reply.ConcurrencyStamp).Invoke(null) + }
}