Merge pull request #5 from joebuhlig/user-activity-votes
User activity votes
This commit is contained in:
commit
8332f28e7a
|
@ -0,0 +1,9 @@
|
||||||
|
export default {
|
||||||
|
resource: 'user',
|
||||||
|
path: 'users/:username',
|
||||||
|
map() {
|
||||||
|
this.resource('userActivity', {path: 'activity'}, function(){
|
||||||
|
this.route('votes')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,10 @@
|
||||||
|
import UserTopicListRoute from "discourse/routes/user-topic-list";
|
||||||
|
import UserAction from "discourse/models/user-action";
|
||||||
|
|
||||||
|
export default UserTopicListRoute.extend({
|
||||||
|
userActionType: UserAction.TYPES.topics,
|
||||||
|
|
||||||
|
model: function() {
|
||||||
|
return this.store.findFiltered('topicList', {filter: 'topics/voted-by/' + this.modelFor('user').get('username_lower') });
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,5 @@
|
||||||
|
<li>
|
||||||
|
{{#link-to 'userActivity.votes'}}
|
||||||
|
<i class="glyph fa fa-heart"></i>{{i18n 'feature_voting.vote_title_plural'}}
|
||||||
|
{{/link-to}}
|
||||||
|
</li>
|
|
@ -1,45 +1,49 @@
|
||||||
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
import TopicRoute from 'discourse/routes/topic';
|
import TopicRoute from 'discourse/routes/topic';
|
||||||
|
|
||||||
|
function startVoting(api){
|
||||||
|
TopicRoute.reopen({
|
||||||
|
actions: {
|
||||||
|
vote() {
|
||||||
|
var topic = this.modelFor('topic');
|
||||||
|
return Discourse.ajax("/voting/vote", {
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
topic_id: topic.id,
|
||||||
|
user_id: Discourse.User.current().id
|
||||||
|
}
|
||||||
|
}).then(function(result) {
|
||||||
|
topic.set('vote_count', result.vote_count);
|
||||||
|
topic.set('user_voted', true);
|
||||||
|
Discourse.User.current().set('vote_limit', result.vote_limit);
|
||||||
|
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
unvote() {
|
||||||
|
var topic = this.modelFor('topic');
|
||||||
|
return Discourse.ajax("/voting/unvote", {
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
topic_id: topic.id,
|
||||||
|
user_id: Discourse.User.current().id
|
||||||
|
}
|
||||||
|
}).then(function(result) {
|
||||||
|
topic.set('vote_count', result.vote_count);
|
||||||
|
topic.set('user_voted', false);
|
||||||
|
Discourse.User.current().set('vote_limit', result.vote_limit);
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'feature-voting',
|
name: 'feature-voting',
|
||||||
initialize(){
|
initialize: function() {
|
||||||
|
withPluginApi('0.1', api => startVoting(api));
|
||||||
TopicRoute.reopen({
|
|
||||||
actions: {
|
|
||||||
vote() {
|
|
||||||
var topic = this.modelFor('topic');
|
|
||||||
return Discourse.ajax("/voting/vote", {
|
|
||||||
type: 'POST',
|
|
||||||
data: {
|
|
||||||
topic_id: topic.id,
|
|
||||||
user_id: Discourse.User.current().id
|
|
||||||
}
|
|
||||||
}).then(function(result) {
|
|
||||||
topic.set('vote_count', result.vote_count);
|
|
||||||
topic.set('user_voted', true);
|
|
||||||
Discourse.User.current().set('vote_limit', result.vote_limit);
|
|
||||||
|
|
||||||
}).catch(function(error) {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
unvote() {
|
|
||||||
var topic = this.modelFor('topic');
|
|
||||||
return Discourse.ajax("/voting/unvote", {
|
|
||||||
type: 'POST',
|
|
||||||
data: {
|
|
||||||
topic_id: topic.id,
|
|
||||||
user_id: Discourse.User.current().id
|
|
||||||
}
|
|
||||||
}).then(function(result) {
|
|
||||||
topic.set('vote_count', result.vote_count);
|
|
||||||
topic.set('user_voted', false);
|
|
||||||
Discourse.User.current().set('vote_limit', result.vote_limit);
|
|
||||||
}).catch(function(error) {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -36,4 +36,16 @@
|
||||||
}
|
}
|
||||||
.list-vote-count{
|
.list-vote-count{
|
||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
|
}
|
||||||
|
.user-voted-topics{
|
||||||
|
height: 34px;
|
||||||
|
line-height: 34px;
|
||||||
|
|
||||||
|
a {
|
||||||
|
padding: 8px 13px;
|
||||||
|
color: #7a7a7a;
|
||||||
|
font-size: 1.143em;
|
||||||
|
line-height: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ en:
|
||||||
feature_voting:
|
feature_voting:
|
||||||
allow_topic_voting: "Allow users to vote on topics in this category"
|
allow_topic_voting: "Allow users to vote on topics in this category"
|
||||||
vote_title: "Vote"
|
vote_title: "Vote"
|
||||||
|
vote_title_plural: "Votes"
|
||||||
unvote_title: "Unvote"
|
unvote_title: "Unvote"
|
||||||
voting_closed_title: "Closed"
|
voting_closed_title: "Closed"
|
||||||
voting_limit: "Limit"
|
voting_limit: "Limit"
|
||||||
|
|
|
@ -3,6 +3,7 @@ es:
|
||||||
feature_voting:
|
feature_voting:
|
||||||
allow_topic_voting: "Permitir a los usuarios votar los temas de esta categoría"
|
allow_topic_voting: "Permitir a los usuarios votar los temas de esta categoría"
|
||||||
vote_title: "Votar"
|
vote_title: "Votar"
|
||||||
|
vote_title_plural: "Votos"
|
||||||
unvote_title: "Quitar"
|
unvote_title: "Quitar"
|
||||||
voting_closed_title: "Cerrado"
|
voting_closed_title: "Cerrado"
|
||||||
voting_limit: "Limitado"
|
voting_limit: "Limitado"
|
||||||
|
|
20
plugin.rb
20
plugin.rb
|
@ -144,9 +144,27 @@ after_initialize do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require_dependency 'list_controller'
|
||||||
|
class ::ListController
|
||||||
|
def voted_by
|
||||||
|
list_opts = build_topic_list_options
|
||||||
|
target_user = fetch_user_from_params(include_inactive: current_user.try(:staff?))
|
||||||
|
list = generate_list_for("voted_by", target_user, list_opts)
|
||||||
|
list.more_topics_url = url_for(construct_url_with(:next, list_opts))
|
||||||
|
list.prev_topics_url = url_for(construct_url_with(:prev, list_opts))
|
||||||
|
respond_with_list(list)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
require_dependency 'topic_query'
|
require_dependency 'topic_query'
|
||||||
class ::TopicQuery
|
class ::TopicQuery
|
||||||
SORTABLE_MAPPING["votes"] = "custom_fields.vote_count"
|
SORTABLE_MAPPING["votes"] = "custom_fields.vote_count"
|
||||||
|
|
||||||
|
def list_voted_by(user)
|
||||||
|
create_list(:user_topics) do |topics|
|
||||||
|
topics.where(id: user.custom_fields["votes"])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency "jobs/base"
|
require_dependency "jobs/base"
|
||||||
|
@ -169,6 +187,7 @@ after_initialize do
|
||||||
def execute(args)
|
def execute(args)
|
||||||
if topic = Topic.find_by(id: args[:topic_id])
|
if topic = Topic.find_by(id: args[:topic_id])
|
||||||
UserCustomField.where(name: "votes_archive", value: args[:topic_id]).find_each do |user_field|
|
UserCustomField.where(name: "votes_archive", value: args[:topic_id]).find_each do |user_field|
|
||||||
|
user = User.find(user_field.user_id)
|
||||||
user.custom_fields["votes"] = user.votes.dup.push(args[:topic_id])
|
user.custom_fields["votes"] = user.votes.dup.push(args[:topic_id])
|
||||||
user.custom_fields["votes_archive"] = user.votes_archive.dup - [args[:topic_id].to_s]
|
user.custom_fields["votes_archive"] = user.votes_archive.dup - [args[:topic_id].to_s]
|
||||||
user.save
|
user.save
|
||||||
|
@ -191,6 +210,7 @@ after_initialize do
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
mount ::DiscourseFeatureVoting::Engine, at: "/voting"
|
mount ::DiscourseFeatureVoting::Engine, at: "/voting"
|
||||||
|
get "topics/voted-by/:username" => "list#voted_by", as: "voted_by", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||||
end
|
end
|
||||||
|
|
||||||
TopicList.preloaded_custom_fields << "vote_count" if TopicList.respond_to? :preloaded_custom_fields
|
TopicList.preloaded_custom_fields << "vote_count" if TopicList.respond_to? :preloaded_custom_fields
|
||||||
|
|
Loading…
Reference in New Issue