Module: Engine2::MetaListSupport

Includes:
MetaAPISupport, MetaMenuSupport, MetaModelSupport, MetaOnChangeSupport, MetaPanelSupport, MetaTabSupport
Included in:
ListMeta
Defined in:
lib/engine2/meta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MetaModelSupport

#action_defined, #get_type_info, #hide_pk, #show_pk, #unsupported_association

Methods included from MetaAPISupport

#config, #decorate, #field_filter, #hide_fields, #info, #info!, #loc!, #reload_routes!, #render, #show_fields

Methods included from MetaTabSupport

#field_tabs, #lazy_tab, #select_tabs

Methods included from MetaPanelSupport

#footer, #modal_action, #panel, #panel_class, #panel_panel_template, #panel_template, #panel_title

Methods included from MetaMenuSupport

#menu

Methods included from MetaOnChangeSupport

#on_change

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



541
542
543
# File 'lib/engine2/meta.rb', line 541

def filters
  @filters
end

#ordersObject (readonly)

Returns the value of attribute orders.



541
542
543
# File 'lib/engine2/meta.rb', line 541

def orders
  @orders
end

Instance Method Details

#filter(name, &blk) ⇒ Object



666
667
668
# File 'lib/engine2/meta.rb', line 666

def filter name, &blk
    (@filters ||= {})[name] = blk
end

#order(name, &blk) ⇒ Object



670
671
672
# File 'lib/engine2/meta.rb', line 670

def order name, &blk
    (@orders ||= {})[name] = blk
end

#post_processObject

def find_renderer type_info

renderer = DefaultSearchRenderers[type_info[:type]] || DefaultSearchRenderers[type_info[:otype]]
raise E2Error.new("No search renderer found for field '#{type_info[:name]}'") unless renderer
renderer.(self, type_info)

end



598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'lib/engine2/meta.rb', line 598

def post_process
    if fields = @meta[:search_fields]
        fields = fields - static.get[:search_fields] if dynamic?

        decorate(fields)
        fields.each do |name|
            type_info = get_type_info(name)

            # render = info[name][:render]
            # if not render
            #     info[name][:render] = find_renderer(type_info)
            # else
            #     info[name][:render].merge!(find_renderer(type_info)){|key, v1, v2|v1}
            # end

            info[name][:render] ||= begin # set before :fields
                renderer = DefaultSearchRenderers[type_info[:type]] || DefaultSearchRenderers[type_info[:otype]]
                raise E2Error.new("No search renderer found for field '#{type_info[:name]}'") unless renderer
                renderer.(self, type_info)
            end

            proc = SearchRendererPostProcessors[type_info[:type]] || ListRendererPostProcessors[type_info[:type]] # ?
            proc.(self, name, type_info) if proc
        end
    end

    if fields = @meta[:fields]
        fields = fields - static.get[:fields] if dynamic?

        decorate(fields)
        fields.each do |name|
            type_info = get_type_info(name)
            proc = ListRendererPostProcessors[type_info[:type]]
            proc.(self, name, type_info) if proc
        end
    end

    super
end

#post_runObject



579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/engine2/meta.rb', line 579

def post_run
    unless panel[:class]
        panel_class case @meta[:fields].size
        when 1..3; ''
        when 4..6; 'modal-large'
        else; 'modal-huge'
        end
    end

    super
    @meta[:primary_fields] = assets[:model].primary_keys
end

#pre_runObject



543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'lib/engine2/meta.rb', line 543

def pre_run
    super
    config.merge!(per_page: 10, use_count: false, show_item_menu: true, selectable: true) # search_active: false,

    # modal_action self.class != ListMeta
    panel_template 'scaffold/list'
    panel_panel_template 'panels/menu_m' unless action.parent.*.assets[:model]
    search_template 'scaffold/search'
    panel_title "#{:list.icon} #{LOCS[assets[:model].name.to_sym]}"
    menu(:panel_menu).option :cancel, icon: "remove"
    menu :menu do
        properties break: 2, group_class: "btn-group-xs"
        option :search_toggle, icon: "search", show: "action.meta.search_fields", class: "action.ui_state.search_active && 'active'", button_loc: false
        # divider
        option :refresh, icon: "refresh", button_loc: false
        option :default_order, icon: "signal", button_loc: false
        divider
        option :debug_info, icon: "list-alt" do
            option :show_meta, icon: "eye-open"
        end
    end

    menu :item_menu do
        properties break: 1, group_class: "btn-group-xs"
    end

    @meta[:state] = [:query, :ui_state]
end

#search_live(*flds) ⇒ Object



647
648
649
650
# File 'lib/engine2/meta.rb', line 647

def search_live *flds
    flds = @meta[:search_fields] if flds.empty?
    info! *flds, search_live: true
end

#search_template(template) ⇒ Object



638
639
640
# File 'lib/engine2/meta.rb', line 638

def search_template template
    panel[:search_template] = template
end

#searchable(*flds) ⇒ Object



652
653
654
655
# File 'lib/engine2/meta.rb', line 652

def searchable *flds
    @meta.delete(:tabs)
    @meta[:search_fields] = *flds
end

#searchable_tabs(tabs) ⇒ Object



657
658
659
660
# File 'lib/engine2/meta.rb', line 657

def searchable_tabs tabs
    searchable *tabs.map{|name, fields|fields}.flatten
    field_tabs tabs
end

#select_toggle_menuObject



572
573
574
575
576
577
# File 'lib/engine2/meta.rb', line 572

def select_toggle_menu
    m = menu :menu
    unless m.option_index(:select_toggle, false)
        m.option_after :default_order, :select_toggle, icon: "check", enabled: "action.meta.config.selectable", button_loc: false
    end
end

#sortable(*flds) ⇒ Object



642
643
644
645
# File 'lib/engine2/meta.rb', line 642

def sortable *flds
    flds = @meta[:fields] if flds.empty?
    info! *flds, sort: true
end

#templateObject



662
663
664
# File 'lib/engine2/meta.rb', line 662

def template
    SearchTemplates
end