Class: Engine2::StarToManyListAction
- Inherits:
-
ListAction
- Object
- Action
- ListAction
- Engine2::StarToManyListAction
- Defined in:
- lib/engine2/action/list.rb
Overview
-
to Many
Direct Known Subclasses
Instance Attribute Summary
Attributes included from ActionListSupport
Attributes inherited from Action
#assets, #invokable, #meta, #node, #static
Instance Method Summary collapse
Methods inherited from ListAction
Methods included from ActionListSupport
#field_tabs, #filter, #filter_case_insensitive, #order, #post_process, #search_live, #search_template, #searchable, #searchable_tabs, #select_toggle_menu, #sortable, #template
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
#field_tabs, #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
Methods included from ActionOnChangeSupport
Methods included from ActionQuerySupport
#find_record, #get_query, #query, #select
Methods inherited from Action
action_type, #action_type, #arguments, #check_static_action, #define_invoke, #dynamic?, #execute, #freeze_action, #http_method, http_method, inherit, inherited, #initialize, #invoke!, #lookup, #merge, #node_defined, #post_process, #repeat, #request, #request_action_proc_params, #split_keys
Constructor Details
This class inherits a constructor from Engine2::Action
Instance Method Details
#list_context(query, handler) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/engine2/action/list.rb', line 164 def list_context query, handler handler.permit parent = handler.params[:parent_id] model = assets[:model] assoc = assets[:assoc] parent_keys = split_keys(parent) case assoc[:type] when :one_to_many keys = assoc[:keys] condition = parent_keys.all?(&:empty?) ? false : Hash[keys.map{|k| model.table_name.q(k)}.zip(parent_keys)] if handler.params[:negate] query = query.exclude(condition) query = query.or(Hash[keys.zip([nil])]) if keys.all?{|k|model.db_schema[k][:allow_null] == true} # type_info[:required] ? query else query.where(condition) end when :many_to_many q_pk = model.primary_keys_qualified j_table = assoc[:join_table] l_keys = assoc[:left_keys].map{|k| j_table.q(k)} r_keys = assoc[:right_keys].map{|k| j_table.q(k)} r_keys_vals = Hash[r_keys.zip(q_pk)] l_keys_vals = parent_keys.all?(&:empty?) ? false : Hash[l_keys.zip(parent_keys)] if handler.params[:negate] query.exclude(model.db[j_table].select(nil).where(r_keys_vals & l_keys_vals).exists) else # query.qualify.join(j_table, [r_keys_vals, l_keys_vals]) if joins = query.opts[:join] and joins.find{|j|j.table == j_table} query else query.qualify.left_join(j_table, r_keys_vals) end.filter(l_keys_vals) end else unsupported_association end end |
#post_run ⇒ Object
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/engine2/action/list.rb', line 202 def post_run super request do |h| if h.initial? && nd = node.parent.nodes[:decode_entry] action = nd.* rec = action.invoke_decode(h, [[h.params[:parent_id]]]).first panel_title "#{static.panel[:title]} - #{rec}" end end end |
#pre_run ⇒ Object
158 159 160 161 162 |
# File 'lib/engine2/action/list.rb', line 158 def pre_run super (:panel_menu).option_at 0, :cancel, icon: "remove" panel_title "#{:list.icon} #{LOCS[assets[:assoc][:name]]}" end |