Class: Engine2::ListAction
- Includes:
- ActionListSupport, ActionQuerySupport
- Defined in:
- lib/engine2/action/list.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes included from ActionListSupport
Attributes inherited from Action
#assets, #invokable, #meta, #node, #static
Instance Method Summary collapse
- #invoke(handler) ⇒ Object
- #list_context(query, handler) ⇒ Object
- #list_search(query, handler, search) ⇒ Object
- #post_run ⇒ Object
Methods included from ActionListSupport
#field_tabs, #filter, #filter_case_insensitive, #order, #post_process, #pre_run, #search_live, #search_template, #searchable, #searchable_tabs, #select_toggle_menu, #sortable, #template
Methods included from ActionModelSupport
#hide_pk, #node_defined, #pre_run, #show_pk, #unsupported_association
Methods included from ActionAPISupport
#config, #decorate, #field_filter, #fields, #fields!, #hide_fields, #loc!, #render, #show_fields
Methods included from ActionTabSupport
#field_tabs, #select_tabs, #tab
Methods included from ActionPanelSupport
#modal_action, #panel, #panel_class, #panel_footer, #panel_header, #panel_panel_template, #panel_template, #panel_title, #pre_run
Methods included from ActionMenuSupport
Methods included from ActionOnChangeSupport
Methods included from ActionDraggableSupport
Methods included from ActionQuerySupport
#find_record, #get_query, #query, #select
Methods inherited from Action
action_type, #action_type, #arguments, #check_anonymous_action_class, #check_static_action, #define_invoke, #define_method, #dynamic?, #execute, #freeze_action, #http_method, http_method, inherit, inherited, #initialize, #invoke!, #join_keys, #lookup, #merge, #node_defined, #post_process, #pre_run, #repeat, #request, #request_action_proc_params, #split_keys
Constructor Details
This class inherits a constructor from Engine2::Action
Instance Method Details
#invoke(handler) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/engine2/action/list.rb', line 85 def invoke handler params = handler.params model = assets[:model] query = list_context(get_query, handler) if search = params[:search] query = list_search(query, handler, search) end count = query.count if lookup(:config, :use_count) if order_str = params[:order] order = order_str.to_sym handler.permit lookup(:fields, order, :sort) if order_blk = (@orders && @orders[order]) || (dynamic? && (static.orders && static.orders[order])) query = order_blk.(handler, query) else order = model.table_name.q(order) if model.type_info[order] query = query.order(order) end query = query.reverse if params[:asc] == "true" end per_page = lookup(:config, :per_page) page = params[:page].to_i handler.permit page >= 0 && page < 1000 query = query.limit(per_page, page) res = {entries: query.load_all} res[:count] = count if count res end |
#list_context(query, handler) ⇒ Object
144 145 146 |
# File 'lib/engine2/action/list.rb', line 144 def list_context query, handler query end |
#list_search(query, handler, search) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/engine2/action/list.rb', line 121 def list_search query, handler, search hash = JSON.parse(search, symbolize_names: true) rescue handler.halt_forbidden model = assets[:model] sfields = lookup(:search_field_list) handler.permit sfields hash.each_pair do |name, value| handler.permit name = sfields.find{|sf|sf.to_sym == name} type_info = model.find_type_info(name) query = if filter = (@filters && @filters[name]) || (dynamic? && (static.filters && static.filters[name])) filter.(handler, query, hash) elsif filter = DefaultFilters[type_info[:otype]] name = model.type_info[name] ? model.table_name.q(name) : Sequel.expr(name) filter.(query, name, value, type_info, hash) else raise E2Error.new("Filter not found for field '#{name}' in model '#{model}'") unless filter end handler.permit query end query end |
#post_run ⇒ Object
80 81 82 83 |
# File 'lib/engine2/action/list.rb', line 80 def post_run query select(*assets[:model].columns.reject{|col| assets[:model].type_info[col][:length].to_i > 20}.take(10)) unless @query super end |