Browse Source

cmskit: reactions auth

pull/5016/head
Yunus Emre Kalkan 6 years ago
parent
commit
d63e614a8d
  1. 5
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Public.cshtml
  2. 10
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs
  3. 7
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js
  4. 28
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/Default.cshtml
  5. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js

5
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Public.cshtml

@ -3,6 +3,7 @@
@using Microsoft.Extensions.Localization
@using Volo.CmsKit.Pages
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.ReactionSelection
@model PublicModel
@inject IStringLocalizer<AbpUiResource> Localizer
<h1>CMS Kit DEMO - Public</h1>
@ -18,7 +19,9 @@
</footer>
</abp-blockquote>
</abp-card-body>
@await Component.InvokeAsync(typeof(CommentingViewComponent), new { entityType = "publicQuote", entityId = "1", loginUrl="Account/Login?ReturnUrl=%2Fpublic" })
@await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new { entityType = "publicQuote", entityId = "1" })
<hr />
@await Component.InvokeAsync(typeof(CommentingViewComponent), new { entityType = "publicQuote", entityId = "1", loginUrl = "Account/Login?ReturnUrl=%2Fpublic" })
</abp-card>
<abp-card class="mb-3">

10
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Users;
using Volo.CmsKit.Reactions;
@ -30,12 +31,13 @@ namespace Volo.CmsKit.Public.Reactions
{
var summaries = await ReactionManager.GetSummariesAsync(entityType, entityId);
var userReactions = (await UserReactionRepository
var userReactions = CurrentUser.IsAuthenticated ?
(await UserReactionRepository
.GetListForUserAsync(
CurrentUser.GetId(),
entityType,
entityId
)).ToDictionary(x => x.ReactionName, x => x);
)).ToDictionary(x => x.ReactionName, x => x) : null;
var reactionWithSelectionDtos = new List<ReactionWithSelectionDto>();
@ -46,7 +48,7 @@ namespace Volo.CmsKit.Public.Reactions
{
Reaction = ConvertToReactionDto(summary.Reaction),
Count = summary.Count,
IsSelectedByCurrentUser = userReactions.ContainsKey(summary.Reaction.Name)
IsSelectedByCurrentUser = userReactions?.ContainsKey(summary.Reaction.Name) ?? false
}
);
}
@ -54,6 +56,7 @@ namespace Volo.CmsKit.Public.Reactions
return new ListResultDto<ReactionWithSelectionDto>(reactionWithSelectionDtos);
}
[Authorize]
public virtual async Task CreateAsync(CreateReactionDto input)
{
await ReactionManager.CreateAsync(
@ -64,6 +67,7 @@ namespace Volo.CmsKit.Public.Reactions
);
}
[Authorize]
public virtual async Task DeleteAsync(DeleteReactionDto input)
{
await ReactionManager.DeleteAsync(

7
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js

@ -87,7 +87,7 @@
abp.message.confirm(l("MessageDeletionConfirmationMessage"), function (ok) {
if (ok){
volo.cmsKit.comments.commentPublic.delete($link.data('id')
volo.cmsKit.public.comments.commentPublic.delete($link.data('id')
).then(function () {
widgetManager.refresh($widget);
});
@ -103,7 +103,7 @@
$form.submit(function (e) {
e.preventDefault();
var formAsObject = $form.serializeFormToObject();
volo.cmsKit.comments.commentPublic.update(
volo.cmsKit.public.comments.commentPublic.update(
formAsObject.id,
{
text: formAsObject.commentText
@ -121,8 +121,7 @@
$form.submit(function (e) {
e.preventDefault();
var formAsObject = $form.serializeFormToObject();
console.log(formAsObject);
volo.cmsKit.comments.commentPublic.create(
volo.cmsKit.public.comments.commentPublic.create(
$.extend(getFilters(), {
repliedCommentId: formAsObject.repliedCommentId,
text: formAsObject.commentText

28
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/Default.cshtml

@ -1,17 +1,23 @@
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.ReactionSelection.ReactionSelectionViewComponent.ReactionSelectionViewModel
@inject ICurrentUser CurrentUser
@using Volo.Abp.Users
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.ReactionSelection.ReactionSelectionViewComponent.ReactionSelectionViewModel
<span class="cms-reaction-area" data-entity-type="@Model.EntityType" data-entity-id="@Model.EntityId">
<a class="cms-reaction-select-icon" tabindex="0"><i class="fa fa-smile-o"></i></a>
<div class="cms-reaction-selection-popover-content" style="display: none">
@foreach (var reaction in Model.Reactions)
{
<span class="mr-1 cms-reaction-icon @(reaction.IsSelectedByCurrentUser ? "cms-reaction-icon-selected" : "")" data-reaction-name="@reaction.Name">
<img src="@reaction.Icon" width="18" height="18"/>
</span>
}
</div>
@if (CurrentUser.IsAuthenticated)
{
<a class="cms-reaction-select-icon" tabindex="0"><i class="fa fa-smile-o"></i></a>
<div class="cms-reaction-selection-popover-content" style="display: none">
@foreach (var reaction in Model.Reactions)
{
<span class="mr-1 cms-reaction-icon @(reaction.IsSelectedByCurrentUser ? "cms-reaction-icon-selected" : "")" data-reaction-name="@reaction.Name">
<img src="@reaction.Icon" width="18" height="18"/>
</span>
}
</div>
}
@foreach (var reaction in Model.Reactions.Where(r => r.Count > 0))
{
<span class="mr-1 cms-reaction-icon @(reaction.IsSelectedByCurrentUser ? "cms-reaction-icon-selected" : "")" data-reaction-name="@reaction.Name">
<span class="mr-1 cms-reaction-icon @(reaction.IsSelectedByCurrentUser ? "cms-reaction-icon-selected" : "")" data-reaction-name="@reaction.Name" data-click-action="@(CurrentUser.IsAuthenticated ? "true" : "false")">
<img src="@reaction.Icon" width="18" height="18"/>
@(reaction.Count)
</span>

8
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js

@ -26,11 +26,15 @@
function registerClickOfReactionIcons($container) {
$container.find('.cms-reaction-icon').each(function () {
var $icon = $(this);
var reactionName = $icon.attr('data-reaction-name');
if ($icon.attr('data-click-action') === 'false'){
return;
}
$icon.click(function () {
var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create';
volo.cmsKit.reactions.reactionPublic[methodName](
volo.cmsKit.public.reactions.reactionPublic[methodName](
$.extend(getFilters(), {
reactionName: $icon.attr('data-reaction-name')
reactionName: reactionName
})
).then(function () {
$selectIcon.popover('hide');

Loading…
Cancel
Save