Class: RefinedTable

Inherits:
Object
  • Object
show all
Includes:
Glimmer::LibUI::CustomControl
Defined in:
lib/glimmer/libui/custom_control/refined_table.rb

Instance Attribute Summary collapse

Attributes included from Glimmer::LibUI::CustomControl

#args, #body_root, #content, #keyword, #libui, #options, #parent, #parent_proxy

Instance Method Summary collapse

Methods included from Glimmer::LibUI::CustomControl

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



166
167
168
169
170
171
172
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 166

def method_missing(method_name, *args, &block)
  if @table&.respond_to?(method_name, *args, &block)
    @table&.send(method_name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#filter_queryObject

Returns the value of attribute filter_query.



11
12
13
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 11

def filter_query
  @filter_query
end

#filter_query_page_stackObject

Returns the value of attribute filter_query_page_stack.



11
12
13
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 11

def filter_query_page_stack
  @filter_query_page_stack
end

#filtered_model_arrayObject

Returns the value of attribute filtered_model_array.



11
12
13
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 11

def filtered_model_array
  @filtered_model_array
end

#paginated_model_arrayObject

Returns the value of attribute paginated_model_array.



11
12
13
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 11

def paginated_model_array
  @paginated_model_array
end

Instance Method Details

#correct_page(page) ⇒ Object



156
157
158
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 156

def correct_page(page)
  [[page, 1].max, page_count].min
end

#indexObject



144
145
146
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 144

def index
  [per_page * (page - 1), 0].max
end

#limitObject



148
149
150
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 148

def limit
  [(filtered_model_array.count - index), per_page].min
end

#page_countObject



152
153
154
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 152

def page_count
  (filtered_model_array.count.to_f / per_page.to_f).ceil
end

#paginate_model_arrayObject



140
141
142
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 140

def paginate_model_array
  self.paginated_model_array = filtered_model_array[index, limit]
end

#respond_to?(method_name, *args, &block) ⇒ Boolean

Ensure proxying properties to @table if body_root (vertical_box) doesn’t support them

Returns:

  • (Boolean)


162
163
164
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 162

def respond_to?(method_name, *args, &block)
  super || @table&.respond_to?(method_name, *args, &block)
end

#table_filterObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 51

def table_filter
  search_entry {
    stretchy false
    text <=> [self, :filter_query,
      before_write: ->(new_filter_query) {
        if new_filter_query != filter_query
          if !@filtered_model_array_stack.key?(new_filter_query)
            @filtered_model_array_stack[new_filter_query] = model_array.dup.filter do |model|
              @table.expand([model])[0].any? do |attribute_value|
                attribute_value.to_s.downcase.include?(new_filter_query.downcase)
              end
            end
          end
          @filtered_model_array = @filtered_model_array_stack[new_filter_query]
          if new_filter_query.size > filter_query.size
            @filter_query_page_stack[filter_query] = page
          end
          self.page = @filter_query_page_stack[new_filter_query] || correct_page(page)
          paginate_model_array
        end
      }
    ]
  }
end

#table_paginatorObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
132
133
134
135
136
137
138
# File 'lib/glimmer/libui/custom_control/refined_table.rb', line 76

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, :paginated_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