Module: Adminpanel::Base::ClassMethods

Defined in:
app/models/concerns/adminpanel/base.rb

Overview

static(class) methods

Instance Method Summary collapse

Instance Method Details

#belongs_to(name, scope = nil, options = {}) ⇒ Object

implementing cache by default.



13
14
15
# File 'app/models/concerns/adminpanel/base.rb', line 13

def belongs_to(name, scope = nil, options = {})
  super(name, scope, options.reverse_merge!({touch: true}))
end

#collection_nameObject

The word that is going to be shown in the side menu, routes and breadcrumb.



29
30
31
# File 'app/models/concerns/adminpanel/base.rb', line 29

def collection_name
  display_name.pluralize(I18n.default_locale)
end

#collection_routesObject



130
131
132
# File 'app/models/concerns/adminpanel/base.rb', line 130

def collection_routes
  []
end

#display_attributes(type) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/concerns/adminpanel/base.rb', line 44

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_nameObject

The name that is going to be shown in the new button and that is going to be pluralized (if not overwritten) to generate collection_name



23
24
25
# File 'app/models/concerns/adminpanel/base.rb', line 23

def display_name
  'please overwrite self.display_name'
end

#fb_share?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'app/models/concerns/adminpanel/base.rb', line 118

def fb_share?
  false
end

#form_attributesObject



17
18
19
# File 'app/models/concerns/adminpanel/base.rb', line 17

def form_attributes
  []
end


102
103
104
# File 'app/models/concerns/adminpanel/base.rb', line 102

def gallery_children
  nil
end

#get_attribute_label(field) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'app/models/concerns/adminpanel/base.rb', line 33

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_relationshipObject



75
76
77
78
79
80
81
82
83
84
# File 'app/models/concerns/adminpanel/base.rb', line 75

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

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
# File 'app/models/concerns/adminpanel/base.rb', line 64

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

Returns:

  • (Boolean)


110
111
112
113
114
115
116
# File 'app/models/concerns/adminpanel/base.rb', line 110

def has_route?(route)
  if (!exclude?(route)) && include_route(route)
    true
  else
    false
  end
end

#iconObject



98
99
100
# File 'app/models/concerns/adminpanel/base.rb', line 98

def icon
  'truck'
end

#is_sortable?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'app/models/concerns/adminpanel/base.rb', line 134

def is_sortable?
  false
end

#member_routesObject



126
127
128
# File 'app/models/concerns/adminpanel/base.rb', line 126

def member_routes
  []
end

#mount_images(relation) ⇒ Object



7
8
9
10
# File 'app/models/concerns/adminpanel/base.rb', line 7

def mount_images(relation)
  has_many relation, dependent: :destroy
  accepts_nested_attributes_for relation, allow_destroy: true
end

#relationships_of(type_property) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'app/models/concerns/adminpanel/base.rb', line 86

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_optionsObject



106
107
108
# File 'app/models/concerns/adminpanel/base.rb', line 106

def routes_options
  { path: collection_name.parameterize }
end

#twitter_share?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'app/models/concerns/adminpanel/base.rb', line 122

def twitter_share?
  false
end