diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs index 530bb6efc1..164e4f691f 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs @@ -22,5 +22,9 @@ namespace Volo.Blogging.Posts public string Content { get; set; } public string Tags { get; set; } + + [StringLength(PostConsts.MaxDescriptionLength)] + public string Description { get; set; } + } } diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs index 08dde7e019..15401afbc6 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs @@ -18,6 +18,8 @@ namespace Volo.Blogging.Posts public string Content { get; set; } + public string Description { get; set; } + public int ReadCount { get; set; } public int CommentCount { get; set; } diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/UpdatePostDto.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/UpdatePostDto.cs index 07c62ba786..16b54fedd6 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/UpdatePostDto.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/UpdatePostDto.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; namespace Volo.Blogging.Posts { @@ -14,6 +15,8 @@ namespace Volo.Blogging.Posts public string Content { get; set; } + public string Description { get; set; } + public string Tags { get; set; } } } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index 76c9a29221..798bf8e39f 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -149,6 +149,7 @@ namespace Volo.Blogging.Posts post.SetTitle(input.Title); post.SetUrl(input.Url); post.Content = input.Content; + post.Description = input.Description; post.CoverImage = input.CoverImage; post = await _postRepository.UpdateAsync(post); @@ -171,7 +172,10 @@ namespace Volo.Blogging.Posts coverImage: input.CoverImage, url: input.Url ) - { Content = input.Content }; + { + Content = input.Content, + Description = input.Description + }; await _postRepository.InsertAsync(post); diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs index 7cfb5b1b30..898de49943 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs +++ b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs @@ -7,5 +7,8 @@ public const int MaxUrlLength = 64; public const int MaxContentLength = 1024 * 1024; //1MB + + public const int MaxDescriptionLength = 200; + } } diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/Post.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/Post.cs index ee44e7e029..ecc21d59d6 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/Post.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/Post.cs @@ -23,13 +23,16 @@ namespace Volo.Blogging.Posts [CanBeNull] public virtual string Content { get; set; } + [CanBeNull] + public virtual string Description { get; set; } + public virtual int ReadCount { get; protected set; } public virtual Collection Tags { get; protected set; } protected Post() { - + } public Post(Guid id, Guid blogId, [NotNull] string title, [NotNull] string coverImage, [NotNull] string url) @@ -63,7 +66,7 @@ namespace Volo.Blogging.Posts public virtual void AddTag(Guid tagId) { - Tags.Add(new PostTag(Id,tagId)); + Tags.Add(new PostTag(Id, tagId)); } public virtual void RemoveTag(Guid tagId) diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/EntityFrameworkCore/BloggingDbContextModelBuilderExtensions.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/EntityFrameworkCore/BloggingDbContextModelBuilderExtensions.cs index 56ef8277d9..a5e909d8a4 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/EntityFrameworkCore/BloggingDbContextModelBuilderExtensions.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/EntityFrameworkCore/BloggingDbContextModelBuilderExtensions.cs @@ -57,6 +57,7 @@ namespace Volo.Blogging.EntityFrameworkCore b.Property(x => x.CoverImage).IsRequired().HasColumnName(nameof(Post.CoverImage)); b.Property(x => x.Url).IsRequired().HasMaxLength(PostConsts.MaxUrlLength).HasColumnName(nameof(Post.Url)); b.Property(x => x.Content).IsRequired(false).HasMaxLength(PostConsts.MaxContentLength).HasColumnName(nameof(Post.Content)); + b.Property(x => x.Description).IsRequired(false).HasMaxLength(PostConsts.MaxDescriptionLength).HasColumnName(nameof(Post.Description)); b.HasMany(p => p.Tags).WithOne().HasForeignKey(qt => qt.PostId); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml index 5c781d1a5a..7bed3d0d68 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml @@ -9,7 +9,8 @@ @inject IAuthorizationService Authorization @model DetailModel @{ - ViewBag.PageTitle = Model.Post.Title; + ViewBag.Title = Model.Post.Title; + ViewBag.Description = Model.Post.Description; var hasCommentingPermission = CurrentUser.IsAuthenticated; //TODO: Apply real policy! } @section scripts { diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml index 4baf807e47..da48e701c4 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml @@ -26,9 +26,12 @@
+ - +
@@ -41,7 +44,9 @@ + + diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs index 9c87723edd..a5a0c5826b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs @@ -56,7 +56,8 @@ namespace Volo.Blogging.Pages.Blog.Posts Url = Post.Url, CoverImage = Post.CoverImage, Content = Post.Content, - Tags = Post.Tags + Tags = Post.Tags, + Description = !Post.Description.IsNullOrWhiteSpace() ? Post.Description : Post.Content.Substring(0,200) }; var editedPost = await _postAppService.UpdateAsync(Post.Id, post); @@ -92,6 +93,9 @@ namespace Volo.Blogging.Pages.Blog.Posts [StringLength(PostConsts.MaxContentLength)] public string Content { get; set; } + [StringLength(PostConsts.MaxDescriptionLength)] + public string Description { get; set; } + public string Tags { get; set; } } } \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml index d26c178898..d99267ef07 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml @@ -27,6 +27,10 @@ + + @@ -44,6 +48,7 @@ +
@@ -69,7 +74,7 @@ @L["Cancel"]
-
+
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs index b566b7bbe0..614d4cdc93 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs @@ -54,6 +54,12 @@ namespace Volo.Blogging.Pages.Blog.Posts public async Task OnPost() { var blog = await _blogAppService.GetAsync(Post.BlogId); + + if (Post.Description == null) + { + Post.Description = Post.Content.Substring(0, 200); + } + var postWithDetailsDto = await _postAppService.CreateAsync(ObjectMapper.Map(Post)); //TODO: Try Url.Page(...) @@ -84,6 +90,10 @@ namespace Volo.Blogging.Pages.Blog.Posts public string Content { get; set; } public string Tags { get; set; } + + [StringLength(PostConsts.MaxDescriptionLength)] + public string Description { get; set; } + } } } \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/edit.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/edit.js index 6b0dd9f02b..835db5979e 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/edit.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/edit.js @@ -27,6 +27,22 @@ }); }; + var checkTitleLength = function () { + var title = $('#Post_Title').val(); + + if (title.length > 60) { + $("#WarningMessage-title").css("display", "block"); + } else { + $("#WarningMessage-title").css("display", "none"); + } + }; + + checkTitleLength(); + + $('#Post_Title').on("change paste keyup", function () { + checkTitleLength(); + }); + $('#CoverImageFile').change(function () { if (!$('#CoverImageFile').prop('files').length) { return; diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/new.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/new.js index 0c3e927264..a9ab5c6d1e 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/new.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/new.js @@ -104,8 +104,10 @@ var title = $('#Post_Title').val(); - if (title.length > 64) { - title = title.substring(0, 64); + if (title.length > 60) { + $("#WarningMessage-title").css("display", "block"); + } else { + $("#WarningMessage-title").css("display", "none"); } title = title.replace(' ', '-');