Merge pull request #288 from clearsightstudio/fix-indexable

Fix indexable
This commit is contained in:
Jamon Holmgren
2013-09-04 08:17:07 -07:00
4 changed files with 32 additions and 14 deletions

View File

@@ -1,8 +1,12 @@
module ProMotion
module Table
module Indexable
def index_from_section_titles
@promotion_table_data.filtered ? nil : @promotion_table_data.sections.collect{ |section| section[:title][0] }
def table_data_index
return nil if @promotion_table_data.filtered || !self.class.get_indexable
index = @promotion_table_data.sections.collect{ |section| section[:title][0] }
index.unshift("{search}") if self.class.get_searchable
index
end
end
end

View File

@@ -180,16 +180,12 @@ module ProMotion
# Set table_data_index if you want the right hand index column (jumplist)
def sectionIndexTitlesForTableView(table_view)
if @promotion_table_data.filtered
nil
return nil if @promotion_table_data.filtered
if self.respond_to?(:table_data_index)
self.table_data_index
else
if self.respond_to?(:table_data_index)
self.table_data_index
elsif self.class.respond_to?(:get_indexable) && self.class.get_indexable
self.index_from_section_titles
else
nil
end
nil
end
end

View File

@@ -11,3 +11,8 @@ class TableScreenIndexable < PM::TableScreen
end
end
class TableScreenIndexableSearchable < TableScreenIndexable
indexable
searchable
end

View File

@@ -1,12 +1,25 @@
describe "PM::Table module" do
describe "PM::Table module indexable" do
before do
@screen = TableScreenIndexable.new
end
it "should automatically return the first letter of each section" do
result = %w{ A G M O S U }
@screen.sectionIndexTitlesForTableView(@screen.table_view).should == result
end
end
describe "PM::Table module indexable/searchable" do
before do
@screen = TableScreenIndexableSearchable.new
end
it "should automatically return the first letter of each section" do
result = %w{ {search} A G M O S U }
@screen.sectionIndexTitlesForTableView(@screen.table_view).should == result
end
end