diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-11-19 18:12:17 +0200 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-11-19 18:12:17 +0200 |
commit | bdf4007cb7b18ed6892455d0a9adf78476188563 (patch) | |
tree | d9db5467ff74c4387777e15a9f0a0bbee6f3e81a | |
parent | 671a49cfd53230b57acf579a609bab958e066982 (diff) | |
download | gitlab-ce-bdf4007cb7b18ed6892455d0a9adf78476188563.tar.gz |
adressing comments
-rw-r--r-- | app/assets/javascripts/awards_handler.coffee | 6 | ||||
-rw-r--r-- | app/controllers/projects/notes_controller.rb | 12 | ||||
-rw-r--r-- | app/models/note.rb | 5 | ||||
-rw-r--r-- | app/services/notes/create_service.rb | 4 | ||||
-rw-r--r-- | app/views/votes/_votes_block.html.haml | 14 |
5 files changed, 21 insertions, 20 deletions
diff --git a/app/assets/javascripts/awards_handler.coffee b/app/assets/javascripts/awards_handler.coffee index f5b9adbe9e2..ae42e390c43 100644 --- a/app/assets/javascripts/awards_handler.coffee +++ b/app/assets/javascripts/awards_handler.coffee @@ -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() diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index 8159cc50838..263b8b8d94e 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -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 } diff --git a/app/models/note.rb b/app/models/note.rb index 39645f8f1ad..e30be444eb5 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -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 diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index dbff58dfb9c..25a985df4d8 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -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 diff --git a/app/views/votes/_votes_block.html.haml b/app/views/votes/_votes_block.html.haml index 04e3b5a3814..7eb27c12d33 100644 --- a/app/views/votes/_votes_block.html.haml +++ b/app/views/votes/_votes_block.html.haml @@ -1,15 +1,15 @@ .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) |