Class: SidebarHelper::SidebarGenerator

Inherits:
Object
  • Object
show all
Defined in:
frontend/app/helpers/sidebar_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(form, opts) ⇒ SidebarGenerator

Returns a new instance of SidebarGenerator.



5
6
7
8
9
10
# File 'frontend/app/helpers/sidebar_helper.rb', line 5

def initialize(form, opts)
  ensure_properties(opts, [:record, :record_type])

  @form = form
  @opts = opts
end

Instance Method Details

#ensure_properties(opts, properties) ⇒ Object



13
14
15
16
17
# File 'frontend/app/helpers/sidebar_helper.rb', line 13

def ensure_properties(opts, properties)
  properties.each do |p|
    raise "Missing required property: #{p}" if !opts[p]
  end
end

#render_for_view_and_edit(opts) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'frontend/app/helpers/sidebar_helper.rb', line 20

def render_for_view_and_edit(opts)
  ensure_properties(opts, [:subrecord_type, :property])

  record = @opts[:record]
  property = opts[:property]
  sidebar_heading = opts[:sidebar_heading]
  sidebar_children = opts[:sidebar_children] || []

  if @form.controller.action_name != "show" || property == :none || !record[property].blank? || (sidebar_heading == true && !sidebar_children.map { |c| record[c]}.flatten.compact.blank?)
    render_entry(opts)
  end
end

#render_for_view_only(opts) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'frontend/app/helpers/sidebar_helper.rb', line 34

def render_for_view_only(opts)
  ensure_properties(opts, [:subrecord_type, :property])

  record = @opts[:record]
  property = opts[:property]
  sidebar_heading = opts[:sidebar_heading]

  if @form.controller.action_name == "show" && (!record[property].blank? || property == :none || sidebar_heading == true)
    render_entry(opts)
  end
end

#show_external_ids_sidebar_entry?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
# File 'frontend/app/helpers/sidebar_helper.rb', line 47

def show_external_ids_sidebar_entry?
  record = @opts[:record]

  @form.controller.action_name == 'show' ||
    @form.controller.action_name != 'show' && !ASUtils.wrap(record['external_ids']).empty?
end