Commit bdf4007c authored by Valery Sizov's avatar Valery Sizov

adressing comments

parent 671a49cf
...@@ -79,11 +79,11 @@ class @AwardsHandler ...@@ -79,11 +79,11 @@ class @AwardsHandler
postEmoji: (emoji, callback) -> postEmoji: (emoji, callback) ->
$.post @post_emoji_url, { $.post @post_emoji_url, { note: {
emoji: emoji note: emoji
noteable_type: @noteable_type noteable_type: @noteable_type
noteable_id: @noteable_id noteable_id: @noteable_id
},(data) -> }},(data) ->
if data.ok if data.ok
callback.call() callback.call()
......
...@@ -59,21 +59,21 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -59,21 +59,21 @@ class Projects::NotesController < Projects::ApplicationController
end end
def award_toggle def award_toggle
noteable = params[:noteable_type] == "Issue" ? Issue : MergeRequest noteable = note_params[:noteable_type] == "issue" ? Issue : MergeRequest
noteable = noteable.find(params[:noteable_id]) noteable = noteable.find_by!(id: note_params[:noteable_id], project: project)
data = { data = {
noteable: noteable,
author: current_user, author: current_user,
is_award: true, is_award: true,
note: params[:emoji] note: note_params[:note]
} }
note = project.notes.find_by(data) note = noteable.notes.find_by(data)
if note if note
note.destroy note.destroy
else else
project.notes.create(data) Notes::CreateService.new(project, current_user, note_params).execute
end end
render json: { ok: true } render json: { ok: true }
......
...@@ -40,13 +40,14 @@ class Note < ActiveRecord::Base ...@@ -40,13 +40,14 @@ class Note < ActiveRecord::Base
delegate :name, :email, to: :author, prefix: true delegate :name, :email, to: :author, prefix: true
validates :note, :project, presence: true validates :note, :project, presence: true
validates :note, uniqueness: { scope: [:author, :noteable_type, :noteable_id] }, if: ->(n) { n.is_award }
validates :line_code, format: { with: /\A[a-z0-9]+_\d+_\d+\Z/ }, allow_blank: true validates :line_code, format: { with: /\A[a-z0-9]+_\d+_\d+\Z/ }, allow_blank: true
# Attachments are deprecated and are handled by Markdown uploader # Attachments are deprecated and are handled by Markdown uploader
validates :attachment, file_size: { maximum: :max_attachment_size } validates :attachment, file_size: { maximum: :max_attachment_size }
validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' } validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' }
validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' } validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' }
validates :author, presence: true, if: ->(n) { n.is_award } validates :author, presence: true
mount_uploader :attachment, AttachmentUploader mount_uploader :attachment, AttachmentUploader
...@@ -102,7 +103,7 @@ class Note < ActiveRecord::Base ...@@ -102,7 +103,7 @@ class Note < ActiveRecord::Base
end end
def grouped_awards def grouped_awards
select(:note).distinct.map do |note| awards.select(:note).distinct.map do |note|
[ note.note, where(note: note.note) ] [ note.note, where(note: note.note) ]
end end
end end
......
...@@ -35,11 +35,11 @@ module Notes ...@@ -35,11 +35,11 @@ module Notes
end end
def contains_emoji_only?(note) def contains_emoji_only?(note)
note =~ /\A:[-_+[:alnum:]]*:\s?\z/ note =~ /\A:?[-_+[:alnum:]]*:?\s?\z/
end end
def emoji_name(note) def emoji_name(note)
note.match(/\A:([-_+[:alnum:]]*):\s?/)[1] note.match(/\A:?([-_+[:alnum:]]*):?\s?/)[1]
end end
end end
end end
.awards.votes-block .awards.votes-block
- votable.notes.awards.grouped_awards.each do | note | - votable.notes.awards.grouped_awards.each do |emoji, notes|
.award{class: (note_active_class(note.last, current_user)), title: emoji_author_list(note.last, current_user)} .award{class: (note_active_class(notes, current_user)), title: emoji_author_list(notes, current_user)}
.icon{"data-emoji" => "#{note.first}"} .icon{"data-emoji" => "#{emoji}"}
= image_tag url_to_emoji(note.first), height: "20px", width: "20px" = image_tag url_to_emoji(emoji), height: "20px", width: "20px"
.counter .counter
= note.last.count = notes.count
- if current_user - if current_user
.dropdown.awards-controls .dropdown.awards-controls
%a.add-award{"data-toggle" => "dropdown", "data-target" => "#", "href" => "#"} %a.add-award{"data-toggle" => "dropdown", "data-target" => "#", "href" => "#"}
= icon('plus-square-o') = icon('smile-o')
%ul.dropdown-menu.awards-menu %ul.dropdown-menu.awards-menu
- emoji_list.each do |emoji| - emoji_list.each do |emoji|
%li{"data-emoji" => "#{emoji}"}= image_tag url_to_emoji(emoji), height: "20px", width: "20px" %li{"data-emoji" => "#{emoji}"}= image_tag url_to_emoji(emoji), height: "20px", width: "20px"
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
- if current_user - if current_user
:coffeescript :coffeescript
post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}" post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}"
noteable_type = "#{votable.class}" noteable_type = "#{votable.class.name.underscore}"
noteable_id = "#{votable.id}" noteable_id = "#{votable.id}"
window.awards_handler = new AwardsHandler(post_emoji_url, noteable_type, noteable_id) window.awards_handler = new AwardsHandler(post_emoji_url, noteable_type, noteable_id)
......
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