Module: ProMotion::Table::Searchable
- Included in:
- DataTable
- Defined in:
- lib/project/pro_motion/data_table_searchable.rb
Instance Method Summary collapse
- #dt_searchDisplayController(controller, shouldReloadTableForSearchString: search_string) ⇒ Object
-
#dt_searchDisplayControllerWillBeginSearch(controller) ⇒ Object
iOS methods, headless camel case #######.
- #dt_searchDisplayControllerWillEndSearch(controller) ⇒ Object
- #make_data_table_searchable(params = {}) ⇒ Object
- #new_frc_with_search(search_string) ⇒ Object
- #reset_search_frc ⇒ Object
- #search_delegate ⇒ Object
- #search_fetch_controller ⇒ Object
Instance Method Details
#dt_searchDisplayController(controller, shouldReloadTableForSearchString: search_string) ⇒ Object
77 78 79 80 81 |
# File 'lib/project/pro_motion/data_table_searchable.rb', line 77 def dt_searchDisplayController(controller, shouldReloadTableForSearchString:search_string) @_data_table_search_string = search_string reset_search_frc true end |
#dt_searchDisplayControllerWillBeginSearch(controller) ⇒ Object
iOS methods, headless camel case #######
63 64 65 66 |
# File 'lib/project/pro_motion/data_table_searchable.rb', line 63 def dt_searchDisplayControllerWillBeginSearch(controller) @_data_table_searching = true search_controller.delegate.will_begin_search if search_controller.delegate.respond_to? "will_begin_search" end |
#dt_searchDisplayControllerWillEndSearch(controller) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/project/pro_motion/data_table_searchable.rb', line 68 def dt_searchDisplayControllerWillEndSearch(controller) @_data_table_searching = false @_search_fetch_controller.delegate = nil unless @_search_fetch_controller.nil? @_search_fetch_controller = nil @_data_table_search_string = nil search_controller.delegate.will_end_search if search_controller.delegate.respond_to? "will_end_search" update_table_data end |
#make_data_table_searchable(params = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/project/pro_motion/data_table_searchable.rb', line 5 def make_data_table_searchable(params={}) if params[:search_bar][:fields].nil? raise "ERROR: You must specify fields:[:example] for your searchable DataTableScreen. It should be an array of fields you want searched in CDQ." else @data_table_predicate_fields = params[:search_bar][:fields] end params[:delegate] = search_delegate params[:search_results_updater] = search_delegate make_searchable(params) end |
#new_frc_with_search(search_string) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/project/pro_motion/data_table_searchable.rb', line 21 def new_frc_with_search(search_string) return if @data_table_predicate_fields.blank? # Create the predicate from the predetermined fetch scope. where = @data_table_predicate_fields.map{|f| "#{f} CONTAINS[cd] \"#{search_string}\"" }.join(" OR ") search_scope = fetch_scope.where(where) # Create the search FRC with the predicate and set delegate search = NSFetchedResultsController.alloc.initWithFetchRequest( search_scope.fetch_request, managedObjectContext: search_scope.context, sectionNameKeyPath: nil, cacheName: nil ) search.delegate = search_delegate # Perform the fetch error_ptr = Pointer.new(:object) unless search.performFetch(error_ptr) raise "Error performing fetch: #{error_ptr[2].description}" end search end |
#reset_search_frc ⇒ Object
46 47 48 49 50 51 |
# File 'lib/project/pro_motion/data_table_searchable.rb', line 46 def reset_search_frc # Update the filter, in this case just blow away the FRC and let # lazy evaluation create another with the relevant search info @_search_fetch_controller.delegate = nil unless @_search_fetch_controller.nil? @_search_fetch_controller = nil end |
#search_delegate ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/project/pro_motion/data_table_searchable.rb', line 53 def search_delegate @_search_delegate ||= begin d = DataTableSeachDelegate.new d.parent = WeakRef.new(self) d end end |
#search_fetch_controller ⇒ Object
17 18 19 |
# File 'lib/project/pro_motion/data_table_searchable.rb', line 17 def search_fetch_controller @_search_fetch_controller ||= new_frc_with_search(search_string) end |