BigW Consortium Gitlab

notes_helper.rb 2.14 KB
Newer Older
1
module NotesHelper
2
  # Helps to distinguish e.g. commit notes in mr notes list
3
  def note_for_main_target?(note)
4
    (@noteable.class.name == note.noteable_type && !note.for_diff_line?)
5 6
  end

7 8 9
  def note_target_fields(note)
    hidden_field_tag(:target_type, note.noteable.class.name.underscore) +
    hidden_field_tag(:target_id, note.noteable.id)
10 11
  end

12 13 14 15
  def note_editable?(note)
    note.editable? && can?(current_user, :admin_note, note)
  end

16
  def link_to_commit_diff_line_note(note)
Riyad Preukschas committed
17
    if note.for_commit_diff_line?
Vinnie Okada committed
18 19 20 21 22
      link_to(
        "#{note.diff_file_name}:L#{note.diff_new_line}",
        namespace_project_commit_path(@project.namespace, @project,
                                      note.noteable, anchor: note.line_code)
      )
Riyad Preukschas committed
23
    end
24
  end
25

26 27 28 29 30 31 32 33
  def noteable_json(noteable)
    {
      id: noteable.id,
      class: noteable.class.name,
      resources: noteable.class.table_name,
      project_id: noteable.project.id,
    }.to_json
  end
34

35
  def link_to_new_diff_note(line_code, line_type = nil)
36 37 38 39 40 41 42 43 44 45 46
    discussion_id = Note.build_discussion_id(
      @comments_target[:noteable_type],
      @comments_target[:noteable_id] || @comments_target[:commit_id],
      line_code
    )

    data = {
      noteable_type: @comments_target[:noteable_type],
      noteable_id:   @comments_target[:noteable_id],
      commit_id:     @comments_target[:commit_id],
      line_code:     line_code,
47 48
      discussion_id: discussion_id,
      line_type:     line_type
49 50
    }

51 52 53
    button_tag(class: 'btn add-diff-note js-add-diff-note-button',
               data: data,
               title: 'Add a comment to this line') do
54
      icon('comment-o')
55
    end
56
  end
57

58
  def link_to_reply_diff(note, line_type = nil)
59 60
    return unless current_user

61 62 63 64 65
    data = {
      noteable_type: note.noteable_type,
      noteable_id:   note.noteable_id,
      commit_id:     note.commit_id,
      line_code:     note.line_code,
66 67
      discussion_id: note.discussion_id,
      line_type:     line_type
68 69
    }

Drew Blessing committed
70
    button_tag class: 'btn btn-nr reply-btn js-discussion-reply-button',
71
               data: data, title: 'Add a reply' do
72
      link_text = icon('comment')
Ciro Santilli committed
73 74
      link_text << ' Reply'
    end
75
  end
76
end