Module: Adminpanel::Base::ClassMethods

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

Overview

instance methods static(class) methods

Instance Method Summary collapse

Instance Method Details

#display_attributes(type) ⇒ Object



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

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
        display_attributes << attribute
      end
    end
  end

  return display_attributes
end

#display_name ⇒ Object



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

def display_name
  'please overwrite self.display_name'
end

#fb_share? ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/models/concerns/adminpanel/base.rb', line 104

def fb_share?
  false
end

#form_attributes ⇒ Object



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

def form_attributes
  []
end


85
86
87
# File 'app/models/concerns/adminpanel/base.rb', line 85

def gallery_children
  nil
end

#get_attribute_label(field) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'app/models/concerns/adminpanel/base.rb', line 21

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



58
59
60
61
62
63
64
65
66
67
# File 'app/models/concerns/adminpanel/base.rb', line 58

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)


47
48
49
50
51
52
53
54
55
56
# File 'app/models/concerns/adminpanel/base.rb', line 47

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)


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

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

#icon ⇒ Object



81
82
83
# File 'app/models/concerns/adminpanel/base.rb', line 81

def icon
  'truck'
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



69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/concerns/adminpanel/base.rb', line 69

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



89
90
91
92
93
94
# File 'app/models/concerns/adminpanel/base.rb', line 89

def routes_options
  { path: ActiveSupport::Inflector.transliterate(
      display_name.pluralize(I18n.default_locale).downcase
    ).tr(' ', '-')
  }
end