Module: ContainersHelper

Defined in:
app/helpers/containers_helper.rb

Instance Method Summary collapse

Instance Method Details



106
107
108
# File 'app/helpers/containers_helper.rb', line 106

def add_or_move_to_container_link(object)
  link_to( (object.contained? ? 'Move to another' : 'Add to' ) + ' container', containerize_collection_object_path(object) )
end

#container_autocomplete_tag(container) ⇒ Object



45
46
47
# File 'app/helpers/containers_helper.rb', line 45

def container_autocomplete_tag(container)
  container_tag(container)
end

#container_collection_item_count(container) ⇒ Object



66
67
68
69
70
# File 'app/helpers/containers_helper.rb', line 66

def container_collection_item_count(container)
  return (:em, 'no container provided') if container.blank?
  v = container.all_contained_objects.count
  v == 0 ? 'empty' : v
end


26
27
28
29
# File 'app/helpers/containers_helper.rb', line 26

def container_link(container)
  return nil if container.nil?
  link_to(container_tag(container.metamorphosize).html_safe, container.metamorphosize)
end

#container_location(object) ⇒ String?

Returns a string representation of the containers location, includes disposition of the containers if provided.

Returns:

  • (String, nil)

    a string representation of the containers location, includes disposition of the containers if provided



74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/containers_helper.rb', line 74

def container_location(object)
  return nil if !object.containable?
  parts = []
  object.enclosing_containers.each do |c|
    s = c.name.blank? ? c.class.class_name : c.name
    s += " [#{c.disposition}]" if !c.disposition.blank?
    parts.push s
  end
  parts.join('; ')
end


55
56
57
58
59
# File 'app/helpers/containers_helper.rb', line 55

def container_parent_link(container)
  return nil if container.container_item.nil?
  return nil if container.container_item.parent.nil?
  link_to(container.container_item.parent.contained_object)
end

#container_parent_tag(container) ⇒ Object



49
50
51
52
53
# File 'app/helpers/containers_helper.rb', line 49

def container_parent_tag(container)
  return nil if container.container_item.nil?
  return nil if container.container_item.parent.nil?
  container_tag(container.container_item.parent.contained_object)
end

#container_tag(container) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/containers_helper.rb', line 3

def container_tag(container)
  return nil if container.nil?
  a = []

  a.push identifier_short_tag(container.identifiers.first)

  if container.name
    a.push container.class.name
  else
    a.push tag.i container.type, class: [:feedback, 'feedback-thin', 'feedback-secondary']
  end

  a.push tag.span container.container_items.count.to_s + ' inside', class: [:feedback, 'feedback-thin', 'feedback-info']

  if container.print_label
    a.push tag.span container.print_label, class: [:feedback, 'feedback-thin', 'feedback-light']
  end

  a.push tag.span 'id: ' + container.to_param

  a.compact.join(' ').html_safe
end

#container_typesObject



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/helpers/containers_helper.rb', line 110

def container_types
  r = []
  Container.descendants.each do |t|
    r.push({
      type: t.name,
      name: t.class_name,
      dimensions: t.dimensions.presence,
      valid_parents: t.valid_parents.presence
    })
  end
  r.sort!{|a,b| a[:type] <=> b[:type]}
  r
end

#containers_search_formObject



62
63
64
# File 'app/helpers/containers_helper.rb', line 62

def containers_search_form
  render('/containers/quick_search_form')
end

#draw_container_tag(container) ⇒ Object

TODO: move content to containers/_card



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/helpers/containers_helper.rb', line 86

def draw_container_tag(container)
  return nil if container.nil?

  (:div, class: :draw_container) do
    (:h2) do
      'Container details'
    end +

    (:h3) do
      container_tag(container)
    end +

    (:div) do
      (:ol, class: [:object_tag_list]) do
        container.container_items.collect{ |a| (:li, container_item_tag(a)) }.join('').html_safe
      end
    end
  end
end

#label_for_container(container) ⇒ Object



31
32
33
34
35
36
37
# File 'app/helpers/containers_helper.rb', line 31

def label_for_container(container)
  return nil if container.nil?
  [ label_for_identifier(container.identifiers.first),
    container.name,
    container.print_label,
  ].compact.join(': ').html_safe
end

#label_for_container_container(container) ⇒ Object

TODO: Clean, refactor



40
41
42
43
# File 'app/helpers/containers_helper.rb', line 40

def label_for_container_container(container)
  return nil if container.nil?
  container.name || container.print_label || label_for_identifier(container.identifiers.first) || container.id
end