BigW Consortium Gitlab

notes_helper.rb 1.96 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.diff_note?
5 6
  end

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

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

18 19 20 21 22 23 24 25
  def noteable_json(noteable)
    {
      id: noteable.id,
      class: noteable.class.name,
      resources: noteable.class.table_name,
      project_id: noteable.project.id,
    }.to_json
  end
26

27
  def link_to_new_diff_note(line_code, line_type = nil)
28
    discussion_id = LegacyDiffNote.build_discussion_id(
29 30 31 32 33 34 35 36 37
      @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],
38
      line_type:     line_type,
39
      line_code:     line_code,
40 41
      note_type:     LegacyDiffNote.name,
      discussion_id: discussion_id
42 43
    }

44 45 46
    button_tag(class: 'btn add-diff-note js-add-diff-note-button',
               data: data,
               title: 'Add a comment to this line') do
47
      icon('comment-o')
48
    end
49
  end
50

51
  def link_to_reply_discussion(note, line_type = nil)
52 53
    return unless current_user

54 55 56 57
    data = {
      noteable_type: note.noteable_type,
      noteable_id:   note.noteable_id,
      commit_id:     note.commit_id,
58 59
      discussion_id: note.discussion_id,
      line_type:     line_type
60 61
    }

62 63 64 65 66 67 68
    if note.diff_note?
      data.merge!(
        line_code: note.line_code,
        note_type: LegacyDiffNote.name
      )
    end

Annabel Dunstone committed
69 70
    button_tag 'Reply...', class: 'btn btn-text-field js-discussion-reply-button',
                           data: data, title: 'Add a reply'
71
  end
72
end