X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7f7cd27d5fc31dc5bbec7f95905fd394a5b317c7..56d21dc3d5823117729df3db6186da96f277b328:/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 7231ff8add..d844350927 100644
--- a/apps/workbench/app/helpers/application_helper.rb
+++ b/apps/workbench/app/helpers/application_helper.rb
@@ -17,6 +17,7 @@ module ApplicationHelper
def human_readable_bytes_html(n)
return h(n) unless n.is_a? Fixnum
+ return "0 bytes" if (n == 0)
orders = {
1 => "bytes",
@@ -141,16 +142,29 @@ module ApplicationHelper
attrvalue = attrvalue.to_json if attrvalue.is_a? Hash or attrvalue.is_a? Array
- link_to attrvalue.to_s, '#', {
+ ajax_options = {
+ "data-pk" => {
+ id: object.uuid,
+ key: object.class.to_s.underscore
+ }
+ }
+ if object.uuid
+ ajax_options['data-url'] = url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore)
+ else
+ ajax_options['data-url'] = url_for(action: "create", controller: object.class.to_s.pluralize.underscore)
+ ajax_options['data-pk'][:defaults] = object.attributes
+ end
+ ajax_options['data-pk'] = ajax_options['data-pk'].to_json
+
+ content_tag 'span', attrvalue.to_s, {
"data-emptytext" => "none",
"data-placement" => "bottom",
"data-type" => input_type,
- "data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore),
"data-title" => "Update #{attr.gsub '_', ' '}",
"data-name" => attr,
- "data-pk" => "{id: \"#{object.uuid}\", key: \"#{object.class.to_s.underscore}\"}",
+ "data-object-uuid" => object.uuid,
:class => "editable"
- }.merge(htmloptions)
+ }.merge(htmloptions).merge(ajax_options)
end
def render_pipeline_component_attribute(object, attr, subattr, value_info, htmloptions={})
@@ -218,27 +232,27 @@ module ApplicationHelper
dn += '[value]'
end
- items = []
+ selectables = []
attrtext = attrvalue
if dataclass and dataclass.is_a? Class
if attrvalue and !attrvalue.empty?
Link.where(head_uuid: attrvalue, link_class: ["tag", "identifier"]).each do |tag|
attrtext += " [#{tag.name}]"
end
- items.append({name: attrtext, uuid: attrvalue, type: dataclass.to_s})
+ selectables.append({name: attrtext, uuid: attrvalue, type: dataclass.to_s})
end
#dataclass.where(uuid: attrvalue).each do |item|
- # items.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s})
+ # selectables.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s})
#end
itemuuids = []
dataclass.limit(10).each do |item|
itemuuids << item.uuid
- items.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s})
+ selectables.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s})
end
Link.where(head_uuid: itemuuids, link_class: ["tag", "identifier"]).each do |tag|
- items.each do |item|
- if item.uuid == tag.head_uuid
- item.name += ' [' + tag.name + ']'
+ selectables.each do |selectable|
+ if selectable['uuid'] == tag.head_uuid
+ selectable['name'] += ' [' + tag.name + ']'
end
end
end
@@ -254,20 +268,32 @@ module ApplicationHelper
"data-pk" => "{id: \"#{object.uuid}\", key: \"#{object.class.to_s.underscore}\"}",
"data-showbuttons" => "false",
"data-value" => attrvalue,
- :class => "editable #{'required' if required}",
+ :class => "editable #{'required' if required} form-control",
:id => id
}.merge(htmloptions)
lt += raw("\n")
lt
end
+
+ def render_arvados_object_list_start(list, button_text, button_href,
+ params={}, *rest, &block)
+ show_max = params.delete(:show_max) || 3
+ params[:class] ||= 'btn btn-xs btn-default'
+ list[0...show_max].each { |item| yield item }
+ unless list[show_max].nil?
+ link_to(h(button_text) +
+ raw(' '),
+ button_href, params, *rest)
+ end
+ end
end