Project

General

Profile

Download (2.29 KB) Statistics
| Branch: | Tag: | Revision:

foreman_docker / app / helpers / containers_helper.rb @ 5d7016fd

1
module ContainersHelper
2
  def managed_icon(container, resource)
3
    icon_text(managed?(container, resource) ? 'check' : 'unchecked')
4
  end
5

    
6
  def managed?(container, resource)
7
    uuids_in_resource(resource).include? container.identity
8
  end
9

    
10
  def uuids_in_resource(resource)
11
    @uuids_in_resource ||= {}
12
    @uuids_in_resource[resource.id] ||= Container.where(:compute_resource_id => resource.id)
13
                                        .pluck(:uuid)
14
  end
15

    
16
  def link_to_container(container, resource)
17
    link_to_if_authorized container.name[1..-1].titleize,
18
                          container_link_hash(container, resource)
19
  end
20

    
21
  def link_to_taxonomies(taxonomies)
22
    taxonomies.map do |taxonomy|
23
      link_to(taxonomy)
24
    end.join(' ')
25
  end
26

    
27
  def container_link_hash(container, resource)
28
    if managed?(container, resource)
29
      hash_for_container_path(:id => Container.find_by_uuid(container.identity).id)
30
    else
31
      hash_for_compute_resource_vm_path(:compute_resource_id => resource,
32
                                        :id                  => container.identity)
33
    end
34
  end
35

    
36
  def container_title_actions(container)
37
    @compute_resource = container.compute_resource
38
    title_actions(
39
        button_group(
40
          link_to(_('Commit'), '#commit-modal', :'data-toggle' => 'modal')
41
        ),
42
        button_group(vm_power_action(container.in_fog)),
43
        button_group(
44
          display_delete_if_authorized(
45
            hash_for_container_path(:id => container.id)
46
                                    .merge(:auth_object => container,
47
                                           :auth_action => 'destroy',
48
                                           :authorizer  => authorizer),
49
            :confirm     => _("Delete %s?") % container.name)
50
        )
51
    )
52
  end
53

    
54
  def auto_complete_docker_search(name, val, options = {})
55
    addClass options, 'form-control'
56
    text_field_tag(name, val, options)
57
  end
58

    
59
  def hub_url(image)
60
    if image['is_official']
61
      "https://registry.hub.docker.com/_/#{image['name']}"
62
    else
63
      "https://registry.hub.docker.com/u/#{image['name']}"
64
    end
65
  end
66

    
67
  # Compatibility fixes - to be removed once 1.7 compatibility is no longer required
68
  if SETTINGS[:version].to_s.to_f <= 1.7
69
    def trunc_with_tooltip(text, length = 32)
70
      trunc(text, length)
71
    end
72
  end
73
end