5417: when input is unreadable, present visual cue even when it is not editable by...
[arvados.git] / apps / workbench / app / helpers / application_helper.rb
index d842e8273b050dbeadc1f8672e538739209c8fae..09adfef16012e672f430d4375a1b7788948703bf 100644 (file)
@@ -180,23 +180,35 @@ module ApplicationHelper
   def link_to_arvados_object_if_readable(attrvalue, link_text_if_not_readable, opts={})
     resource_class = resource_class_for_uuid(attrvalue)
     if !resource_class
-      return link_text_if_not_readable
+      return link_to_if_arvados_object attrvalue, opts
     end
 
+    readable = object_readable attrvalue, resource_class
+    if readable
+      link_to_if_arvados_object attrvalue, opts
+    elsif opts[:required]
+      raw('<div><input type="text" style="border:none;width:100%;background:#ffdddd" disabled=true class="required unreadable-input" value="' +
+           link_text_if_not_readable + '" ></input></div>')
+    else
+      link_text_if_not_readable
+    end
+  end
+
+  def object_readable attrvalue, resource_class=nil
+    # if it is a collection filename, check readable for the locator
+    attrvalue = attrvalue.split('/')[0] if attrvalue
+
+    resource_class = resource_class_for_uuid(attrvalue)
+    return if resource_class.nil?
+
     if resource_class.to_s == 'Collection'
       if CollectionsHelper.match(attrvalue)
-        readable = collection_for_pdh(attrvalue).any?
+        collection_for_pdh(attrvalue).any?
       else
-        readable = collections_for_object(attrvalue).any?
+        collections_for_object(attrvalue).any?
       end
     else
-      readable = object_for_dataclass(resource_class, attrvalue)
-    end
-
-    if readable
-      link_to_if_arvados_object attrvalue, opts
-    else
-      link_text_if_not_readable
+      object_for_dataclass(resource_class, attrvalue)
     end
   end
 
@@ -294,7 +306,7 @@ module ApplicationHelper
     end
 
     if not object.andand.attribute_editable?(attr)
-      return link_to_arvados_object_if_readable(attrvalue, attrvalue, attrvalue, true)
+      return link_to_arvados_object_if_readable(attrvalue, attrvalue, {friendly_name: true, required: required})
     end
 
     if dataclass
@@ -346,10 +358,11 @@ module ApplicationHelper
            success: 'page-refresh'
          }.to_json,
         })
+      is_readable_input = object_readable attrvalue unless attrvalue.andand.empty?
       return content_tag('div', :class => 'input-group') do
         html = text_field_tag(dn, display_value,
                               :class =>
-                              "form-control #{'required' if required}")
+                              "form-control #{'required' if required} #{'unreadable-input' if !attrvalue.andand.empty? and !is_readable_input}")
         html + content_tag('span', :class => 'input-group-btn') do
           link_to('Choose',
                   modal_path,