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
#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
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 201 202 203 204 205 206 207 |
# File 'lib/engine2/action/list.rb', line 171 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
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/engine2/action/list.rb', line 209 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.meta[:decode_fields].map{|f|rec[f]}.join(action.meta[:separator])}" end end if nd end |
#pre_run ⇒ Object
165 166 167 168 169 |
# File 'lib/engine2/action/list.rb', line 165 def pre_run super (:panel_menu).option_at 0, :close, icon: "remove" panel_title "#{:list.icon} #{LOCS[assets[:assoc][:name]]}" end |