Class: Phlexi::Table::Base
Overview
Base class for creating customizable table components
Defined Under Namespace
Classes: ActionsColumn, ColumnGroup, DataColumn, Display, SelectionColumn
Instance Attribute Summary collapse
Instance Method Summary
collapse
#has_table_description?, #table_description
#has_table_caption?, #table_caption
Constructor Details
#initialize(collection, **options) ⇒ Base
Initialize a new table component
53
54
55
56
57
58
59
60
|
# File 'lib/phlexi/table/base.rb', line 53
def initialize(collection, **options)
@collection = Array(collection)
raise ArgumentError, "Collection cannot be empty" if @collection.empty?
@columns = {}
@options = options
initialize_key
end
|
Instance Attribute Details
#collection ⇒ Enumerable
The collection of items to display in the table
29
30
31
|
# File 'lib/phlexi/table/base.rb', line 29
def collection
@collection
end
|
#columns ⇒ Hash
The columns defined for the table
29
30
31
|
# File 'lib/phlexi/table/base.rb', line 29
def columns
@columns
end
|
#key ⇒ Object
Returns the value of attribute key.
44
45
46
|
# File 'lib/phlexi/table/base.rb', line 44
def key
@key
end
|
#options ⇒ Object
Returns the value of attribute options.
44
45
46
|
# File 'lib/phlexi/table/base.rb', line 44
def options
@options
end
|
Instance Method Details
#actions ⇒ Object
110
111
112
113
114
115
|
# File 'lib/phlexi/table/base.rb', line 110
def actions(**, &)
raise "Action column already added" if @has_action_column
@has_action_column = true
add_column(actions_column_class.new(:phlexi_table_actions, self, label: "Actions", **, &))
end
|
#actions_column_class ⇒ Object
137
138
139
|
# File 'lib/phlexi/table/base.rb', line 137
def actions_column_class
self.class::ActionsColumn
end
|
#add_column(column) ⇒ void
This method returns an undefined value.
Add a column to the table
88
89
90
91
92
|
# File 'lib/phlexi/table/base.rb', line 88
def add_column(column)
raise ArgumentError, "Column '#{column.key}' already exists" if @columns.key?(column.key)
@columns[column.key] = column
end
|
#around_template ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/phlexi/table/base.rb', line 62
def around_template
original_template = Phlexi::Display::Theme.instance
Phlexi::Display::Theme.instance = Phlexi::Table::DisplayTheme.instance
super
ensure
Phlexi::Display::Theme.instance = original_template
end
|
#before_template ⇒ Object
70
71
72
73
|
# File 'lib/phlexi/table/base.rb', line 70
def before_template
super
table_template
end
|
#column(key) ⇒ Object
94
95
96
|
# File 'lib/phlexi/table/base.rb', line 94
def column(key, **, &)
add_column(column_class.new(key, self, **, &))
end
|
#column_class ⇒ Object
129
130
131
|
# File 'lib/phlexi/table/base.rb', line 129
def column_class
self.class::DataColumn
end
|
#column_group(key) ⇒ Object
105
106
107
108
|
# File 'lib/phlexi/table/base.rb', line 105
def column_group(key, **, &)
@has_grouped_columns = true
add_column(column_group_class.new(key, self, **, &))
end
|
#column_group_class ⇒ Object
141
142
143
|
# File 'lib/phlexi/table/base.rb', line 141
def column_group_class
self.class::ColumnGroup
end
|
#dom_id ⇒ Object
125
126
127
|
# File 'lib/phlexi/table/base.rb', line 125
def dom_id
key
end
|
#sample ⇒ Object
117
118
119
|
# File 'lib/phlexi/table/base.rb', line 117
def sample
collection[0]
end
|
#selection_column(key) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/phlexi/table/base.rb', line 98
def selection_column(key, **, &)
raise "Selection column already added" if @has_selection_column
@has_selection_column = true
add_column(selection_column_class.new(key, self, **, &))
end
|
#selection_column_class ⇒ Object
133
134
135
|
# File 'lib/phlexi/table/base.rb', line 133
def selection_column_class
self.class::SelectionColumn
end
|
#table_template ⇒ Object
79
80
81
|
# File 'lib/phlexi/table/base.rb', line 79
def table_template
end
|
#view_template ⇒ Object
75
76
77
|
# File 'lib/phlexi/table/base.rb', line 75
def view_template
render_table
end
|
#wrapped_sample ⇒ Object
121
122
123
|
# File 'lib/phlexi/table/base.rb', line 121
def wrapped_sample
@wrapped_sample ||= WrappedObject.new(sample, index: -1, display_class: self.class::Display)
end
|