Class: TkInspectRails::SqlPanel::RootComponent

Inherits:
TkComponent::Base
  • Object
show all
Defined in:
lib/tk_inspect_rails/sql_panel/root_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expressionObject

Returns the value of attribute expression.



5
6
7
# File 'lib/tk_inspect_rails/sql_panel/root_component.rb', line 5

def expression
  @expression
end

#resultsObject

Returns the value of attribute results.



6
7
8
# File 'lib/tk_inspect_rails/sql_panel/root_component.rb', line 6

def results
  @results
end

#sql_panelObject

Returns the value of attribute sql_panel.



4
5
6
# File 'lib/tk_inspect_rails/sql_panel/root_component.rb', line 4

def sql_panel
  @sql_panel
end

Instance Method Details

#execute_sql(e) ⇒ Object



30
31
32
33
34
# 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) ⇒ Object



26
27
28
# File 'lib/tk_inspect_rails/sql_panel/root_component.rb', line 26

def items_for_path(path)
  @results || []
end

#render(p, parent_component) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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