Module: Engine2::ActionListSupport

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ActionModelSupport

#get_type_info, #hide_pk, #node_defined, #show_pk, #unsupported_association

Methods included from ActionAPISupport

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

Methods included from ActionTabSupport

#lazy_tab, #select_tabs

Methods included from ActionPanelSupport

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

Methods included from ActionMenuSupport

#menu, #menu?

Methods included from ActionOnChangeSupport

#on_change

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



630
631
632
# File 'lib/engine2/action.rb', line 630

def filters
  @filters
end

#ordersObject (readonly)

Returns the value of attribute orders.



630
631
632
# File 'lib/engine2/action.rb', line 630

def orders
  @orders
end

Instance Method Details

#field_tabs(hash) ⇒ Object



658
659
660
661
# File 'lib/engine2/action.rb', line 658

def field_tabs hash
    super
    search_template 'scaffold/search_tabs'
end

#filter(name, &blk) ⇒ Object



758
759
760
# File 'lib/engine2/action.rb', line 758

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

#filter_case_insensitive(name) ⇒ Object

Raises:



762
763
764
765
# File 'lib/engine2/action.rb', line 762

def filter_case_insensitive name
    raise E2Error.new("Field '#{name}' needs to be a string one") unless get_type_info(name)[:otype] == :string
    filter(name){|query, hash, handler| query.where(name.ilike("%#{hash[name]}%")) }
end

#order(name, &blk) ⇒ Object



767
768
769
# File 'lib/engine2/action.rb', line 767

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



689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'lib/engine2/action.rb', line 689

def post_process
    if fields = @meta[:search_fields]
        fields = fields - static.meta[: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.meta[: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



670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/engine2/action.rb', line 670

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



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# File 'lib/engine2/action.rb', line 632

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

    panel_template 'scaffold/list'
    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 if Handler::development?
    end

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

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

#search_live(*flds) ⇒ Object



738
739
740
741
# File 'lib/engine2/action.rb', line 738

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

#search_template(template) ⇒ Object



729
730
731
# File 'lib/engine2/action.rb', line 729

def search_template template
    panel[:search_template] = template
end

#searchable(*flds) ⇒ Object



743
744
745
746
747
# File 'lib/engine2/action.rb', line 743

def searchable *flds
    @meta.delete(:tabs)
    search_template 'scaffold/search'
    @meta[:search_fields] = *flds
end

#searchable_tabs(tabs) ⇒ Object



749
750
751
752
# File 'lib/engine2/action.rb', line 749

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

#select_toggle_menuObject



663
664
665
666
667
668
# File 'lib/engine2/action.rb', line 663

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



733
734
735
736
# File 'lib/engine2/action.rb', line 733

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

#templateObject



754
755
756
# File 'lib/engine2/action.rb', line 754

def template
    SearchTemplates
end