1 module ApplicationHelper
3 controller.current_user
7 Rails.configuration.arvados_v1_base.gsub /https?:\/\/|\/arvados\/v1/,''
10 def render_content_from_database(markup)
11 raw RedCloth.new(markup).to_html
14 def human_readable_bytes_html(n)
15 return h(n) unless n.is_a? Fixnum
21 (1024*1024*1024) => "GiB",
22 (1024*1024*1024*1024) => "TiB"
27 if sig >=1 and sig < 1024
29 return "%i #{v}" % sig
31 return "%0.1f #{v}" % sig
40 # cooked = ',' + raw[-3..-1] + cooked
43 #cooked = raw + cooked
46 def resource_class_for_uuid(attrvalue, opts={})
47 ArvadosBase::resource_class_for_uuid(attrvalue, opts)
50 def link_to_if_arvados_object(attrvalue, opts={}, style_opts={})
51 if (resource_class = resource_class_for_uuid(attrvalue, opts))
52 link_uuid = attrvalue.is_a?(ArvadosBase) ? attrvalue.uuid : attrvalue
53 link_name = opts[:link_text]
57 if opts[:friendly_name]
59 friendly_name = resource_class.find(link_uuid).friendly_link_name
60 if friendly_name and not friendly_name.empty?
61 link_name = friendly_name
64 # If that lookup failed, the link will too. So don't make one.
68 if opts[:with_class_name]
69 link_name = "#{resource_class.to_s}: #{link_name}"
72 link_to link_name, { controller: resource_class.to_s.underscore.pluralize, action: 'show', id: link_uuid }, style_opts
78 def render_editable_attribute(object, attr, attrvalue=nil, htmloptions={})
79 attrvalue = object.send(attr) if attrvalue.nil?
80 return attrvalue if !object.attribute_editable? attr
83 case object.class.attribute_info[attr.to_sym].andand[:type]
85 input_type = 'textarea'
92 attrvalue = attrvalue.to_json if attrvalue.is_a? Hash or attrvalue.is_a? Array
94 link_to attrvalue.to_s, '#', {
95 "data-emptytext" => "none",
96 "data-placement" => "bottom",
97 "data-type" => input_type,
98 "data-resource" => object.class.to_s.underscore,
100 "data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore),
101 "data-original-title" => "Update #{attr.gsub '_', ' '}",