show full uuid even in uuid column on index pages
[arvados.git] / apps / workbench / app / helpers / application_helper.rb
1 module ApplicationHelper
2   def current_user
3     controller.current_user
4   end
5
6   def render_content_from_database(markup)
7     raw RedCloth.new(markup).to_html
8   end
9
10   def human_readable_bytes_html(n)
11     return h(n) unless n.is_a? Fixnum
12     raw = n.to_s
13     cooked = ''
14     while raw.length > 3
15       cooked = ',' + raw[-3..-1] + cooked
16       raw = raw[0..-4]
17     end
18     cooked = raw + cooked
19   end
20
21   def link_to_if_arvados_object(attrvalue, opts={}, style_opts={})
22     if (resource_class = ArvadosBase::resource_class_for_uuid(attrvalue, opts))
23       link_uuid = attrvalue.is_a?(ArvadosBase) ? attrvalue.uuid : attrvalue
24       link_name = opts[:link_text]
25       if !link_name
26         link_name = link_uuid
27         if opts[:with_class_name]
28           link_name = "#{resource_class.to_s} #{link_name}"
29         end
30         style_opts = style_opts.merge(style: 'font-family: monospace')
31       end
32       link_to link_name, { controller: resource_class.to_s.underscore.pluralize, action: 'show', id: link_uuid }, style_opts
33     else
34       attrvalue
35     end
36   end
37
38   def render_editable_attribute(object, attr, attrvalue=nil, htmloptions={})
39     attrvalue = object.send(attr) if attrvalue.nil?
40     return attrvalue if !object.attribute_editable? attr
41
42     input_type = 'text'
43     case object.class.attribute_info[attr.to_sym][:type]
44     when 'text'
45       input_type = 'textarea'
46     when 'datetime'
47       input_type = 'date'
48     else
49       input_type = 'text'
50     end
51
52     link_to attrvalue.to_s, '#', {
53       "data-emptytext" => "none",
54       "data-placement" => "bottom",
55       "data-type" => input_type,
56       "data-resource" => object.class.to_s.underscore,
57       "data-name" => attr,
58       "data-value" => object.send(attr),
59       "data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore),
60       "data-original-title" => "Update #{attr.gsub '_', ' '}",
61       :class => "editable"
62     }.merge(htmloptions)
63   end
64 end