8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/activeadmin/sqlpage.rb', line 8
def register
ActiveAdmin.register_page "SQL" do
priority: 1, label: "SQL"
content title: "SQL" do
columns do
column do
form action: admin_sql_query_path, method: :post do |f|
div class: :table_tools do
input type: :hidden,
name: :authenticity_token,
value: form_authenticity_token
textarea name: :sql,
onkeypress: %{
if(event.keyCode==10||(event.ctrlKey && event.keyCode==13)) {
$('form').submit();
}
}, autofocus: 1, title: 'Ctrl+Enter' do
params[:sql]
end
button :submit, title: 'Ctrl+Enter'
end
end
unless params[:sql].nil?
begin
result = ActiveRecord::Base.connection.exec_query( params[:sql] )
rescue Exception => e
result = ActiveRecord::Result.new( [:error], [[e.message]] )
end
table class: 'index_table index' do
thead do
tr do
result.columns.each do |name|
th name, class: :col
end
end
end
tbody do
result.rows.each_with_index do |col,i|
tr class: (0==i%2?'odd':'even') do
col.each do |val|
td val, class: :col
end
end
end
end
end
end
end
end
end
page_action :query, method: :post do
render action: :index, layout: false
end
end
end
|