Skip to content

Commit

Permalink
Use new methods render text and image in quadicon
Browse files Browse the repository at this point in the history
  • Loading branch information
karelhala committed Dec 13, 2017
1 parent 92e137b commit 8a42d62
Showing 1 changed file with 56 additions and 12 deletions.
68 changes: 56 additions & 12 deletions app/helpers/quadicon_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def img_tag_reflection
end

# Renders a quadicon for PhysicalServer
#
# TODO: use quadicon decorator
def render_physical_server_quadicon(item, options)
output = []
if settings(:quadicons, :physical_server)
Expand Down Expand Up @@ -472,7 +472,7 @@ def render_service_quadicon(item, options)
end

# Renders a quadicon for resource_pools
#
# TODO: use quadicon decorator
def render_resource_pool_quadicon(item, options)
img = item.vapp ? "100/vapp.png" : "100/resource_pool.png"
output = []
Expand Down Expand Up @@ -502,7 +502,7 @@ def currentstate_icon(state)
end

# Renders a quadicon for hosts
#
# TODO: use quadicon decorator
def render_host_quadicon(item, options)
output = []

Expand Down Expand Up @@ -546,6 +546,55 @@ def db_for_quadicon
end
end

POSITION_MAPPER = {
:top_left => "a72",
:top_right => "b72",
:bottom_left => "c72",
:bottom_right => "d72",
}.freeze

# Render text inside quadicon, every text with more than 3 characters will use smaller font.
# Returns text inside html element
#
# ==== Attributes
#
# * +text+ - text to render inside quad
# * +position+ - where to render text
def render_quad_text(text, position)
font_size = text.to_s.size > 2 ? "font-size: 12px;" : ""
flobj_p_simple(position, text, font_size)
end

# Render images and fonticons.
# Returns img string inside html element.
#
# ==== Attributes
#
# * +img+ - either URL to img or fonticon text
# * +position+ - where to render image
# * +type+ - default to nil, if small given it will use :flobj_img_smal for others it uses :flobj_img_simple
def render_quad_image(img, position, type = nil)
method = type == "small" ? method(:flobj_img_small) : method(:flobj_img_simple)
method.call(img, position)
end

# Transforms quadicon hash to array of strings with their location in quadicon.
# Returns array of strings
#
# ==== Attributes
#
# * +quadicon+ - quadicon hash
def transform_quadicon(quadicon)
quadicon.map do |key, value|
if value.try(:[], :text)
render_quad_text(value[:text], POSITION_MAPPER[key])
elsif value.try(:[], :fileicon) || value.try(:[], :img)
render_quad_image(value.try(:[], :fileicon) || value.try(:[], :img), POSITION_MAPPER[key], value.try(:type))
else
""
end
end
end

# Renders a quadicon for ext_management_systems
#
Expand All @@ -555,12 +604,7 @@ def render_ext_management_system_quadicon(item, options)

if settings(:quadicons, db_for_quadicon) && quadicon
output << flobj_img_simple("layout/base.svg")
top_left = quadicon[:top_left][:text]
top_right = quadicon[:top_right][:text]
output << flobj_p_simple("a72", top_left, top_left.to_s.size > 2 ? "font-size: 12px;" : "")
output << flobj_p_simple("b72", top_right, top_right.to_s.size > 2 ? "font-size: 12px;" : "")
output << flobj_img_simple(quadicon[:bottom_left][:fileicon], "c72")
output << flobj_img_simple(quadicon[:bottom_right][:img], "d72")
output.concat(transform_quadicon(quadicon))
output << flobj_img_simple('100/shield.png', "g72") unless item.get_policies.empty?
else
output << flobj_img_simple("layout/base-single.svg")
Expand All @@ -585,7 +629,7 @@ def render_ext_management_system_quadicon(item, options)
end

# Renders quadicon for ems_clusters
#
# TODO: use quadicon decorator
def render_ems_cluster_quadicon(item, options)
output = []

Expand Down Expand Up @@ -704,7 +748,7 @@ def img_for_health_state(item)
end

# Renders a storage quadicon
#
# TODO: use quadicon decorator
def render_storage_quadicon(item, options)
output = []

Expand Down Expand Up @@ -771,7 +815,7 @@ def quadicon_storage_img_options(item)
end

# Renders a vm quadicon
#
# TODO: use quadicon decorator
def render_vm_or_template_quadicon(item, options)
output = []

Expand Down

0 comments on commit 8a42d62

Please sign in to comment.