From 06c1a8a9ae34e2a4fe7b4f4edb58bacfaf6df5c9 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 8 Sep 2012 02:08:35 +0200 Subject: [PATCH 1/9] Make notes recognize downvotes --- app/models/note.rb | 6 ++++++ spec/models/note_spec.rb | 23 +++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/models/note.rb b/app/models/note.rb index d8494edd..4c46c7df 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -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 # diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index dddfd34c..7809953f 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -24,6 +24,13 @@ describe Note do it "recognizes a neutral note" do note = Factory(:note, note: "This is not a +1 note") note.should_not be_upvote + note.should_not be_downvote + end + + it "recognizes a neutral emoji note" do + note = build(:note, note: "I would :+1: this, but I don't want to") + note.should_not be_upvote + note.should_not be_downvote end it "recognizes a +1 note" do @@ -31,19 +38,19 @@ describe Note do note.should be_upvote end - it "recognizes a -1 note as no vote" do - note = Factory(:note, note: "-1 for this") - note.should_not be_upvote - end - it "recognizes a +1 emoji as a vote" do note = build(:note, note: ":+1: for this") note.should be_upvote end - it "recognizes a neutral emoji note" do - note = build(:note, note: "I would :+1: this, but I don't want to") - note.should_not be_upvote + it "recognizes a -1 note" do + note = Factory(:note, note: "-1 for this") + note.should be_downvote + end + + it "recognizes a -1 emoji as a vote" do + note = build(:note, note: ":-1: for this") + note.should be_downvote end end From a2a0060034171e22962129d53cc74fb7bde54476 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 8 Sep 2012 02:23:49 +0200 Subject: [PATCH 2/9] Rename Upvote role to Votes --- app/models/issue.rb | 2 +- app/models/merge_request.rb | 2 +- app/roles/{upvote.rb => votes.rb} | 2 +- spec/models/issue_spec.rb | 2 +- spec/models/merge_request_spec.rb | 2 +- spec/roles/{upvote_spec.rb => votes_spec.rb} | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename app/roles/{upvote.rb => votes.rb} (88%) rename spec/roles/{upvote_spec.rb => votes_spec.rb} (100%) diff --git a/app/models/issue.rb b/app/models/issue.rb index 6409eeba..96a54907 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1,6 +1,6 @@ class Issue < ActiveRecord::Base include IssueCommonality - include Upvote + include Votes acts_as_taggable_on :labels diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 542817b0..3376e31b 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -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" diff --git a/app/roles/upvote.rb b/app/roles/votes.rb similarity index 88% rename from app/roles/upvote.rb rename to app/roles/votes.rb index 7efa6f20..29409292 100644 --- a/app/roles/upvote.rb +++ b/app/roles/votes.rb @@ -1,4 +1,4 @@ -module Upvote +module Votes # Return the number of +1 comments (upvotes) def upvotes notes.select(&:upvote?).size diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index ca6307e7..34192da9 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -12,7 +12,7 @@ describe Issue do describe 'modules' do it { should include_module(IssueCommonality) } - it { should include_module(Upvote) } + it { should include_module(Votes) } end subject { Factory.create(:issue) } diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index d1253b35..523e823d 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -8,6 +8,6 @@ describe MergeRequest do describe 'modules' do it { should include_module(IssueCommonality) } - it { should include_module(Upvote) } + it { should include_module(Votes) } end end diff --git a/spec/roles/upvote_spec.rb b/spec/roles/votes_spec.rb similarity index 100% rename from spec/roles/upvote_spec.rb rename to spec/roles/votes_spec.rb From 2e0d5c2250ad34273a0ad6e207f2717b9a98bd86 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 8 Sep 2012 02:30:47 +0200 Subject: [PATCH 3/9] Add downvotes --- app/roles/votes.rb | 5 ++++ spec/roles/votes_spec.rb | 60 ++++++++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/app/roles/votes.rb b/app/roles/votes.rb index 29409292..fb132a33 100644 --- a/app/roles/votes.rb +++ b/app/roles/votes.rb @@ -3,4 +3,9 @@ module Votes def upvotes notes.select(&:upvote?).size end + + # Return the number of -1 comments (downvotes) + def downvotes + notes.select(&:downvote?).size + end end diff --git a/spec/roles/votes_spec.rb b/spec/roles/votes_spec.rb index 24288ada..43817999 100644 --- a/spec/roles/votes_spec.rb +++ b/spec/roles/votes_spec.rb @@ -1,27 +1,53 @@ require 'spec_helper' -describe Issue, "Upvote" do +describe Issue do let(:issue) { create(:issue) } - it "with no notes has a 0/0 score" do - issue.upvotes.should == 0 + describe "#upvotes" do + it "with no notes has a 0/0 score" do + issue.upvotes.should == 0 + end + + it "should recognize non-+1 notes" do + issue.notes << create(:note, note: "No +1 here") + issue.should have(1).note + issue.notes.first.upvote?.should be_false + issue.upvotes.should == 0 + end + + it "should recognize a single +1 note" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.upvotes.should == 1 + end + + it "should recognize multiple +1 notes" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "+1 I want this") + issue.upvotes.should == 2 + end end - it "should recognize non-+1 notes" do - issue.notes << create(:note, note: "No +1 here") - issue.should have(1).note - issue.notes.first.upvote?.should be_false - issue.upvotes.should == 0 - end + describe "#downvotes" do + it "with no notes has a 0/0 score" do + issue.downvotes.should == 0 + end - it "should recognize a single +1 note" do - issue.notes << create(:note, note: "+1 This is awesome") - issue.upvotes.should == 1 - end + it "should recognize non--1 notes" do + issue.notes << create(:note, note: "Almost got a -1") + issue.should have(1).note + issue.notes.first.downvote?.should be_false + issue.downvotes.should == 0 + end - it "should recognize multiple +1 notes" do - issue.notes << create(:note, note: "+1 This is awesome") - issue.notes << create(:note, note: "+1 I want this") - issue.upvotes.should == 2 + it "should recognize a single -1 note" do + issue.notes << create(:note, note: "-1 This is bad") + issue.downvotes.should == 1 + end + + it "should recognize multiple -1 notes" do + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "-1 Away with this") + issue.downvotes.should == 2 + end end end From 7b0c7ae52c299584e810fc4b1a33893ebdbb8ac3 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 8 Sep 2012 02:37:29 +0200 Subject: [PATCH 4/9] Add votes_count --- app/roles/votes.rb | 5 +++++ spec/roles/votes_spec.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/roles/votes.rb b/app/roles/votes.rb index fb132a33..3a584d8b 100644 --- a/app/roles/votes.rb +++ b/app/roles/votes.rb @@ -8,4 +8,9 @@ module Votes def downvotes notes.select(&:downvote?).size end + + # Return the total number of votes + def votes_count + upvotes + downvotes + end end diff --git a/spec/roles/votes_spec.rb b/spec/roles/votes_spec.rb index 43817999..5c3548a5 100644 --- a/spec/roles/votes_spec.rb +++ b/spec/roles/votes_spec.rb @@ -50,4 +50,33 @@ describe Issue do issue.downvotes.should == 2 end end + + describe "#votes_count" do + it "with no notes has a 0/0 score" do + issue.votes_count.should == 0 + end + + it "should recognize non notes" do + issue.notes << create(:note, note: "No +1 here") + issue.should have(1).note + issue.votes_count.should == 0 + end + + it "should recognize a single +1 note" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.votes_count.should == 1 + end + + it "should recognize a single -1 note" do + issue.notes << create(:note, note: "-1 This is bad") + issue.votes_count.should == 1 + end + + it "should recognize multiple notes" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "+1 I want this") + issue.votes_count.should == 3 + end + end end From 1271b4ce66d4251f8f038d8d339fbecbab2d0900 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 8 Sep 2012 03:30:41 +0200 Subject: [PATCH 5/9] Update display of merge requests and issues to also show downvotes --- app/assets/stylesheets/common.scss | 20 ++++++++++++++----- app/views/issues/_show.html.haml | 2 ++ app/views/issues/show.html.haml | 6 ++++-- .../merge_requests/_merge_request.html.haml | 2 ++ .../merge_requests/show/_mr_title.html.haml | 6 ++++-- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index aa27a280..d52cb1fc 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -406,13 +406,23 @@ p.time { } } -.upvotes { +.votes { font-size: 14px; font-weight: bold; - color: #468847; - text-align: right; - padding: 4px; - margin: 2px; + padding: 4px 0; + margin: 2px 0; + .upvotes { + display: inline-block; + color: #468847; + padding: 0 4px; + margin: 0 2px; + } + .downvotes { + display: inline-block; + color: #B94A48; + padding: 0 4px; + margin: 0 2px; + } } /* Fix for readme code (stopped it from being yellow) */ diff --git a/app/views/issues/_show.html.haml b/app/views/issues/_show.html.haml index 8500cd40..e37ea3df 100644 --- a/app/views/issues/_show.html.haml +++ b/app/views/issues/_show.html.haml @@ -36,3 +36,5 @@ - if issue.upvotes > 0 %span.badge.badge-success= "+#{issue.upvotes}" + - if issue.downvotes > 0 + %span.badge.badge-important= "-#{issue.downvotes}" diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index dce8cf6a..36af1f49 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -17,8 +17,10 @@ Edit %br - - if @issue.upvotes > 0 - .upvotes#upvotes= "+#{pluralize @issue.upvotes, 'upvote'}" + .votes#votes + Votes: + .upvotes#upvotes= "#{@issue.upvotes} up" + .downvotes#downvotes= "#{@issue.downvotes} down" .back_link = link_to project_issues_path(@project) do diff --git a/app/views/merge_requests/_merge_request.html.haml b/app/views/merge_requests/_merge_request.html.haml index 74996090..8d0a6dcf 100644 --- a/app/views/merge_requests/_merge_request.html.haml +++ b/app/views/merge_requests/_merge_request.html.haml @@ -25,3 +25,5 @@ ago - if merge_request.upvotes > 0 %span.badge.badge-success= "+#{merge_request.upvotes}" + - if merge_request.downvotes > 0 + %span.badge.badge-important= "-#{merge_request.downvotes}" diff --git a/app/views/merge_requests/show/_mr_title.html.haml b/app/views/merge_requests/show/_mr_title.html.haml index 3ae1050d..f8ab6c19 100644 --- a/app/views/merge_requests/show/_mr_title.html.haml +++ b/app/views/merge_requests/show/_mr_title.html.haml @@ -24,8 +24,10 @@ Edit %br - - if @merge_request.upvotes > 0 - .upvotes#upvotes= "+#{pluralize @merge_request.upvotes, 'upvote'}" + .votes#votes + Votes: + .upvotes#upvotes= "#{@merge_request.upvotes} up" + .downvotes#downvotes= "#{@merge_request.downvotes} down" .back_link From 5ca31aa252d67372d9a90cceb61f16721dca3841 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 8 Sep 2012 16:00:38 +0200 Subject: [PATCH 6/9] Make issue buttons look more consistent with MRs --- app/views/issues/show.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index 36af1f49..12394ac5 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -8,11 +8,11 @@ %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 From a5164ea2ed4e809cb4af7a070652ef2a6b19fbf3 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 8 Sep 2012 16:44:56 +0200 Subject: [PATCH 7/9] Show votes as a bar --- app/assets/stylesheets/common.scss | 41 +++++++++++++++---- app/views/issues/_show.html.haml | 13 ++++-- app/views/issues/show.html.haml | 15 ++++--- .../merge_requests/_merge_request.html.haml | 13 ++++-- .../merge_requests/show/_mr_title.html.haml | 15 ++++--- 5 files changed, 70 insertions(+), 27 deletions(-) diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index d52cb1fc..829bece3 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -407,21 +407,46 @@ p.time { } .votes { - font-size: 14px; - font-weight: bold; - padding: 4px 0; - margin: 2px 0; + 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; - padding: 0 4px; - margin: 0 2px; } .downvotes { display: inline-block; color: #B94A48; - padding: 0 4px; - margin: 0 2px; + } +} +.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; } } diff --git a/app/views/issues/_show.html.haml b/app/views/issues/_show.html.haml index e37ea3df..db394873 100644 --- a/app/views/issues/_show.html.haml +++ b/app/views/issues/_show.html.haml @@ -34,7 +34,12 @@ - else   - - if issue.upvotes > 0 - %span.badge.badge-success= "+#{issue.upvotes}" - - if issue.downvotes > 0 - %span.badge.badge-important= "-#{issue.downvotes}" + - if issue.votes_count > 0 + .votes.votes-inline + .upvotes= issue.upvotes + .progress + - up_percent = 100.0/issue.votes_count*issue.upvotes + - down_percent = 100.0-up_percent + .bar.bar-success{style: "width: #{up_percent}%;"} + .bar.bar-danger{style: "width: #{down_percent}%;"} + .downvotes= issue.downvotes diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index 12394ac5..1ec03951 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -16,16 +16,21 @@ %i.icon-edit Edit - %br - .votes#votes - Votes: - .upvotes#upvotes= "#{@issue.upvotes} up" - .downvotes#downvotes= "#{@issue.downvotes} down" +.right + .span3.votes.votes-block#votes + .progress + - up_percent = 100.0/@issue.votes_count*@issue.upvotes + - down_percent = 100.0-up_percent + .bar.bar-success{style: "width: #{up_percent}%;"} + .bar.bar-danger{style: "width: #{down_percent}%;"} + .upvotes= "#{@issue.upvotes} up" + .downvotes= "#{@issue.downvotes} down" .back_link = link_to project_issues_path(@project) do ← To issues list + .main_box .top_box_content %h4 diff --git a/app/views/merge_requests/_merge_request.html.haml b/app/views/merge_requests/_merge_request.html.haml index 8d0a6dcf..08420fd2 100644 --- a/app/views/merge_requests/_merge_request.html.haml +++ b/app/views/merge_requests/_merge_request.html.haml @@ -23,7 +23,12 @@ 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.downvotes > 0 - %span.badge.badge-important= "-#{merge_request.downvotes}" + - if merge_request.votes_count > 0 + .votes.votes-inline + .upvotes= merge_request.upvotes + .progress + - up_percent = 100.0/merge_request.votes_count*merge_request.upvotes + - down_percent = 100.0-up_percent + .bar.bar-success{style: "width: #{up_percent}%;"} + .bar.bar-danger{style: "width: #{down_percent}%;"} + .downvotes= merge_request.downvotes diff --git a/app/views/merge_requests/show/_mr_title.html.haml b/app/views/merge_requests/show/_mr_title.html.haml index f8ab6c19..c0ad4be5 100644 --- a/app/views/merge_requests/show/_mr_title.html.haml +++ b/app/views/merge_requests/show/_mr_title.html.haml @@ -23,12 +23,15 @@ %i.icon-edit Edit - %br - .votes#votes - Votes: - .upvotes#upvotes= "#{@merge_request.upvotes} up" - .downvotes#downvotes= "#{@merge_request.downvotes} down" - +.right + .span3.votes.votes-block#votes + .progress + - up_percent = 100.0/@merge_request.votes_count*@merge_request.upvotes + - down_percent = 100.0-up_percent + .bar.bar-success{style: "width: #{up_percent}%;"} + .bar.bar-danger{style: "width: #{down_percent}%;"} + .upvotes= "#{@merge_request.upvotes} up" + .downvotes= "#{@merge_request.downvotes} down" .back_link = link_to project_merge_requests_path(@project) do From f7c70eaaedd196accbe8e952ddc4738a96b81998 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Tue, 11 Sep 2012 16:47:59 +0200 Subject: [PATCH 8/9] Add *votes_in_percent --- app/roles/votes.rb | 16 +++++++++++++ spec/roles/votes_spec.rb | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/app/roles/votes.rb b/app/roles/votes.rb index 3a584d8b..043a6feb 100644 --- a/app/roles/votes.rb +++ b/app/roles/votes.rb @@ -4,11 +4,27 @@ module Votes 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 diff --git a/spec/roles/votes_spec.rb b/spec/roles/votes_spec.rb index 5c3548a5..98666022 100644 --- a/spec/roles/votes_spec.rb +++ b/spec/roles/votes_spec.rb @@ -79,4 +79,54 @@ describe Issue do issue.votes_count.should == 3 end end + + describe "#upvotes_in_percent" do + it "with no notes has a 0% score" do + issue.upvotes_in_percent.should == 0 + end + + it "should count a single 1 note as 100%" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.upvotes_in_percent.should == 100 + end + + it "should count multiple +1 notes as 100%" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "+1 I want this") + issue.upvotes_in_percent.should == 100 + end + + it "should count fractions for multiple +1 and -1 notes correctly" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "+1 I want this") + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "+1 me too") + issue.upvotes_in_percent.should == 75 + end + end + + describe "#downvotes_in_percent" do + it "with no notes has a 0% score" do + issue.downvotes_in_percent.should == 0 + end + + it "should count a single -1 note as 100%" do + issue.notes << create(:note, note: "-1 This is bad") + issue.downvotes_in_percent.should == 100 + end + + it "should count multiple -1 notes as 100%" do + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "-1 Away with this") + issue.downvotes_in_percent.should == 100 + end + + it "should count fractions for multiple +1 and -1 notes correctly" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "+1 I want this") + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "+1 me too") + issue.downvotes_in_percent.should == 25 + end + end end From 0bfcc574b660108646bd2c99a611163a0c847251 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 10 Sep 2012 15:27:14 +0200 Subject: [PATCH 9/9] Extract displaying votes into partials --- app/views/issues/_show.html.haml | 9 +-------- app/views/issues/show.html.haml | 9 +-------- app/views/merge_requests/_merge_request.html.haml | 10 ++-------- app/views/merge_requests/show/_mr_title.html.haml | 9 +-------- app/views/votes/_votes_block.html.haml | 6 ++++++ app/views/votes/_votes_inline.html.haml | 6 ++++++ 6 files changed, 17 insertions(+), 32 deletions(-) create mode 100644 app/views/votes/_votes_block.html.haml create mode 100644 app/views/votes/_votes_inline.html.haml diff --git a/app/views/issues/_show.html.haml b/app/views/issues/_show.html.haml index db394873..22101aa1 100644 --- a/app/views/issues/_show.html.haml +++ b/app/views/issues/_show.html.haml @@ -35,11 +35,4 @@   - if issue.votes_count > 0 - .votes.votes-inline - .upvotes= issue.upvotes - .progress - - up_percent = 100.0/issue.votes_count*issue.upvotes - - down_percent = 100.0-up_percent - .bar.bar-success{style: "width: #{up_percent}%;"} - .bar.bar-danger{style: "width: #{down_percent}%;"} - .downvotes= issue.downvotes + = render 'votes/votes_inline', votable: issue diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index 1ec03951..9b1c72a3 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -17,14 +17,7 @@ Edit .right - .span3.votes.votes-block#votes - .progress - - up_percent = 100.0/@issue.votes_count*@issue.upvotes - - down_percent = 100.0-up_percent - .bar.bar-success{style: "width: #{up_percent}%;"} - .bar.bar-danger{style: "width: #{down_percent}%;"} - .upvotes= "#{@issue.upvotes} up" - .downvotes= "#{@issue.downvotes} down" + .span3#votes= render 'votes/votes_block', votable: @issue .back_link = link_to project_issues_path(@project) do diff --git a/app/views/merge_requests/_merge_request.html.haml b/app/views/merge_requests/_merge_request.html.haml index 08420fd2..9d94d670 100644 --- a/app/views/merge_requests/_merge_request.html.haml +++ b/app/views/merge_requests/_merge_request.html.haml @@ -23,12 +23,6 @@ authored by #{merge_request.author_name} = time_ago_in_words(merge_request.created_at) ago + - if merge_request.votes_count > 0 - .votes.votes-inline - .upvotes= merge_request.upvotes - .progress - - up_percent = 100.0/merge_request.votes_count*merge_request.upvotes - - down_percent = 100.0-up_percent - .bar.bar-success{style: "width: #{up_percent}%;"} - .bar.bar-danger{style: "width: #{down_percent}%;"} - .downvotes= merge_request.downvotes + = render 'votes/votes_inline', votable: merge_request diff --git a/app/views/merge_requests/show/_mr_title.html.haml b/app/views/merge_requests/show/_mr_title.html.haml index c0ad4be5..8708469c 100644 --- a/app/views/merge_requests/show/_mr_title.html.haml +++ b/app/views/merge_requests/show/_mr_title.html.haml @@ -24,14 +24,7 @@ Edit .right - .span3.votes.votes-block#votes - .progress - - up_percent = 100.0/@merge_request.votes_count*@merge_request.upvotes - - down_percent = 100.0-up_percent - .bar.bar-success{style: "width: #{up_percent}%;"} - .bar.bar-danger{style: "width: #{down_percent}%;"} - .upvotes= "#{@merge_request.upvotes} up" - .downvotes= "#{@merge_request.downvotes} down" + .span3#votes= render 'votes/votes_block', votable: @merge_request .back_link = link_to project_merge_requests_path(@project) do diff --git a/app/views/votes/_votes_block.html.haml b/app/views/votes/_votes_block.html.haml new file mode 100644 index 00000000..bded53b2 --- /dev/null +++ b/app/views/votes/_votes_block.html.haml @@ -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" diff --git a/app/views/votes/_votes_inline.html.haml b/app/views/votes/_votes_inline.html.haml new file mode 100644 index 00000000..91bd200d --- /dev/null +++ b/app/views/votes/_votes_inline.html.haml @@ -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