From 8a42d6244fc88127f91e02bf31d5b4f1896db35c Mon Sep 17 00:00:00 2001 From: Karel Hala Date: Wed, 13 Dec 2017 14:55:52 +0100 Subject: [PATCH] Use new methods render text and image in quadicon --- app/helpers/quadicon_helper.rb | 68 ++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/app/helpers/quadicon_helper.rb b/app/helpers/quadicon_helper.rb index 6a52db75e22c..2555c97d2fe7 100644 --- a/app/helpers/quadicon_helper.rb +++ b/app/helpers/quadicon_helper.rb @@ -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) @@ -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 = [] @@ -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 = [] @@ -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 # @@ -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") @@ -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 = [] @@ -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 = [] @@ -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 = []