Class: Glimmer::LibUI::CustomControl::RefinedTable
Constant Summary
collapse
- FILTER_DEFAULT =
lambda do |row_hash, query|
text = row_hash.values.map(&:downcase).join(' ')
if query != @last_query
@last_query = query
@query_words = []
query_text = query.strip
until query_text.empty?
exact_term_double_quoted_regexp = /"[^"]+"/
specific_column_double_quoted_column_name_regexp = /"[^":]+":[^": ]+/
specific_column_double_quoted_column_value_regexp = /[^": ]+:"[^":]+"/
specific_column_double_quoted_column_name_and_value_regexp = /"[^":]+":"[^":]+"/
single_word_regexp = /\S+/
query_match = (query_text + ' ').match(/^(#{exact_term_double_quoted_regexp}|#{specific_column_double_quoted_column_name_regexp}|#{specific_column_double_quoted_column_value_regexp}|#{specific_column_double_quoted_column_name_and_value_regexp}|#{single_word_regexp})\s+/)
if query_match && query_match[1]
query_word = query_match[1]
query_text = query_text.sub(query_word, '').strip
query_word = query_word.sub(/^"/, '').sub(/"$/, '') if query_word.start_with?('"') && query_word.end_with?('"') && !query_word.include?(':')
@query_words << query_word
end
end
end
@query_words.all? do |word|
if word.include?(':')
column_name, column_value = word.split(':')
column_value = column_value.to_s
column_name = column_name.sub(/^"/, '').sub(/"$/, '') if column_name.start_with?('"') && column_name.end_with?('"')
column_value = column_value.sub(/^"/, '').sub(/"$/, '') if column_value.start_with?('"') && column_value.end_with?('"')
column_human_name = row_hash.keys.find do |table_column_name|
table_column_name.underscore.start_with?(column_name.underscore)
end
if column_human_name
row_hash[column_human_name].downcase.include?(column_value.downcase)
else
text.downcase.include?(word.downcase)
end
else
text.downcase.include?(word.downcase)
end
end
end
Instance Attribute Summary collapse
#args, #body_root, #content, #keyword, #libui, #options, #parent, #parent_proxy
Instance Method Summary
collapse
add_custom_control_namespaces_for, after_body, before_body, body, #can_handle_listener?, custom_control_namespaces, def_option_attr_accessors, flyweight_custom_control_classes, for, #handle_listener, #has_instance_method?, #initialize, keyword, namespaces_for_class, #observer_registrations, option, options, #post_add_content, #post_initialize_child, reset_custom_control_namespaces, shortcut_keyword
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
257
258
259
260
261
262
263
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 257
def method_missing(method_name, *args, &block)
if @table_proxy&.respond_to?(method_name, *args, &block)
@table_proxy&.send(method_name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#filtered_model_array ⇒ Object
filtered model array (intermediary, non-paginated)
83
84
85
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 83
def filtered_model_array
@filtered_model_array
end
|
#refined_model_array ⇒ Object
paginated filtered model array
84
85
86
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 84
def refined_model_array
@refined_model_array
end
|
#table_proxy ⇒ Object
Returns the value of attribute table_proxy.
85
86
87
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 85
def table_proxy
@table_proxy
end
|
Instance Method Details
#correct_page(page) ⇒ Object
247
248
249
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 247
def correct_page(page)
[[page, 1].max, page_count].min
end
|
#filter_model_array ⇒ Object
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 212
def filter_model_array
return unless (@last_filter_query.nil? || filter_query != @last_filter_query)
if !@filtered_model_array_stack.key?(filter_query)
table_column_names = @table_proxy.columns.map(&:name)
@filtered_model_array_stack[filter_query] = model_array.dup.filter do |model|
row_values = @table_proxy.expand([model])[0].map(&:to_s)
row_hash = Hash[table_column_names.zip(row_values)]
filter.call(row_hash, filter_query)
end
end
@filtered_model_array = @filtered_model_array_stack[filter_query]
if @last_filter_query.nil? || filter_query.size > @last_filter_query.size
@filter_query_page_stack[filter_query] = correct_page(page)
end
self.page = @filter_query_page_stack[filter_query] || correct_page(page)
paginate_model_array
@last_filter_query = filter_query
end
|
#index ⇒ Object
235
236
237
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 235
def index
[per_page * (page - 1), 0].max
end
|
#init_model_array ⇒ Object
203
204
205
206
207
208
209
210
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 203
def init_model_array
@last_filter_query = nil
@filter_query_page_stack = {}
@filtered_model_array = model_array.dup
@filtered_model_array_stack = {'' => @filtered_model_array}
self.page = correct_page(page)
filter_model_array if @table_proxy
end
|
#limit ⇒ Object
239
240
241
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 239
def limit
[(filtered_model_array.count - index), per_page].min
end
|
#page_count ⇒ Object
243
244
245
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 243
def page_count
(filtered_model_array.count.to_f / per_page.to_f).ceil
end
|
#paginate_model_array ⇒ Object
231
232
233
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 231
def paginate_model_array
self.refined_model_array = filtered_model_array[index, limit]
end
|
#respond_to?(method_name, *args, &block) ⇒ Boolean
Ensure proxying properties to @table_proxy if body_root (vertical_box) doesn't support them
253
254
255
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 253
def respond_to?(method_name, *args, &block)
super || @table_proxy&.respond_to?(method_name, *args, &block)
end
|
#table_filter ⇒ Object
132
133
134
135
136
137
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 132
def table_filter
search_entry {
stretchy false
text <=> [self, :filter_query]
}
end
|
#table_paginator ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 139
def table_paginator
horizontal_box {
stretchy false
button('<<') {
enabled <= [self, :page, on_read: ->(val) {val > 1}]
on_clicked do
unless self.page == 0
self.page = 1
paginate_model_array
end
end
}
button('<') {
enabled <= [self, :page, on_read: ->(val) {val > 1}]
on_clicked do
unless self.page == 0
self.page = [page - 1, 1].max
paginate_model_array
end
end
}
entry {
text <=> [self, :page,
on_read: :to_s,
on_write: ->(val) { correct_page(val.to_i) },
after_write: ->(val) { paginate_model_array },
]
}
if visible_page_count
label {
text <= [self, :refined_model_array, on_read: ->(val) {"of #{page_count} pages"}]
}
end
button('>') {
enabled <= [self, :page, on_read: ->(val) {val < page_count}]
on_clicked do
unless self.page == 0
self.page = [page + 1, page_count].min
paginate_model_array
end
end
}
button('>>') {
enabled <= [self, :page, on_read: ->(val) {val < page_count}]
on_clicked do
unless self.page == 0
self.page = page_count
paginate_model_array
end
end
}
}
end
|