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_footer ⇒ Object
- #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
- #read_data_source ⇒ Object
- #remove_excludes(attrs, excludes) ⇒ Object
- #scopes ⇒ 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
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bhf/platform/base.rb', line 93 def columns return @columns if @columns tmp = default_attrs(table_columns, attributes[0..5]) 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
179 180 181 |
# File 'lib/bhf/platform/base.rb', line 179 def columns_count columns.count + (sortable ? 2 : 1) end |
#custom_columns? ⇒ Boolean
145 146 147 |
# File 'lib/bhf/platform/base.rb', line 145 def custom_columns? table_columns.is_a?(Array) end |
#custom_footer ⇒ Object
137 138 139 |
# File 'lib/bhf/platform/base.rb', line 137 def table_value(:custom_footer) end |
#custom_link ⇒ Object
199 200 201 |
# File 'lib/bhf/platform/base.rb', line 199 def custom_link table_value 'custom_link' end |
#custom_partial ⇒ Object
207 208 209 |
# File 'lib/bhf/platform/base.rb', line 207 def custom_partial table_value 'partial' end |
#custom_search ⇒ Object
133 134 135 |
# File 'lib/bhf/platform/base.rb', line 133 def custom_search table_value(:custom_search) end |
#data_source ⇒ Object
215 216 217 218 219 220 |
# File 'lib/bhf/platform/base.rb', line 215 def data_source temp_scope = read_data_source return unless temp_scope return temp_scope[0] if temp_scope.is_a?(Array) temp_scope end |
#definitions ⇒ Object
104 105 106 107 108 109 |
# File 'lib/bhf/platform/base.rb', line 104 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
237 238 239 |
# File 'lib/bhf/platform/base.rb', line 237 def entries_per_page table_value(:per_page) end |
#fields ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bhf/platform/base.rb', line 82 def fields return @fields if @fields tmp = default_attrs(form_value(:display), attributes) if sortable and ! form_value(:display) tmp = remove_excludes(tmp, [sortable_property.to_s]) end @fields = remove_excludes(tmp, form_value(:exclude)) end |
#form ⇒ Object
161 162 163 |
# File 'lib/bhf/platform/base.rb', line 161 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 54 55 56 |
# 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 if [:scope].present? chain = chain.send [:scope] elsif data_source chain = chain.send data_source end end if [:order].present? and [:direction].present? 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
111 112 113 114 115 116 117 118 |
# File 'lib/bhf/platform/base.rb', line 111 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
187 188 189 |
# File 'lib/bhf/platform/base.rb', line 187 def hide_create table_value('hide_create') || table_value('hide_new') || table_value('hide_add') end |
#hide_delete ⇒ Object
195 196 197 |
# File 'lib/bhf/platform/base.rb', line 195 def hide_delete table_value('hide_delete') || table_value('hide_destroy') end |
#hide_edit ⇒ Object
183 184 185 |
# File 'lib/bhf/platform/base.rb', line 183 def hide_edit table_value 'hide_edit' end |
#hooks(method) ⇒ Object
165 166 167 168 169 |
# File 'lib/bhf/platform/base.rb', line 165 def hooks(method) if @data['hooks'] && @data['hooks'][method.to_s] @data['hooks'][method.to_s].to_sym end end |
#model ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/bhf/platform/base.rb', line 58 def model @model ||= if @data['model'] @data['model'] else @name end.classify.constantize end |
#model_name ⇒ Object
66 67 68 |
# File 'lib/bhf/platform/base.rb', line 66 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 |
#read_data_source ⇒ Object
211 212 213 |
# File 'lib/bhf/platform/base.rb', line 211 def read_data_source table_value(:source) || table_value(:scope) end |
#remove_excludes(attrs, excludes) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/bhf/platform/base.rb', line 74 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 |
#scopes ⇒ Object
222 223 224 225 226 227 228 229 230 231 |
# File 'lib/bhf/platform/base.rb', line 222 def scopes temp_scope = read_data_source return unless temp_scope.is_a?(Array) and temp_scope.count > 1 temp_scope.each_with_object([]) do |s, array| array << OpenStruct.new( name: I18n.t("bhf.platforms.#{@name}.scopes.#{s}", default: s), value: s ) end end |
#search? ⇒ Boolean
125 126 127 |
# File 'lib/bhf/platform/base.rb', line 125 def search? table_value(:search) != false end |
#search_field? ⇒ Boolean
129 130 131 |
# File 'lib/bhf/platform/base.rb', line 129 def search_field? table_value(:search_field) != false end |
#show ⇒ Object
157 158 159 |
# File 'lib/bhf/platform/base.rb', line 157 def show @data['show'] end |
#show_duplicate ⇒ Object
191 192 193 |
# File 'lib/bhf/platform/base.rb', line 191 def show_duplicate table_value 'show_duplicate' end |
#show_extra_fields ⇒ Object
233 234 235 |
# File 'lib/bhf/platform/base.rb', line 233 def show_extra_fields show_value(:extra_fields) end |
#sortable ⇒ Object
171 172 173 |
# File 'lib/bhf/platform/base.rb', line 171 def sortable table_value 'sortable' end |
#sortable_property ⇒ Object
175 176 177 |
# File 'lib/bhf/platform/base.rb', line 175 def sortable_property (@data['sortable_property'] || :position).to_sym end |
#table ⇒ Object
153 154 155 |
# File 'lib/bhf/platform/base.rb', line 153 def table @data['table'] end |
#table_columns ⇒ Object
141 142 143 |
# File 'lib/bhf/platform/base.rb', line 141 def table_columns table_value(:display) || table_value(:columns) end |
#table_hide? ⇒ Boolean
70 71 72 |
# File 'lib/bhf/platform/base.rb', line 70 def table_hide? table_value(:hide) == true || model. end |
#table_quick_edit ⇒ Object
203 204 205 |
# File 'lib/bhf/platform/base.rb', line 203 def table_quick_edit table_value 'quick_edit' end |
#user_scope? ⇒ Boolean
149 150 151 |
# File 'lib/bhf/platform/base.rb', line 149 def user_scope? @user && table_value(:user_scope) end |