From bf32f09208063a380f96148e887767bf97ed288d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 4 Jan 2015 13:49:04 +0100 Subject: [PATCH] Improved code layout. --- app/models/object_manager.rb | 58 ++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/app/models/object_manager.rb b/app/models/object_manager.rb index 7f5174e77..f007f302b 100644 --- a/app/models/object_manager.rb +++ b/app/models/object_manager.rb @@ -68,19 +68,20 @@ list of all attributes add a new activity entry for an object ObjectManager::Attribute.add( - :object => 'Ticket', - :name => 'group_id', - :frontend => 'Group', - :data_type => 'select', + :object => 'Ticket', + :name => 'group_id', + :frontend => 'Group', + :data_type => 'select', :data_option => { - :relation => 'Group', + :relation => 'Group', :relation_condition => { :access => 'rw' }, - :multiple => false, - :null => true, + :multiple => false, + :null => true, + :translate => false, }, - :editable => false, - :active => true, - :screens => { + :editable => false, + :active => true, + :screens => { :create => { '-all-' => { :required => true, @@ -92,12 +93,12 @@ add a new activity entry for an object }, }, }, - :pending_migration => false, - :position => 20, - :created_by_id => 1, - :updated_by_id => 1, - :created_at => '2014-06-04 10:00:00', - :updated_at => '2014-06-04 10:00:00', + :pending_migration => false, + :position => 20, + :created_by_id => 1, + :updated_by_id => 1, + :created_at => '2014-06-04 10:00:00', + :updated_at => '2014-06-04 10:00:00', ) @@ -183,4 +184,29 @@ returns: attributes end +=begin + +get user based list of object attributes as hash + + attribute_list = ObjectManager::Attribute.by_object_as_hash('Ticket', user) + +returns: + + { + 'api_key' => { :name => 'api_key', :display => 'API KEY', :tag => 'input', :null => true, :edit => true, :maxlength => 32 }, + 'api_ip_regexp' => { :name => 'api_ip_regexp', :display => 'API IP RegExp', :tag => 'input', :null => true, :edit => true }, + 'api_ip_max' => { :name => 'api_ip_max', :display => 'API IP Max', :tag => 'input', :null => true, :edit => true }, + } + +=end + + def self.by_object_as_hash(object, user) + list = self.by_object(object, user) + hash = {} + list.each {|item| + hash[ item[:name] ] = item + } + hash + end + end \ No newline at end of file