Browse Source

added description field in posts and updated create and edit page for post

pull/3432/head
Akın Sabri Çam 7 years ago
parent
commit
92a021611a
  1. 4
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs
  2. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs
  3. 3
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/UpdatePostDto.cs
  4. 6
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  5. 3
      modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs
  6. 7
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/Post.cs
  7. 1
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/EntityFrameworkCore/BloggingDbContextModelBuilderExtensions.cs
  8. 3
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml
  9. 7
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml
  10. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs
  11. 7
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml
  12. 10
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs
  13. 16
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/edit.js
  14. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/new.js

4
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; }
}
}

2
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; }

3
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; }
}
}

6
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);

3
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;
}
}

7
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<PostTag> 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)

1
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);

3
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 {

7
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml

@ -26,9 +26,12 @@
<div class="card-body">
<form method="post" id="edit-post-form">
<abp-input asp-for="Post.Title" auto-focus="true" />
<div class="alert alert-warning" id="WarningMessage-title" role="alert">
Keep your title size under 60 characters to be SEO friendly!
</div>
<abp-input asp-for="Post.Url" />
<abp-input asp-for="Post.CoverImage" />
<abp-row>
<abp-column size-sm="_9">
<div class="form-group">
@ -41,7 +44,9 @@
</abp-column>
</abp-row>
<abp-input asp-for="Post.Tags" />
<abp-input asp-for="Post.Description" />
<abp-input asp-for="Post.BlogId" />
<abp-input asp-for="Post.Id" />
<abp-input asp-for="Post.Content" />

6
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; }
}
}

7
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml

@ -27,6 +27,10 @@
<form method="post" id="new-post-form">
<abp-input asp-for="Post.BlogId" />
<abp-input asp-for="Post.Title" auto-focus="true" />
<div class="alert alert-warning" id="WarningMessage-title" style="display: none" role="alert">
Keep your title size under 60 characters to be SEO friendly!
</div>
<abp-input asp-for="Post.Url" />
<abp-input asp-for="Post.CoverImage" />
@ -44,6 +48,7 @@
<abp-input asp-for="Post.Content" />
<abp-input asp-for="Post.Tags" />
<abp-input asp-for="Post.Description" />
<div class="form-group">
@ -69,7 +74,7 @@
<a asp-page="./Index" class="btn btn-default mr-2"><span>@L["Cancel"]</span></a>
</div>
</div>
</div>
</form>
</div>
</div>

10
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<ActionResult> 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<CreatePostViewModel,CreatePostDto>(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; }
}
}
}

16
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;

6
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(' ', '-');

Loading…
Cancel
Save