Project

General

Profile

Download (1.84 KB) Statistics
| Branch: | Tag: | Revision:
bb9a1ad1 Paul Kelly
module PuppetclassesAndEnvironmentsHelper
5f029ed6 Daniel Lobato
def class_update_text(pcs, env)
bb9a1ad1 Paul Kelly
if pcs.empty?
bfbf7ed8 Lukas Zapletal
_("Empty environment")
bb9a1ad1 Paul Kelly
elsif pcs == ["_destroy_"]
bfbf7ed8 Lukas Zapletal
_("Deleted environment")
bb9a1ad1 Paul Kelly
elsif pcs.delete "_destroy_"
bfbf7ed8 Lukas Zapletal
_("Deleted environment %{env} and %{pcs}") % { :env => env, :pcs => pcs.to_sentence }
eb0834f5 Sebastian Gräßl
elsif pcs == ["_ignored_"]
_("Ignored environment")
bb9a1ad1 Paul Kelly
else
f8d94608 Amos Benari
pretty_print(pcs.is_a?(Hash) ? pcs.keys : pcs)
bb9a1ad1 Paul Kelly
end
end
22a2bcb1 Amos Benari
5f029ed6 Daniel Lobato
def import_proxy_select(hash)
2272591b Shlomi Zadok
select_action_button(_('Import'), {}, import_proxy_links(hash, true))
10ac0055 Neil Miao
end

2272591b Shlomi Zadok
def import_proxy_links(hash, import_env_text = false, classes = nil)
import_from_text = import_env_text ? _("Import environments from %s") : _("Import classes from %s")
3cdaa292 Dmitri Dolguikh
SmartProxy.with_features("Puppet").map do |proxy|
9d43fc71 Michael Moll
display_link_if_authorized(import_from_text % proxy.name, hash.merge(:proxy => proxy), {:class => classes})
10ac0055 Neil Miao
end.flatten
22a2bcb1 Amos Benari
end
f8d94608 Amos Benari
private
abd8f1d1 Daniel Lobato
5f029ed6 Daniel Lobato
def pretty_print(classes)
f8d94608 Amos Benari
hash = { }
classes.each do |klass|
if (mod = klass.gsub(/::.*/, ""))
hash[mod] ||= []
hash[mod] << klass
end
end
hash.keys.sort.map do |key|
958e87e6 ripcurld00d
num = hash[key].size
num_tag = "<span class='label label-info'>#{num}</span>".html_safe
71b46a72 Tomer Brisker
content_tag(:a, key, { :rel => "popover",
9bc1f99c Tomer Brisker
:data => { :content => hash[key].sort.join('<br>').html_safe,
:"original-title" => n_("%{name} has %{num_tag} class", "%{name} has %{num_tag} classes", num) % {:name => key, :num_tag => num_tag},
:trigger => "focus",
:container => 'body',
:html => true },
:role => 'button',
:tabindex => '-1' })
f8d94608 Amos Benari
end.to_sentence.html_safe
end
bb9a1ad1 Paul Kelly
end