link to pipeline invocations from factory_jobs page
authorTom Clegg <tom@clinicalfuture.com>
Thu, 7 Feb 2013 19:03:40 +0000 (14:03 -0500)
committerTom Clegg <tom@clinicalfuture.com>
Thu, 7 Feb 2013 19:03:40 +0000 (14:03 -0500)
app/helpers/application_helper.rb
app/models/orvos_base.rb
app/views/application/_orvos_object.html.erb

index 7106a140edaf76b460695e07dbb7c3e66fe4149f..8a14e27b6699ce845fd90abd9f36eb10cb52ccf8 100644 (file)
@@ -13,9 +13,17 @@ module ApplicationHelper
     cooked = raw + cooked
   end
 
-  def link_to_if_orvos_object(attrvalue, attr, object)
-    if (resource_class = OrvosBase::resource_class_for_uuid(attrvalue, attr, object))
-      link_to "#{resource_class.to_s} #{attrvalue}", { controller: resource_class.to_s.camelize(:lower).pluralize, action: 'show', id: attrvalue }
+  def link_to_if_orvos_object(attrvalue, opts={})
+    if (resource_class = OrvosBase::resource_class_for_uuid(attrvalue, opts[:referring_attr], opts[:referring_object]))
+      link_uuid = attrvalue.is_a?(OrvosBase) ? attrvalue.uuid : attrvalue
+      link_name = link_uuid
+      if !opts[:with_prefixes]
+        link_name = link_name.sub /^.{5}-.{5}-/, ''
+      end
+      if opts[:with_class_name]
+        link_name = "#{resource_class.to_s} #{link_name}"
+      end
+      link_to link_name, { controller: resource_class.to_s.underscore.pluralize, action: 'show', id: link_uuid }
     else
       attrvalue
     end
index e42039bced4bff0eaec6556a8afdc56f6a4536d6..43da26a30da5512c656d67cd88bf3891177248e4 100644 (file)
@@ -178,6 +178,9 @@ class OrvosBase < ActiveRecord::Base
   end
 
   def self.resource_class_for_uuid(uuid, attr_name=nil, object=nil)
+    if uuid.is_a? OrvosBase
+      return uuid.class
+    end
     unless uuid.is_a? String
       return nil
     end
@@ -190,7 +193,7 @@ class OrvosBase < ActiveRecord::Base
         kind_class(self.uuid_infix_object_kind[re[1]])
     end
     if object and attr_name and attr_name.match /_uuid$/
-      resource_class ||= $orvos_api_client.kind_class(object.attributes[attr.sub(/_uuid$/, '_kind')])
+      resource_class ||= $orvos_api_client.kind_class(object.attributes[attr_name.sub(/_uuid$/, '_kind')])
     end
     resource_class
   end
index b977c6674984d14aae09eda1f0a421cba95454d9..b0d4259ff0904c6a82c6561bba6ba738ea35129a 100644 (file)
@@ -22,7 +22,7 @@
     <% elsif attrvalue.is_a? String or attrvalue.respond_to? :to_s %>
     <tr>
       <td><%= attr %></td>
-      <td><%= link_to_if_orvos_object attrvalue, attr, @object %></td>
+      <td><%= link_to_if_orvos_object attrvalue, {referring_attr: attr, referring_object: @object, with_prefixes: true, with_class_name: true} %></td>
     </tr>
     <% end; end %>
   </tbody>