mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-05-24 09:13:24 +08:00
Merge pull request #288 from clearsightstudio/fix-indexable
Fix indexable
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -11,3 +11,8 @@ class TableScreenIndexable < PM::TableScreen
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class TableScreenIndexableSearchable < TableScreenIndexable
|
||||
indexable
|
||||
searchable
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user