Begin to add vote_limit

This commit is contained in:
Joe Buhlig 2016-02-19 15:17:15 -06:00
parent 1b2ca1a41e
commit 2c66d8dea0
5 changed files with 32 additions and 6 deletions

View File

@ -3,9 +3,10 @@ module DiscourseFeatureVoting
requires_plugin 'discourse-feature-voting'
def add
topic = Topic.find_by(id: params["topic_id"])
user = User.find_by(id: params["user_id"])
topic = Topic.find_by(id: params["topic_id"])
topic.custom_fields["vote_count"] = topic.custom_fields["vote_count"].to_i + 1
topic.save

View File

@ -17,7 +17,11 @@
{{#if model.user_voted}}
<a href {{action "unvote"}} class="vote-button unvote">{{i18n 'feature_voting.unvote_title'}}</a>
{{else}}
<a href {{action "vote"}} class="vote-button vote">{{i18n 'feature_voting.vote_title'}}</a>
{{#if currentUser.vote_limit}}
<div class="vote-button vote-limited unvote">{{i18n 'feature_voting.voting_limit'}}</div>
{{else}}
<a href {{action "vote"}} class="vote-button vote">{{i18n 'feature_voting.vote_title'}}</a>
{{/if}}
{{/if}}
{{/if}}
{{/if}}

View File

@ -7,6 +7,7 @@ export default {
TopicRoute.reopen({
actions: {
vote() {
console.log(this.currentUser);
var topic = this.modelFor('topic');
return Discourse.ajax("/voting/vote", {
type: 'POST',
@ -16,6 +17,10 @@ export default {
}
}).then(function(result) {
topic.reload();
Discourse.User.findByUsername(Discourse.User.current().username).catch(function(result){
console.log(result);
Discourse.User.resetCurrent(result);
});
}).catch(function(error) {
console.log(error);
});

View File

@ -5,6 +5,7 @@ en:
vote_title: "Vote"
unvote_title: "Unvote"
voting_closed_title: "Closed"
voting_limit: "Limit"
vote:
one: "vote"
multiple: "votes"

View File

@ -43,7 +43,6 @@ after_initialize do
return false
end
end
end
add_to_serializer(:topic_list_item, :vote_count) { object.vote_count }
@ -77,11 +76,10 @@ after_initialize do
require_dependency 'user'
class ::User
def vote_count
if self.custom_fields["votes"]
user_votes = self.custom_fields["votes"]
return user_votes.length
return user_votes.length - 1
else
return 0
end
@ -95,8 +93,25 @@ after_initialize do
end
end
def vote_limit
if self.vote_count >= SiteSetting.feature_voting_vote_limit
return true
else
return false
end
end
end
require_dependency 'current_user_serializer'
class ::CurrentUserSerializer
attributes :vote_limit
def vote_limit
object.vote_limit
end
end
require_dependency 'topic'
class ::Topic