diff --git a/EasyAbp.EasyComment.sln.DotSettings b/EasyAbp.EasyComment.sln.DotSettings index cb0b2c9..adf7c7c 100644 --- a/EasyAbp.EasyComment.sln.DotSettings +++ b/EasyAbp.EasyComment.sln.DotSettings @@ -19,5 +19,6 @@ True False False + EC SQL \ No newline at end of file diff --git a/host/EasyAbp.EasyComment.IdentityServer/yarn.lock b/host/EasyAbp.EasyComment.IdentityServer/yarn.lock index f4162d3..b27e5ce 100644 --- a/host/EasyAbp.EasyComment.IdentityServer/yarn.lock +++ b/host/EasyAbp.EasyComment.IdentityServer/yarn.lock @@ -1637,9 +1637,9 @@ minizlib@^1.2.1: minipass "^2.2.1" mixin-deep@^1.2.0: - version "1.3.1" - resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe" - integrity sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ== + version "1.3.2" + resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.2.tgz#1120b43dc359a785dce65b55b82e257ccf479566" + integrity sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA== dependencies: for-in "^1.0.2" is-extendable "^1.0.1" diff --git a/host/EasyAbp.EasyComment.Web.Unified/Pages/Comments.cshtml b/host/EasyAbp.EasyComment.Web.Unified/Pages/Comments.cshtml index 4c103c8..a31fa00 100644 --- a/host/EasyAbp.EasyComment.Web.Unified/Pages/Comments.cshtml +++ b/host/EasyAbp.EasyComment.Web.Unified/Pages/Comments.cshtml @@ -1,11 +1,13 @@ @page @model EasyAbp.EasyComment.Pages.Comments -

Comments

-@await Component.InvokeAsync("CommentWidget", new -{ - ItemType = "TestItemType", - ItemKey = "TestItemKey" -}) +
+

Comments

+ @await Component.InvokeAsync("CommentsWidget", new + { + ItemType = "TestItemType", + ItemKey = "TestItemKey" + }) +
diff --git a/src/EasyAbp.EasyComment.Application.Contracts/Comments/ICommentAppService.cs b/src/EasyAbp.EasyComment.Application.Contracts/Comments/ICommentAppService.cs index ec60833..acbc0c7 100644 --- a/src/EasyAbp.EasyComment.Application.Contracts/Comments/ICommentAppService.cs +++ b/src/EasyAbp.EasyComment.Application.Contracts/Comments/ICommentAppService.cs @@ -14,7 +14,8 @@ public interface ICommentAppService : CreateUpdateCommentDto, CreateUpdateCommentDto> { + Task AddCommentAsync(CreateUpdateCommentDto input); Task UpdateContentAsync(UpdateContentInput input); - Task DeleteCommentAsync(Guid id); + Task RemoveCommentAsync(Guid id); } } diff --git a/src/EasyAbp.EasyComment.Application/Comments/CommentAppService.cs b/src/EasyAbp.EasyComment.Application/Comments/CommentAppService.cs index c8b56b8..5fd1570 100644 --- a/src/EasyAbp.EasyComment.Application/Comments/CommentAppService.cs +++ b/src/EasyAbp.EasyComment.Application/Comments/CommentAppService.cs @@ -55,6 +55,18 @@ protected override CommentDto MapToGetListOutputDto(Comment entity) return dto; } + [Authorize] + public virtual async Task AddCommentAsync(CreateUpdateCommentDto input) + { + var entity = MapToEntity(input); + + TryToSetTenantId(entity); + + await Repository.InsertAsync(entity, autoSave: true); + + return MapToGetOutputDto(entity); + } + [Authorize] public virtual async Task UpdateContentAsync(UpdateContentInput input) { @@ -69,7 +81,7 @@ public virtual async Task UpdateContentAsync(UpdateContentInput inpu } [Authorize] - public virtual async Task DeleteCommentAsync(Guid id) + public virtual async Task RemoveCommentAsync(Guid id) { var comment = await GetEntityByIdAsync(id); if (comment.CreatorId != CurrentUser.GetId()) diff --git a/src/EasyAbp.EasyComment.Domain.Shared/Localization/EasyComment/en.json b/src/EasyAbp.EasyComment.Domain.Shared/Localization/EasyComment/en.json index 2c00842..e267cbd 100644 --- a/src/EasyAbp.EasyComment.Domain.Shared/Localization/EasyComment/en.json +++ b/src/EasyAbp.EasyComment.Domain.Shared/Localization/EasyComment/en.json @@ -11,7 +11,7 @@ "Comment": "Comment", "CommentItemType": "Item Type", "CommentItemKey": "Item Key", - "CommentContent": "Content", + "CommentContent": "Comment Content", "CommentReplyTo": "Reply To", "CreateComment": "Create Comment", "EditComment": "Edit Comment", @@ -19,6 +19,13 @@ "SuccessfullyDeleted": "Successfully deleted", "EasyComment:001" : "Users are only allowed to edit their own comments", "EasyComment:002" : "Users are only allowed to delete their own comments", - "TotalComments" : "{0} comments" + "TotalComments" : "{0} comments", + "PublishComment": "Publish", + "LeaveComment": "Leave Comment", + "NeedCommentContent": "Please enter the content", + "SuccessfullyPublishComment": "Comment published successfully", + "Remove": "Delete", + "Reference": "Reference", + "Reply": "Reply", } } \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Domain.Shared/Localization/EasyComment/zh-Hans.json b/src/EasyAbp.EasyComment.Domain.Shared/Localization/EasyComment/zh-Hans.json index 172e66f..d92a607 100644 --- a/src/EasyAbp.EasyComment.Domain.Shared/Localization/EasyComment/zh-Hans.json +++ b/src/EasyAbp.EasyComment.Domain.Shared/Localization/EasyComment/zh-Hans.json @@ -12,7 +12,7 @@ "Comment": "评论", "CommentItemType": "项目类型", "CommentItemKey": "项目键值", - "CommentContent": "内容", + "CommentContent": "评论内容", "CommentReplyTo": "回复给", "CreateComment": "创建评论", "EditComment": "编辑评论", @@ -20,6 +20,13 @@ "SuccessfullyDeleted": "删除成功", "EasyComment:001" : "用户只能更新自己的评论", "EasyComment:002" : "用户只能删除自己的评论", - "TotalComments" : "共 {0} 条评论" + "TotalComments" : "共 {0} 条评论", + "PublishComment": "发表", + "LeaveComment": "发表评论", + "NeedCommentContent": "请输入评论内容", + "SuccessfullyPublishComment": "发表评论成功", + "Remove": "删除", + "Reference": "引用", + "Reply": "回复" } } \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.HttpApi/Comments/CommentController.cs b/src/EasyAbp.EasyComment.HttpApi/Comments/CommentController.cs index 936ef80..5dae620 100644 --- a/src/EasyAbp.EasyComment.HttpApi/Comments/CommentController.cs +++ b/src/EasyAbp.EasyComment.HttpApi/Comments/CommentController.cs @@ -8,7 +8,7 @@ namespace EasyAbp.EasyComment.Comments { [RemoteService(Name = "CommentService")] - [Route("/api/EasyComment/comment")] + [Route("/api/easyComment/comment")] public class CommentController : EasyCommentController, ICommentAppService { private readonly ICommentAppService _service; @@ -51,6 +51,13 @@ public Task DeleteAsync(Guid id) return _service.DeleteAsync(id); } + [HttpPost] + [Route("comment")] + public Task AddCommentAsync(CreateUpdateCommentDto input) + { + return _service.AddCommentAsync(input); + } + [HttpPut] [Route("content")] public Task UpdateContentAsync(UpdateContentInput input) @@ -60,9 +67,9 @@ public Task UpdateContentAsync(UpdateContentInput input) [HttpDelete] [Route("{id}/comment")] - public Task DeleteCommentAsync(Guid id) + public Task RemoveCommentAsync(Guid id) { - return _service.DeleteCommentAsync(id); + return _service.RemoveCommentAsync(id); } } } \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.HttpApi/EasyAbp.EasyComment.HttpApi.csproj b/src/EasyAbp.EasyComment.HttpApi/EasyAbp.EasyComment.HttpApi.csproj index 6807f35..925d3b0 100644 --- a/src/EasyAbp.EasyComment.HttpApi/EasyAbp.EasyComment.HttpApi.csproj +++ b/src/EasyAbp.EasyComment.HttpApi/EasyAbp.EasyComment.HttpApi.csproj @@ -12,8 +12,4 @@ - - - - diff --git a/src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/Default.cshtml b/src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/Default.cshtml deleted file mode 100644 index 5d343af..0000000 --- a/src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/Default.cshtml +++ /dev/null @@ -1,23 +0,0 @@ -@using EasyAbp.EasyComment.Comments.Dtos -@using EasyAbp.EasyComment.Localization -@using Microsoft.AspNetCore.Mvc.Localization -@inject IHtmlLocalizer L - - - - @L["TotalComments", Model.TotalCount] - - @{ int i = 1;} - @foreach (CommentDto comment in Model.Items) - { - - - #@(i++) -

@comment.CreatorName

- @comment.CreationTime -
-

@comment.Content

-
-
- } -
\ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/Default.css b/src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/Default.css deleted file mode 100644 index 3f1f9a8..0000000 --- a/src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/Default.css +++ /dev/null @@ -1,27 +0,0 @@ -div.ec-comments { - margin: 10px; -} - -div.ec-comment { - margin: 10px; -} - -div.ec-comment span { - margin-left: 5px; -} - -a.ec-comment-link { - margin-right: 5px; -} - -p.ec-creator { - font-weight: bold; -} - -p.ec-content { - line-break: anywhere; -} - -span.ec-comment-time { - color: gray; -} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorViewModel.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorViewModel.cs new file mode 100644 index 0000000..e18d199 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; + +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentEditorWidget +{ + public class CommentEditorViewModel + { + public bool ShowLabel { get; set; } + + [Required(ErrorMessage = "NeedCommentContent")] + [TextArea] + [Display(Name = "CommentContent")] + public string Content { get; set; } + + public bool EditModel { get; set; } + } +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorWidgetController.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorWidgetController.cs new file mode 100644 index 0000000..eaef86f --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorWidgetController.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.AspNetCore.Mvc; + +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentEditorWidget +{ + [Route("/widgets/easyComment")] + public class CommentEditorWidgetController : EasyCommentController + { + [HttpGet] + [Route("showCommentEditor")] + public IActionResult ShowCommentEditor(Guid? id, bool showLabel, bool editModel) + { + return ViewComponent("CommentEditorWidget", new {id, showLabel, editModel}); + } + } +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorWidgetViewComponent.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorWidgetViewComponent.cs new file mode 100644 index 0000000..fac52fe --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/CommentEditorWidgetViewComponent.cs @@ -0,0 +1,37 @@ +using System; +using System.Threading.Tasks; +using EasyAbp.EasyComment.Comments; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.UI.Widgets; + +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentEditorWidget +{ + [Widget( + RefreshUrl = "/widgets/easyComment/showCommentEditor" + )] + public class CommentEditorWidgetViewComponent : AbpViewComponent + { + private readonly ICommentAppService _service; + + public CommentEditorWidgetViewComponent(ICommentAppService service) + { + _service = service; + } + + public async Task InvokeAsync(Guid? id, bool showLabel, bool editModel) + { + var viewModel = new CommentEditorViewModel + { + ShowLabel = showLabel, + EditModel = editModel, + }; + if (id.HasValue) + { + var comment = await _service.GetAsync(id.Value); + viewModel.Content = comment.Content; + } + return View(viewModel); + } + } +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/Default.cshtml b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/Default.cshtml new file mode 100644 index 0000000..d0c30a1 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentEditorWidget/Default.cshtml @@ -0,0 +1,24 @@ +@using EasyAbp.EasyComment.Localization +@using Microsoft.AspNetCore.Mvc.Localization +@model EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentEditorWidget.CommentEditorViewModel +@inject IHtmlLocalizer L + +
+ @if (Model.ShowLabel) + { + + } + + @if (Model.EditModel) + { +
+ + +
+ } + else + { + + } + +
\ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerViewModel.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerViewModel.cs new file mode 100644 index 0000000..6e125e1 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerViewModel.cs @@ -0,0 +1,10 @@ +using System; + +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentViewerWidget +{ + public class CommentViewerViewModel + { + public Guid Id { get; set; } + public string Content { get; set; } + } +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerWidgetController.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerWidgetController.cs new file mode 100644 index 0000000..45af749 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerWidgetController.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.AspNetCore.Mvc; + +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentViewerWidget +{ + [Route("/widgets/easyComment")] + public class CommentViewerWidgetController : EasyCommentController + { + [HttpGet] + [Route("showCommentViewer")] + public IActionResult ShowCommentViewer(Guid id, string content, bool fromServer) + { + return ViewComponent("CommentViewerWidget", new {id, content, fromServer}); + } + } +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerWidgetViewComponent.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerWidgetViewComponent.cs new file mode 100644 index 0000000..b5fa948 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/CommentViewerWidgetViewComponent.cs @@ -0,0 +1,36 @@ +using System; +using System.Threading.Tasks; +using EasyAbp.EasyComment.Comments; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.UI.Widgets; + +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentViewerWidget +{ + [Widget( + RefreshUrl = "/widgets/easyComment/showCommentViewer" + )] + public class CommentViewerWidgetViewComponent : AbpViewComponent + { + private readonly ICommentAppService _service; + + public CommentViewerWidgetViewComponent(ICommentAppService service) + { + _service = service; + } + + public async Task InvokeAsync(Guid id, string content, bool fromServer) + { + if (fromServer) + { + var comment = await _service.GetAsync(id); + content = comment.Content; + } + return View(new CommentViewerViewModel + { + Id = id, + Content = content, + }); + } + } +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/Default.cshtml b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/Default.cshtml new file mode 100644 index 0000000..cf7585c --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentViewerWidget/Default.cshtml @@ -0,0 +1,3 @@ +@model EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentViewerWidget.CommentViewerViewModel + +

@Model.Content

\ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetController.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetController.cs new file mode 100644 index 0000000..7e6005e --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetController.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Mvc; + +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentsWidget +{ + [Route("/widgets/easyComment")] + public class CommentsWidgetController : EasyCommentController + { + [HttpGet] + [Route("comments")] + public IActionResult Comments(string itemType, string itemKey) + { + return ViewComponent("CommentsWidget", new {itemType, itemKey}); + } + } +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/CommentWidgetViewComponent.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetViewComponent.cs similarity index 51% rename from src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/CommentWidgetViewComponent.cs rename to src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetViewComponent.cs index a98857b..b36c64f 100644 --- a/src/EasyAbp.EasyComment.Web/Pages/Components/CommentWidget/CommentWidgetViewComponent.cs +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetViewComponent.cs @@ -5,16 +5,18 @@ using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; -namespace EasyAbp.EasyComment.Web.Pages.Components.CommentWidget +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentsWidget { [Widget( - StyleFiles = new[] {"/Pages/Components/CommentWidget/Default.css"} + RefreshUrl = "/widgets/easyComment/comments", + ScriptFiles = new[]{"/Pages/Shared/Components/CommentsWidget/Default.js"}, + StyleFiles = new[] {"/Pages/Shared/Components/CommentsWidget/Default.css"} )] - public class CommentWidgetViewComponent : AbpViewComponent + public class CommentsWidgetViewComponent : AbpViewComponent { private readonly ICommentAppService _service; - public CommentWidgetViewComponent(ICommentAppService service) + public CommentsWidgetViewComponent(ICommentAppService service) { _service = service; } @@ -26,7 +28,12 @@ public async Task InvokeAsync(string itemType, string item ItemType = itemType, ItemKey = itemKey, }); - return View(comments); + return View(new CommentsWidgetViewModel + { + ItemType = itemType, + ItemKey = itemKey, + Comments = comments, + }); } } } \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetViewModel.cs b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetViewModel.cs new file mode 100644 index 0000000..66234ca --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/CommentsWidgetViewModel.cs @@ -0,0 +1,18 @@ +using EasyAbp.EasyComment.Comments.Dtos; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Application.Dtos; + +namespace EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentsWidget +{ + public class CommentsWidgetViewModel + { + [HiddenInput] + public string ItemType { get; set; } + + [HiddenInput] + public string ItemKey { get; set; } + + public PagedResultDto Comments { get; set; } + + } +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.cshtml b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.cshtml new file mode 100644 index 0000000..48833f1 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.cshtml @@ -0,0 +1,69 @@ +@using EasyAbp.EasyComment.Comments.Dtos +@using EasyAbp.EasyComment.Localization +@using EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentEditorWidget +@using EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentViewerWidget +@using Microsoft.AspNetCore.Mvc.Localization +@using Volo.Abp.Users +@model EasyAbp.EasyComment.Web.Pages.Shared.Components.CommentsWidget.CommentsWidgetViewModel +@inject IHtmlLocalizer L +@inject ICurrentUser CurrentUser + + + + + + @L["TotalComments", Model.Comments.TotalCount] + + @{ int i = 1; } + @foreach (CommentDto comment in Model.Comments.Items) + { + + + + + #@(i++) +

@comment.CreatorName

+ +
+
+ + @if (CurrentUser.IsAuthenticated) + { + + + + @if (comment.CreatorId == CurrentUser.GetId()) + { + @L["Edit"] + } + @L["Reply"] + @L["Reference"] + @if (comment.CreatorId == CurrentUser.GetId()) + { + + @L["Remove"] + } + + + } + +
+
+ @await Component.InvokeAsync("CommentViewerWidget", new {Id = comment.Id, Content = comment.Content, FromServer = false}) +
+
+
+ } + @if (CurrentUser.IsAuthenticated) + { + @await Component.InvokeAsync("CommentEditorWidget", new + { + ShowLabel = true, + Content = String.Empty, + }) + } + else + { + // TODO + } +
\ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.css b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.css new file mode 100644 index 0000000..3e6537f --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.css @@ -0,0 +1,49 @@ +div.ec-comments { + margin: 10px; +} + +.ec-comment { + margin: 10px; +} + +.ec-comment-link { + margin-right: 5px; +} + +.ec-creator { + font-weight: bold; +} + +.ec-content { + line-break: anywhere; + white-space: pre-wrap; +} + +.ec-comment-time { + color: gray; + margin-left: 5px; +} + +.ec-leave-comment { + margin-top: 20px; + font-size: medium; +} + +.ec-textarea-new-comment { + width:100%; +} + +/*Remove the arrow of dropdowns */ +.dropdown-toggle::after { + border: none; + content: none; +} + +.ec-button-publish { + margin-bottom: 20px; + float: right; +} + +.ec-button-group-edit { + float : right; +} \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.js b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.js new file mode 100644 index 0000000..fca3563 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/Components/CommentsWidget/Default.js @@ -0,0 +1,75 @@ +$(function () { + var l = abp.localization.getResource("EasyComment"); + + var getCommentWidget = function (e) { + return e.parents(".abp-widget-wrapper").last(); + }; + + $(".ec-button-publish").click(function (e) { + e.preventDefault(); + + var form = $(this).closest("form"); + if (!$(form).valid()) return; + + var widget = getCommentWidget(form); + var service = easyAbp.easyComment.comments.comment; + var itemType = $(widget).find("#ItemType").val(); + var itemKey = $(widget).find("#ItemKey").val(); + var content = $(widget).find(".ec-textarea-new-comment").val(); + + service.addComment({ + itemType: itemType, + itemKey: itemKey, + content: content, + // TODO: replyTo: replyTo + }) + .then(function () { + abp.notify.info(l("SuccessfullyPublishComment")); + var widgetManager = new abp.WidgetManager($(widget).parent()); + widgetManager.init(); + widgetManager.refresh(); + }); + }); + + $(document).on("change", "form :input", function () { + $(this).closest('form').data('changed', true); + }) + + $(".ec-edit-comment").click(function () { + var commentDiv = $(this).closest(".ec-comment"); + var commentHolder = commentDiv.find(".ec-comment-holder"); + var commentId = commentDiv.attr("data-comment-id"); + + commentHolder.find("[data-widget-name=CommentViewerWidget]").hide(); + $.get("/widgets/easyComment/showCommentEditor", { + id: commentId, + showLabel: false, + editModel: true, + }, function (html) { + commentDiv.find(".ec-comment-holder").append(html); + }) + }); + + $(document).on("click", ".ec-button-cancel", function () { + var btnCancel = $(this); + + var cancelEdit = function () { + var commentDiv = btnCancel.closest(".ec-comment"); + var commentHolder = commentDiv.find(".ec-comment-holder"); + commentHolder.find("[data-widget-name=CommentViewerWidget]").show(); + commentHolder.find("[data-widget-name=CommentEditorWidget]").remove(); + } + + if ($(this).closest('form').data('changed')) { + abp.message.confirm(l("AreYouSureYouWantToCancelEditingWarningMessage")) + .done(function (result) { + if (result) { + cancelEdit(); + } + }) + } else { + cancelEdit(); + } + }); +}) + diff --git a/src/EasyAbp.EasyComment.Web/Pages/Shared/_ViewImports.cshtml b/src/EasyAbp.EasyComment.Web/Pages/Shared/_ViewImports.cshtml new file mode 100644 index 0000000..c1da1f5 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/Pages/Shared/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI +@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap +@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling \ No newline at end of file diff --git a/src/EasyAbp.EasyComment.Web/TagHelpers/ECInputTagHelperService.cs b/src/EasyAbp.EasyComment.Web/TagHelpers/ECInputTagHelperService.cs new file mode 100644 index 0000000..23894a4 --- /dev/null +++ b/src/EasyAbp.EasyComment.Web/TagHelpers/ECInputTagHelperService.cs @@ -0,0 +1,25 @@ +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers; +using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; +using Volo.Abp.DependencyInjection; + +namespace EasyAbp.EasyComment.Web.TagHelpers +{ + [ExposeServices(typeof(AbpInputTagHelperService))] + public class ECInputTagHelperService : AbpInputTagHelperService + { + public ECInputTagHelperService(IHtmlGenerator generator, HtmlEncoder encoder, IAbpTagHelperLocalizer tagHelperLocalizer) : base(generator, encoder, tagHelperLocalizer) + { + } + + protected override async Task GetLabelAsHtmlAsync(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag, bool isCheckbox) + { + if (context.AllAttributes.ContainsName("no-label")) return ""; + + return await base.GetLabelAsHtmlAsync(context, output, inputTag, isCheckbox); + } + } +} \ No newline at end of file