Module: Engine2::ActionListSupport
Instance Attribute Summary collapse
Instance Method Summary
collapse
#hide_pk, #node_defined, #show_pk, #unsupported_association
#config, #decorate, #field_filter, #fields, #fields!, #hide_fields, #loc!, #render, #show_fields
#select_tabs, #tab
#modal_action, #panel, #panel_class, #panel_footer, #panel_header, #panel_panel_template, #panel_template, #panel_title
#menu, #menu?
#on_change
#draggable
Instance Attribute Details
#default_order_field ⇒ Object
Returns the value of attribute default_order_field.
638
639
640
|
# File 'lib/engine2/action.rb', line 638
def default_order_field
@default_order_field
end
|
Returns the value of attribute filters.
638
639
640
|
# File 'lib/engine2/action.rb', line 638
def filters
@filters
end
|
Returns the value of attribute orders.
638
639
640
|
# File 'lib/engine2/action.rb', line 638
def orders
@orders
end
|
Instance Method Details
#default_order(order) ⇒ Object
748
749
750
|
# File 'lib/engine2/action.rb', line 748
def default_order order
@default_order_field = order
end
|
#field_tabs(hash) ⇒ Object
666
667
668
669
|
# File 'lib/engine2/action.rb', line 666
def field_tabs hash
super
search_template 'scaffold/search_tabs'
end
|
#filter(name, &blk) ⇒ Object
776
777
778
|
# File 'lib/engine2/action.rb', line 776
def filter name, &blk
(@filters ||= {})[name] = blk
end
|
#filter_case_insensitive(name) ⇒ Object
780
781
782
783
784
785
786
787
|
# File 'lib/engine2/action.rb', line 780
def filter_case_insensitive name
model = assets[:model]
raise E2Error.new("Field '#{name}' needs to be a string") unless model.find_type_info(name)[:otype] == :string
filter name do |handler, query, hash|
value = hash[name]
value ? query.where(model.table_name.q(name).ilike("%#{value}%")) : query
end
end
|
#order(name, &blk) ⇒ Object
789
790
791
|
# File 'lib/engine2/action.rb', line 789
def order name, &blk
(@orders ||= {})[name] = blk
end
|
#post_process ⇒ Object
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
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
728
729
730
731
732
733
734
735
736
737
|
# File 'lib/engine2/action.rb', line 698
def post_process
model = assets[:model]
if fields = @meta[:search_field_list]
fields = fields - static.meta[:search_field_list] if dynamic?
decorate(fields)
fields.each do |name|
type_info = model.find_type_info(name)
fields(name)[:render] ||= begin 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[:field_list]
fields = fields - static.meta[:field_list] if dynamic?
decorate(fields)
fields.each do |name|
type_info = model.find_type_info(name)
proc = ListRendererPostProcessors[type_info[:type]]
proc.(self, name, type_info) if proc
end
end
super
end
|
678
679
680
681
682
683
684
685
686
687
688
689
690
|
# File 'lib/engine2/action.rb', line 678
def post_run
super
unless panel[:class]
panel_class case @meta[:field_list].size
when 1..3; ''
when 4..6; 'modal-large'
else; 'modal-huge'
end
end
@meta[:primary_fields] = assets[:model].primary_keys
end
|
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
# File 'lib/engine2/action.rb', line 640
def pre_run
super
config.merge!(per_page: 10, use_count: false, selectable: true)
panel_template 'scaffold/list'
panel_title "#{assets[:model].model_icon.icon} #{LOCS[assets[:model].model_route]}"
loc! LOCS[:list_locs]
:menu do
properties break: 2, group_class: "btn-group-sm"
option :search_toggle, icon: "search", show: "action.meta.search_field_list", active: "action.ui_state.search_active", button_loc: false
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
:item_menu do
properties break: 1, group_class: "btn-group-sm"
end
@meta[:state] = [:query, :ui_state]
end
|
#search_live(*flds) ⇒ Object
752
753
754
755
756
757
758
|
# File 'lib/engine2/action.rb', line 752
def search_live *flds
if flds.empty?
flds = @meta[:search_field_list]
@meta[:disable_search_button] = true
end
fields! *flds, search_live: true
end
|
#search_template(template) ⇒ Object
739
740
741
|
# File 'lib/engine2/action.rb', line 739
def search_template template
panel[:search_template] = template
end
|
#searchable(*flds) ⇒ Object
760
761
762
763
764
765
|
# File 'lib/engine2/action.rb', line 760
def searchable *flds
@meta.delete(:tab_list)
@meta.delete(:tabs)
search_template 'scaffold/search'
@meta[:search_field_list] = *flds
end
|
#searchable_tabs(tabs) ⇒ Object
767
768
769
770
|
# File 'lib/engine2/action.rb', line 767
def searchable_tabs tabs
searchable *tabs.map{|name, fields|fields}.flatten
field_tabs tabs
end
|
671
672
673
674
675
676
|
# File 'lib/engine2/action.rb', line 671
def
m = :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
743
744
745
746
|
# File 'lib/engine2/action.rb', line 743
def sortable *flds
flds = @meta[:field_list] if flds.empty?
fields! *flds, sort: true
end
|
772
773
774
|
# File 'lib/engine2/action.rb', line 772
def template
SearchTemplates
end
|