Module: Adminpanel::Base::ClassMethods
- Defined in:
- app/models/concerns/adminpanel/base.rb
Overview
instance methods static(class) methods
Instance Method Summary collapse
- #belongs_to(name, scope = nil, options = {}) ⇒ Object
- #collection_routes ⇒ Object
- #display_attributes(type) ⇒ Object
- #display_name ⇒ Object
- #fb_share? ⇒ Boolean
- #form_attributes ⇒ Object
- #gallery_children ⇒ Object
- #get_attribute_label(field) ⇒ Object
- #get_image_relationship ⇒ Object
- #has_images? ⇒ Boolean
- #has_route?(route) ⇒ Boolean
- #icon ⇒ Object
- #is_sortable? ⇒ Boolean
- #member_routes ⇒ Object
- #mount_images(relation) ⇒ Object
- #relationships_of(type_property) ⇒ Object
- #routes_options ⇒ Object
- #twitter_share? ⇒ Boolean
Instance Method Details
#belongs_to(name, scope = nil, options = {}) ⇒ Object
13 14 15 |
# File 'app/models/concerns/adminpanel/base.rb', line 13 def belongs_to(name, scope = nil, = {}) super(name, scope, .reverse_merge!({touch: true})) end |
#collection_routes ⇒ Object
122 123 124 |
# File 'app/models/concerns/adminpanel/base.rb', line 122 def collection_routes [] end |
#display_attributes(type) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/concerns/adminpanel/base.rb', line 36 def display_attributes(type) display_attributes = [] form_attributes.each do |attribute| attribute.each do |name, properties| if ( properties['show'].nil? || properties['show'] == 'true' || ( properties['show'] == type && properties['type'] != 'adminpanel_file_field' #file fields get only displayed in form ) ) display_attributes << attribute end end end return display_attributes end |
#display_name ⇒ Object
21 22 23 |
# File 'app/models/concerns/adminpanel/base.rb', line 21 def display_name 'please overwrite self.display_name' end |
#fb_share? ⇒ Boolean
110 111 112 |
# File 'app/models/concerns/adminpanel/base.rb', line 110 def fb_share? false end |
#form_attributes ⇒ Object
17 18 19 |
# File 'app/models/concerns/adminpanel/base.rb', line 17 def form_attributes [] end |
#gallery_children ⇒ Object
94 95 96 |
# File 'app/models/concerns/adminpanel/base.rb', line 94 def gallery_children nil end |
#get_attribute_label(field) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/concerns/adminpanel/base.rb', line 25 def get_attribute_label(field) form_attributes.each do |attribute| attribute.each do |name, properties| if name == field return properties['label'] end end end return "field #{field} 'label' property not found :(" end |
#get_image_relationship ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/concerns/adminpanel/base.rb', line 67 def get_image_relationship form_attributes.each do |fields| fields.each do |attribute, properties| if properties['type'] == 'adminpanel_file_field' return attribute end end end return false end |
#has_images? ⇒ Boolean
56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/concerns/adminpanel/base.rb', line 56 def has_images? form_attributes.each do |fields| fields.each do |attribute, properties| if properties['type'] == 'adminpanel_file_field' return true end end end return false end |
#has_route?(route) ⇒ Boolean
102 103 104 105 106 107 108 |
# File 'app/models/concerns/adminpanel/base.rb', line 102 def has_route?(route) if (!exclude?(route)) && include_route(route) true else false end end |
#icon ⇒ Object
90 91 92 |
# File 'app/models/concerns/adminpanel/base.rb', line 90 def icon 'truck' end |
#is_sortable? ⇒ Boolean
126 127 128 |
# File 'app/models/concerns/adminpanel/base.rb', line 126 def is_sortable? false end |
#member_routes ⇒ Object
118 119 120 |
# File 'app/models/concerns/adminpanel/base.rb', line 118 def member_routes [] end |
#mount_images(relation) ⇒ Object
8 9 10 11 |
# File 'app/models/concerns/adminpanel/base.rb', line 8 def mount_images(relation) has_many relation, dependent: :destroy accepts_nested_attributes_for relation, allow_destroy: true end |
#relationships_of(type_property) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/concerns/adminpanel/base.rb', line 78 def relationships_of(type_property) classes_of_relation = [] form_attributes.each do |fields| fields.each do |attribute, properties| if properties['type'] == type_property classes_of_relation << properties['model'].classify.constantize end end end return classes_of_relation end |
#routes_options ⇒ Object
98 99 100 |
# File 'app/models/concerns/adminpanel/base.rb', line 98 def { path: display_name.pluralize(I18n.default_locale).parameterize } end |
#twitter_share? ⇒ Boolean
114 115 116 |
# File 'app/models/concerns/adminpanel/base.rb', line 114 def twitter_share? false end |