Browse Source

filter by user completed

pull/12064/head
Musa Demir 5 years ago
parent
commit
cf226dca52
No known key found for this signature in database GPG Key ID: 117DF92322553DC8
  1. 3
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostRepository.cs
  2. 6
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs
  3. 6
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs
  4. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostGetListInput.cs
  5. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogPostPublicAppService.cs
  6. 12
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs
  7. 15
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogPostPublicController.cs
  8. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml
  9. 39
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml
  10. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs
  11. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.css
  12. 18
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.js

3
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostRepository.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Blogs; namespace Volo.CmsKit.Blogs;
@ -25,4 +26,6 @@ public interface IBlogPostRepository : IBasicRepository<BlogPost, Guid>
Task<bool> SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default); Task<bool> SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default);
Task<BlogPost> GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default); Task<BlogPost> GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default);
Task<List<CmsUser>> GetAuthorsHasBlogPosts(CancellationToken cancellationToken = default);
} }

6
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs

@ -97,4 +97,10 @@ public class EfCoreBlogPostRepository : EfCoreRepository<CmsKitDbContext, BlogPo
return await (await GetDbSetAsync()).AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, return await (await GetDbSetAsync()).AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug,
GetCancellationToken(cancellationToken)); GetCancellationToken(cancellationToken));
} }
public async Task<List<CmsUser>> GetAuthorsHasBlogPosts(CancellationToken cancellationToken = default)
{
return await (await GetDbContextAsync()).BlogPosts.Select(x => x.Author).Distinct()
.ToListAsync(GetCancellationToken(cancellationToken));
}
} }

6
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs

@ -101,4 +101,10 @@ public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, B
var queryable = await GetMongoQueryableAsync(token); var queryable = await GetMongoQueryableAsync(token);
return await queryable.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, token); return await queryable.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, token);
} }
public async Task<List<CmsUser>> GetAuthorsHasBlogPosts(CancellationToken cancellationToken = default)
{
var queryable = (await GetQueryableAsync()).Select(x => x.Author).Distinct();
return await AsyncExecuter.ToListAsync(queryable, GetCancellationToken(cancellationToken));
}
} }

2
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostGetListInput.cs

@ -5,7 +5,5 @@ namespace Volo.CmsKit.Public.Blogs;
public class BlogPostGetListInput : PagedAndSortedResultRequestDto public class BlogPostGetListInput : PagedAndSortedResultRequestDto
{ {
public string BlogSlug { get; set; }
public Guid? AuthorId { get; set; } public Guid? AuthorId { get; set; }
} }

8
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogPostPublicAppService.cs

@ -1,13 +1,17 @@
using JetBrains.Annotations; using System.Collections.Generic;
using JetBrains.Annotations;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Public.Blogs; namespace Volo.CmsKit.Public.Blogs;
public interface IBlogPostPublicAppService : IApplicationService public interface IBlogPostPublicAppService : IApplicationService
{ {
Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(BlogPostGetListInput input); Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(string blogSlug, BlogPostGetListInput input);
Task<BlogPostPublicDto> GetAsync([NotNull] string blogSlug, [NotNull] string blogPostSlug); Task<BlogPostPublicDto> GetAsync([NotNull] string blogSlug, [NotNull] string blogPostSlug);
Task<List<CmsUserDto>> GetAuthorsHasBlogPosts();
} }

12
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs

@ -5,6 +5,7 @@ using Volo.Abp.Application.Dtos;
using Volo.Abp.GlobalFeatures; using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Blogs; using Volo.CmsKit.Blogs;
using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Public.Blogs; namespace Volo.CmsKit.Public.Blogs;
@ -14,6 +15,7 @@ public class BlogPostPublicAppService : CmsKitPublicAppServiceBase, IBlogPostPub
protected IBlogRepository BlogRepository { get; } protected IBlogRepository BlogRepository { get; }
protected IBlogPostRepository BlogPostRepository { get; } protected IBlogPostRepository BlogPostRepository { get; }
public BlogPostPublicAppService( public BlogPostPublicAppService(
IBlogRepository blogRepository, IBlogRepository blogRepository,
@ -32,9 +34,9 @@ public class BlogPostPublicAppService : CmsKitPublicAppServiceBase, IBlogPostPub
return ObjectMapper.Map<BlogPost, BlogPostPublicDto>(blogPost); return ObjectMapper.Map<BlogPost, BlogPostPublicDto>(blogPost);
} }
public virtual async Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(BlogPostGetListInput input) public virtual async Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(string blogSlug, BlogPostGetListInput input)
{ {
var blog = await BlogRepository.GetBySlugAsync(input.BlogSlug); var blog = await BlogRepository.GetBySlugAsync(blogSlug);
var blogPosts = await BlogPostRepository.GetListAsync(null, blog.Id, input.AuthorId, input.MaxResultCount, var blogPosts = await BlogPostRepository.GetListAsync(null, blog.Id, input.AuthorId, input.MaxResultCount,
input.SkipCount, input.Sorting); input.SkipCount, input.Sorting);
@ -43,4 +45,10 @@ public class BlogPostPublicAppService : CmsKitPublicAppServiceBase, IBlogPostPub
await BlogPostRepository.GetCountAsync(blogId: blog.Id), await BlogPostRepository.GetCountAsync(blogId: blog.Id),
ObjectMapper.Map<List<BlogPost>, List<BlogPostPublicDto>>(blogPosts)); ObjectMapper.Map<List<BlogPost>, List<BlogPostPublicDto>>(blogPosts));
} }
public virtual async Task<List<CmsUserDto>> GetAuthorsHasBlogPosts()
{
var authors = await BlogPostRepository.GetAuthorsHasBlogPosts();
return ObjectMapper.Map<List<CmsUser>, List<CmsUserDto>>(authors);
}
} }

15
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogPostPublicController.cs

@ -1,11 +1,13 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Content; using Volo.Abp.Content;
using Volo.Abp.GlobalFeatures; using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Public.Blogs; namespace Volo.CmsKit.Public.Blogs;
@ -30,8 +32,15 @@ public class BlogPostPublicController : CmsKitPublicControllerBase, IBlogPostPub
} }
[HttpGet] [HttpGet]
public virtual Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(BlogPostGetListInput input) [Route("{blogSlug}")]
public virtual Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(string blogSlug, BlogPostGetListInput input)
{ {
return BlogPostPublicAppService.GetListAsync(input); return BlogPostPublicAppService.GetListAsync(blogSlug, input);
} }
}
[HttpGet]
public virtual Task<List<CmsUserDto>> GetAuthorsHasBlogPosts()
{
return BlogPostPublicAppService.GetAuthorsHasBlogPosts();
}
}

4
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml

@ -41,7 +41,9 @@
<div class="col-lg-8 col-md-10 mx-auto pb-4"> <div class="col-lg-8 col-md-10 mx-auto pb-4">
<h1 class="mt-lg-4 mt-md-3">@Model.BlogPost.Title</h1> <h1 class="mt-lg-4 mt-md-3">@Model.BlogPost.Title</h1>
<p class="mb-lg-5 mb-md-3"> <p class="mb-lg-5 mb-md-3">
<span class="font-weight-bold">@@@Model.BlogPost.Author?.UserName</span> <a href="/blogs/@Model.BlogSlug?authorId=@Model.BlogPost.Author.Id">
<span class="font-weight-bold">@@@Model.BlogPost.Author?.UserName</span>
</a>
<small style="opacity:.65;">@Model.BlogPost.CreationTime</small> <small style="opacity:.65;">@Model.BlogPost.CreationTime</small>
</p> </p>

39
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml

@ -8,12 +8,40 @@
@model IndexModel @model IndexModel
@section styles{ @section styles{
<abp-style src="/Pages/Public/CmsKit/Blogs/index.css" /> <abp-style src="/Pages/Public/CmsKit/Blogs/index.css"/>
} }
@section scripts {
<abp-script-bundle>
<abp-script src="/Pages/Public/CmsKit/Blogs/index.js"/>
</abp-script-bundle>
}
@{ @{
const string dummyImageSource = "https://dummyimage.com/320x180/a3a3a3/fff.png"; const string dummyImageSource = "https://dummyimage.com/320x180/a3a3a3/fff.png";
} }
<abp-row id="blogs-filter-area">
<abp-column size="_4">
<div class="mb-3">
<label class="form-label" asp-for="@Model.Authors"></label>
<select id="AuthorSelect" class="form-control">
<option value="">@L["SelectAnAuthor"]</option>
@foreach (var author in Model.Authors)
{
if (author.Id == Model.AuthorId)
{
<option value="@author.Id" selected>@author.Name @author.Surname</option>
}
else
{
<option value="@author.Id">@author.Name @author.Surname</option>
}
}
</select>
</div>
</abp-column>
</abp-row>
<abp-row id="blogs-container"> <abp-row id="blogs-container">
@foreach (var blog in Model.Blogs.Items) @foreach (var blog in Model.Blogs.Items)
{ {
@ -21,16 +49,16 @@
<abp-card> <abp-card>
@if (blog.CoverImageMediaId != null) @if (blog.CoverImageMediaId != null)
{ {
<img src="/api/cms-kit/media/@blog.CoverImageMediaId" class="card-img-top" onerror="this.src='@dummyImageSource'" /> <img src="/api/cms-kit/media/@blog.CoverImageMediaId" class="card-img-top" onerror="this.src='@dummyImageSource'"/>
} }
else else
{ {
<img src="@(dummyImageSource)?text=@blog.Title" class="card-img-top" /> <img src="@(dummyImageSource)?text=@blog.Title" class="card-img-top"/>
} }
<abp-card-body class="p-4"> <abp-card-body class="p-4">
<h5>@blog.Title</h5> <h5>@blog.Title</h5>
<p class="mb-2"> <p class="mb-2">
<span class="font-weight-bold">@@@blog.Author?.UserName</span> <span class="font-weight-bold author-name-span" data-author-id="@blog.Author.Id">@@@blog.Author?.UserName</span>
<small style="opacity:.65;">@blog.CreationTime</small> <small style="opacity:.65;">@blog.CreationTime</small>
</p> </p>
<p style="min-height: 60px;">@blog.ShortDescription</p> <p style="min-height: 60px;">@blog.ShortDescription</p>
@ -42,11 +70,10 @@
</abp-card-body> </abp-card-body>
</abp-card> </abp-card>
</abp-column> </abp-column>
} }
</abp-row> </abp-row>
<abp-row> <abp-row>
<abp-column> <abp-column>
<abp-paginator model="Model.PagerModel" /> <abp-paginator model="Model.PagerModel"/>
</abp-column> </abp-column>
</abp-row> </abp-row>

13
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Pagination; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Pagination;
using Volo.CmsKit.Public.Blogs; using Volo.CmsKit.Public.Blogs;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs;
@ -19,10 +20,16 @@ public class IndexModel : CmsKitPublicPageModelBase
[BindProperty(SupportsGet = true)] [BindProperty(SupportsGet = true)]
public int CurrentPage { get; set; } = 1; public int CurrentPage { get; set; } = 1;
[BindProperty(SupportsGet = true)]
public Guid? AuthorId { get; set; }
public PagedResultDto<BlogPostPublicDto> Blogs { get; private set; } public PagedResultDto<BlogPostPublicDto> Blogs { get; private set; }
public PagerModel PagerModel => new PagerModel(Blogs.TotalCount, Blogs.Items.Count, CurrentPage, PageSize, Request.Path.ToString()); public PagerModel PagerModel => new PagerModel(Blogs.TotalCount, Blogs.Items.Count, CurrentPage, PageSize, Request.Path.ToString());
[BindProperty(SupportsGet = true)]
public List<CmsUserDto> Authors { get; set; }
protected IBlogPostPublicAppService BlogPostPublicAppService { get; } protected IBlogPostPublicAppService BlogPostPublicAppService { get; }
@ -34,10 +41,14 @@ public class IndexModel : CmsKitPublicPageModelBase
public async Task OnGetAsync() public async Task OnGetAsync()
{ {
Blogs = await BlogPostPublicAppService.GetListAsync( Blogs = await BlogPostPublicAppService.GetListAsync(
BlogSlug,
new BlogPostGetListInput new BlogPostGetListInput
{ {
SkipCount = PageSize * (CurrentPage - 1), SkipCount = PageSize * (CurrentPage - 1),
MaxResultCount = PageSize MaxResultCount = PageSize,
AuthorId = AuthorId
}); });
Authors = await BlogPostPublicAppService.GetAuthorsHasBlogPosts();
} }
} }

4
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.css

@ -3,4 +3,8 @@
.popover { .popover {
min-width: 276px; min-width: 276px;
}
.author-name-span{
cursor: pointer;
} }

18
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.js

@ -0,0 +1,18 @@
$(function () {
var $selectAuthor = $('#AuthorSelect');
var $authorNameSpan = $('.author-name-span');
$selectAuthor.on('change', function () {
var authorId = $selectAuthor.val();
reloadPageWithQueryString({'authorId': authorId});
});
$authorNameSpan.click(function () {
var authorId = $(this).data('author-id');
reloadPageWithQueryString({'authorId': authorId});
});
function reloadPageWithQueryString(param) {
window.location.href = window.location.pathname + "?" + $.param(param);
}
});
Loading…
Cancel
Save