Merge pull request #1409 from riyad/update-votes
Update votes for issues and merge requests
This commit is contained in:
commit
40eec08c99
17 changed files with 256 additions and 66 deletions
|
@ -415,13 +415,48 @@ p.time {
|
|||
}
|
||||
}
|
||||
|
||||
.upvotes {
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
color: #468847;
|
||||
text-align: right;
|
||||
padding: 4px;
|
||||
margin: 2px;
|
||||
.votes {
|
||||
font-size: 13px;
|
||||
line-height: 15px;
|
||||
.progress {
|
||||
height: 4px;
|
||||
margin: 0;
|
||||
.bar {
|
||||
float: left;
|
||||
height: 100%;
|
||||
}
|
||||
.bar-success {
|
||||
background-color: #468847;
|
||||
@include bg-gradient(#62C462, #51A351);
|
||||
}
|
||||
.bar-danger {
|
||||
background-color: #B94A48;
|
||||
@include bg-gradient(#EE5F5B, #BD362F);
|
||||
}
|
||||
}
|
||||
.upvotes {
|
||||
display: inline-block;
|
||||
color: #468847;
|
||||
}
|
||||
.downvotes {
|
||||
display: inline-block;
|
||||
color: #B94A48;
|
||||
}
|
||||
}
|
||||
.votes-block {
|
||||
margin: 14px 6px 6px 0;
|
||||
.downvotes {
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
.votes-inline {
|
||||
display: inline-block;
|
||||
margin: 0 8px;
|
||||
.progress {
|
||||
display: inline-block;
|
||||
padding: 0 0 2px;
|
||||
width: 45px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fix for readme code (stopped it from being yellow) */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Issue < ActiveRecord::Base
|
||||
include IssueCommonality
|
||||
include Upvote
|
||||
include Votes
|
||||
|
||||
acts_as_taggable_on :labels
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.join(Rails.root, "app/models/commit")
|
|||
|
||||
class MergeRequest < ActiveRecord::Base
|
||||
include IssueCommonality
|
||||
include Upvote
|
||||
include Votes
|
||||
|
||||
BROKEN_DIFF = "--broken-diff"
|
||||
|
||||
|
|
|
@ -105,6 +105,12 @@ class Note < ActiveRecord::Base
|
|||
def upvote?
|
||||
note.start_with?('+1') || note.start_with?(':+1:')
|
||||
end
|
||||
|
||||
# Returns true if this is a downvote note,
|
||||
# otherwise false is returned
|
||||
def downvote?
|
||||
note.start_with?('-1') || note.start_with?(':-1:')
|
||||
end
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
module Upvote
|
||||
# Return the number of +1 comments (upvotes)
|
||||
def upvotes
|
||||
notes.select(&:upvote?).size
|
||||
end
|
||||
end
|
32
app/roles/votes.rb
Normal file
32
app/roles/votes.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
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
|
||||
notes.select(&:downvote?).size
|
||||
end
|
||||
|
||||
def downvotes_in_percent
|
||||
if votes_count.zero?
|
||||
0
|
||||
else
|
||||
100.0 - upvotes_in_percent
|
||||
end
|
||||
end
|
||||
|
||||
# Return the total number of votes
|
||||
def votes_count
|
||||
upvotes + downvotes
|
||||
end
|
||||
end
|
|
@ -34,5 +34,5 @@
|
|||
- else
|
||||
|
||||
|
||||
- if issue.upvotes > 0
|
||||
%span.badge.badge-success= "+#{issue.upvotes}"
|
||||
- if issue.votes_count > 0
|
||||
= render 'votes/votes_inline', votable: issue
|
||||
|
|
|
@ -8,22 +8,22 @@
|
|||
%span.right
|
||||
- if can?(current_user, :admin_project, @project) || @issue.author == current_user
|
||||
- if @issue.closed
|
||||
= link_to 'Reopen', project_issue_path(@project, @issue, issue: {closed: false }, status_only: true), method: :put, class: "btn small"
|
||||
= link_to 'Reopen', project_issue_path(@project, @issue, issue: {closed: false }, status_only: true), method: :put, class: "btn grouped success"
|
||||
- else
|
||||
= link_to 'Close', project_issue_path(@project, @issue, issue: {closed: true }, status_only: true), method: :put, class: "btn small", title: "Close Issue"
|
||||
= link_to 'Close', project_issue_path(@project, @issue, issue: {closed: true }, status_only: true), method: :put, class: "btn grouped danger", title: "Close Issue"
|
||||
- if can?(current_user, :admin_project, @project) || @issue.author == current_user
|
||||
= link_to edit_project_issue_path(@project, @issue), class: "btn small" do
|
||||
= link_to edit_project_issue_path(@project, @issue), class: "btn grouped" do
|
||||
%i.icon-edit
|
||||
Edit
|
||||
|
||||
%br
|
||||
- if @issue.upvotes > 0
|
||||
.upvotes#upvotes= "+#{pluralize @issue.upvotes, 'upvote'}"
|
||||
.right
|
||||
.span3#votes= render 'votes/votes_block', votable: @issue
|
||||
|
||||
.back_link
|
||||
= link_to project_issues_path(@project) do
|
||||
← To issues list
|
||||
|
||||
|
||||
.main_box
|
||||
.top_box_content
|
||||
%h4
|
||||
|
|
|
@ -23,5 +23,6 @@
|
|||
authored by #{merge_request.author_name}
|
||||
= time_ago_in_words(merge_request.created_at)
|
||||
ago
|
||||
- if merge_request.upvotes > 0
|
||||
%span.badge.badge-success= "+#{merge_request.upvotes}"
|
||||
|
||||
- if merge_request.votes_count > 0
|
||||
= render 'votes/votes_inline', votable: merge_request
|
||||
|
|
|
@ -23,10 +23,8 @@
|
|||
%i.icon-edit
|
||||
Edit
|
||||
|
||||
%br
|
||||
- if @merge_request.upvotes > 0
|
||||
.upvotes#upvotes= "+#{pluralize @merge_request.upvotes, 'upvote'}"
|
||||
|
||||
.right
|
||||
.span3#votes= render 'votes/votes_block', votable: @merge_request
|
||||
|
||||
.back_link
|
||||
= link_to project_merge_requests_path(@project) do
|
||||
|
|
6
app/views/votes/_votes_block.html.haml
Normal file
6
app/views/votes/_votes_block.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
.votes.votes-block
|
||||
.progress
|
||||
.bar.bar-success{style: "width: #{votable.upvotes_in_percent}%;"}
|
||||
.bar.bar-danger{style: "width: #{votable.downvotes_in_percent}%;"}
|
||||
.upvotes= "#{votable.upvotes} up"
|
||||
.downvotes= "#{votable.downvotes} down"
|
6
app/views/votes/_votes_inline.html.haml
Normal file
6
app/views/votes/_votes_inline.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
.votes.votes-inline
|
||||
.upvotes= votable.upvotes
|
||||
.progress
|
||||
.bar.bar-success{style: "width: #{votable.upvotes_in_percent}%;"}
|
||||
.bar.bar-danger{style: "width: #{votable.downvotes_in_percent}%;"}
|
||||
.downvotes= votable.downvotes
|
Loading…
Add table
Add a link
Reference in a new issue