rails_db 0.9.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/rails_db/tables_controller.rb +32 -14
- data/app/helpers/rails_db/application_helper.rb +0 -52
- data/app/views/rails_db/dashboard/index.html.erb +1 -1
- data/app/views/rails_db/sql/_explain.html.erb +1 -1
- data/app/views/rails_db/tables/_data.html.erb +11 -5
- data/app/views/rails_db/tables/_edit.html.erb +1 -1
- data/app/views/rails_db/tables/_new.html.erb +25 -0
- data/app/views/rails_db/tables/_sql.html.erb +7 -0
- data/app/views/rails_db/tables/create.js.erb +9 -0
- data/app/views/rails_db/tables/new.js.erb +7 -0
- data/config/routes.rb +2 -0
- data/lib/rails_db/version.rb +1 -1
- data/test/dashboard_controller_test.rb +8 -0
- data/test/dummy/db/rails_db.sqlite3 +0 -0
- data/test/dummy/db/rails_db_dev.sqlite3 +0 -0
- metadata +6 -4
- data/test/dummy/tmp/pids/server.pid +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b8edcd55cb5deaa338dde74868d85c838906507
|
4
|
+
data.tar.gz: 4f641001dc8e886869ed8644a6a7e9dff4575ae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48b2dc79959b7f7682f43cf6577b784db747aa8df3ad45325ca0922c65105ddca9b532bf5aabc62be1f9bf17c69e6044a5cb26ff136850c3b1166f9129049ae0
|
7
|
+
data.tar.gz: 553f9b1c71c073a75c3dd4f7c773dfaae90cc7d9def1b6a8e7ef589e70610cbc979b9d0cae92d755a5a456b0b6fbb28c8fff3e177282a4e14392187ee2c24cbe
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module RailsDb
|
2
2
|
class TablesController < RailsDb::ApplicationController
|
3
|
+
LOAD_TABLE_ACTIONS = [:show, :data, :csv, :truncate, :destroy, :edit, :update, :xlsx, :search, :new, :create]
|
4
|
+
|
3
5
|
if Rails::VERSION::MAJOR >= 4
|
4
|
-
before_action :find_table, only:
|
6
|
+
before_action :find_table, only: LOAD_TABLE_ACTIONS
|
5
7
|
else
|
6
|
-
before_filter :find_table
|
8
|
+
before_filter :find_table, only: LOAD_TABLE_ACTIONS
|
7
9
|
end
|
8
10
|
|
9
11
|
def index
|
@@ -13,14 +15,23 @@ module RailsDb
|
|
13
15
|
def show
|
14
16
|
end
|
15
17
|
|
18
|
+
def new
|
19
|
+
@record = model.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
@record = model.new(record_attributes)
|
24
|
+
@record.save!
|
25
|
+
build_search
|
26
|
+
respond_to do |page|
|
27
|
+
page.html { redirect_to action: :data, table_id: params[:table_id] }
|
28
|
+
page.js {}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
16
32
|
def data
|
17
33
|
session[:per_page] = per_page
|
18
|
-
|
19
|
-
@q = @model.ransack(params[:q])
|
20
|
-
@sql = @q.result.page(params[:page]).per(per_page).to_sql
|
21
|
-
@records = @q.result.page(params[:page]).per(per_page)
|
22
|
-
@q.build_condition if @q.conditions.empty?
|
23
|
-
@q.build_sort if @q.sorts.empty?
|
34
|
+
build_search
|
24
35
|
respond_to do |page|
|
25
36
|
page.html {}
|
26
37
|
page.js {}
|
@@ -41,12 +52,7 @@ module RailsDb
|
|
41
52
|
end
|
42
53
|
|
43
54
|
def destroy
|
44
|
-
|
45
|
-
@q = @model.ransack(params[:q])
|
46
|
-
@sql = @q.result.page(params[:page]).per(per_page).to_sql
|
47
|
-
@records = @q.result.page(params[:page]).per(per_page)
|
48
|
-
@q.build_condition if @q.conditions.empty?
|
49
|
-
@q.build_sort if @q.sorts.empty?
|
55
|
+
build_search
|
50
56
|
@table.delete(params[:pk_id])
|
51
57
|
respond_to do |page|
|
52
58
|
page.html { redirect_to action: :data, table_id: params[:table_id] }
|
@@ -73,6 +79,18 @@ module RailsDb
|
|
73
79
|
|
74
80
|
private
|
75
81
|
|
82
|
+
def build_search
|
83
|
+
@q = model.ransack(params[:q])
|
84
|
+
@sql = @q.result.page(params[:page]).per(per_page).to_sql
|
85
|
+
@records = @q.result.page(params[:page]).per(per_page)
|
86
|
+
@q.build_condition if @q.conditions.empty?
|
87
|
+
@q.build_sort if @q.sorts.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
def model
|
91
|
+
@model ||= @table.as_model
|
92
|
+
end
|
93
|
+
|
76
94
|
def record_attributes
|
77
95
|
if Rails::VERSION::MAJOR >= 4
|
78
96
|
params[:record].permit!
|
@@ -42,58 +42,6 @@ module RailsDb
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def paginate_table_entries(entries)
|
46
|
-
params.delete(:id)
|
47
|
-
return if entries.total_pages == 1
|
48
|
-
prev_page_text = "#{fa_icon('arrow-left')} Previous".html_safe
|
49
|
-
next_page_text = "Next #{fa_icon('arrow-right')}".html_safe
|
50
|
-
|
51
|
-
html = '<div class="pagination">'
|
52
|
-
if entries.previous_page
|
53
|
-
html << link_to(prev_page_text, params.merge({ action: :data, page: entries.previous_page }), { remote: true, class: 'page' })
|
54
|
-
end
|
55
|
-
html << "#{page_links_for_pagination(entries)}"
|
56
|
-
if entries.next_page
|
57
|
-
html << link_to(next_page_text, params.merge({ action: :data, page: entries.next_page }), { remote: true, class: 'page' })
|
58
|
-
end
|
59
|
-
html << '</div>'
|
60
|
-
|
61
|
-
sanitize(html)
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def page_links_for_pagination(entries)
|
67
|
-
pages = pages_for_pagination(entries)
|
68
|
-
links = []
|
69
|
-
|
70
|
-
pages.each_with_index do |page,index|
|
71
|
-
if page == entries.current_page
|
72
|
-
links << content_tag(:b, page, { class: 'page current' })
|
73
|
-
else
|
74
|
-
links << link_to(page, params.merge({ action: :data, page: page}), { remote: true, class: 'page' })
|
75
|
-
end
|
76
|
-
links << ' ... ' if page != pages.last && (page + 1) != pages[index+1]
|
77
|
-
end
|
78
|
-
|
79
|
-
links.join(' ')
|
80
|
-
end
|
81
|
-
|
82
|
-
def pages_for_pagination(entries)
|
83
|
-
last_page = entries.total_pages
|
84
|
-
current_page = entries.current_page
|
85
|
-
|
86
|
-
pages = if last_page > 10
|
87
|
-
[1, 2, 3] +
|
88
|
-
(current_page-2..current_page+2).to_a +
|
89
|
-
(last_page-2..last_page).to_a
|
90
|
-
else
|
91
|
-
(1..last_page).to_a
|
92
|
-
end
|
93
|
-
|
94
|
-
pages.uniq.select { |p| p > 0 && p <= last_page }
|
95
|
-
end
|
96
|
-
|
97
45
|
def db_hint_options
|
98
46
|
result = {}
|
99
47
|
RailsDb::Database.accessible_tables.each do |table_name|
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<ul>
|
9
9
|
<li>use command line tools `railsdb` and `runsql` to run app and sql for your apps.</li>
|
10
10
|
<li>view content and schema of DB tables (including indexes)</li>
|
11
|
-
<li>edit content</li>
|
11
|
+
<li>create, edit content</li>
|
12
12
|
<li>sort content of DB tables</li>
|
13
13
|
<li>filters support</li>
|
14
14
|
<li>execute SQL queries</li>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<div id="explain_modal" class="reveal-modal" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
|
2
|
-
<h2 id="modalTitle">Explain
|
2
|
+
<h2 id="modalTitle">Explain SQL</h2>
|
3
3
|
<p class="lead"><%= sql %></p>
|
4
4
|
<pre>
|
5
5
|
<% sql_query.explain.rows.each do |row| %>
|
@@ -1,6 +1,9 @@
|
|
1
1
|
<% title "'#{@table.name}'"%>
|
2
2
|
|
3
|
-
<h2>Table: <%= @table.name %></h2>
|
3
|
+
<h2 class='left'>Table: <%= @table.name %></h2>
|
4
|
+
<div class='right'>
|
5
|
+
<%= link_to '+ ADD', table_new_path(@table), remote: true, class: 'button small' %>
|
6
|
+
</div>
|
4
7
|
|
5
8
|
<div class='clear'></div>
|
6
9
|
|
@@ -68,7 +71,7 @@
|
|
68
71
|
<% end %>
|
69
72
|
<% @model.column_names.each do |column| %>
|
70
73
|
<th class="column_<%= column %>" style="<%= display_style_column(@table.name, column)%>">
|
71
|
-
<%= sort_link
|
74
|
+
<%= sort_link @q, column, controller: :tables, action: :data %>
|
72
75
|
</th>
|
73
76
|
<% end %>
|
74
77
|
</tr>
|
@@ -92,7 +95,7 @@
|
|
92
95
|
<th colspan="2">Actions</th>
|
93
96
|
<% end %>
|
94
97
|
<% @model.column_names.each do |column| %>
|
95
|
-
<th> <%= sort_link
|
98
|
+
<th> <%= sort_link @q, column, controller: :tables, action: :data %> </th>
|
96
99
|
<% end %>
|
97
100
|
</tr>
|
98
101
|
</tfoot>
|
@@ -102,6 +105,7 @@
|
|
102
105
|
|
103
106
|
<p>
|
104
107
|
<span class="radius success label">Total: <%= pluralize @records.total_count, 'record' %></span>
|
108
|
+
<span class="radius secondary label"><a href="#" data-reveal-id="sql_modal" id='sql_modal_link'>SQL</a></span>
|
105
109
|
</p>
|
106
110
|
|
107
111
|
<% if @records.total_count > 10 %>
|
@@ -112,8 +116,10 @@
|
|
112
116
|
</div>
|
113
117
|
|
114
118
|
<div class='left per_page_pagination'>
|
115
|
-
<%= paginate @records, remote: true %>
|
119
|
+
<%= paginate @records, remote: true, params: { controller: :tables, action: :data } %>
|
116
120
|
</div>
|
117
121
|
<% end %>
|
118
122
|
|
119
|
-
<div class='clear'></div>
|
123
|
+
<div class='clear'></div>
|
124
|
+
|
125
|
+
<%= render 'sql', sql: @sql %>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<div class='scrollable_form'>
|
7
7
|
<% @record.class.columns.each do |column| %>
|
8
8
|
<% name = column.name %>
|
9
|
-
<% next if name ==
|
9
|
+
<% next if name == @table.primary_key %>
|
10
10
|
|
11
11
|
<% if ['datetime', 'date', 'time'].include?(column.sql_type) %>
|
12
12
|
<div class='form-inline'>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<a class="close-reveal-modal" aria-label="Close">×</a>
|
2
|
+
|
3
|
+
<h2 id="modalTitle">New</h2>
|
4
|
+
|
5
|
+
<%= simple_form_for @record, as: 'record', url: table_create_path(@table, pk_id: @record[@table.primary_key]), remote: true, method: :post, html: {class: 'vertical_form'} do |form| %>
|
6
|
+
<div class='scrollable_form'>
|
7
|
+
<% @record.class.columns.each do |column| %>
|
8
|
+
<% name = column.name %>
|
9
|
+
<% next if [@table.primary_key, 'created_at', 'updated_at'].include?(column.name) %>
|
10
|
+
|
11
|
+
<% if ['datetime', 'date', 'time'].include?(column.sql_type) %>
|
12
|
+
<div class='form-inline'>
|
13
|
+
<%= form.input name, label: name, input_html: {class: 'date_or_time'} %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<% else %>
|
17
|
+
<%= form.input name, label: name %>
|
18
|
+
<% end %>
|
19
|
+
<% end %>
|
20
|
+
</div>
|
21
|
+
<%= form.submit 'SAVE', class: 'button small' %>
|
22
|
+
<a class='close' onclick="$('#system_modal').foundation('reveal', 'close');$">Close</a>
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
<span class="radius warning label">NOTE: Update will happen without any validations.</span>
|
data/config/routes.rb
CHANGED
data/lib/rails_db/version.rb
CHANGED
@@ -69,6 +69,14 @@ class DashboardControllerTest < ActionDispatch::IntegrationTest
|
|
69
69
|
assert_equal 200, status
|
70
70
|
edit_user.reload
|
71
71
|
assert_equal 'JOHN', edit_user.name
|
72
|
+
|
73
|
+
xhr :get, '/rails/db/tables/users/new'
|
74
|
+
assert_equal 200, status
|
75
|
+
|
76
|
+
assert_equal 1, User.count
|
77
|
+
xhr :post, '/rails/db/tables/users/create', {record: { name: 'XXX' }}
|
78
|
+
assert_equal 200, status
|
79
|
+
assert_equal 2, User.count
|
72
80
|
end
|
73
81
|
|
74
82
|
end
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -311,14 +311,18 @@ files:
|
|
311
311
|
- app/views/rails_db/tables/_condition_fields.html.erb
|
312
312
|
- app/views/rails_db/tables/_data.html.erb
|
313
313
|
- app/views/rails_db/tables/_edit.html.erb
|
314
|
+
- app/views/rails_db/tables/_new.html.erb
|
314
315
|
- app/views/rails_db/tables/_row.html.erb
|
315
316
|
- app/views/rails_db/tables/_search.html.erb
|
316
317
|
- app/views/rails_db/tables/_show.html.erb
|
318
|
+
- app/views/rails_db/tables/_sql.html.erb
|
319
|
+
- app/views/rails_db/tables/create.js.erb
|
317
320
|
- app/views/rails_db/tables/data.html.erb
|
318
321
|
- app/views/rails_db/tables/data.js.erb
|
319
322
|
- app/views/rails_db/tables/destroy.js.erb
|
320
323
|
- app/views/rails_db/tables/edit.js.erb
|
321
324
|
- app/views/rails_db/tables/index.html.erb
|
325
|
+
- app/views/rails_db/tables/new.js.erb
|
322
326
|
- app/views/rails_db/tables/show.html.erb
|
323
327
|
- app/views/rails_db/tables/show.js.erb
|
324
328
|
- app/views/rails_db/tables/table.xls.axlsx
|
@@ -443,7 +447,6 @@ files:
|
|
443
447
|
- test/dummy/test/models/legacy_account_test.rb
|
444
448
|
- test/dummy/test/models/project_test.rb
|
445
449
|
- test/dummy/test/models/user_test.rb
|
446
|
-
- test/dummy/tmp/pids/server.pid
|
447
450
|
- test/rails_db_data_table_helper_test.rb
|
448
451
|
- test/rails_db_test.rb
|
449
452
|
- test/sql_import_test.rb
|
@@ -611,7 +614,6 @@ test_files:
|
|
611
614
|
- test/dummy/test/models/legacy_account_test.rb
|
612
615
|
- test/dummy/test/models/project_test.rb
|
613
616
|
- test/dummy/test/models/user_test.rb
|
614
|
-
- test/dummy/tmp/pids/server.pid
|
615
617
|
- test/rails_db_data_table_helper_test.rb
|
616
618
|
- test/rails_db_test.rb
|
617
619
|
- test/sql_import_test.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
91954
|