Class: ProMotion::TableData
- Inherits:
-
Object
- Object
- ProMotion::TableData
- Defined in:
- lib/ProMotion/screens/_tables/table_data.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#filtered ⇒ Object
Returns the value of attribute filtered.
-
#filtered_data ⇒ Object
Returns the value of attribute filtered_data.
-
#table_view ⇒ Object
Returns the value of attribute table_view.
Instance Method Summary collapse
- #cell(params = {}) ⇒ Object
- #create_table_cell(data_cell) ⇒ Object
- #delete_cell(params = {}) ⇒ Object
-
#initialize(data, table_view) ⇒ TableData
constructor
A new instance of TableData.
- #remap_data_cell(data_cell) ⇒ Object
- #search(search_string) ⇒ Object
- #section(index) ⇒ Object
- #section_length(index) ⇒ Object
- #sections ⇒ Object
- #set_data_cell_defaults(data_cell) ⇒ Object
- #stop_searching ⇒ Object
- #table_view_cell(params = {}) ⇒ Object
Constructor Details
#initialize(data, table_view) ⇒ TableData
Returns a new instance of TableData.
5 6 7 8 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 5 def initialize(data, table_view) self.data = data self.table_view = table_view end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 3 def data @data end |
#filtered ⇒ Object
Returns the value of attribute filtered.
3 4 5 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 3 def filtered @filtered end |
#filtered_data ⇒ Object
Returns the value of attribute filtered_data.
3 4 5 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 3 def filtered_data @filtered_data end |
#table_view ⇒ Object
Returns the value of attribute table_view.
3 4 5 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 3 def table_view @table_view end |
Instance Method Details
#cell(params = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 23 def cell(params={}) if params[:index_path] params[:section] = params[:index_path].section params[:index] = params[:index_path].row end table_section = self.section(params[:section]) table_section[:cells].at(params[:index].to_i) end |
#create_table_cell(data_cell) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 133 def create_table_cell(data_cell) table_cell = table_view.dequeueReusableCellWithIdentifier(data_cell[:cell_identifier]) unless table_cell table_cell = data_cell[:cell_class].alloc.initWithStyle(data_cell[:cell_style], reuseIdentifier:data_cell[:cell_identifier]) table_cell.extend ProMotion::TableViewCellModule unless table_cell.is_a?(ProMotion::TableViewCellModule) table_cell.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin end table_cell.setup(data_cell) table_cell end |
#delete_cell(params = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 33 def delete_cell(params={}) if params[:index_path] params[:section] = params[:index_path].section params[:index] = params[:index_path].row end table_section = self.section(params[:section]) table_section[:cells].delete_at(params[:index].to_i) end |
#remap_data_cell(data_cell) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 95 def remap_data_cell(data_cell) # Re-maps legacy data cell calls mappings = { cell_style: :cellStyle, cell_identifier: :cellIdentifier, cell_class: :cellClass, masks_to_bounds: :masksToBounds, background_color: :backgroundColor, selection_style: :selectionStyle, cell_class_attributes: :cellClassAttributes, accessory_view: :accessoryView, accessory_type: :accessoryType, accessory_checked: :accessoryDefault, remote_image: :remoteImage, subviews: :subViews } if data_cell[:masks_to_bounds] PM.logger.deprecated "masks_to_bounds: (value) is deprecated. Use layer: { masks_to_bounds: (value) } instead." data_cell[:layer] ||= {} data_cell[:layer][:masks_to_bounds] = data_cell[:masks_to_bounds] # TODO: Deprecate and then remove this. end mappings.each_pair do |n, old| if data_cell[old] warn "[DEPRECATION] `:#{old}` is deprecated in TableScreens. Use `:#{n}`" data_cell[n] = data_cell[old] end end if data_cell[:styles] && data_cell[:styles][:textLabel] warn "[DEPRECATION] `:textLabel` is deprecated in TableScreens. Use `:label`" data_cell[:styles][:label] = data_cell[:styles][:textLabel] end data_cell end |
#search(search_string) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 43 def search(search_string) self.filtered_data = [] self.filtered = true search_string = search_string.downcase.strip self.data.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?(search_string) ? cell : nil end.compact if new_section[:cells] && new_section[:cells].length > 0 new_section[:title] = section[:title] self.filtered_data << new_section end end self.filtered_data end |
#section(index) ⇒ Object
10 11 12 13 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 10 def section(index) s = sections.at(index) s || { title: nil, cells: [] } end |
#section_length(index) ⇒ Object
19 20 21 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 19 def section_length(index) section(index)[:cells].length end |
#sections ⇒ Object
15 16 17 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 15 def sections self.filtered ? self.filtered_data : self.data end |
#set_data_cell_defaults(data_cell) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 88 def set_data_cell_defaults(data_cell) data_cell[:cell_style] ||= UITableViewCellStyleDefault data_cell[:cell_identifier] ||= "Cell" data_cell[:cell_class] ||= ProMotion::TableViewCell data_cell end |
#stop_searching ⇒ Object
66 67 68 69 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 66 def stop_searching self.filtered_data = [] self.filtered = false end |
#table_view_cell(params = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ProMotion/screens/_tables/table_data.rb', line 71 def table_view_cell(params={}) if params[:index_path] params[:section] = params[:index_path].section params[:index] = params[:index_path].row end data_cell = self.cell(section: params[:section], index: params[:index]) return UITableViewCell.alloc.init unless data_cell # No data? data_cell = self.remap_data_cell(data_cell) # TODO: Deprecated, remove in version 1.0 data_cell = self.set_data_cell_defaults(data_cell) table_cell = self.create_table_cell(data_cell) table_cell end |