Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
71a8aace001c
Unverified
Commit
00056c82
authored
Dec 27, 2013
by
Dmitriy Zaporozhets
Browse files
Update votes ferom comments dynamically
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
bf4c149ef362
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/assets/javascripts/notes.js.coffee
View file @
71a8aace
...
...
@@ -232,6 +232,7 @@ class Notes
###
addNote
:
(
xhr
,
note
,
status
)
=>
@
renderNote
(
note
)
@
updateVotes
()
###
Called in response to the new note form being submitted
...
...
@@ -425,4 +426,7 @@ class Notes
form
=
$
(
e
.
target
).
closest
(
".js-discussion-note-form"
)
@
removeDiscussionNoteForm
(
form
)
updateVotes
:
->
(
new
NotesVotes
).
updateVotes
()
@
Notes
=
Notes
app/assets/javascripts/notes_votes.js.coffee
0 → 100644
View file @
71a8aace
class
NotesVotes
updateVotes
:
->
votes
=
$
(
"#votes .votes"
)
notes
=
$
(
"#notes-list .note .vote"
)
# only update if there is a vote display
if
votes
.
size
()
upvotes
=
notes
.
filter
(
".upvote"
).
size
()
downvotes
=
notes
.
filter
(
".downvote"
).
size
()
votesCount
=
upvotes
+
downvotes
upvotesPercent
=
(
if
votesCount
then
(
100.0
/
votesCount
*
upvotes
)
else
0
)
downvotesPercent
=
(
if
votesCount
then
(
100.0
-
upvotesPercent
)
else
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
)
@
NotesVotes
=
NotesVotes
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment