Check category for custom fields
This commit is contained in:
parent
da948d9855
commit
3543ec9330
|
@ -2,7 +2,11 @@
|
||||||
<div class="voting title-voting">
|
<div class="voting title-voting">
|
||||||
<div class="voting-wrapper">
|
<div class="voting-wrapper">
|
||||||
{{#if siteSettings.feature_voting_show_who_voted}}
|
{{#if siteSettings.feature_voting_show_who_voted}}
|
||||||
<a href {{action "showWhoVoted"}} class="vote-count">{{model.vote_count}}</a>
|
{{#if model.has_votes}}
|
||||||
|
<a href {{action "showWhoVoted"}} class="vote-count">{{model.vote_count}}</a>
|
||||||
|
{{else}}
|
||||||
|
<div class="vote-count">{{model.vote_count}}</div>
|
||||||
|
{{/if}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="vote-count">{{model.vote_count}}</div>
|
<div class="vote-count">{{model.vote_count}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -70,7 +70,12 @@ function startVoting(api){
|
||||||
getWhoVoted() {
|
getWhoVoted() {
|
||||||
const { attrs, state } = this;
|
const { attrs, state } = this;
|
||||||
var users = attrs.who_voted;
|
var users = attrs.who_voted;
|
||||||
return state.whoVotedUsers = users.map(whoVotedAvatars);
|
if (users.length){
|
||||||
|
return state.whoVotedUsers = users.map(whoVotedAvatars);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return state.whoVotedUsers = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
12
plugin.rb
12
plugin.rb
|
@ -16,10 +16,10 @@ after_initialize do
|
||||||
|
|
||||||
require_dependency 'topic_view_serializer'
|
require_dependency 'topic_view_serializer'
|
||||||
class ::TopicViewSerializer
|
class ::TopicViewSerializer
|
||||||
attributes :can_vote, :single_vote, :vote_count, :user_voted, :who_voted
|
attributes :can_vote, :single_vote, :vote_count, :has_votes, :user_voted, :who_voted
|
||||||
|
|
||||||
def can_vote
|
def can_vote
|
||||||
return object.topic.category.custom_fields["enable_topic_voting"]
|
return object.topic.category.respond_to?(:custom_fields) ? !!object.topic.category.custom_fields["enable_topic_voting"] : false
|
||||||
end
|
end
|
||||||
|
|
||||||
def single_vote
|
def single_vote
|
||||||
|
@ -34,6 +34,14 @@ after_initialize do
|
||||||
object.topic.vote_count
|
object.topic.vote_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_votes
|
||||||
|
if object.topic.vote_count.to_i > 0
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def user_voted
|
def user_voted
|
||||||
user = scope.user
|
user = scope.user
|
||||||
if user && user.custom_fields["votes"]
|
if user && user.custom_fields["votes"]
|
||||||
|
|
Loading…
Reference in New Issue