Class: MegaEnv
- Inherits:
-
Object
- Object
- MegaEnv
- Defined in:
- lib/mega_bar/layout_engine.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#block_action ⇒ Object
readonly
Returns the value of attribute block_action.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#kontroller_inst ⇒ Object
readonly
Returns the value of attribute kontroller_inst.
-
#kontroller_klass ⇒ Object
readonly
Returns the value of attribute kontroller_klass.
-
#kontroller_path ⇒ Object
readonly
Returns the value of attribute kontroller_path.
-
#mega_displays ⇒ Object
Returns the value of attribute mega_displays.
-
#mega_model_properties ⇒ Object
Returns the value of attribute mega_model_properties.
-
#modle ⇒ Object
readonly
Returns the value of attribute modle.
-
#modle_id ⇒ Object
readonly
Returns the value of attribute modle_id.
-
#nested_class_info ⇒ Object
readonly
Returns the value of attribute nested_class_info.
-
#nested_ids ⇒ Object
Returns the value of attribute nested_ids.
-
#params_hash_arr ⇒ Object
readonly
Returns the value of attribute params_hash_arr.
Instance Method Summary collapse
-
#initialize(blck, rout, page_info, pagination) ⇒ MegaEnv
constructor
A new instance of MegaEnv.
- #is_displayable?(format) ⇒ Boolean
- #meta_programming(klass, modle) ⇒ Object
- #nest_info(blck, rout, page_info) ⇒ Object
- #set_mega_displays(displays) ⇒ Object
- #set_nested_class_info(nested_classes) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(blck, rout, page_info, pagination) ⇒ MegaEnv
Returns a new instance of MegaEnv.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/mega_bar/layout_engine.rb', line 230 def initialize(blck, rout, page_info, pagination) @block_model_displays = MegaBar::ModelDisplay.by_block(blck.id) @displays = blck.actions == 'current' ? @block_model_displays.by_block(blck.id).by_action(rout[:action]) : @block_model_displays.by_block(blck.id) @block_action = @displays.empty? ? rout[:action] : @displays.first.action @modle = MegaBar::Model.by_model(@block_model_displays.first.model_id).first @modle_id = @modle.id @modyule = @modle.modyule.empty? ? '' : @modle.modyule + '::' @kontroller_klass = @modyule + @modle.classname.classify.pluralize + "Controller" @kontroller_path = @modle.modyule.nil? || @modle.modyule.empty? ? @modle.classname.pluralize.underscore : @modyule.split('::').map { | m | m = m.underscore }.join('/') + '/' + @modle.classname.pluralize.underscore @klass = (@modyule + @modle.classname.classify).constantize (@klass, @modle) @kontroller_inst = @modle.classname.underscore @mega_displays = set_mega_displays(@displays) @nested_ids, @params_hash_arr, @nested_classes = nest_info(blck, rout, page_info) @nested_class_info = set_nested_class_info(@nested_classes) @block = blck @page_number = pagination.map {|info| info[:page].to_i if info[:kontrlr] == @kontroller_inst + '_page' }.compact.first end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def block @block end |
#block_action ⇒ Object (readonly)
Returns the value of attribute block_action.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def block_action @block_action end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def klass @klass end |
#kontroller_inst ⇒ Object (readonly)
Returns the value of attribute kontroller_inst.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def kontroller_inst @kontroller_inst end |
#kontroller_klass ⇒ Object (readonly)
Returns the value of attribute kontroller_klass.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def kontroller_klass @kontroller_klass end |
#kontroller_path ⇒ Object (readonly)
Returns the value of attribute kontroller_path.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def kontroller_path @kontroller_path end |
#mega_displays ⇒ Object
Returns the value of attribute mega_displays.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def mega_displays @mega_displays end |
#mega_model_properties ⇒ Object
Returns the value of attribute mega_model_properties.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def mega_model_properties @mega_model_properties end |
#modle ⇒ Object (readonly)
Returns the value of attribute modle.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def modle @modle end |
#modle_id ⇒ Object (readonly)
Returns the value of attribute modle_id.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def modle_id @modle_id end |
#nested_class_info ⇒ Object (readonly)
Returns the value of attribute nested_class_info.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def nested_class_info @nested_class_info end |
#nested_ids ⇒ Object
Returns the value of attribute nested_ids.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def nested_ids @nested_ids end |
#params_hash_arr ⇒ Object (readonly)
Returns the value of attribute params_hash_arr.
228 229 230 |
# File 'lib/mega_bar/layout_engine.rb', line 228 def params_hash_arr @params_hash_arr end |
Instance Method Details
#is_displayable?(format) ⇒ Boolean
338 339 340 |
# File 'lib/mega_bar/layout_engine.rb', line 338 def is_displayable?(format) return (format == 'hidden' || format == 'off') ? false : true end |
#meta_programming(klass, modle) ⇒ Object
264 265 266 267 |
# File 'lib/mega_bar/layout_engine.rb', line 264 def (klass, modle) position_parent_method = modle.position_parent.split("::").last.underscore.downcase.to_sym unless modle.position_parent.blank? klass.class_eval{ acts_as_list scope: position_parent_method, add_new_at: :bottom } if position_parent_method end |
#nest_info(blck, rout, page_info) ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/mega_bar/layout_engine.rb', line 298 def nest_info(blck, rout, page_info) params_hash_arr = [] nested_ids = [] nested_classes = [] puts "=================" puts blck, rout, page_info if blck.path_base if page_info[:page_path].starts_with?(blck.path_base) || blck.path_base.starts_with?(page_info[:page_path]) block_path_vars = blck.path_base.split('/').map{ | m | m if m[0] == ':'} - ["", nil] depth = 0 puts 'bpv' + block_path_vars.to_s until depth == block_path_vars.size + 1 # puts MegaBar::Model.find(blck.send("nest_level_#{depth}")) blck_model = depth == 0 ? modle : MegaBar::Model.find(blck.send("nest_level_#{depth}")) fk_field = depth == 0 ? 'id' : blck_model.classname.underscore.downcase + '_id' new_hash = {fk_field => page_info[:vars][block_path_vars.size - depth]} params_hash_arr << new_hash nested_ids << new_hash if depth > 0 nested_classes << blck_model depth += 1 end end else # you can do layouts with a block nested one deep without setting path_base params_hash_arr << h =(rout[:id] && blck.nest_level_1.nil?) ? {id: rout[:id]} : {id: nil} params_hash_arr << i = {MegaBar::Model.find(blck.nest_level_1).classname.underscore + '_id' => rout[:id]} if !blck.nest_level_1.nil? nested_ids << i if i end return nested_ids, params_hash_arr, nested_classes end |
#set_mega_displays(displays) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/mega_bar/layout_engine.rb', line 268 def set_mega_displays(displays) mega_displays_info = [] # collects model and field display settings displays.each do | display | model_display_format = MegaBar::ModelDisplayFormat.find(display.format) model_display_collection_settings = MegaBar::ModelDisplayCollection.by_model_display_id(display.id).first if display.collection_or_member == 'collection' field_displays = MegaBar::FieldDisplay.by_model_display_id(display.id).order('position asc') displayable_fields = [] field_displays.each do |field_disp| field = MegaBar::Field.find(field_disp.field_id) if is_displayable?(field_disp.format) #lets figure out how to display it right here. puts field_disp.format data_format = Object.const_get('MegaBar::' + field_disp.format.classify).by_field_display_id(field_disp.id).last #data_display models have to have this scope! if field_disp.format == 'select' = MegaBar::Option.where(field_id: field.id).collect {|o| [ o.text, o.value ] } end displayable_fields << {field_display: field_disp, field: field, data_format: data_format, options: , obj: @mega_instance} end end info = { :model_display_format => model_display_format, # Object.const_get('MegaBar::' + MegaBar::RecordsFormat.find(md.format).name).new, :displayable_fields => displayable_fields, :model_display => display, :collection_settings => model_display_collection_settings } mega_displays_info << info end mega_displays_info end |
#set_nested_class_info(nested_classes) ⇒ Object
329 330 331 332 333 334 335 336 337 |
# File 'lib/mega_bar/layout_engine.rb', line 329 def set_nested_class_info(nested_classes) nested_class_info = [] nested_classes.each_with_index do |nc, idx| modyule = nc.modyule.empty? ? '' : nc.modyule + '::' klass = modyule + nc.classname.classify nested_class_info << [klass, nc.classname.underscore] if idx != 0 end nested_class_info end |
#to_hash ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/mega_bar/layout_engine.rb', line 249 def to_hash { block: @block, modle_id: @modle_id, mega_model_properties: @modle, klass: @klass, kontroller_inst: @kontroller_inst, kontroller_path: @kontroller_path, mega_displays: @mega_displays, nested_ids: @nested_ids, nested_class_info: @nested_class_info, page_number: @page_number } end |