Module: ActiveAdmin::Annotations::PanelHelper

Defined in:
app/helpers/active_admin/annotations/panel_helper.rb

Instance Method Summary collapse

Instance Method Details

#activeadmin_annotations_panel(subject:, field:, context:, context_digest: nil, context_panels: [], categories: nil, category_label: nil, content: nil, content_revision_enabled: nil, content_revision_version: nil, latest_content_revision_version: nil, content_stale: false, advance_review_url: nil, annotations: nil, review: nil, &content_block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/active_admin/annotations/panel_helper.rb', line 5

def activeadmin_annotations_panel(
  subject:,
  field:,
  context:,
  context_digest: nil,
  context_panels: [],
  categories: nil,
  category_label: nil,
  content: nil,
  content_revision_enabled: nil,
  content_revision_version: nil,
  latest_content_revision_version: nil,
  content_stale: false,
  advance_review_url: nil,
  annotations: nil,
  review: nil,
  &content_block
)
  rendered_content = content.presence || capture(&content_block)
  reviewer = current_activeadmin_annotations_reviewer
  unless reviewer
    return render partial: "active_admin/annotations/read_only_content",
      locals: {content: rendered_content}
  end

  revision_enabled = content_revision_enabled.nil? ? ContentRevision.enabled_for?(subject) : content_revision_enabled
  review ||= ReviewService.find_or_sync_review!(
    subject: subject,
    reviewer: reviewer,
    context: context,
    context_digest: context_digest,
    content_revision_version: content_revision_version || 0,
    latest_content_revision_version: latest_content_revision_version || content_revision_version || 0,
    content_revision_enabled: revision_enabled
  )
  annotations ||= annotations_for(review:, field:, revision_enabled:)
  stale_message = stale_message_for(
    review: review,
    revision_enabled: revision_enabled,
    pinned_version: review.content_revision_version,
    latest_version: latest_content_revision_version || review.content_revision_version
  )

  render partial: "active_admin/annotations/panel",
    locals: {
      subject: subject,
      field: field.to_s,
      review: review,
      annotations: annotations,
      context_panels: context_panels,
      categories: categories || ActiveAdmin::Annotations.categories,
      category_label: category_label || ActiveAdmin::Annotations.category_label,
      content: rendered_content,
      content_revision_enabled: revision_enabled,
      content_revision_version: review.content_revision_version,
      latest_content_revision_version: latest_content_revision_version || review.content_revision_version,
      content_revision_label: ContentRevision.version_label(review.content_revision_version),
      content_stale: content_stale || review.context_stale?,
      stale_message: stale_message,
      advance_review_url: advance_review_url
    }
end