lib/ProMotion/table/data/table_data.rb in ProMotion-2.0.0 vs lib/ProMotion/table/data/table_data.rb in ProMotion-2.0.1
- old
+ new
@@ -1,7 +1,9 @@
module ProMotion
class TableData
+ include ProMotion::Table::Utils
+
attr_accessor :data, :filtered_data, :search_string, :original_search_string, :filtered, :table_view
def initialize(data, table_view)
self.data = data
self.table_view = WeakRef.new(table_view)
@@ -19,40 +21,27 @@
def section_length(index)
section(index)[:cells].length
end
def cell(params={})
- if params[:index_path]
- params[:section] = params[:index_path].section
- params[:index] = params[:index_path].row
- end
-
+ params = index_path_to_section_index(params)
table_section = self.section(params[:section])
c = table_section[:cells].at(params[:index].to_i)
set_data_cell_defaults c
end
def delete_cell(params={})
- if params[:index_path]
- params[:section] = params[:index_path].section
- params[:index] = params[:index_path].row
- end
-
+ params = index_path_to_section_index(params)
table_section = self.section(params[:section])
table_section[:cells].delete_at(params[:index].to_i)
end
def search(search_string)
- self.filtered_data = []
- self.filtered = true
+ start_searching(search_string)
- self.original_search_string = search_string
- self.search_string = search_string.downcase.strip
-
self.data.compact.each do |section|
new_section = {}
- new_section[:cells] = []
new_section[:cells] = section[:cells].map do |cell|
cell[:searchable] != false && "#{cell[:title]}\n#{cell[:search_text]}".downcase.strip.include?(self.search_string) ? cell : nil
end.compact
@@ -97,7 +86,15 @@
ident << "-remoteimage" if data_cell[:remote_image]
ident << "-image" if data_cell[:image]
ident
end
+ private
+
+ def start_searching(search_string)
+ self.filtered_data = []
+ self.filtered = true
+ self.search_string = search_string.downcase.strip
+ self.original_search_string = search_string
+ end
end
end