Class: Engine2::ArrayListAction

Inherits:
Action show all
Includes:
ActionListSupport
Defined in:
lib/engine2/action/array.rb

Instance Attribute Summary

Attributes included from ActionListSupport

#default_order_field, #filters, #orders

Attributes inherited from Action

#assets, #invokable, #meta, #node, #static

Instance Method Summary collapse

Methods included from ActionListSupport

#default_order, #field_tabs, #filter, #filter_case_insensitive, #order, #post_process, #post_run, #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, #post_run, #pre_run

Methods included from ActionMenuSupport

#menu, #menu?, #post_process

Methods included from ActionOnChangeSupport

#on_change

Methods included from ActionDraggableSupport

#draggable, #post_run

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, #post_run, #pre_run, #repeat, #request, #request_action_proc_params, #split_keys

Constructor Details

This class inherits a constructor from Engine2::Action

Instance Method Details

#data_source(handler) ⇒ Object



42
43
44
# File 'lib/engine2/action/array.rb', line 42

def data_source handler
    []
end

#invoke(handler) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/engine2/action/array.rb', line 50

def invoke handler
    params = handler.params
    # if params[:initial] || params[:refresh]
    entries = data_source(handler)

    per_page = lookup(:config, :per_page)
    page = params[:page].to_i
    handler.permit page >= 0 && page < 1000

    if order_str = params[:order]
        order = order_str.to_sym
        handler.permit lookup(:fields, order, :sort)
        entries = entries.sort_by{|e|e[order].to_s}
        entries = entries.reverse if params[:asc] == "true"
    end

    if search = params[:search]
        entries = list_search(entries, handler, search)
    end

    {entries: page_frame(handler, entries[page, per_page]), count: entries.size}
end

#list_search(entries, handler, search) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/engine2/action/array.rb', line 73

def list_search entries, 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 sfields.include?(name)

        type_info = model.find_type_info(name)
        entries = if filter = (@filters && @filters[name]) || (dynamic? && (static.filters && static.filters[name]))
            filter.(handler, entries, hash)
        elsif filter = DefaultFilters[type_info[:otype]]
            filter.(entries, name, value, type_info, hash)
        else
            raise E2Error.new("Filter not found for field '#{name}' in model '#{model}'") unless filter
        end

        handler.permit entries
    end

    entries
end

#page_frame(handler, entries) ⇒ Object



46
47
48
# File 'lib/engine2/action/array.rb', line 46

def page_frame handler, entries
    entries
end