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

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

Methods included from MetaMenuSupport

#menu, #menu?

Methods included from MetaOnChangeSupport

#on_change

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



545
546
547
# File 'lib/engine2/meta.rb', line 545

def filters
  @filters
end

#ordersObject (readonly)

Returns the value of attribute orders.



545
546
547
# File 'lib/engine2/meta.rb', line 545

def orders
  @orders
end

Instance Method Details

#filter(name, &blk) ⇒ Object



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

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

#order(name, &blk) ⇒ Object



673
674
675
# File 'lib/engine2/meta.rb', line 673

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



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
637
638
639
# File 'lib/engine2/meta.rb', line 601

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



582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/engine2/meta.rb', line 582

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



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

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

    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]}"
    loc! LOCS[:list_locs]
    menu :menu do
        properties break: 2, group_class: "btn-group-xs"
        option :search_toggle, icon: "search", show: "action.meta.search_fields", active: "action.ui_state.search_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



650
651
652
653
# File 'lib/engine2/meta.rb', line 650

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

#search_template(template) ⇒ Object



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

def search_template template
    panel[:search_template] = template
end

#searchable(*flds) ⇒ Object



655
656
657
658
# File 'lib/engine2/meta.rb', line 655

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

#searchable_tabs(tabs) ⇒ Object



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

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

#select_toggle_menuObject



575
576
577
578
579
580
# File 'lib/engine2/meta.rb', line 575

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", active: "action.selection", button_loc: false
    end
end

#sortable(*flds) ⇒ Object



645
646
647
648
# File 'lib/engine2/meta.rb', line 645

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

#templateObject



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

def template
    SearchTemplates
end