projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch '2107-radhika-user-guide-minor-updates'
[arvados.git]
/
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 78504655a8e28d04321b017e2bddb4034e7fe689..cd8e5279dd0bdf595bbce465c2c9b693c0385a53 100644
(file)
--- a/
apps/workbench/app/helpers/application_helper.rb
+++ b/
apps/workbench/app/helpers/application_helper.rb
@@
-3,35
+3,70
@@
module ApplicationHelper
controller.current_user
end
controller.current_user
end
+ def current_api_host
+ Rails.configuration.arvados_v1_base.gsub /https?:\/\/|\/arvados\/v1/,''
+ end
+
def render_content_from_database(markup)
raw RedCloth.new(markup).to_html
end
def human_readable_bytes_html(n)
return h(n) unless n.is_a? Fixnum
def render_content_from_database(markup)
raw RedCloth.new(markup).to_html
end
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
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={})
+ ArvadosBase::resource_class_for_uuid(attrvalue, opts)
end
def link_to_if_arvados_object(attrvalue, opts={}, style_opts={})
end
def link_to_if_arvados_object(attrvalue, opts={}, style_opts={})
- if (resource_class =
ArvadosBase::
resource_class_for_uuid(attrvalue, opts))
+ if (resource_class = resource_class_for_uuid(attrvalue, opts))
link_uuid = attrvalue.is_a?(ArvadosBase) ? attrvalue.uuid : attrvalue
link_name = opts[:link_text]
if !link_name
link_name = link_uuid
link_uuid = attrvalue.is_a?(ArvadosBase) ? attrvalue.uuid : attrvalue
link_name = opts[:link_text]
if !link_name
link_name = link_uuid
- if !opts[:with_prefixes]
- link_name = link_name.sub /^.{5}-.{5}-/, ''
+
+ 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]
end
if opts[:with_class_name]
- link_name = "#{resource_class.to_s} #{link_name}"
+ link_name = "#{resource_class.to_s}
:
#{link_name}"
end
end
- style_opts = style_opts.merge(style: 'font-family: monospace')
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
link_to link_name, { controller: resource_class.to_s.underscore.pluralize, action: 'show', id: link_uuid }, style_opts
else
attrvalue
@@
-43,7
+78,7
@@
module ApplicationHelper
return attrvalue if !object.attribute_editable? attr
input_type = 'text'
return attrvalue if !object.attribute_editable? attr
input_type = 'text'
- case object.class.attribute_info[attr.to_sym][:type]
+ case object.class.attribute_info[attr.to_sym]
.andand
[:type]
when 'text'
input_type = 'textarea'
when 'datetime'
when 'text'
input_type = 'textarea'
when 'datetime'
@@
-52,15
+87,16
@@
module ApplicationHelper
input_type = 'text'
end
input_type = 'text'
end
+ attrvalue = attrvalue.to_json if attrvalue.is_a? Hash or attrvalue.is_a? Array
+
link_to attrvalue.to_s, '#', {
"data-emptytext" => "none",
"data-placement" => "bottom",
"data-type" => input_type,
link_to attrvalue.to_s, '#', {
"data-emptytext" => "none",
"data-placement" => "bottom",
"data-type" => input_type,
- "data-resource" => object.class.to_s.underscore,
- "data-name" => attr,
- "data-value" => object.send(attr),
"data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore),
"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 '_', ' '}",
+ "data-name" => attr,
+ "data-pk" => "{id: \"#{object.uuid}\", key: \"#{object.class.to_s.underscore}\"}",
:class => "editable"
}.merge(htmloptions)
end
:class => "editable"
}.merge(htmloptions)
end