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
#default_order_field, #filters, #orders
Attributes inherited from Action
#assets, #invokable, #meta, #node, #static
Instance Method Summary collapse
Methods inherited from ListAction
#invoke, #list_order, #list_search, #page_frame
Methods included from ActionListSupport
#default_order, #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
#hide_pk, #node_defined, #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
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, #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
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/engine2/action/list.rb', line 217 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
255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/engine2/action/list.rb', line 255 def post_run super nd = node.parent.nodes[:decode_entry] request do |h| if h.initial? action = nd.* rec = action.invoke_decode(h, [split_keys(h.params[:parent_id])]).first panel_title "#{static.panel[:title]} - #{action.[:decode_fields].map{|f|rec[f]}.join(action.[:separator])}" end end if nd end |
#pre_run ⇒ Object
211 212 213 214 215 |
# File 'lib/engine2/action/list.rb', line 211 def pre_run super (:panel_menu).option_at 0, :close, icon: "remove" panel_title "#{assets[:model].model_icon.icon} #{LOCS[assets[:assoc][:name]]}" end |