From b8113334a86639b87d5f89cc78e2279a8ae4e38a Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 15 Sep 2012 11:54:46 +0200 Subject: [PATCH 1/3] Highlight voting notes for issues and merge requests --- app/assets/stylesheets/sections/notes.scss | 13 +++++++++++++ app/helpers/notes_helper.rb | 8 ++++++++ app/views/issues/show.html.haml | 2 +- app/views/merge_requests/_show.html.haml | 2 +- app/views/notes/_note.html.haml | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/sections/notes.scss b/app/assets/stylesheets/sections/notes.scss index 148807d6521..06b929c6843 100644 --- a/app/assets/stylesheets/sections/notes.scss +++ b/app/assets/stylesheets/sections/notes.scss @@ -81,6 +81,19 @@ border-top: 1px solid #eee; } +/* mark vote notes */ +.voting_notes .note { + padding: 8px 0 8px 12px; + &.upvote { + padding-left: 8px; + border-left: 4px solid #468847; + } + &.downvote { + padding-left: 8px; + border-left: 4px solid #B94A48; + } +} + .notes-status { margin: 18px; } diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 28701661dc4..65389e383d9 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -6,4 +6,12 @@ module NotesHelper def loading_new_notes? params[:loading_new].present? end + + def note_vote_class(note) + if note.upvote? + "vote upvote" + elsif note.downvote? + "vote downvote" + end + end end diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index 0b72a820bb4..e7365e10eeb 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -61,4 +61,4 @@ = markdown @issue.description -.issue_notes#notes= render "notes/notes_with_form", tid: @issue.id, tt: "issue" +.issue_notes.voting_notes#notes= render "notes/notes_with_form", tid: @issue.id, tt: "issue" diff --git a/app/views/merge_requests/_show.html.haml b/app/views/merge_requests/_show.html.haml index 40b72190199..f1d0c8aaafb 100644 --- a/app/views/merge_requests/_show.html.haml +++ b/app/views/merge_requests/_show.html.haml @@ -15,7 +15,7 @@ %i.icon-list-alt Diff -.merge_request_notes#notes{ class: (controller.action_name == 'show') ? "" : "hide" } +.merge_request_notes.voting_notes#notes{ class: (controller.action_name == 'show') ? "" : "hide" } = render("notes/notes_with_form", tid: @merge_request.id, tt: "merge_request") .merge-request-diffs = render "merge_requests/show/diffs" if @diffs diff --git a/app/views/notes/_note.html.haml b/app/views/notes/_note.html.haml index 3412e4ebae5..23145f128a8 100644 --- a/app/views/notes/_note.html.haml +++ b/app/views/notes/_note.html.haml @@ -1,4 +1,4 @@ -%li{id: dom_id(note), class: "note"} +%li{id: dom_id(note), class: "note #{note_vote_class(note)}"} = image_tag gravatar_icon(note.author.email), class: "avatar s32" %div.note-author %strong= note.author_name -- GitLab From 6aebb76b5d05bf7668a8f389a00648fdb405af7d Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sat, 15 Sep 2012 11:55:17 +0200 Subject: [PATCH 2/3] Update votes when creating or refreshing notes --- app/assets/javascripts/notes.js | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 81bb1d6d1b0..7b59cc77e7f 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -21,15 +21,18 @@ var NoteList = { this.getContent(); $("#notes-list, #new-notes-list").on("ajax:success", ".delete-note", function() { - $(this).closest('li').fadeOut(); + $(this).closest('li').fadeOut(function() { + $(this).remove(); + NoteList.updateVotes(); + }); }); $(".note-form-holder").on("ajax:before", function(){ - $(".submit_note").disable() + $(".submit_note").disable(); }) $(".note-form-holder").on("ajax:complete", function(){ - $(".submit_note").enable() + $(".submit_note").enable(); }) disableButtonIfEmptyField(".note-text", ".submit_note"); @@ -154,6 +157,8 @@ var NoteList = { if (!this.reversed) { this.initRefreshNew(); } + // make sure we are up to date + this.updateVotes(); }, @@ -193,6 +198,7 @@ var NoteList = { replaceNewNotes: function(html) { $("#new-notes-list").html(html); + this.updateVotes(); }, /** @@ -205,6 +211,37 @@ var NoteList = { } else { $("#new-notes-list").append(html); } + this.updateVotes(); + }, + + /** + * Recalculates the votes and updates them (if they are displayed at all). + * + * Assumes all relevant notes are displayed (i.e. there are no more notes to + * load via getMore()). + * Might produce inaccurate results when not all notes have been loaded and a + * recalculation is triggered (e.g. when deleting a note). + */ + updateVotes: + function() { + var votes = $("#votes .votes"); + var notes = $("#notes-list, #new-notes-list").find(".note.vote"); + + // only update if there is a vote display + if (votes.size()) { + var upvotes = notes.filter(".upvote").size(); + var downvotes = notes.filter(".downvote").size(); + var votesCount = upvotes + downvotes; + var upvotesPercent = votesCount ? (100.0 / votesCount * upvotes) : 0; + var downvotesPercent = votesCount ? (100.0 - upvotesPercent) : 0; + + // change vote bar lengths + votes.find(".bar-success").css("width", upvotesPercent+"%"); + votes.find(".bar-danger").css("width", downvotesPercent+"%"); + // replace vote numbers + votes.find(".upvotes").text(votes.find(".upvotes").text().replace(/\d+/, upvotes)); + votes.find(".downvotes").text(votes.find(".downvotes").text().replace(/\d+/, downvotes)); + } } }; -- GitLab From 64e76a87aaddf76c3b3a487c5eb39e4490e4724f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 18 Sep 2012 09:17:55 +0300 Subject: [PATCH 3/3] Notes votes: use icons instead of borders. Removed unnecessary padding --- app/assets/stylesheets/common.scss | 12 ++++++++++++ app/assets/stylesheets/sections/notes.scss | 10 +--------- app/views/notes/_note.html.haml | 10 +++++++++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index fda8d54cec8..ffabdf8bfb7 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -158,6 +158,18 @@ span.update-author { padding: 6px; } } + + &.label-success { + background-color: #8D8; + color: #333; + text-shadow: 0 1px 1px white; + } + + &.label-error { + background-color: #D88; + color: #333; + text-shadow: 0 1px 1px white; + } } .event_label { diff --git a/app/assets/stylesheets/sections/notes.scss b/app/assets/stylesheets/sections/notes.scss index e14a0828fe9..267a9b4356c 100644 --- a/app/assets/stylesheets/sections/notes.scss +++ b/app/assets/stylesheets/sections/notes.scss @@ -73,15 +73,7 @@ /* mark vote notes */ .voting_notes .note { - padding: 8px 0 8px 12px; - &.upvote { - padding-left: 8px; - border-left: 4px solid #468847; - } - &.downvote { - padding-left: 8px; - border-left: 4px solid #B94A48; - } + padding: 8px 0; } .notes-status { diff --git a/app/views/notes/_note.html.haml b/app/views/notes/_note.html.haml index 23145f128a8..5234e55dcd0 100644 --- a/app/views/notes/_note.html.haml +++ b/app/views/notes/_note.html.haml @@ -6,8 +6,16 @@ %cite.cgray = time_ago_in_words(note.updated_at) ago + - if note.upvote? + %span.label.label-success + %i.icon-thumbs-up + \+1 + - if note.downvote? + %span.label.label-error + %i.icon-thumbs-down + \-1 - if(note.author_id == current_user.id) || can?(current_user, :admin_note, @project) - = link_to [@project, note], confirm: 'Are you sure?', method: :delete, remote: true, class: "cred delete-note btn very_small" do + = link_to [@project, note], confirm: 'Are you sure?', method: :delete, remote: true, class: "cred delete-note btn very_small" do %i.icon-trash Remove -- GitLab