mirror of https://github.com/abpframework/abp.git
22 changed files with 319 additions and 59 deletions
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.CmsKit.Reactions |
||||
|
{ |
||||
|
public class ReactionSummary |
||||
|
{ |
||||
|
public ReactionDefinition Reaction { get; set; } |
||||
|
|
||||
|
public int Count { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.CmsKit.Reactions |
||||
|
{ |
||||
|
public class ReactionSummaryQueryResultItem |
||||
|
{ |
||||
|
public string ReactionName { get; set; } |
||||
|
|
||||
|
public int Count { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.CmsKit.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.CmsKit.Reactions |
||||
|
{ |
||||
|
public class EfCoreUserReactionRepository : EfCoreRepository<ICmsKitDbContext, UserReaction, Guid>, IUserReactionRepository |
||||
|
{ |
||||
|
public EfCoreUserReactionRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public Task<UserReaction> FindAsync(Guid userId, string entityType, string entityId, string reactionName) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public Task<List<UserReaction>> GetListForUserAsync(Guid userId, string entityType, string entityId) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public Task<List<ReactionSummaryQueryResultItem>> GetSummariesAsync(string inputEntityType, string inputEntityId) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.CmsKit.Reactions |
||||
|
{ |
||||
|
public class GetForSelectionInput |
||||
|
{ |
||||
|
public string EntityType { get; set; } |
||||
|
|
||||
|
public string EntityId { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.CmsKit.Reactions |
||||
|
{ |
||||
|
public class GetMyReactionsDto |
||||
|
{ |
||||
|
public string EntityType { get; set; } |
||||
|
|
||||
|
public string EntityId { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.CmsKit.Reactions |
||||
|
{ |
||||
|
public class GetReactionSummariesDto |
||||
|
{ |
||||
|
public string EntityType { get; set; } |
||||
|
|
||||
|
public string EntityId { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.CmsKit.Reactions |
||||
|
{ |
||||
|
public class ReactionSummaryDto |
||||
|
{ |
||||
|
public ReactionDto Reaction { get; set; } |
||||
|
|
||||
|
public int Count { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
namespace Volo.CmsKit.Reactions |
||||
|
{ |
||||
|
public class ReactionWithSelectionDto |
||||
|
{ |
||||
|
public ReactionDto Reaction { get; set; } |
||||
|
|
||||
|
public int Count { get; set; } |
||||
|
|
||||
|
public bool IsSelectedByCurrentUser { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -1,31 +1,108 @@ |
|||||
using System.Linq; |
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
namespace Volo.CmsKit.Reactions |
namespace Volo.CmsKit.Reactions |
||||
{ |
{ |
||||
|
//TODO: Authorization
|
||||
public class ReactionPublicAppService : CmsKitPublicAppService, IReactionPublicAppService |
public class ReactionPublicAppService : CmsKitPublicAppService, IReactionPublicAppService |
||||
{ |
{ |
||||
protected IReactionDefinitionStore ReactionDefinitionStore { get; } |
protected IReactionDefinitionStore ReactionDefinitionStore { get; } |
||||
|
|
||||
public ReactionPublicAppService(IReactionDefinitionStore reactionDefinitionStore) |
protected IUserReactionRepository UserReactionRepository { get; } |
||||
|
|
||||
|
protected ReactionManager ReactionManager { get; } |
||||
|
|
||||
|
public ReactionPublicAppService( |
||||
|
IReactionDefinitionStore reactionDefinitionStore, |
||||
|
IUserReactionRepository userReactionRepository, |
||||
|
ReactionManager reactionManager) |
||||
{ |
{ |
||||
ReactionDefinitionStore = reactionDefinitionStore; |
ReactionDefinitionStore = reactionDefinitionStore; |
||||
|
UserReactionRepository = userReactionRepository; |
||||
|
ReactionManager = reactionManager; |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ListResultDto<ReactionDto>> GetAvailableReactions( |
public virtual async Task<ListResultDto<ReactionDto>> GetAvailableReactions( |
||||
GetAvailableReactionsDto input) |
GetAvailableReactionsDto input) |
||||
{ |
{ |
||||
var reactionDefinitions = await ReactionDefinitionStore.GetAvailableReactionsAsync(input.EntityType, CurrentUser.Id); |
var reactionDefinitions = await ReactionManager |
||||
|
.GetAvailableReactionsAsync( |
||||
|
input.EntityType |
||||
|
); |
||||
|
|
||||
var reactionDtos = reactionDefinitions |
var reactionDtos = reactionDefinitions |
||||
.Select(reactionDefinition => new ReactionDto |
.Select(ConvertToReactionDto) |
||||
|
.ToList(); |
||||
|
|
||||
|
return new ListResultDto<ReactionDto>(reactionDtos); |
||||
|
} |
||||
|
|
||||
|
public async Task<ListResultDto<ReactionSummaryDto>> GetReactionSummariesAsync(GetReactionSummariesDto input) |
||||
|
{ |
||||
|
var summaries = await ReactionManager.GetSummariesAsync(input.EntityType, input.EntityId); |
||||
|
|
||||
|
var summaryDtos = summaries |
||||
|
.Select(summary => new ReactionSummaryDto |
||||
{ |
{ |
||||
Name = reactionDefinition.Name, |
Count = summary.Count, |
||||
DisplayName = reactionDefinition.DisplayName?.Localize(StringLocalizerFactory) |
Reaction = ConvertToReactionDto(summary.Reaction) |
||||
}).ToList(); |
}) |
||||
|
.ToList(); |
||||
|
|
||||
|
return new ListResultDto<ReactionSummaryDto>(summaryDtos); |
||||
|
} |
||||
|
|
||||
|
public async Task<ListResultDto<ReactionDto>> GetMyReactions(GetMyReactionsDto input) |
||||
|
{ |
||||
|
var userReactions = await ReactionManager.GetUserReactionsAsync( |
||||
|
CurrentUser.GetId(), |
||||
|
input.EntityType, |
||||
|
input.EntityId |
||||
|
); |
||||
|
|
||||
|
var reactionDtos = userReactions |
||||
|
.Select(ConvertToReactionDto) |
||||
|
.ToList(); |
||||
|
|
||||
return new ListResultDto<ReactionDto>(reactionDtos); |
return new ListResultDto<ReactionDto>(reactionDtos); |
||||
} |
} |
||||
|
|
||||
|
public async Task<ListResultDto<ReactionWithSelectionDto>> GetForSelectionAsync(GetForSelectionInput input) |
||||
|
{ |
||||
|
var reactionDefinitions = await ReactionManager |
||||
|
.GetAvailableReactionsAsync( |
||||
|
input.EntityType |
||||
|
); |
||||
|
|
||||
|
//var summaries = await ReactionManager.GetSummariesAsync(input.EntityType, input.EntityId);
|
||||
|
|
||||
|
var reactionDtos = new List<ReactionWithSelectionDto>(); |
||||
|
|
||||
|
foreach (var reactionDefinition in reactionDefinitions) |
||||
|
{ |
||||
|
reactionDtos.Add( |
||||
|
new ReactionWithSelectionDto |
||||
|
{ |
||||
|
Reaction = ConvertToReactionDto(reactionDefinition), |
||||
|
Count = 0, |
||||
|
IsSelectedByCurrentUser = false |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
return new ListResultDto<ReactionWithSelectionDto>(reactionDtos); |
||||
|
} |
||||
|
|
||||
|
private ReactionDto ConvertToReactionDto(ReactionDefinition reactionDefinition) |
||||
|
{ |
||||
|
return new ReactionDto |
||||
|
{ |
||||
|
Name = reactionDefinition.Name, |
||||
|
DisplayName = reactionDefinition.DisplayName?.Localize(StringLocalizerFactory) |
||||
|
}; |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,12 +1,16 @@ |
|||||
@model Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.ReactionSelection.ReactionSelectionViewModel |
@model Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.ReactionSelection.ReactionSelectionViewModel |
||||
<span class="cms-reaction-selection"> |
<span class="cms-reaction-selection"> |
||||
<a class="cms-reaction-selection-button"> |
<div class="cms-reaction-selection-available-reactions"> |
||||
<i class="far fa-smile"></i> |
Pick a reaction: |
||||
</a> |
|
||||
<div class="cms-reaction-selection-area" style="display: none"> |
|
||||
@foreach (var reaction in Model.Reactions) |
@foreach (var reaction in Model.Reactions) |
||||
{ |
{ |
||||
<cms-icon name="@reaction.Icon"/> |
<cms-icon name="@reaction.Icon" highlight="@reaction.IsSelectedByCurrentUser"/> |
||||
|
} |
||||
|
</div> |
||||
|
<div class="cms-reaction-selection-reactions"> |
||||
|
@foreach (var reaction in Model.Reactions.Where(r => r.Count > 0)) |
||||
|
{ |
||||
|
<cms-icon name="@reaction.Icon" highlight="@reaction.IsSelectedByCurrentUser"/><span> - @reaction.Count |</span> |
||||
} |
} |
||||
</div> |
</div> |
||||
</span> |
</span> |
||||
|
|||||
@ -1,16 +1,13 @@ |
|||||
(function () { |
(function () { |
||||
$(document).ready(function () { |
$(document).ready(function () { |
||||
|
|
||||
$('.cms-reaction-selection').each(function () { |
function initReactionSelection(){ |
||||
var $this = $(this); |
var $this = $(this); |
||||
var $selectionButton = $this.find('.cms-reaction-selection-button'); |
var $availableReactions = $this.find('.cms-reaction-selection-available-reactions'); |
||||
var $selectionArea = $this.find('.cms-reaction-selection-area'); |
|
||||
|
} |
||||
|
|
||||
|
$('.cms-reaction-selection').each(initReactionSelection) |
||||
|
|
||||
$selectionButton.popover({ |
|
||||
html: true, |
|
||||
placement: 'right', |
|
||||
content: $selectionArea.html() |
|
||||
}); |
|
||||
}) |
|
||||
}); |
}); |
||||
})(); |
})(); |
||||
|
|||||
Loading…
Reference in new issue