rails_db 0.7.2 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6b56dd1eb7a49cc7c77519b6f5679bd55987b03
4
- data.tar.gz: cc7a02d441486ac40934af7fb03bc3bcab17b9c2
3
+ metadata.gz: 549de677a4e83f22444e963e0ab6ca6c35066b77
4
+ data.tar.gz: 30a2294ea9e10ed00b3801ad9e4bd63a2d9eaeef
5
5
  SHA512:
6
- metadata.gz: 6260b0ef99dcccbef87987f9226a74033b0f3a8cddbf60acdfcb972260f3cd2ab4eb0066aee014c8f271d726543755cc32a6ad697ab0d03699974bd9f4d4427f
7
- data.tar.gz: ef67819e6f10057129450fccab2e54a44c0ebbc074dad5035aa0d7d8f98c2cb573201dda79b71a1172823896fdaff7902c9e21db86896833ecef2d9854dce5ee
6
+ metadata.gz: 3d6ba65479b6f329d53a04d6bd2bc663aec5ab9737cb87bfee3de43b5858106669d023d06c7be9ec2a0ebc4194ca7e35aadfb6bb24e8512eff309cbe43717253
7
+ data.tar.gz: f76cc094514cff3e4c4604dada282b9a364d38a7866ccff5691a65014ae66e698621fa29680fc1ded01bdbd8cf107b7d12019709d6070a53d10945f684e9b9db
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gem 'jquery-rails'
8
8
  gem 'font-awesome-rails'
9
9
  gem 'codemirror-rails'
10
10
  gem 'terminal-table'
11
+ gem 'axlsx_rails'
11
12
 
12
13
  group :assets do
13
14
  gem 'sass-rails'
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_db (0.7.1)
4
+ rails_db (0.8)
5
+ axlsx_rails
5
6
  codemirror-rails
6
7
  font-awesome-rails
7
8
  jquery-rails
@@ -51,6 +52,13 @@ GEM
51
52
  tzinfo (~> 1.1)
52
53
  addressable (2.3.8)
53
54
  arel (6.0.3)
55
+ axlsx (2.0.1)
56
+ htmlentities (~> 4.3.1)
57
+ nokogiri (>= 1.4.1)
58
+ rubyzip (~> 1.0.0)
59
+ axlsx_rails (0.4.0)
60
+ axlsx (>= 2.0.1)
61
+ rails (>= 3.1)
54
62
  builder (3.2.2)
55
63
  codemirror-rails (5.6)
56
64
  railties (>= 3.0, < 5)
@@ -60,6 +68,7 @@ GEM
60
68
  railties (>= 3.2, < 5.0)
61
69
  globalid (0.3.6)
62
70
  activesupport (>= 4.1.0)
71
+ htmlentities (4.3.4)
63
72
  i18n (0.7.0)
64
73
  jquery-rails (4.0.5)
65
74
  rails-dom-testing (~> 1.0)
@@ -107,6 +116,7 @@ GEM
107
116
  rake (>= 0.8.7)
108
117
  thor (>= 0.18.1, < 2.0)
109
118
  rake (10.4.2)
119
+ rubyzip (1.0.0)
110
120
  sass (3.4.19)
111
121
  sass-rails (5.0.4)
112
122
  railties (>= 4.0.0, < 5.0)
@@ -135,6 +145,7 @@ PLATFORMS
135
145
  ruby
136
146
 
137
147
  DEPENDENCIES
148
+ axlsx_rails
138
149
  codemirror-rails
139
150
  font-awesome-rails
140
151
  jquery-rails
@@ -1,13 +1,29 @@
1
1
  //= require jquery
2
2
  //= require jquery_ujs
3
+ //= require rails_db/foundation/foundation.abide
4
+ //= require rails_db/foundation/foundation.accordion
5
+ //= require rails_db/foundation/foundation.alert
6
+ //= require rails_db/foundation/foundation.clearing
7
+ //= require rails_db/foundation/foundation.dropdown
8
+ //= require rails_db/foundation/foundation.equalizer
9
+ //= require rails_db/foundation/foundation.interchange
10
+ //= require rails_db/foundation/foundation.joyride
3
11
  //= require rails_db/foundation.min
4
- //= require_tree ../rails_db/foundation/
12
+ //= require rails_db/foundation/foundation.magellan
13
+ //= require rails_db/foundation/foundation.offcanvas
14
+ //= require rails_db/foundation/foundation.orbit
15
+ //= require rails_db/foundation/foundation.reveal
16
+ //= require rails_db/foundation/foundation.slider
17
+ //= require rails_db/foundation/foundation.tab
18
+ //= require rails_db/foundation/foundation.tooltip
19
+ //= require rails_db/foundation/foundation.topbar
5
20
  //= require rails_db/sticky
6
21
  //= require rails_db/jquery.cookie
7
22
  //= require codemirror
8
23
  //= require codemirror/modes/sql
9
24
  //= require codemirror/addons/hint/show-hint.js
10
25
  //= require codemirror/addons/hint/sql-hint.js
26
+ //= require rails_db/show_hide_columns.js
11
27
 
12
28
  $(function(){
13
29
  $(document).foundation();
@@ -76,4 +92,4 @@ function init_sql_editor(mime, tables) {
76
92
  });
77
93
  editor.setSize('100%', '300');
78
94
  editor.focus();
79
- };
95
+ };
@@ -0,0 +1,54 @@
1
+ $(function(){
2
+
3
+ $('body').on('click', '.settings-link', function() {
4
+ $('.rails-db-settings').toggle();
5
+ });
6
+
7
+ $('body').on('click', '.column-name input', function() {
8
+ table_name = 'Table: ' + $('a[table_name]').attr('table_name');
9
+ column_name = $(this).prop('name');
10
+ if($(this).prop('checked') == false) {
11
+ write_column_to_cookie(table_name, column_name);
12
+ } else {
13
+ remove_column_from_cookie(table_name, column_name);
14
+ }
15
+ switch_column_visibility(column_name);
16
+ toggle_columns();
17
+ });
18
+
19
+ });
20
+
21
+ function write_column_to_cookie(table_name, column_name) {
22
+ column_names = get_column_names_from_cookie(table_name);
23
+ $.cookie(table_name, column_names += ',' + column_name);
24
+ };
25
+
26
+ function remove_column_from_cookie(table_name, column_name) {
27
+ column_names = get_column_names_from_cookie(table_name);
28
+ $.cookie(table_name, column_names.replace(',' + column_name, ''));
29
+ };
30
+
31
+ function get_column_names_from_cookie(table_name) {
32
+ cookie = $.cookie(table_name);
33
+ if(cookie == undefined) {
34
+ return '';
35
+ } else {
36
+ return cookie;
37
+ }
38
+ };
39
+
40
+ function switch_column_visibility(column_name) {
41
+ $('th.column_' + column_name).toggle();
42
+ $('td.column_' + column_name).toggle();
43
+ };
44
+
45
+ function toggle_columns() {
46
+ if($('.column-name input:checked').length == 0) {
47
+ $('.column-name input[type=checkbox]').each(function() {
48
+ column_name = $(this).prop('name');
49
+ $(this).prop("checked", true);
50
+ remove_column_from_cookie(table_name, column_name);
51
+ switch_column_visibility(column_name);
52
+ });
53
+ }
54
+ };
@@ -4,4 +4,9 @@ span.pk {
4
4
 
5
5
  .delete_td {
6
6
  width: 24px;
7
+ }
8
+
9
+ .column-name {
10
+ float: left;
11
+ width: 20%;
7
12
  }
@@ -15,6 +15,11 @@ module RailsDb
15
15
  send_data(@sql_query.to_csv, type: 'text/csv; charset=utf-8; header=present', filename: 'results.csv')
16
16
  end
17
17
 
18
+ def xls
19
+ load_query
20
+ render xlsx: 'xls', filename: 'results.xlsx'
21
+ end
22
+
18
23
  def import
19
24
  end
20
25
 
@@ -41,5 +41,10 @@ module RailsDb
41
41
  end
42
42
  end
43
43
 
44
+ def xlsx
45
+ @table = RailsDb::Table.new(params[:table_id])
46
+ render xlsx: 'table', filename: "#{@table.name}.xlsx"
47
+ end
48
+
44
49
  end
45
50
  end
@@ -43,5 +43,17 @@ module RailsDb
43
43
  params.merge({action: :data})
44
44
  end
45
45
 
46
+ def column_is_checked?(table_name, column_name)
47
+ if cookies["Table: #{table_name}"].present?
48
+ !cookies["Table: #{table_name}"].split(',').include?(column_name)
49
+ else
50
+ true
51
+ end
52
+ end
53
+
54
+ def display_style_column(table_name, column_name)
55
+ column_is_checked?(table_name, column_name) ? 'display' : 'display:none'
56
+ end
57
+
46
58
  end
47
59
  end
@@ -14,7 +14,8 @@
14
14
  <li>filter tables for easier navigation</li>
15
15
  <li>use history of your SQL queries</li>
16
16
  <li>see EXPLAIN results for your queries</li>
17
- <li>export data to CSV</li>
17
+ <li>export data to CSV and Excel</li>
18
+ <li>hide/show columns</li>
18
19
  <li>import SQL files</li>
19
20
  <li>expand/collapse sidebar</li>
20
21
  <li>experience added HTTP_BASIC auth for Rails DB</li>
@@ -5,7 +5,8 @@
5
5
  <span class="radius success label">Total: <%= pluralize sql_query.data.count, 'record' %></span>
6
6
  <span class="radius info label">Time: <%= sql_query.data.time %> seconds</span>
7
7
  <span class="radius secondary label"><a href="#" data-reveal-id="explain_modal" id='explain_modal_link'>Explain</a></span>
8
- <span class="radius warning label"><%= link_to raw("#{fa_icon('file-excel-o')} Export"), sql_csv_path(sql: sql), method: :post %></span>
8
+ <span class="radius warning label"><%= link_to raw("#{fa_icon('file-text-o')} Export to CSV"), sql_csv_path(sql: sql, format: 'csv'), method: :post %></span>
9
+ <span class="radius warning label"><%= link_to raw("#{fa_icon('file-excel-o')} Export to Excel"), sql_xls_path(sql: sql, format: 'xls'), method: :post %></span>
9
10
  </p>
10
11
  <hr>
11
12
  <%= render 'explain', sql_query: sql_query, sql: sql %>
@@ -0,0 +1,9 @@
1
+ wb = xlsx_package.workbook
2
+
3
+ wb.add_worksheet(name: 'Results') do |sheet|
4
+ sheet.add_row @sql_query.data.columns
5
+
6
+ @sql_query.data.rows.each do |row|
7
+ sheet.add_row row
8
+ end
9
+ end
@@ -11,26 +11,45 @@
11
11
  <dd class="active"><%= link_to raw("#{fa_icon('table')} Records"), table_data_path(@table), remote: true %></dd>
12
12
  <dd><%= link_to raw("#{fa_icon('tasks')} Schema"), table_path(@table), remote: true %></dd>
13
13
  <dd><%= select_top_from_table(@table.name) %></dd>
14
- <dd><%= link_to raw("#{fa_icon('file-excel-o')} Export"), table_csv_path(@table) %></dd>
14
+ <dd>
15
+ <a href="#" data-options="align: bottom" data-dropdown="download-files"><%= fa_icon 'download' %> Export</a>
16
+ </dd>
15
17
  <dd>
16
18
  <a href="#" data-options="align: bottom" data-dropdown="drop"><%= fa_icon 'th-large' %> Functions</a>
17
19
  </dd>
20
+ <dd class="right"><%= link_to raw("#{fa_icon('cogs')} Settings"), '#', :class => 'settings-link', :table_name => "#{@table.name}" %></dd>
18
21
  </dl>
22
+ <div class="clearfix"></div>
23
+
19
24
 
20
25
  <ul id="drop" class="f-dropdown" data-dropdown-content>
21
- <li><%= link_to raw("#{fa_icon('trash-o')} Truncate Table"), table_truncate_path(@table), remote: true, confirm: 'Are you sure?', data: {confirm: 'Are you sure?'} %></a></li>
26
+ <li><%= link_to raw("#{fa_icon('trash-o')} Truncate Table"), table_truncate_path(@table), data: {confirm: 'Are you sure?'} %></li>
27
+ </ul>
28
+
29
+ <ul id="download-files" class="f-dropdown" data-dropdown-content>
30
+ <li><%= link_to raw("#{fa_icon('file-text-o')} Export to CSV"), table_csv_path(@table) %></li>
31
+ <li><%= link_to raw("#{fa_icon('file-excel-o')} Export to Excel"), table_xlsx_path(@table, format: 'xls') %></li>
22
32
  </ul>
23
33
 
24
34
  <div class='scrollable'>
25
- <table>
35
+ <div class='rails-db-settings' style="display:none">
36
+ <h6>Settings</h6>
37
+ <% @table.columns.each do |column| %>
38
+ <label class='column-name'>
39
+ <%= check_box_tag(column.name, nil, column_is_checked?(@table.name, column.name), class: "#{column.name}") %>
40
+ <%= column.name %>
41
+ </label>
42
+ <% end %>
43
+ </div>
26
44
 
45
+ <table>
27
46
  <thead>
28
47
  <tr>
29
48
  <% if @table.primary_key.present? %>
30
49
  <th class='delete_td'></th>
31
50
  <% end %>
32
51
  <% @table.columns.each do |column| %>
33
- <th>
52
+ <th class="column_<%= column.name %>" style=<%= display_style_column(@table.name, column.name) %>>
34
53
  <%= sortable column.name %>
35
54
  </th>
36
55
  <% end %>
@@ -49,7 +68,7 @@
49
68
  <% end %>
50
69
 
51
70
  <% @table.columns.each do |column| %>
52
- <td>
71
+ <td class="column_<%= column.name %>" style=<%= display_style_column(@table.name, column.name) %>>
53
72
  <% name = column.name %>
54
73
  <%= format_value(column, record[name]) %>
55
74
  </td>
@@ -0,0 +1,9 @@
1
+ wb = xlsx_package.workbook
2
+
3
+ wb.add_worksheet(name: @table.name) do |sheet|
4
+ sheet.add_row @table.columns.map(&:name)
5
+
6
+ @table.data.each do |row|
7
+ sheet.add_row row.values
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ Mime::Type.register "application/vnd.ms-excel", :xls unless Mime::Type.lookup_by_extension(:xls)
@@ -6,12 +6,15 @@ RailsDb::Engine.routes.draw do
6
6
  get 'csv'
7
7
  get 'truncate'
8
8
  get 'destroy' # to handle opens in new window (GET)
9
+ get 'xlsx'
9
10
  end
10
11
 
11
12
  get '/sql' => 'sql#index', as: :sql
12
13
  get '/import' => 'sql#import', as: :sql_import
14
+
13
15
  post '/execute' => 'sql#execute', as: :sql_execute
14
16
  post '/sql-csv' => 'sql#csv', as: :sql_csv
17
+ post '/sql-xls' => 'sql#xls', as: :sql_xls
15
18
  post '/import-start' => 'sql#import_start', as: :sql_start_import
16
19
 
17
20
  get '/data-table' => 'dashboard#data_table', as: :data_table
@@ -6,6 +6,7 @@ require "jquery-rails"
6
6
  require 'codemirror-rails'
7
7
  require 'terminal-table'
8
8
  require 'csv'
9
+ require 'axlsx_rails'
9
10
 
10
11
  module RailsDb
11
12
  # Custom require relative that work with older rubies also
@@ -1,3 +1,3 @@
1
1
  module RailsDb
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8"
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = ["igorkasyanchuk@gmail.com"]
10
10
  s.homepage = "https://github.com/igorkasyanchuk/rails_db"
11
11
  s.summary = "Inspect your Rails DB (table content viewer, execute sql queries, export & import data"
12
- s.description = "Quick way to inspect your Rails database, see content of tables, export them to CSV, EXPLAIN SQL and run SQL queries."
12
+ s.description = "Quick way to inspect your Rails database, see content of tables, filter, export them to CSV, Excel, EXPLAIN SQL and run SQL queries."
13
13
  s.license = "MIT"
14
14
 
15
15
  s.files = Dir["{app,config,lib,test}/**/*", "rails_db.gemspec", "Gemfile", "Gemfile.lock", "MIT-LICENSE", "Rakefile", "README.rdoc", "bin/rails_db", "bin/railsdb", "bin/runsql"]
@@ -25,8 +25,11 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency 'codemirror-rails'
26
26
  s.add_dependency 'launchy'
27
27
  s.add_dependency 'terminal-table'
28
+ s.add_dependency 'axlsx_rails'
28
29
 
29
30
  s.add_development_dependency "sqlite3"
30
31
  s.add_development_dependency "mysql2", '<= 0.3.20'
31
32
  s.add_development_dependency "pg"
32
- end
33
+ # s.add_development_dependency 'populator'
34
+ # s.add_development_dependency 'faker'
35
+ end
@@ -43,11 +43,23 @@ class DashboardControllerTest < ActionDispatch::IntegrationTest
43
43
  assert_equal 302, status
44
44
  assert_equal 0, User.count
45
45
 
46
- get '/rails/db/tables/accounts/csv'
46
+ get '/rails/db/tables/users/csv'
47
47
  assert_equal 200, status
48
48
 
49
49
  get '/rails/db/standalone'
50
50
  assert_equal 200, status
51
+
52
+ get '/rails/db/tables/users/xlsx.xls'
53
+ assert_equal 200, status
54
+
55
+ get '/rails/db/sql?sql=select+%2A+from+users+limit+10'
56
+ assert_equal 200, status
57
+
58
+ post '/rails/db/sql-csv.csv?sql=select+%2A+from+users+limit+10'
59
+ assert_equal 200, status
60
+
61
+ post '/rails/db/sql-xls.xls?sql=select+%2A+from+users+limit+10'
62
+ assert_equal 200, status
51
63
  end
52
64
 
53
65
  end
@@ -6,6 +6,7 @@ gem 'jquery-rails'
6
6
  gem 'font-awesome-rails'
7
7
  gem 'codemirror-rails'
8
8
  gem 'terminal-table'
9
+ gem 'axlsx_rails'
9
10
 
10
11
  group :assets do
11
12
  gem 'sass-rails'
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class TablesHelperTest < ActionView::TestCase
4
+ include RailsDb::TablesHelper
5
+
6
+ def setup
7
+ clean_db
8
+ end
9
+
10
+ test "method column_is_checked? returns true for checkbox status if cookie does not contain hash_key for this table" do
11
+ status = column_is_checked?('users', 'created_at')
12
+ assert_equal true, status
13
+ end
14
+
15
+ test "method column_is_checked? returns true for checkbox status if cookie does not contain record for this table:column" do
16
+ cookies['Table: users'] = 'created_at,'
17
+ status = column_is_checked?('users', 'name')
18
+ assert_equal true, status
19
+ end
20
+
21
+ test "method column_is_checked? returns false for checkbox status if cookie contains record for this table:column" do
22
+ cookies['Table: users'] = 'created_at,'
23
+ status = column_is_checked?('users', 'created_at')
24
+ assert_equal false, status
25
+ end
26
+
27
+ test "method display_style_column returns 'display:none' if cookie contains record for this table:column" do
28
+ cookies['Table: users'] = 'created_at,'
29
+ style = display_style_column('users', 'created_at')
30
+ assert_equal 'display:none', style
31
+ end
32
+
33
+ test "method display_style_column returns 'display' if cookie does not contain record for this table:column" do
34
+ cookies['Table: users'] = 'created_at,'
35
+ style = display_style_column('users', 'name')
36
+ assert_equal 'display', style
37
+ end
38
+
39
+ end
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.7.2
4
+ version: '0.8'
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-05 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: axlsx_rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: sqlite3
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -164,8 +178,8 @@ dependencies:
164
178
  - - ">="
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0'
167
- description: Quick way to inspect your Rails database, see content of tables, export
168
- them to CSV, EXPLAIN SQL and run SQL queries.
181
+ description: Quick way to inspect your Rails database, see content of tables, filter,
182
+ export them to CSV, Excel, EXPLAIN SQL and run SQL queries.
169
183
  email:
170
184
  - igorkasyanchuk@gmail.com
171
185
  executables:
@@ -207,6 +221,7 @@ files:
207
221
  - app/assets/javascripts/rails_db/foundation/foundation.tooltip.js
208
222
  - app/assets/javascripts/rails_db/foundation/foundation.topbar.js
209
223
  - app/assets/javascripts/rails_db/jquery.cookie.js
224
+ - app/assets/javascripts/rails_db/show_hide_columns.js
210
225
  - app/assets/javascripts/rails_db/sticky.js
211
226
  - app/assets/javascripts/rails_db/vendor/fastclick.js
212
227
  - app/assets/javascripts/rails_db/vendor/jquery.cookie.js
@@ -247,6 +262,7 @@ files:
247
262
  - app/views/rails_db/sql/_results.html.erb
248
263
  - app/views/rails_db/sql/import.html.erb
249
264
  - app/views/rails_db/sql/index.html.erb
265
+ - app/views/rails_db/sql/xls.xls.axlsx
250
266
  - app/views/rails_db/tables/_data.html.erb
251
267
  - app/views/rails_db/tables/_show.html.erb
252
268
  - app/views/rails_db/tables/data.html.erb
@@ -255,10 +271,12 @@ files:
255
271
  - app/views/rails_db/tables/index.html.erb
256
272
  - app/views/rails_db/tables/show.html.erb
257
273
  - app/views/rails_db/tables/show.js.erb
274
+ - app/views/rails_db/tables/table.xls.axlsx
258
275
  - bin/rails_db
259
276
  - bin/railsdb
260
277
  - bin/runsql
261
278
  - config/database.travis.yml
279
+ - config/initializers/mime_types.rb
262
280
  - config/routes.rb
263
281
  - lib/ext/string_ext.rb
264
282
  - lib/generators/USAGE
@@ -425,6 +443,7 @@ files:
425
443
  - test/standalone/public/500.html
426
444
  - test/standalone/public/favicon.ico
427
445
  - test/table_test.rb
446
+ - test/tables_helper_test.rb
428
447
  - test/test_helper.rb
429
448
  - test/test_sql_mysql.sql
430
449
  - test/test_sql_postgres.sql
@@ -590,6 +609,7 @@ test_files:
590
609
  - test/standalone/Rakefile
591
610
  - test/standalone/README.rdoc
592
611
  - test/table_test.rb
612
+ - test/tables_helper_test.rb
593
613
  - test/test_helper.rb
594
614
  - test/test_sql_mysql.sql
595
615
  - test/test_sql_postgres.sql