Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check & move related blog posts on deletion #21348

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class BlogDto : ExtensibleEntityDto<Guid>, IHasConcurrencyStamp

public string Slug { get; set; }
public string ConcurrencyStamp { get; set; }

public int BlogPostCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace Volo.CmsKit.Admin.Blogs;

public interface IBlogAdminAppService : ICrudAppService<BlogDto, Guid, BlogGetListInput, CreateBlogDto, UpdateBlogDto>
{
Task<ListResultDto<BlogDto>> GetAllListAsync();

Task MoveAllBlogPostsAsync(Guid blogId, Guid? assignToBlogId);
realLiangshiwei marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
Expand All @@ -20,37 +21,64 @@ namespace Volo.CmsKit.Admin.Blogs;
public class BlogAdminAppService : CmsKitAdminAppServiceBase, IBlogAdminAppService
{
protected IBlogRepository BlogRepository { get; }
protected IBlogPostRepository BlogPostRepository { get; }
protected BlogManager BlogManager { get; }
protected BlogFeatureManager BlogFeatureManager { get; }

public BlogAdminAppService(
IBlogRepository blogRepository,
BlogManager blogManager,
BlogManager blogManager,
IBlogPostRepository blogPostRepository,
BlogFeatureManager blogFeatureManager = null)
{
BlogRepository = blogRepository;
BlogManager = blogManager;
BlogPostRepository = blogPostRepository;
BlogFeatureManager = blogFeatureManager;
}

public virtual async Task<BlogDto> GetAsync(Guid id)
{
var blog = await BlogRepository.GetAsync(id);

return ObjectMapper.Map<Blog, BlogDto>(blog);
var blogDto = ObjectMapper.Map<Blog, BlogDto>(blog);
blogDto.BlogPostCount = await BlogPostRepository.GetCountAsync(blogId : blog.Id);

return blogDto;
}

public virtual async Task<PagedResultDto<BlogDto>> GetListAsync(BlogGetListInput input)
{
var totalCount = await BlogRepository.GetCountAsync(input.Filter);

var blogs = await BlogRepository.GetListAsync(
var blogs = await BlogRepository.GetListWithBlogPostCountAsync(
input.Filter,
input.Sorting,
input.MaxResultCount,
input.SkipCount);

var blogDtos = new PagedResultDto<BlogDto>(totalCount, ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs.Select(x => x.Blog).ToList()));

foreach (var blogDto in blogDtos.Items)
{
blogDto.BlogPostCount = blogs.First(x => x.Blog.Id == blogDto.Id).BlogPostCount;
}

return new PagedResultDto<BlogDto>(totalCount, ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs));
return blogDtos;
}

public virtual async Task<ListResultDto<BlogDto>> GetAllListAsync()
{
var blogs = await BlogRepository.GetListWithBlogPostCountAsync(maxResultCount: int.MaxValue);

var blogDtos = new ListResultDto<BlogDto>(ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs.Select(x => x.Blog).ToList()));

foreach (var blogDto in blogDtos.Items)
{
blogDto.BlogPostCount = blogs.First(x => x.Blog.Id == blogDto.Id).BlogPostCount;
}

return blogDtos;
}

[Authorize(CmsKitAdminPermissions.Blogs.Create)]
Expand Down Expand Up @@ -79,10 +107,18 @@ public virtual async Task<BlogDto> UpdateAsync(Guid id, UpdateBlogDto input)

return ObjectMapper.Map<Blog, BlogDto>(blog);
}

[Authorize(CmsKitAdminPermissions.Blogs.Delete)]
public virtual async Task MoveAllBlogPostsAsync(Guid blogId, Guid? assignToBlogId)
{
var blog = await BlogRepository.GetAsync(blogId);
await BlogPostRepository.UpdateBlogAsync(blog.Id, assignToBlogId);
}

[Authorize(CmsKitAdminPermissions.Blogs.Delete)]
public virtual Task DeleteAsync(Guid id)
{

return BlogRepository.DeleteAsync(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public CmsKitAdminApplicationAutoMapperProfile()
CreateMap<CreateBlogPostDto, BlogPost>(MemberList.Source).MapExtraProperties();
CreateMap<UpdateBlogPostDto, BlogPost>(MemberList.Source).MapExtraProperties();

CreateMap<Blog, BlogDto>().MapExtraProperties();
CreateMap<Blog, BlogDto>().Ignore(b => b.BlogPostCount).MapExtraProperties();

CreateMap<TagEntityTypeDefiniton, TagDefinitionDto>(MemberList.Destination);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ public virtual async Task DeleteAsync(Guid id)
{ typeof(Guid), id }
});
}

public virtual Task<ListResultDto<BlogDto>> GetAllListAsync()
{
return RequestAsync<ListResultDto<BlogDto>>(nameof(GetAllListAsync));
}

public virtual async Task MoveAllBlogPostsAsync(Guid blogId, Guid? assignToBlogId)
{
await RequestAsync(nameof(MoveAllBlogPostsAsync), new ClientProxyRequestTypeValue
{
{ typeof(Guid), blogId },
{ typeof(Guid?), assignToBlogId }
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ public Task DeleteAsync(Guid id)
{
return BlogAdminAppService.DeleteAsync(id);
}

[HttpGet]
[Route("all")]
public Task<ListResultDto<BlogDto>> GetAllListAsync()
{
throw new NotImplementedException();
realLiangshiwei marked this conversation as resolved.
Show resolved Hide resolved
}

[HttpPut]
[Route("{id}/move-all-blog-posts")]
[Authorize(CmsKitAdminPermissions.Blogs.Delete)]
public Task MoveAllBlogPostsAsync(Guid blogId, [FromQuery]Guid? assignToBlogId)
{
return BlogAdminAppService.MoveAllBlogPostsAsync(blogId, assignToBlogId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Blogs
@using Volo.CmsKit.Localization
@model DeleteBlogModal
@inject IHtmlLocalizer<CmsKitResource> L
@{
Layout = null;
}

<form method="post" asp-page="/CmsKit/Blogs/DeleteBlogModal" autocomplete="off">
@{
var deleteAllClicked = "checked";
var deleteButtonDisabled = "";
<abp-modal>
<abp-modal-header title="@L["AreYouSure"].Value"></abp-modal-header>
<abp-modal-body>

<abp-input asp-for="Blog.Id" type="hidden"></abp-input>

<p class="fw-bold">@L.GetString("BlogDeletionConfirmationMessage", Model.Blog.Name).Value</p>

@if (Model.Blog.BlogPostCount > 0)
{
<p class="mt-2">@L.GetString("ChooseAnActionForBlog", Model.Blog.BlogPostCount).Value</p>


if (Model.Blog.OtherBlogs.Any())
{
deleteAllClicked = "";
deleteButtonDisabled = "disabled";
<div class="form-check">
<input class="form-check-input" type="radio" checked name="assign" id="assign">
<label class="form-check-label" for="assign">@L["AssignBlogPostsToOtherBlog"].Value</label>
</div>
<select name="Blog.AssignToBlogId" id="Blog_AssignToBlogId" class="form-select mt-2">
<option value="" selected>@L["SelectAnBlogToAssign"].Value</option>
@foreach (var blog in Model.Blog.OtherBlogs)
{
<option value="@blog.Key">@blog.Value</option>
}
</select>
}

<div class="form-check mt-2">
<input class="form-check-input" type="radio" @deleteAllClicked name="assign" id="deleteAll">
<label class="form-check-label" for="deleteAll">@L["DeleteAllBlogPostsOfThisBlog"].Value</label>
</div>
}
</abp-modal-body>
<abp-modal-footer>
<button class="btn btn-outline-danger" data-bs-dismiss="modal" type="button">@L["Cancel"]</button>
<button class="btn btn-danger" @deleteButtonDisabled type="submit"><i class="fa fa-trash"></i> <span>@L["Delete"]</span></button>
</abp-modal-footer>
</abp-modal>
}

</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Abp.ObjectExtending;
using Volo.CmsKit.Admin.Blogs;

namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Blogs;

public class DeleteBlogModal : CmsKitAdminPageModel
{
[BindProperty]
public BlogInfoModel Blog { get; set; }

protected IBlogAdminAppService BlogAdminAppService { get; }

public DeleteBlogModal(IBlogAdminAppService blogAdminAppService)
{
BlogAdminAppService = blogAdminAppService;
}

public virtual async Task OnGetAsync(Guid id)
{
var blog = await BlogAdminAppService.GetAsync(id);
var allBlogs = await BlogAdminAppService.GetAllListAsync();

Blog = new BlogInfoModel
{
Id = blog.Id,
Name = blog.Name,
BlogPostCount = blog.BlogPostCount,
OtherBlogs = allBlogs.Items.Where(b => b.Id != blog.Id).Select(e => new KeyValuePair<Guid, string>(e.Id, e.Name)).ToList()
};
}

public virtual async Task<IActionResult> OnPostAsync()
{
await BlogAdminAppService.MoveAllBlogPostsAsync(Blog.Id, Blog.AssignToBlogId);
await BlogAdminAppService.DeleteAsync(Blog.Id);
return NoContent();
}

public class BlogInfoModel : ExtensibleObject
{
public Guid Id { get; set; }

public string Name { get; set; }

public int BlogPostCount { get; set; }

public List<KeyValuePair<Guid, string>> OtherBlogs { get; set; }

public Guid? AssignToBlogId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ $(function () {
var updateModal = new abp.ModalManager({ viewUrl: abp.appPath + "CmsKit/Blogs/UpdateModal", modalClass: 'updateBlog' });
var featuresModal = new abp.ModalManager(abp.appPath + "CmsKit/Blogs/FeaturesModal");


var deleteBlogModal = new abp.ModalManager(abp.appPath + 'CmsKit/Blogs/DeleteBlogModal');

deleteBlogModal.onResult(function(){
abp.notify.success(l('DeletedSuccessfully'));
});

deleteBlogModal.onOpen(function () {
var $form = deleteBlogModal.getForm();
$form.find('#assign').click(function () {
$form.find('#Blog_AssignToBlogId').show();
$form.find('[type=submit]').attr("disabled","disabled")
})
$form.find('#deleteAll').click(function () {
$form.find('#Blog_AssignToBlogId').hide();
$form.find('#Blog_AssignToBlogId').val("");
$form.find('[type=submit]').removeAttr("disabled");
})

$("#Blog_AssignToBlogId").on("change", function () {
var val = $(this).val();
if(val === ''){
$form.find('[type=submit]').attr("disabled","disabled")
}else{
$form.find('[type=submit]').removeAttr("disabled");
}
})
})

var blogsService = volo.cmsKit.admin.blogs.blogAdmin;

var dataTable = $("#BlogsTable").DataTable(abp.libs.datatables.normalizeConfiguration({
Expand Down Expand Up @@ -41,16 +70,10 @@ $(function () {
{
text: l('Delete'),
visible: abp.auth.isGranted('CmsKit.Blogs.Delete'),
confirmMessage: function (data) {
return l("BlogDeletionConfirmationMessage", data.record.name)
},
action: function (data) {
blogsService
.delete(data.record.id)
.then(function () {
dataTable.ajax.reloadEx();
abp.notify.success(l('DeletedSuccessfully'));
});
deleteBlogModal.open({
id: data.record.id
});
}
}
]
Expand All @@ -74,11 +97,16 @@ $(function () {
createModal.open();
});


createModal.onResult(function () {
dataTable.ajax.reloadEx();
});

updateModal.onResult(function () {
dataTable.ajax.reloadEx();
});

deleteBlogModal.onResult(function () {
dataTable.ajax.reloadEx();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@
"CssClass": "فئة CSS",
"TagsHelpText": "يجب أن تكون العلامات مفصولة بفواصل (على سبيل المثال: tag1، tag2، tag3)",
"ThisPartOfContentCouldntBeLoaded": "لا يمكن تحميل هذا الجزء من المحتوى.",
"DuplicateCommentAttemptMessage": "تم اكتشاف محاولة نشر تعليق مكررة. لقد تم بالفعل تقديم تعليقك."
"DuplicateCommentAttemptMessage": "تم اكتشاف محاولة نشر تعليق مكررة. لقد تم بالفعل تقديم تعليقك.",
"ChooseAnActionForBlog": "اختر إجراءً للمدونة",
"AssignBlogPostsToOtherBlog": "تعيين مشاركات المدونة إلى مدونة أخرى",
"SelectAnBlogToAssign": "حدد مدونة لتعيين مشاركات المدونة إليها",
"DeleteAllBlogPostsOfThisBlog": "حذف جميع مشاركات المدونة"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@
"CssClass": "Třída CSS",
"TagsHelpText": "Značky by měly být odděleny čárkami (např.: tag1, tag2, tag3)",
"ThisPartOfContentCouldntBeLoaded": "Tato část obsahu nemohla být načtena.",
"DuplicateCommentAttemptMessage": "Byl zjištěn duplicitní pokus o vložení komentáře. Váš komentář již byl odeslán."
"DuplicateCommentAttemptMessage": "Byl zjištěn duplicitní pokus o vložení komentáře. Váš komentář již byl odeslán.",
"ChooseAnActionForBlog": "Vyberte akci pro blog",
"AssignBlogPostsToOtherBlog": "Přiřaďte blogové příspěvky k jinému blogu",
"SelectAnBlogToAssign": "Vyberte blog, ke kterému chcete přiřadit blogové příspěvky",
"DeleteAllBlogPostsOfThisBlog": "Smazat všechny blogové příspěvky tohoto blogu"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@
"YourFullName": "Ihren vollständigen Namen",
"YourMessage": "Ihre Nachricht",
"YourReply": "Ihre Antwort",
"ThisPartOfContentCouldntBeLoaded": "Dieser Teil des Inhalts konnte nicht geladen werden."
"ThisPartOfContentCouldntBeLoaded": "Dieser Teil des Inhalts konnte nicht geladen werden.",
"ChooseAnActionForBlog": "Wählen Sie eine Aktion für den Blog",
"AssignBlogPostsToOtherBlog": "Blogbeiträge einem anderen Blog zuweisen",
"SelectAnBlogToAssign": "Wählen Sie einen Blog aus, um Blogbeiträge zuzuweisen",
"DeleteAllBlogPostsOfThisBlog": "Alle Blogbeiträge dieses Blogs löschen"
}
}
Loading
Loading