Module: Engine2::ActionModelSupport
- Included in:
- ActionApproveSupport, ActionBulkDeleteSupport, ActionDeleteSupport, ActionFormSupport, ActionListSupport, ActionViewSupport, DecodeAction, StarToManyLinkAction, StarToManyUnlinkActionBase
- Defined in:
- lib/engine2/action.rb
Instance Method Summary collapse
- #get_type_info(name) ⇒ Object
- #hide_pk ⇒ Object
-
#node_defined ⇒ Object
while prnt && prnt.*.assets == model prnt = prnt.parent end m = prnt.*.assets m ? m.name : nil end.
- #pre_run ⇒ Object
- #show_pk ⇒ Object
- #unsupported_association(assoc) ⇒ Object
Instance Method Details
#get_type_info(name) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/engine2/action.rb', line 324 def get_type_info name model = assets[:model] info = case name when Symbol model.type_info[name] when Sequel::SQL::QualifiedIdentifier assoc = model.many_to_one_associations[name.table] || model.many_to_many_associations[name.table] raise E2Error.new("Association #{name.table} not found for model #{model}") unless assoc assoc.associated_class.type_info[name.column] else raise E2Error.new("Unknown type info key: #{name} in model #{model}") end raise E2Error.new("Type info not found for '#{name}' in model '#{model}'") unless info info end |
#hide_pk ⇒ Object
316 317 318 |
# File 'lib/engine2/action.rb', line 316 def hide_pk hide_fields *assets[:model].primary_keys end |
#node_defined ⇒ Object
while prnt && prnt.*.assets == model
prnt = prnt.parent
end
m = prnt.*.assets[:model]
m ? m.name : nil
end
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/engine2/action.rb', line 352 def node_defined super # p_model_name = parent_model_name model = @assets[:model] at = action_type case at when :list, :star_to_many_list, :star_to_many_link_list, :star_to_many_field, :star_to_many_field_link_list # :many_to_one_list model.many_to_one_associations.each do |assoc_name, assoc| unless assoc[:propagate] == false # || p_model_name == assoc[:class_name] dc = model.type_info[assoc[:keys].first][:decode] node.run_scheme :decode, model, assoc_name, dc[:search] end end end case at when :modify, :create model.many_to_one_associations.each do |assoc_name, assoc| unless assoc[:propagate] == false # || p_model_name == assoc[:class_name] dc = model.type_info[assoc[:keys].first][:decode] node.run_scheme :decode, model, assoc_name, dc[:form] end end end case at when :list #, :star_to_many_list, :many_to_one_list # list dropdowns divider = false model.one_to_many_associations.merge(model.many_to_many_associations).each do |assoc_name, assoc| unless assoc[:propagate] == false (:item_menu).divider unless divider divider ||= true (:item_menu).option :"#{assoc_name}!", icon: "list" # , click: "action.show_assoc($index, \"#{assoc_name}!\")" node.run_scheme :star_to_many, :"#{assoc_name}!", assoc end end end case at when :modify, :create model.type_info.each do |field, info| case info[:type] when :blob_store node.run_scheme :blob_store, model, field when :foreign_blob_store node.run_scheme :foreign_blob_store, model, field when :file_store node.run_scheme :file_store, model, field when :star_to_many_field assoc = model.association_reflections[info[:assoc_name]] # info[:name] ? raise E2Error.new("Association '#{info[:assoc_name]}' not found for model '#{model}'") unless assoc node.run_scheme :star_to_many_field, assoc, field end end end end |
#pre_run ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/engine2/action.rb', line 291 def pre_run if !(mdl = @assets[:model]) act = node begin act = act.parent raise E2Error.new("Model not found in tree for node: #{node.name}") unless act mdl = act.*.assets[:model] end until mdl if asc = @assets[:assoc] @assets[:model] = asc.associated_class # raise E2Error.new("Association '#{asc}' for model '#{asc[:class_name]}' not found") unless @assets[:model] else @assets[:model] = mdl asc = act.*.assets[:assoc] @assets[:assoc] = asc if asc end end # @meta[:model!] = assets[:model] # @meta[:assoc!] = assets[:assoc] ? assets[:assoc][:name] : nil # @meta[:action_class!] = self.class super end |
#show_pk ⇒ Object
320 321 322 |
# File 'lib/engine2/action.rb', line 320 def show_pk show_fields *assets[:model].primary_keys end |
#unsupported_association(assoc) ⇒ Object
410 411 412 |
# File 'lib/engine2/action.rb', line 410 def unsupported_association assoc raise E2Error.new("Unsupported association: #{assoc}") end |