lib/engine2/action/decode.rb in engine2-1.0.5 vs lib/engine2/action/decode.rb in engine2-1.0.6

- old
+ new

@@ -17,12 +17,12 @@ def show_max_selected max @meta[:show_max_selected] = max end def post_process - if fields = @meta[:fields] - fields = fields - static.meta[:fields] if dynamic? + if fields = @meta[:field_list] + fields = fields - static.meta[:field_list] if dynamic? # no decorate here fields.each do |name| type_info = assets[:model].type_info[name] # foreign keys ? proc = ListRendererPostProcessors[type_info[:type]] # like... checkboxes, list_selects proc.(self, name, type_info) if proc @@ -53,33 +53,37 @@ class DecodeListAction < DecodeAction action_type :decode_list def invoke handler - {entries: get_query.limit(200).all} + {entries: get_query.limit(200).load_all} end end class TypeAheadAction < DecodeAction action_type :typeahead def pre_run super - limit 10 + @limit = 10 end def limit lmt - @meta[:limit] = lmt + @limit = lmt end + def case_insensitive + @case_insensitive = true + end + def invoke handler if query = handler.params[:query] - condition = @meta[:decode_fields].map{|f|f.like("%#{query}%")}.reduce{|q, f| q | f} - {entries: get_query.where(condition).limit(@meta[:limit]).all} + condition = @meta[:decode_fields].map{|f|f.like("%#{query}%", case_insensitive: @case_insensitive)}.reduce{|q, f| q | f} + {entries: get_query.where(condition).limit(@limit).load_all} else handler.permit id = handler.params[:id] - record = get_query[Hash[assets[:model].primary_keys.zip(split_keys(id))]] + record = get_query.load Hash[assets[:model].primary_keys.zip(split_keys(id))] # handler.halt_not_found(LOCS[:no_entry]) unless record {entry: record} end end end @@ -90,10 +94,10 @@ def invoke handler {entries: invoke_decode(handler, handler.param_to_json(:ids))} end def invoke_decode handler, ids - records = get_query.where(ids.map{|keys| Hash[assets[:model].primary_keys.zip(keys)]}.reduce{|q, c| q | c}).all + records = get_query.where(ids.map{|keys| Hash[assets[:model].primary_keys.zip(keys)]}.reduce{|q, c| q | c}).load_all # handler.halt_not_found(LOCS[:no_entry]) if records.empty? records end def post_run \ No newline at end of file