Class: Bhf::Platform::Base
- Inherits:
-
Object
- Object
- Bhf::Platform::Base
- Defined in:
- lib/bhf/platform/base.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#page_name ⇒ Object
readonly
Returns the value of attribute page_name.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#title_singular ⇒ Object
readonly
Returns the value of attribute title_singular.
-
#title_zero ⇒ Object
readonly
Returns the value of attribute title_zero.
Instance Method Summary collapse
- #columns ⇒ Object
- #columns_count ⇒ Object
- #custom_columns? ⇒ Boolean
- #custom_link ⇒ Object
- #custom_partial ⇒ Object
- #custom_search ⇒ Object
- #data_source ⇒ Object
- #definitions ⇒ Object
- #entries_per_page ⇒ Object
- #fields ⇒ Object
- #form ⇒ Object
- #get_objects(options = {}, paginate_options = nil) ⇒ Object
- #has_file_upload? ⇒ Boolean
- #hide_create ⇒ Object
- #hide_delete ⇒ Object
- #hide_edit ⇒ Object
- #hooks(method) ⇒ Object
-
#initialize(options) ⇒ Base
constructor
A new instance of Base.
- #model ⇒ Object
- #model_name ⇒ Object
- #pagination ⇒ Object
- #remove_excludes(attrs, excludes) ⇒ Object
- #search? ⇒ Boolean
- #search_field? ⇒ Boolean
- #show ⇒ Object
- #show_duplicate ⇒ Object
- #show_extra_fields ⇒ Object
- #sortable ⇒ Object
- #sortable_property ⇒ Object
- #table ⇒ Object
- #table_columns ⇒ Object
- #table_hide? ⇒ Boolean
- #table_quick_edit ⇒ Object
- #user_scope? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bhf/platform/base.rb', line 5 def initialize() @objects = [] @name = .name @data = .hash @settings = .settings_base @user = @settings.user t_model_path = "activerecord.models.#{model.model_name.to_s.downcase}" model_name = I18n.t(t_model_path, count: 2, default: @name.pluralize.capitalize) @title = I18n.t("bhf.platforms.#{@name}.title", count: 2, default: model_name) model_name = I18n.t(t_model_path, count: 1, default: @name.singularize.capitalize) @title_singular = I18n.t("bhf.platforms.#{@name}.title", count: 1, default: model_name) model_name = I18n.t(t_model_path, count: 0, default: @name.singularize.capitalize) @title_zero = I18n.t("bhf.platforms.#{@name}.title", count: 0, default: model_name) @page_name = .page_name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bhf/platform/base.rb', line 3 def name @name end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
3 4 5 |
# File 'lib/bhf/platform/base.rb', line 3 def objects @objects end |
#page_name ⇒ Object (readonly)
Returns the value of attribute page_name.
3 4 5 |
# File 'lib/bhf/platform/base.rb', line 3 def page_name @page_name end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/bhf/platform/base.rb', line 3 def title @title end |
#title_singular ⇒ Object (readonly)
Returns the value of attribute title_singular.
3 4 5 |
# File 'lib/bhf/platform/base.rb', line 3 def title_singular @title_singular end |
#title_zero ⇒ Object (readonly)
Returns the value of attribute title_zero.
3 4 5 |
# File 'lib/bhf/platform/base.rb', line 3 def title_zero @title_zero end |
Instance Method Details
#columns ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/bhf/platform/base.rb', line 83 def columns return @columns if @columns tmp = default_attrs(table_columns, attributes[0..5], true) if sortable and ! table_columns tmp = remove_excludes(tmp, [sortable_property.to_s]) end @columns = remove_excludes(tmp, table_value(:exclude)) end |
#columns_count ⇒ Object
165 166 167 |
# File 'lib/bhf/platform/base.rb', line 165 def columns_count columns.count + (sortable ? 2 : 1) end |
#custom_columns? ⇒ Boolean
131 132 133 |
# File 'lib/bhf/platform/base.rb', line 131 def custom_columns? table_columns.is_a?(Array) end |
#custom_link ⇒ Object
185 186 187 |
# File 'lib/bhf/platform/base.rb', line 185 def custom_link table_value 'custom_link' end |
#custom_partial ⇒ Object
193 194 195 |
# File 'lib/bhf/platform/base.rb', line 193 def custom_partial table_value 'partial' end |
#custom_search ⇒ Object
123 124 125 |
# File 'lib/bhf/platform/base.rb', line 123 def custom_search table_value(:custom_search) end |
#data_source ⇒ Object
197 198 199 |
# File 'lib/bhf/platform/base.rb', line 197 def data_source table_value(:source) || table_value(:scope) end |
#definitions ⇒ Object
94 95 96 97 98 99 |
# File 'lib/bhf/platform/base.rb', line 94 def definitions return @definitions if @definitions tmp = default_attrs(show_value(:display) || show_value(:definitions), attributes) @definitions = remove_excludes(tmp, show_value(:exclude)) end |
#entries_per_page ⇒ Object
205 206 207 |
# File 'lib/bhf/platform/base.rb', line 205 def entries_per_page table_value(:per_page) end |
#fields ⇒ Object
79 80 81 |
# File 'lib/bhf/platform/base.rb', line 79 def fields @fields ||= remove_excludes(default_attrs(form_value(:display), attributes), form_value(:exclude)) end |
#form ⇒ Object
147 148 149 |
# File 'lib/bhf/platform/base.rb', line 147 def form @data['form'] end |
#get_objects(options = {}, paginate_options = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bhf/platform/base.rb', line 29 def get_objects( = {}, = nil) if user_scope? and @user chain = @user.send(table_value(:user_scope).to_sym) else chain = model chain = chain.send data_source if data_source end unless [:order].blank? chain = chain.reorder("#{[:order]} #{[:direction]}") end if search? && [:search].present? chain = do_search(chain, [:search]) end if && !sortable chain = chain.page([:page]).per([:per_page]) elsif chain == model chain = chain.all end @objects = chain end |
#has_file_upload? ⇒ Boolean
101 102 103 104 105 106 107 108 |
# File 'lib/bhf/platform/base.rb', line 101 def has_file_upload? return true if form_value(:multipart) == true fields.each do |field| return true if field.form_type == :file end false end |
#hide_create ⇒ Object
173 174 175 |
# File 'lib/bhf/platform/base.rb', line 173 def hide_create table_value('hide_create') || table_value('hide_new') || table_value('hide_add') end |
#hide_delete ⇒ Object
181 182 183 |
# File 'lib/bhf/platform/base.rb', line 181 def hide_delete table_value('hide_delete') || table_value('hide_destroy') end |
#hide_edit ⇒ Object
169 170 171 |
# File 'lib/bhf/platform/base.rb', line 169 def hide_edit table_value 'hide_edit' end |
#hooks(method) ⇒ Object
151 152 153 154 155 |
# File 'lib/bhf/platform/base.rb', line 151 def hooks(method) if @data['hooks'] && @data['hooks'][method.to_s] @data['hooks'][method.to_s].to_sym end end |
#model ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/bhf/platform/base.rb', line 55 def model @model ||= if @data['model'] @data['model'] else @name end.classify.constantize end |
#model_name ⇒ Object
63 64 65 |
# File 'lib/bhf/platform/base.rb', line 63 def model_name ActiveModel::Naming.singular(model) end |
#pagination ⇒ Object
25 26 27 |
# File 'lib/bhf/platform/base.rb', line 25 def pagination @pagination ||= Bhf::Platform::Pagination.new(entries_per_page) end |
#remove_excludes(attrs, excludes) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/bhf/platform/base.rb', line 71 def remove_excludes(attrs, excludes) return attrs unless excludes attrs.each_with_object([]) do |attribute, obj| next if excludes.include?(attribute.name.to_s) obj << attribute end end |
#search? ⇒ Boolean
115 116 117 |
# File 'lib/bhf/platform/base.rb', line 115 def search? table_value(:search) != false end |
#search_field? ⇒ Boolean
119 120 121 |
# File 'lib/bhf/platform/base.rb', line 119 def search_field? table_value(:search_field) != false end |
#show ⇒ Object
143 144 145 |
# File 'lib/bhf/platform/base.rb', line 143 def show @data['show'] end |
#show_duplicate ⇒ Object
177 178 179 |
# File 'lib/bhf/platform/base.rb', line 177 def show_duplicate table_value 'show_duplicate' end |
#show_extra_fields ⇒ Object
201 202 203 |
# File 'lib/bhf/platform/base.rb', line 201 def show_extra_fields show_value(:extra_fields) end |
#sortable ⇒ Object
157 158 159 |
# File 'lib/bhf/platform/base.rb', line 157 def sortable table_value 'sortable' end |
#sortable_property ⇒ Object
161 162 163 |
# File 'lib/bhf/platform/base.rb', line 161 def sortable_property (@data['sortable_property'] || :position).to_sym end |
#table ⇒ Object
139 140 141 |
# File 'lib/bhf/platform/base.rb', line 139 def table @data['table'] end |
#table_columns ⇒ Object
127 128 129 |
# File 'lib/bhf/platform/base.rb', line 127 def table_columns table_value(:display) || table_value(:columns) end |
#table_hide? ⇒ Boolean
67 68 69 |
# File 'lib/bhf/platform/base.rb', line 67 def table_hide? table_value(:hide) == true || model. end |
#table_quick_edit ⇒ Object
189 190 191 |
# File 'lib/bhf/platform/base.rb', line 189 def table_quick_edit table_value 'quick_edit' end |
#user_scope? ⇒ Boolean
135 136 137 |
# File 'lib/bhf/platform/base.rb', line 135 def user_scope? @user && table_value(:user_scope) end |