X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/567c0270bc7665e630bf5012e0fd2953fea462ce..8ac83bf6c1464344721514494c8c50ad6679a5bc:/apps/workbench/app/helpers/application_helper.rb diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb index fe35bfe99e..1edd22ac33 100644 --- a/apps/workbench/app/helpers/application_helper.rb +++ b/apps/workbench/app/helpers/application_helper.rb @@ -13,13 +13,34 @@ module ApplicationHelper def human_readable_bytes_html(n) return h(n) unless n.is_a? Fixnum - raw = n.to_s - cooked = '' - while raw.length > 3 - cooked = ',' + raw[-3..-1] + cooked - raw = raw[0..-4] + + orders = { + 1 => "bytes", + 1024 => "KiB", + (1024*1024) => "MiB", + (1024*1024*1024) => "GiB", + (1024*1024*1024*1024) => "TiB" + } + + orders.each do |k, v| + sig = (n.to_f/k) + if sig >=1 and sig < 1024 + if v == 'bytes' + return "%i #{v}" % sig + else + return "%0.1f #{v}" % sig + end + end end - cooked = raw + cooked + + return h(n) + #raw = n.to_s + #cooked = '' + #while raw.length > 3 + # cooked = ',' + raw[-3..-1] + cooked + # raw = raw[0..-4] + #end + #cooked = raw + cooked end def resource_class_for_uuid(attrvalue, opts={}) @@ -32,17 +53,20 @@ module ApplicationHelper link_name = opts[:link_text] if !link_name link_name = link_uuid - opts[:friendly_name] - if opts[:friendly_name] and resource_class.column_names.include? "name" - link_name = resource_class.find(link_uuid).name - elsif opts[:friendly_name] and resource_class.column_names.include? "first_name" - link_name = "#{resource_class.find(link_uuid).first_name} #{resource_class.find(link_uuid).last_name}" - else - if opts[:with_class_name] - link_name = "#{resource_class.to_s} #{link_name}" + + if opts[:friendly_name] + begin + link_name = resource_class.find(link_uuid).friendly_link_name + rescue RuntimeError + # If that lookup failed, the link will too. So don't make one. + return attrvalue end end + if opts[:with_class_name] + link_name = "#{resource_class.to_s}: #{link_name}" + end end + style_opts[:class] = (style_opts[:class] || '') + ' nowrap' link_to link_name, { controller: resource_class.to_s.underscore.pluralize, action: 'show', id: link_uuid }, style_opts else attrvalue @@ -69,10 +93,10 @@ module ApplicationHelper "data-emptytext" => "none", "data-placement" => "bottom", "data-type" => input_type, - "data-resource" => object.class.to_s.underscore, "data-name" => attr, + "data-pk" => object.uuid, "data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore), - "data-original-title" => "Update #{attr.gsub '_', ' '}", + "data-title" => "Update #{attr.gsub '_', ' '}", :class => "editable" }.merge(htmloptions) end