Fix vote counting
This commit is contained in:
parent
6c6f415cae
commit
ae067ee322
7 changed files with 186 additions and 117 deletions
|
@ -1,12 +1,4 @@
|
|||
module NotesHelper
|
||||
def loading_more_notes?
|
||||
params[:loading_more].present?
|
||||
end
|
||||
|
||||
def loading_new_notes?
|
||||
params[:loading_new].present?
|
||||
end
|
||||
|
||||
# Helps to distinguish e.g. commit notes in mr notes list
|
||||
def note_for_main_target?(note)
|
||||
!@mixed_targets || (@target.class.name == note.noteable_type && !note.for_diff_line?)
|
||||
|
@ -23,4 +15,12 @@ module NotesHelper
|
|||
link_to "#{note.diff_file_name}:L#{note.diff_new_line}", diffs_project_merge_request_path(note.project, note.noteable_id, anchor: note.line_code)
|
||||
end
|
||||
end
|
||||
|
||||
def loading_more_notes?
|
||||
params[:loading_more].present?
|
||||
end
|
||||
|
||||
def loading_new_notes?
|
||||
params[:loading_new].present?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -85,7 +85,9 @@ class Note < ActiveRecord::Base
|
|||
# Returns true if this is a downvote note,
|
||||
# otherwise false is returned
|
||||
def downvote?
|
||||
note.start_with?('-1') || note.start_with?(':-1:')
|
||||
votable? && (note.start_with?('-1') ||
|
||||
note.start_with?(':-1:')
|
||||
)
|
||||
end
|
||||
|
||||
def for_commit?
|
||||
|
@ -100,6 +102,10 @@ class Note < ActiveRecord::Base
|
|||
line_code.present?
|
||||
end
|
||||
|
||||
def for_issue?
|
||||
noteable_type == "Issue"
|
||||
end
|
||||
|
||||
def for_merge_request?
|
||||
noteable_type == "MergeRequest"
|
||||
end
|
||||
|
@ -150,6 +156,12 @@ class Note < ActiveRecord::Base
|
|||
# Returns true if this is an upvote note,
|
||||
# otherwise false is returned
|
||||
def upvote?
|
||||
note.start_with?('+1') || note.start_with?(':+1:')
|
||||
votable? && (note.start_with?('+1') ||
|
||||
note.start_with?(':+1:')
|
||||
)
|
||||
end
|
||||
|
||||
def votable?
|
||||
for_issue? || (for_merge_request? && !for_diff_line?)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +1,4 @@
|
|||
module Votes
|
||||
# Return the number of +1 comments (upvotes)
|
||||
def upvotes
|
||||
notes.select(&:upvote?).size
|
||||
end
|
||||
|
||||
def upvotes_in_percent
|
||||
if votes_count.zero?
|
||||
0
|
||||
else
|
||||
100.0 / votes_count * upvotes
|
||||
end
|
||||
end
|
||||
|
||||
# Return the number of -1 comments (downvotes)
|
||||
def downvotes
|
||||
|
@ -25,6 +13,19 @@ module Votes
|
|||
end
|
||||
end
|
||||
|
||||
# Return the number of +1 comments (upvotes)
|
||||
def upvotes
|
||||
notes.select(&:upvote?).size
|
||||
end
|
||||
|
||||
def upvotes_in_percent
|
||||
if votes_count.zero?
|
||||
0
|
||||
else
|
||||
100.0 / votes_count * upvotes
|
||||
end
|
||||
end
|
||||
|
||||
# Return the total number of votes
|
||||
def votes_count
|
||||
upvotes + downvotes
|
||||
|
|
|
@ -14,16 +14,14 @@
|
|||
= time_ago_in_words(note.updated_at)
|
||||
ago
|
||||
|
||||
-# only show vote if it's a note for the main target
|
||||
- if note_for_main_target?(note)
|
||||
- if note.upvote?
|
||||
%span.vote.upvote.label.label-success
|
||||
%i.icon-thumbs-up
|
||||
\+1
|
||||
- if note.downvote?
|
||||
%span.vote.downvote.label.label-error
|
||||
%i.icon-thumbs-down
|
||||
\-1
|
||||
- if note.upvote?
|
||||
%span.vote.upvote.label.label-success
|
||||
%i.icon-thumbs-up
|
||||
\+1
|
||||
- if note.downvote?
|
||||
%span.vote.downvote.label.label-error
|
||||
%i.icon-thumbs-down
|
||||
\-1
|
||||
|
||||
|
||||
.note-body
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue