Count +1 votes in issue notes.

This commit is contained in:
Ariejan de Vroom 2012-03-14 15:31:31 +02:00
parent ed11ca13e8
commit 8d8b82127f
6 changed files with 81 additions and 15 deletions

View file

@ -45,6 +45,11 @@ class Issue < ActiveRecord::Base
def new?
today? && created_at == updated_at
end
# Return the number of +1 comments (upvotes)
def upvotes
notes.select(&:upvote?).size
end
end
# == Schema Information
#

View file

@ -47,27 +47,27 @@ class Note < ActiveRecord::Base
end
def target
if noteable_type == "Commit"
if noteable_type == "Commit"
project.commit(noteable_id)
else
else
noteable
end
# Temp fix to prevent app crash
# if note commit id doesnt exist
rescue
rescue
nil
end
# Check if we can notify commit author
# with email about our comment
#
# If commit author email exist in project
# and commit author is not passed user we can
# If commit author email exist in project
# and commit author is not passed user we can
# send email to him
#
# params:
# user - current user
#
#
# return:
# Boolean
#
@ -81,12 +81,18 @@ class Note < ActiveRecord::Base
end
def commit_author
@commit_author ||=
project.users.find_by_email(target.author_email) ||
@commit_author ||=
project.users.find_by_email(target.author_email) ||
project.users.find_by_name(target.author_name)
rescue
rescue
nil
end
# Returns true if this is an upvote note,
# otherwise false is returned
def upvote?
note =~ /^\+1/ ? true : false
end
end
# == Schema Information
#

View file

@ -14,6 +14,8 @@
%span.label.important critical
- if issue.today?
%span.label.success today
- if issue.upvotes > 0
%span.label.success= "+#{issue.upvotes}"

View file

@ -35,6 +35,9 @@
%cite.cgray and currently assigned to
= image_tag gravatar_icon(@issue.assignee_email), :width => 16, :class => "lil_av"
%strong.author= link_to_issue_assignee(@issue)
- if @issue.upvotes > 0
%span.label.success= "+#{@issue.upvotes}"
%hr