class TkInspectRails::SqlPanel::RootComponent

Attributes

expression[RW]
results[RW]
sql_panel[RW]

Public Instance Methods

execute_sql(e) click to toggle source
# File lib/tk_inspect_rails/sql_panel/root_component.rb, line 30
def execute_sql(e)
  @expression = @text.value
  @results = @sql_panel.execute_sql(@expression)
  regenerate
end
items_for_path(path) click to toggle source
# File lib/tk_inspect_rails/sql_panel/root_component.rb, line 26
def items_for_path(path)
  @results || []
end
render(p, parent_component) click to toggle source
# File lib/tk_inspect_rails/sql_panel/root_component.rb, line 8
def render(p, parent_component)
  p.vpaned(sticky: 'wens', x_flex: 1, y_flex: 1) do |f|
    f.vframe(sticky: 'wens', x_flex: 1) do |vf|
      vf.hframe(sticky: 'wen', padding: 8, x_flex: 1) do |hf|
        hf.label(text: "SQL Expression", sticky: 'w', x_flex: 1)
        hf.button(text: "Execute", sticky: 'e', on_click: :execute_sql)
      end
      @text = vf.text(value: @expression.to_s, width: 20, height: 5, scrollers: 'y',
                      x_flex: 1, y_flex: 1, sticky: 'news')
    end
    f.insert_component(TkComponent::TableViewComponent, self,
                       data_source: self,
                       columns: @results&.first&.keys&.map { |k| { key: k, text: k } } || [],
                       scrollers: 'xy',
                       sticky: 'nsew', x_flex: 1, y_flex: 1)
  end
end