add ApiClient#is_trusted, show list of api tokens in Workbench
[arvados.git] / apps / workbench / app / helpers / application_helper.rb
index 8422ed247ac6fa8b653ced8a45f3c5b4eac74bf1..78504655a8e28d04321b017e2bddb4034e7fe689 100644 (file)
@@ -2,6 +2,11 @@ module ApplicationHelper
   def current_user
     controller.current_user
   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
     raw = n.to_s
@@ -13,9 +18,9 @@ module ApplicationHelper
     cooked = raw + cooked
   end
 
-  def link_to_if_orvos_object(attrvalue, opts={}, style_opts={})
-    if (resource_class = OrvosBase::resource_class_for_uuid(attrvalue, opts))
-      link_uuid = attrvalue.is_a?(OrvosBase) ? attrvalue.uuid : attrvalue
+  def link_to_if_arvados_object(attrvalue, opts={}, style_opts={})
+    if (resource_class = ArvadosBase::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
@@ -32,4 +37,31 @@ module ApplicationHelper
       attrvalue
     end
   end
+
+  def render_editable_attribute(object, attr, attrvalue=nil, htmloptions={})
+    attrvalue = object.send(attr) if attrvalue.nil?
+    return attrvalue if !object.attribute_editable? attr
+
+    input_type = 'text'
+    case object.class.attribute_info[attr.to_sym][:type]
+    when 'text'
+      input_type = 'textarea'
+    when 'datetime'
+      input_type = 'date'
+    else
+      input_type = 'text'
+    end
+
+    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-original-title" => "Update #{attr.gsub '_', ' '}",
+      :class => "editable"
+    }.merge(htmloptions)
+  end
 end