Commit bdf4007c authored by Valery Sizov's avatar Valery Sizov

adressing comments

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