mirror of https://github.com/abpframework/abp.git
10 changed files with 196 additions and 0 deletions
@ -0,0 +1,16 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace Volo.CmsKit.Tags |
||||
|
{ |
||||
|
public class GetRelatedTagsInput |
||||
|
{ |
||||
|
[Required] |
||||
|
public string EntityType { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
public string EntityId { get; set; } |
||||
|
|
||||
|
public List<string> Tags { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace Volo.CmsKit.Tags |
||||
|
{ |
||||
|
public interface ITagAppService : IApplicationService |
||||
|
{ |
||||
|
Task<List<TagDto>> GetAllRelatedTagsAsync(GetRelatedTagsInput input); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace Volo.CmsKit.Tags |
||||
|
{ |
||||
|
public class TagDto : EntityDto<Guid> |
||||
|
{ |
||||
|
public string EntityType { get; set; } |
||||
|
|
||||
|
public string Name { get; protected set; } |
||||
|
|
||||
|
public string HexColor { get; protected set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.CmsKit.Tags |
||||
|
{ |
||||
|
public class TagAppService : CmsKitAppServiceBase, ITagAppService |
||||
|
{ |
||||
|
protected readonly ITagManager TagManager; |
||||
|
protected readonly ITagRepository TagRepository; |
||||
|
protected readonly IEntityTagRepository EntityTagRepository; |
||||
|
|
||||
|
public TagAppService( |
||||
|
ITagManager tagManager, |
||||
|
ITagRepository tagRepository, IEntityTagRepository entityTagRepository) |
||||
|
{ |
||||
|
TagManager = tagManager; |
||||
|
TagRepository = tagRepository; |
||||
|
EntityTagRepository = entityTagRepository; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<TagDto>> GetAllRelatedTagsAsync(GetRelatedTagsInput input) |
||||
|
{ |
||||
|
var entities = await TagRepository.GetAllRelatedTagsAsync( |
||||
|
input.EntityType, |
||||
|
input.EntityId, |
||||
|
CurrentTenant.Id); |
||||
|
|
||||
|
if (input.Tags?.Count > 0) |
||||
|
{ |
||||
|
var nonExisting = input.Tags |
||||
|
.Where(x => |
||||
|
!entities.Any(a => |
||||
|
a.Name.Equals(x.Trim(), |
||||
|
StringComparison.InvariantCultureIgnoreCase))); |
||||
|
|
||||
|
foreach (var tag in nonExisting) |
||||
|
{ |
||||
|
var insertedTag = await TagManager.GetOrAddAsync( |
||||
|
input.EntityType, |
||||
|
tag, |
||||
|
tenantId: CurrentTenant?.Id); |
||||
|
|
||||
|
await EntityTagRepository.InsertAsync( |
||||
|
new EntityTag( |
||||
|
insertedTag.Id, |
||||
|
input.EntityId, |
||||
|
CurrentTenant?.Id)); |
||||
|
|
||||
|
entities.Add(insertedTag); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return ObjectMapper.Map<List<Tag>, List<TagDto>>(entities); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.CmsKit.Controllers; |
||||
|
using Volo.CmsKit.Tags; |
||||
|
|
||||
|
namespace Volo.CmsKit.Common.HttpApi.Volo.CmsKit.Controllers.Tags |
||||
|
{ |
||||
|
public class TagController : CmsKitControllerBase, ITagAppService |
||||
|
{ |
||||
|
protected readonly ITagAppService TagAppService; |
||||
|
|
||||
|
public TagController(ITagAppService tagAppService) |
||||
|
{ |
||||
|
TagAppService = tagAppService; |
||||
|
} |
||||
|
|
||||
|
public Task<List<TagDto>> GetAllRelatedTagsAsync(GetRelatedTagsInput input) |
||||
|
{ |
||||
|
return TagAppService.GetAllRelatedTagsAsync(input); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
@using Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.Tags |
||||
|
|
||||
|
@model TagViewComponent.TagViewModel |
||||
|
|
||||
|
@if (Model.Tags != null) |
||||
|
{ |
||||
|
foreach (var tag in Model.Tags) |
||||
|
{ |
||||
|
<span class="cmskit-tag" data-color="#@tag.HexColor"> |
||||
|
@tag.Name |
||||
|
</span> |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.CmsKit.Tags; |
||||
|
|
||||
|
namespace Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.Tags |
||||
|
{ |
||||
|
[ViewComponent(Name = "CmsTags")] |
||||
|
public class TagViewComponent : AbpViewComponent |
||||
|
{ |
||||
|
protected readonly ITagAppService TagAppService; |
||||
|
|
||||
|
public TagViewComponent(ITagAppService tagAppService) |
||||
|
{ |
||||
|
TagAppService = tagAppService; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<IViewComponentResult> InvokeAsync( |
||||
|
string entityType, |
||||
|
string entityId, |
||||
|
IEnumerable<string> tags = null) |
||||
|
{ |
||||
|
var tagDtos = await TagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput |
||||
|
{ |
||||
|
EntityId = entityId, |
||||
|
EntityType = entityType, |
||||
|
Tags = tags?.ToList() |
||||
|
}); |
||||
|
|
||||
|
var viewModel = new TagViewModel |
||||
|
{ |
||||
|
EntityId = entityId, |
||||
|
EntityType = entityType, |
||||
|
Tags = tagDtos |
||||
|
}; |
||||
|
|
||||
|
return View("~/Pages/CmsKit/Shared/Components/Tags/Default.cshtml", viewModel); |
||||
|
} |
||||
|
|
||||
|
public class TagViewModel |
||||
|
{ |
||||
|
public List<TagDto> Tags { get; set; } |
||||
|
public string EntityId { get; set; } |
||||
|
public string EntityType { get; set; } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,4 @@ |
|||||
|
.cmskit-tag { |
||||
|
border-radius: 2px; |
||||
|
border: 1px solid; |
||||
|
} |
||||
Loading…
Reference in new issue