Module: ForemanDatacenter::ApplicationHelper

Defined in:
app/helpers/foreman_datacenter/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#associated_objects(object) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 51

def associated_objects(object)
  case object
  when 'site'
    '(Racks, RackGroups, Devices, Interfaces, Ports, etc)'
  when 'rack_group'
    '(Racks, Devices, Interfaces, Ports, etc)'
  when 'rack'
    '(Devices, Interfaces, Ports, etc)'
  when 'platform'
    '(Devices, Interfaces, Ports, etc)'
  when 'device'
    '(Interfaces, Ports, etc)'
  when 'device_role'
    '(Devices)'
  when 'device_type'
    '(Devices)'
  when 'manufacturer'
    '(DeviceTypes, Templates, Devices, Interfaces, Port)'
  else
    '(...)'
  end
end

#display_fake_delete_if_authorized(options = {}, html_options = {}, as = 'button') ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 25

def display_fake_delete_if_authorized(options = {}, html_options = {}, as = 'button')
  text = options.delete(:text) || _("Delete")
  method = options.delete(:method) || :delete
  options = {:auth_action => :destroy}.merge(options)
  html_options = {}.merge(html_options)
  if authorized_for(options)
    link_to(text, options, html_options)
  else
    ""
  end
end

#documentation_url(section = "", options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 12

def documentation_url(section = "", options = {})
  if request.env['PATH_INFO'].include?("datacenter")
	root_url = options[:root_url] || "https://github.com/theforeman/foreman_datacenter/wiki"
	if section.empty?
	  "https://github.com/theforeman/foreman_datacenter/wiki"
	else
	  root_url + section
	end
  else
	super
  end
end

#help_buttonObject



4
5
6
7
8
9
10
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 4

def help_button
  if request.env['PATH_INFO'].include?("datacenter")
	link_to(_("Help"), { :action => "welcome" }, { :class => 'btn btn-default' }) if File.exist?("#{ForemanDatacenter::Engine.root}/app/views/foreman_datacenter/#{controller_name}/welcome.html.erb")
  else
	super
  end
end

#muted_text(text, *ct) ⇒ Object



47
48
49
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 47

def muted_text(text, *ct)
  recursive_tags(text, ct)
end

#object_name(object) ⇒ Object



79
80
81
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 79

def object_name(object)
  object.model_name.element
end

#object_path(object) ⇒ Object



74
75
76
77
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 74

def object_path(object)
  object_name = object.model_name.plural.gsub("foreman_datacenter_","")
  "/datacenter/#{object_name}/#{object.id}"
end

#recursive_tags(text, tags) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 37

def recursive_tags(text, tags)
  return _("#{text}") if tags.empty?
  ct = tags[0].parameterize.underscore.to_sym
  if tags.length == 1
    (ct, _("#{text}"), class: 'text-muted')
  else
    (ct, recursive_tags(text, tags.drop(1)))
  end
end

#search_params(objects, parameter, sp) ⇒ Object



83
84
85
86
87
88
89
90
# File 'app/helpers/foreman_datacenter/application_helper.rb', line 83

def search_params(objects, parameter, sp)
  str = ""
  objects.each_with_index do |o, i|
    str += ' or ' if i > 0
    str += "#{sp}=#{o.send(parameter)}"
  end
  return str
end