class OrvosBase < ActiveRecord::Base
self.abstract_class = true
+ attr_accessor :attribute_sortkey
+
+ def self.uuid_infix_object_kind
+ @@uuid_infix_object_kind ||= {
+ '4zz18' => 'orvos#collection',
+ 'tpzed' => 'orvos#user',
+ 'ozdt8' => 'orvos#api_client',
+ '57u5n' => 'orvos#log'
+ }
+ end
+
+ def initialize
+ super
+ @attribute_sortkey ||= {
+ 'id' => nil,
+ 'uuid' => '000',
+ 'owner' => '001',
+ 'created_at' => '002',
+ 'modified_at' => '003',
+ 'modified_by_user' => '004',
+ 'modified_by_client' => '005',
+ 'tail_kind' => '100',
+ 'tail_uuid' => '100',
+ 'head_kind' => '101',
+ 'head_uuid' => '101',
+ 'info' => 'zzz-000',
+ 'updated_at' => 'zzz-999'
+ }
+ end
def self.columns
return @columns unless @columns.nil?
super.forget_uuid!
end
+ def attributes_for_display
+ self.attributes.reject { |k,v|
+ attribute_sortkey.has_key?(k) and !attribute_sortkey[k]
+ }.sort_by { |k,v|
+ attribute_sortkey[k] or k
+ }
+ end
+
+ def self.resource_class_for_uuid(uuid, attr_name=nil, object=nil)
+ resource_class = nil
+ if uuid.match /^[0-9a-f]{32}(\+[^,]+)*(,[0-9a-f]{32}(\+[^,]+)*)*$/
+ return 'orvos#collection'
+ end
+ uuid.match /^[0-9a-z]{5}-([0-9a-z]{5})-[0-9a-z]{15}$/ do |re|
+ resource_class ||= $orvos_api_client.
+ 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')])
+ end
+ resource_class
+ end
+
protected
def forget_uuid!
--- /dev/null
+<table class="table topalign">
+ <thead>
+ </thead>
+ <tbody>
+ <% @object.attributes_for_display.each do |attr, attrvalue| %>
+ <% if attrvalue.is_a? Hash then attrvalue.each do |infokey, infocontent| %>
+ <tr>
+ <td><%= infokey %></td>
+ <td>
+ <tt>
+ <% if infocontent.is_a? Array then infocontent.each do |message| %>
+ <%= message %><br />
+ <% end; elsif infocontent.is_a? String %>
+ <%= infocontent %>
+ <% else %>
+ <%= infocontent.inspect %>
+ <% end %>
+ </tt>
+ </td>
+ </tr>
+ <% end %>
+ <% elsif attrvalue.is_a? String or attrvalue.respond_to? :to_s %>
+ <tr>
+ <td><%= attr %></td>
+ <% if attrvalue.is_a? String and (resource_class = OrvosBase::resource_class_for_uuid(attrvalue, attr, @object)) %>
+ <td><%= link_to "#{resource_class.to_s} #{attrvalue}", { controller: resource_class.to_s.camelize(:lower).pluralize, action: 'show', id: attrvalue } %></td>
+ <% else %>
+ <td><%= attrvalue %></td>
+ <% end %>
+ </tr>
+ <% end; end %>
+ </tbody>
+</table>
-<table class="table topalign">
- <thead>
- </thead>
- <tbody>
- <% %w(event_type summary created_at modified_at info).each do |attr| %>
- <% attrvalue = @object.send attr %>
- <% if attrvalue.is_a? Hash then attrvalue.each do |infokey, infocontent| %>
- <tr>
- <td><%= infokey %></td>
- <td>
- <tt>
- <% if infocontent.is_a? Array then infocontent.each do |message| %>
- <%= message %><br />
- <% end; elsif infocontent.is_a? String %>
- <%= infocontent %>
- <% else %>
- <%= infocontent.inspect %>
- <% end %>
- </tt>
- </td>
- </tr>
- <% end %>
- <% elsif attrvalue.is_a? String or attrvalue.respond_to? :to_s %>
- <tr>
- <td><%= attr %></td>
- <td><%= attrvalue %></td>
- </tr>
- <% end; end %>
- </tbody>
-</table>
+<%= render :partial => 'application/orvos_object' %>