Commit 2aafd7cf authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'update-votes-when-adding-notes' of...

Merge branch 'update-votes-when-adding-notes' of https://github.com/riyad/gitlabhq into riyad-update-votes-when-adding-notes
parents 249cb19d 6aebb76b
...@@ -21,15 +21,18 @@ var NoteList = { ...@@ -21,15 +21,18 @@ var NoteList = {
this.getContent(); this.getContent();
$("#notes-list, #new-notes-list").on("ajax:success", ".delete-note", function() { $("#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(){ $(".note-form-holder").on("ajax:before", function(){
$(".submit_note").disable() $(".submit_note").disable();
}) })
$(".note-form-holder").on("ajax:complete", function(){ $(".note-form-holder").on("ajax:complete", function(){
$(".submit_note").enable() $(".submit_note").enable();
}) })
disableButtonIfEmptyField(".note-text", ".submit_note"); disableButtonIfEmptyField(".note-text", ".submit_note");
...@@ -159,6 +162,8 @@ var NoteList = { ...@@ -159,6 +162,8 @@ var NoteList = {
if (!this.reversed) { if (!this.reversed) {
this.initRefreshNew(); this.initRefreshNew();
} }
// make sure we are up to date
this.updateVotes();
}, },
...@@ -198,6 +203,7 @@ var NoteList = { ...@@ -198,6 +203,7 @@ var NoteList = {
replaceNewNotes: replaceNewNotes:
function(html) { function(html) {
$("#new-notes-list").html(html); $("#new-notes-list").html(html);
this.updateVotes();
}, },
/** /**
...@@ -210,6 +216,37 @@ var NoteList = { ...@@ -210,6 +216,37 @@ var NoteList = {
} else { } else {
$("#new-notes-list").append(html); $("#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));
}
} }
}; };
......
...@@ -71,6 +71,19 @@ ...@@ -71,6 +71,19 @@
border-top: 1px solid #eee; 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 { .notes-status {
margin: 18px; margin: 18px;
} }
......
...@@ -6,4 +6,12 @@ module NotesHelper ...@@ -6,4 +6,12 @@ module NotesHelper
def loading_new_notes? def loading_new_notes?
params[:loading_new].present? params[:loading_new].present?
end end
def note_vote_class(note)
if note.upvote?
"vote upvote"
elsif note.downvote?
"vote downvote"
end
end
end end
...@@ -61,4 +61,4 @@ ...@@ -61,4 +61,4 @@
= markdown @issue.description = 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"
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
%i.icon-list-alt %i.icon-list-alt
Diff 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") = render("notes/notes_with_form", tid: @merge_request.id, tt: "merge_request")
.merge-request-diffs .merge-request-diffs
= render "merge_requests/show/diffs" if @diffs = render "merge_requests/show/diffs" if @diffs
......
%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" = image_tag gravatar_icon(note.author.email), class: "avatar s32"
%div.note-author %div.note-author
%strong= note.author_name %strong= note.author_name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment