From 87ebbc14e68bae19daa6e10ea48d6ee25bdcfff9 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 7 Feb 2013 12:52:28 -0500 Subject: [PATCH 1/1] add generic #show page for orvos objects and use it for Log and User --- app/models/orvos_base.rb | 52 ++++++++++++++++++++ app/views/application/_orvos_object.html.erb | 33 +++++++++++++ app/views/logs/show.html.erb | 31 +----------- app/views/users/show.html.erb | 1 + 4 files changed, 87 insertions(+), 30 deletions(-) create mode 100644 app/views/application/_orvos_object.html.erb create mode 100644 app/views/users/show.html.erb diff --git a/app/models/orvos_base.rb b/app/models/orvos_base.rb index 9a02001c9b..ed6a6a59b3 100644 --- a/app/models/orvos_base.rb +++ b/app/models/orvos_base.rb @@ -1,5 +1,34 @@ 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? @@ -140,6 +169,29 @@ class OrvosBase < ActiveRecord::Base 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! diff --git a/app/views/application/_orvos_object.html.erb b/app/views/application/_orvos_object.html.erb new file mode 100644 index 0000000000..0fa55665c7 --- /dev/null +++ b/app/views/application/_orvos_object.html.erb @@ -0,0 +1,33 @@ + + + + + <% @object.attributes_for_display.each do |attr, attrvalue| %> + <% if attrvalue.is_a? Hash then attrvalue.each do |infokey, infocontent| %> + + + + + <% end %> + <% elsif attrvalue.is_a? String or attrvalue.respond_to? :to_s %> + + + <% if attrvalue.is_a? String and (resource_class = OrvosBase::resource_class_for_uuid(attrvalue, attr, @object)) %> + + <% else %> + + <% end %> + + <% end; end %> + +
<%= infokey %> + + <% if infocontent.is_a? Array then infocontent.each do |message| %> + <%= message %>
+ <% end; elsif infocontent.is_a? String %> + <%= infocontent %> + <% else %> + <%= infocontent.inspect %> + <% end %> +
+
<%= attr %><%= link_to "#{resource_class.to_s} #{attrvalue}", { controller: resource_class.to_s.camelize(:lower).pluralize, action: 'show', id: attrvalue } %><%= attrvalue %>
diff --git a/app/views/logs/show.html.erb b/app/views/logs/show.html.erb index 818177f2fb..68f5fa9a54 100644 --- a/app/views/logs/show.html.erb +++ b/app/views/logs/show.html.erb @@ -1,30 +1 @@ - - - - - <% %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| %> - - - - - <% end %> - <% elsif attrvalue.is_a? String or attrvalue.respond_to? :to_s %> - - - - - <% end; end %> - -
<%= infokey %> - - <% if infocontent.is_a? Array then infocontent.each do |message| %> - <%= message %>
- <% end; elsif infocontent.is_a? String %> - <%= infocontent %> - <% else %> - <%= infocontent.inspect %> - <% end %> -
-
<%= attr %><%= attrvalue %>
+<%= render :partial => 'application/orvos_object' %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000000..68f5fa9a54 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'application/orvos_object' %> -- 2.30.2