Fix supervotes-left calculation
This commit is contained in:
parent
45357b179d
commit
6aa17eff0c
|
@ -16,6 +16,7 @@ module DiscourseFeatureVoting
|
|||
obj = {
|
||||
vote_limit: user.vote_limit,
|
||||
super_vote_limit: user.super_vote_limit,
|
||||
super_votes_remaining: user.super_votes_remaining,
|
||||
vote_count: topic.custom_fields["vote_count"].to_i,
|
||||
super_vote_count: topic.super_vote_count,
|
||||
who_voted: who_voted(topic),
|
||||
|
@ -41,6 +42,7 @@ module DiscourseFeatureVoting
|
|||
obj = {
|
||||
vote_limit: user.vote_limit,
|
||||
super_vote_limit: user.super_vote_limit,
|
||||
super_votes_remaining: user.super_votes_remaining,
|
||||
vote_count: topic.custom_fields["vote_count"].to_i,
|
||||
super_vote_count: topic.super_vote_count,
|
||||
who_voted: who_voted(topic),
|
||||
|
@ -60,6 +62,7 @@ module DiscourseFeatureVoting
|
|||
obj = {
|
||||
vote_limit: user.vote_limit,
|
||||
super_vote_limit: user.super_vote_limit,
|
||||
super_votes_remaining: user.super_votes_remaining,
|
||||
vote_count: topic.custom_fields["vote_count"].to_i,
|
||||
super_vote_count: topic.super_vote_count,
|
||||
who_voted: who_voted(topic),
|
||||
|
@ -79,6 +82,7 @@ module DiscourseFeatureVoting
|
|||
obj = {
|
||||
vote_limit: user.vote_limit,
|
||||
super_vote_limit: user.super_vote_limit,
|
||||
super_votes_remaining: user.super_votes_remaining,
|
||||
vote_count: topic.custom_fields["vote_count"].to_i,
|
||||
super_vote_count: topic.super_vote_count,
|
||||
who_voted: who_voted(topic),
|
||||
|
@ -104,4 +108,4 @@ module DiscourseFeatureVoting
|
|||
return users
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ export default createWidget('add-super-vote', {
|
|||
|
||||
html(attrs, state){
|
||||
var user = this.currentUser;
|
||||
var superVotesRemaining = user.super_vote_count - user.super_vote_limit;
|
||||
var superVotesRemaining = user.super_votes_remaining;
|
||||
if (superVotesRemaining == 1){
|
||||
var superVoteDescription = I18n.t("feature_voting.super_votes_remaining.singular");
|
||||
}
|
||||
|
@ -23,4 +23,4 @@ export default createWidget('add-super-vote', {
|
|||
click(){
|
||||
this.sendWidgetAction('upgradeVote');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ export default createWidget('remove-super-vote', {
|
|||
|
||||
html(attrs, state){
|
||||
var user = this.currentUser;
|
||||
var superVotesRemaining = user.super_vote_count - user.super_vote_limit;
|
||||
var superVotesRemaining = user.super_votes_remaining;
|
||||
if (superVotesRemaining == 1){
|
||||
var superVoteDescription = I18n.t("feature_voting.super_votes_remaining.singular");
|
||||
}
|
||||
|
@ -23,4 +23,4 @@ export default createWidget('remove-super-vote', {
|
|||
click(){
|
||||
this.sendWidgetAction('downgradeVote');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ export default createWidget('upgrade-vote', {
|
|||
|
||||
html(attrs, state){
|
||||
var user = this.currentUser;
|
||||
var superVotesRemaining = user.super_vote_count - user.super_vote_limit;
|
||||
var superVotesRemaining = user.super_votes_remaining;
|
||||
if (superVotesRemaining == 1){
|
||||
var superVoteDescription = I18n.t("feature_voting.super_votes_remaining.singular");
|
||||
}
|
||||
|
@ -25,4 +25,4 @@ export default createWidget('upgrade-vote', {
|
|||
click(){
|
||||
this.sendWidgetAction('upgradeVote');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -34,6 +34,7 @@ export default createWidget('vote-box', {
|
|||
topic.set('has_votes', true);
|
||||
topic.set('user_voted', true);
|
||||
Discourse.User.current().set('vote_limit', result.vote_limit);
|
||||
Discourse.User.current().set('super_votes_remaining', result.super_votes_remaining);
|
||||
topic.set('who_voted', result.who_voted);
|
||||
state.allowClick = true;
|
||||
}).catch(function(error) {
|
||||
|
@ -63,6 +64,7 @@ export default createWidget('vote-box', {
|
|||
topic.set('user_super_voted', false);
|
||||
Discourse.User.current().set('vote_limit', result.vote_limit);
|
||||
Discourse.User.current().set('super_vote_limit', result.super_vote_limit);
|
||||
Discourse.User.current().set('super_votes_remaining', result.super_votes_remaining);
|
||||
topic.set('who_voted', result.who_voted);
|
||||
topic.set('who_super_voted', result.who_super_voted);
|
||||
state.allowClick = true;
|
||||
|
@ -86,6 +88,7 @@ export default createWidget('vote-box', {
|
|||
topic.set('has_super_votes', true);
|
||||
topic.set('user_super_voted', true);
|
||||
Discourse.User.current().set('super_vote_limit', result.super_vote_limit);
|
||||
Discourse.User.current().set('super_votes_remaining', result.super_votes_remaining);
|
||||
topic.set('who_super_voted', result.who_super_voted);
|
||||
state.allowClick = true;
|
||||
}).catch(function(error) {
|
||||
|
@ -110,10 +113,11 @@ export default createWidget('vote-box', {
|
|||
}
|
||||
topic.set('user_super_voted', false);
|
||||
Discourse.User.current().set('super_vote_limit', result.super_vote_limit);
|
||||
Discourse.User.current().set('super_votes_remaining', result.super_votes_remaining);
|
||||
topic.set('who_super_voted', result.who_super_voted);
|
||||
state.allowClick = true;
|
||||
}).catch(function(error) {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
10
plugin.rb
10
plugin.rb
|
@ -172,6 +172,10 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
def super_votes_remaining
|
||||
[0, SiteSetting.send("feature_voting_tl#{self.trust_level}_super_vote_limit") - self.super_vote_count].max
|
||||
end
|
||||
|
||||
def vote_limit
|
||||
self.vote_count >= SiteSetting.send("feature_voting_tl#{self.trust_level}_vote_limit")
|
||||
end
|
||||
|
@ -183,7 +187,7 @@ after_initialize do
|
|||
|
||||
require_dependency 'current_user_serializer'
|
||||
class ::CurrentUserSerializer
|
||||
attributes :vote_limit, :super_vote_limit, :vote_count, :super_vote_count
|
||||
attributes :vote_limit, :super_vote_limit, :vote_count, :super_vote_count, :super_votes_remaining
|
||||
|
||||
def vote_limit
|
||||
object.vote_limit
|
||||
|
@ -193,6 +197,10 @@ after_initialize do
|
|||
object.super_vote_limit
|
||||
end
|
||||
|
||||
def super_votes_remaining
|
||||
object.super_votes_remaining
|
||||
end
|
||||
|
||||
def vote_count
|
||||
object.vote_count
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue