Begin to add vote_limit
This commit is contained in:
parent
1b2ca1a41e
commit
2c66d8dea0
|
@ -3,9 +3,10 @@ module DiscourseFeatureVoting
|
||||||
requires_plugin 'discourse-feature-voting'
|
requires_plugin 'discourse-feature-voting'
|
||||||
|
|
||||||
def add
|
def add
|
||||||
topic = Topic.find_by(id: params["topic_id"])
|
|
||||||
user = User.find_by(id: params["user_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.custom_fields["vote_count"] = topic.custom_fields["vote_count"].to_i + 1
|
||||||
topic.save
|
topic.save
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,11 @@
|
||||||
{{#if model.user_voted}}
|
{{#if model.user_voted}}
|
||||||
<a href {{action "unvote"}} class="vote-button unvote">{{i18n 'feature_voting.unvote_title'}}</a>
|
<a href {{action "unvote"}} class="vote-button unvote">{{i18n 'feature_voting.unvote_title'}}</a>
|
||||||
{{else}}
|
{{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}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -7,6 +7,7 @@ export default {
|
||||||
TopicRoute.reopen({
|
TopicRoute.reopen({
|
||||||
actions: {
|
actions: {
|
||||||
vote() {
|
vote() {
|
||||||
|
console.log(this.currentUser);
|
||||||
var topic = this.modelFor('topic');
|
var topic = this.modelFor('topic');
|
||||||
return Discourse.ajax("/voting/vote", {
|
return Discourse.ajax("/voting/vote", {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
@ -16,6 +17,10 @@ export default {
|
||||||
}
|
}
|
||||||
}).then(function(result) {
|
}).then(function(result) {
|
||||||
topic.reload();
|
topic.reload();
|
||||||
|
Discourse.User.findByUsername(Discourse.User.current().username).catch(function(result){
|
||||||
|
console.log(result);
|
||||||
|
Discourse.User.resetCurrent(result);
|
||||||
|
});
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@ en:
|
||||||
vote_title: "Vote"
|
vote_title: "Vote"
|
||||||
unvote_title: "Unvote"
|
unvote_title: "Unvote"
|
||||||
voting_closed_title: "Closed"
|
voting_closed_title: "Closed"
|
||||||
|
voting_limit: "Limit"
|
||||||
vote:
|
vote:
|
||||||
one: "vote"
|
one: "vote"
|
||||||
multiple: "votes"
|
multiple: "votes"
|
21
plugin.rb
21
plugin.rb
|
@ -43,7 +43,6 @@ after_initialize do
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_to_serializer(:topic_list_item, :vote_count) { object.vote_count }
|
add_to_serializer(:topic_list_item, :vote_count) { object.vote_count }
|
||||||
|
@ -77,11 +76,10 @@ after_initialize do
|
||||||
|
|
||||||
require_dependency 'user'
|
require_dependency 'user'
|
||||||
class ::User
|
class ::User
|
||||||
|
|
||||||
def vote_count
|
def vote_count
|
||||||
if self.custom_fields["votes"]
|
if self.custom_fields["votes"]
|
||||||
user_votes = self.custom_fields["votes"]
|
user_votes = self.custom_fields["votes"]
|
||||||
return user_votes.length
|
return user_votes.length - 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
@ -95,8 +93,25 @@ after_initialize do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def vote_limit
|
||||||
|
if self.vote_count >= SiteSetting.feature_voting_vote_limit
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require_dependency 'current_user_serializer'
|
||||||
|
class ::CurrentUserSerializer
|
||||||
|
attributes :vote_limit
|
||||||
|
|
||||||
|
def vote_limit
|
||||||
|
object.vote_limit
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
require_dependency 'topic'
|
require_dependency 'topic'
|
||||||
class ::Topic
|
class ::Topic
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue