db_admin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ <table class='table'>
2
+ <thead>
3
+ <% @dataset.columns.each_with_index do |column, i| %>
4
+ <% if i == 0 %>
5
+ <th></th>
6
+ <% end %>
7
+ <th>
8
+ <%= column %>
9
+ </th>
10
+ <% end %>
11
+ </thead>
12
+
13
+ <tbody>
14
+ <% @dataset.each_with_index do |row, row_num| %>
15
+ <tr id='tr<%= row_num %>' onmouseover='show_delete_button.call(this)' onmouseout='hide_delete_button.call(this)'>
16
+ <% @dataset.columns.each_with_index do |column, column_num| %>
17
+ <% if column_num == 0 && row[:id] %>
18
+ <td width='40px' id='<%= row[:id] %>'>
19
+ <a href='#_' onclick='delete_this_row.call(this)' style='display: none' title='Delete this row' data-url=<%= "/tables/#{params[:table_name]}/delete_one/#{row[:id]}" %>>Del</a>
20
+ </td>
21
+ <% end %>
22
+
23
+ <td id=<%= "td_#{row_num}_#{column_num}" %>>
24
+ <span title="<%= row[column] %>">
25
+ <%= show_column_text(row, column) %>
26
+ </span>
27
+
28
+ <% unless row[:id].nil? %>
29
+ <a style='display: none;' href='#' onclick='save_this_data.call(this)' data-url=<%= "/tables/#{params[:table_name]}/#{row[:id]}/#{column}" %>>Save</a>
30
+ <% end %>
31
+
32
+ <input type='text' value="<%= row[column] %>" style='display: none;' />
33
+ </td>
34
+ <% end %>
35
+ </tr>
36
+ <% end %>
37
+
38
+ <script>
39
+ $('.table').on('dblclick', 'span', function() {
40
+ $(this).closest('td').find('span').hide();
41
+ $(this).closest('td').find(':text').show();
42
+ $(this).closest('td').find(':text').select();
43
+ $(this).closest('td').find('a').show();
44
+ });
45
+
46
+ function save_this_data() {
47
+ $.ajax({
48
+ url: $(this).attr('data-url'),
49
+ data: 'new_value=' + $(this).closest('td').find(':text').val() + '&td_id=' + $(this).closest('td').attr('id'),
50
+ type: 'PUT',
51
+ success: function(data) {
52
+ $('#' + data['td_id']).find(':text').hide();
53
+ $('#' + data['td_id']).find('a').hide();
54
+ $('#' + data['td_id']).find('span').show();
55
+ $('#' + data['td_id']).find('span').attr('title', 'Save success! The original data before update is \n' + $('#' + data['td_id']).find('span').attr('title'));
56
+ $('#' + data['td_id']).find('span').html(data['new_value']);
57
+ },
58
+ error: function(jqXHR) {
59
+ alert('Save failed!\n' + $.parseJSON(jqXHR.responseText)['message']);
60
+ }
61
+ });
62
+ }
63
+
64
+ function delete_this_row() {
65
+ $.ajax({
66
+ url: $(this).attr('data-url'),
67
+ type: 'DELETE',
68
+ success: function(data) {
69
+ $('#' + data['id']).closest('tr').hide();
70
+ },
71
+ error: function() {
72
+ alert('Delete failed!');
73
+ }
74
+ });
75
+ }
76
+
77
+ function show_delete_button() {
78
+ $(this).find('td:first a').show();
79
+ }
80
+
81
+ function hide_delete_button() {
82
+ $(this).find('td:first a').hide();
83
+ }
84
+
85
+ function show_full_content() {
86
+ $(this).closest('span').html($(this).closest('span').attr('title'));
87
+ }
88
+
89
+ function belongs_to_table_find() {
90
+ $.ajax({
91
+ url: $(this).attr('data-url'),
92
+ data: 'rand_id=' + $(this).attr('data-rand-id'),
93
+ success: function(data) {
94
+ var result = '';
95
+ $.each(data, function(k, v) {
96
+ if ($.inArray(k, ['rand_id', 'table_name']) == -1) {
97
+ result += (k + ': ' + v + '<br>');
98
+ }
99
+ });
100
+ $('#ul_belongs_to_' + data['rand_id']).html(data['table_name'] + '<br>' + result);
101
+ },
102
+ error: function(jqXHR) {
103
+ var data = $.parseJSON(jqXHR.responseText);
104
+ $('#ul_belongs_to_' + data['rand_id']).html('id=' + data['id'] + ' not found in ' + data['table_name'] + ' !');
105
+ $('#ul_belongs_to_' + data['rand_id']).addClass('text-danger');
106
+ }
107
+ });
108
+ }
109
+ </script>
110
+ </tbody>
111
+ </table>
@@ -0,0 +1,41 @@
1
+ <%= notice_error %>
2
+
3
+ <div>
4
+ <h2>Connect to another database</h2>
5
+
6
+ <form action='connect_another_db' method="post">
7
+ <select name='adapter'>
8
+ <% puts adapter_hash %>
9
+ <% adapter_hash.reject!{ |k| k == :mysql }.each do |adapter_key, adapter_value| %>
10
+ <option value='<%= adapter_key %>' <%= 'selected' if database_adapter == adapter_value || adapter_key == params[:adapter] %>><%= adapter_value %></option>
11
+ <% end %>
12
+ </select>
13
+
14
+ <textarea name='connect_hash' cols='30' rows='5' class='form-control'><%= "host: '#{params[:host] || db_hash[:host] || '127.0.0.1' }'&#13;&#10;database: '#{params[:database] || db_hash[:database]}'&#13;&#10;user: '#{params[:user] || db_hash[:user]}'&#13;&#10;password: ''" %></textarea>
15
+
16
+ <button type='submit' class='btn btn-success'>Connect</button>
17
+ (You can also add 'port: ' to textarea.)
18
+ </form>
19
+ <br>
20
+ </div>
21
+
22
+ <div>
23
+ <h2>Usage</h2>
24
+ <b>Double click</b> to modify any column on the table pages.
25
+ <br>
26
+ <br>
27
+ </div>
28
+
29
+ <div>
30
+ <button type='button' class='btn btn-primary' onclick='show_sql_panel.call(this)'>Execute SQL</button>
31
+ <br>
32
+
33
+ <%= erb :_execute_sql %>
34
+
35
+ <br>
36
+ <br>
37
+ <br>
38
+ <br>
39
+ </div>
40
+
41
+ <a href='https://github.com/gazeldx/ruby-db-admin' target='_blank'>ruby-db-admin</a>@github
@@ -0,0 +1,40 @@
1
+ <%= notice_error %>
2
+
3
+ <div>
4
+ <h4>Connect to database</h4>
5
+
6
+ <form action='connect_another_db' method="post">
7
+ <select name='adapter'>
8
+ <% adapter_hash.reject!{ |k| k == :mysql }.each do |adapter_key, adapter_value| %>
9
+ <option value='<%= adapter_key %>' <%= 'selected' if adapter_key == params[:adapter] %>><%= adapter_value %></option>
10
+ <% end %>
11
+ </select>
12
+
13
+ <textarea name='connect_hash' cols='30' rows='5' class='form-control'><%= "host: '#{params[:host] || '127.0.0.1' }'&#13;&#10;database: '#{params[:database]}'&#13;&#10;user: '#{params[:user]}'&#13;&#10;password: ''" %></textarea>
14
+
15
+ <button type='submit' class='btn btn-success'>Connect</button>
16
+ (You can also add 'port: ' to textarea.)
17
+ </form>
18
+ <br>
19
+ </div>
20
+
21
+ <div>
22
+ <h4>Usage</h4>
23
+ <b>Double click</b> to modify any column on the table pages.
24
+ <br>
25
+ <br>
26
+ </div>
27
+
28
+ <div>
29
+ <button type='button' class='btn btn-primary' onclick='show_sql_panel.call(this)'>Execute SQL</button>
30
+ <br>
31
+
32
+ <%= erb :_execute_sql %>
33
+
34
+ <br>
35
+ <br>
36
+ <br>
37
+ <br>
38
+ </div>
39
+
40
+ <a href='https://github.com/gazeldx/ruby-db-admin' target='_blank'>ruby-db-admin</a>@github
@@ -0,0 +1,65 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <meta name='viewport' content='width=device-width, initial-scale=1'>
6
+ <title>Database</title>
7
+ <link href='/css/bootstrap.min.css' rel='stylesheet'>
8
+
9
+ <script src='/js/jquery.min.js'></script>
10
+ <script src='/js/bootstrap.min.js'></script>
11
+
12
+ <style>
13
+ select, button {
14
+ margin-top: 5px;
15
+ margin-bottom: 5px;
16
+ }
17
+
18
+ h1 a:link { color: #000000; }
19
+ h1 a:visited { color: #000000; }
20
+ h1 a:hover { color: #4666FF; }
21
+ </style>
22
+ </head>
23
+
24
+ <body>
25
+ <div class='container'>
26
+ <div>
27
+ <h1 title='Current database. Click to visit home page.'>
28
+ <a href='/home'><%= "#{database_adapter} - #{database_name}@#{database_host}" %></a>
29
+ </h1>
30
+ </div>
31
+
32
+ <div class='row'>
33
+ <div class='col-sm-2'>
34
+ <%= erb :_recent_databases %>
35
+
36
+ <hr>
37
+
38
+ <div class='sidebar-module'>
39
+ <h4>Tables</h4>
40
+ <ol class='list-unstyled'>
41
+ <% DB.tables.sort.each do |table_name| %>
42
+ <li><a href="/tables/<%= table_name %>"><%= table_name %></a></li>
43
+ <% end %>
44
+ </ol>
45
+ </div>
46
+
47
+ <hr>
48
+
49
+ <div class='sidebar-module'>
50
+ <h4>Views</h4>
51
+ <ol class='list-unstyled'>
52
+ <% DB.views.each do |view_name| %>
53
+ <li><a href="/views/<%= view_name %>"><%= view_name %></a></li>
54
+ <% end %>
55
+ </ol>
56
+ </div>
57
+ </div>
58
+
59
+ <div class='col-sm-10 blog-main'>
60
+ <%= yield %>
61
+ </div>
62
+ </div>
63
+ </div>
64
+ </body>
65
+ </html>
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <meta name='viewport' content='width=device-width, initial-scale=1'>
6
+ <title>Database</title>
7
+ <link href='/css/bootstrap.min.css' rel='stylesheet'>
8
+
9
+ <script src='/js/jquery.min.js'></script>
10
+ <script src='/js/bootstrap.min.js'></script>
11
+
12
+ <style>
13
+ select, button {
14
+ margin-top: 5px;
15
+ margin-bottom: 5px;
16
+ }
17
+
18
+ h1 a:link { color: #000000; }
19
+ h1 a:visited { color: #000000; }
20
+ h1 a:hover { color: #4666FF; }
21
+ </style>
22
+ </head>
23
+
24
+ <body>
25
+ <div class='container'>
26
+ <div>
27
+ <h1>
28
+ <a href='/'>Ruby Database Admin</a>
29
+ </h1>
30
+ </div>
31
+
32
+ <div class='row'>
33
+ <div class='col-sm-2'>
34
+ <%= erb :_recent_databases %>
35
+ </div>
36
+
37
+ <div class='col-sm-10 blog-main'>
38
+ <%= yield %>
39
+ </div>
40
+ </div>
41
+ </div>
42
+ </body>
43
+ </html>
@@ -0,0 +1,13 @@
1
+ <%= notice_error %>
2
+
3
+ <div class='panel panel-default'>
4
+ <div class='panel-heading'>
5
+ <h3 class='panel-title'>
6
+ <%= params[:sql] %>
7
+ </h3>
8
+ </div>
9
+
10
+ <%= erb :_table %>
11
+
12
+ <%= erb :_pagination %>
13
+ </div>
@@ -0,0 +1,23 @@
1
+ <%= notice_error %>
2
+
3
+ <div class='panel panel-default'>
4
+ <div class='panel-heading'>
5
+ <h3 class='panel-title'>
6
+ :<%= params[:table_name] %>
7
+
8
+ <%= erb :_operations %>
9
+ </h3>
10
+ </div>
11
+
12
+ <div class='panel-body'>
13
+ <%= erb :_execute_sql %>
14
+
15
+ <%= erb :_insert_panel %>
16
+
17
+ <%= erb :_schema %>
18
+ </div>
19
+
20
+ <%= erb :_table %>
21
+
22
+ <%= erb :_pagination %>
23
+ </div>
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: db_admin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lane Zhang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sequel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 'A Web to manage databases. Support PostgerSQL, MySQL, SQLite, Oracle,
42
+ MS-SQL, SQLAnywhere, DB2, Access, etc.
43
+
44
+ '
45
+ email: zjloveztt@gmail.com
46
+ executables:
47
+ - db_admin
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - README.md
52
+ - bin/db_admin
53
+ - lib/db_admin.rb
54
+ - lib/public/css/bootstrap.min.css
55
+ - lib/public/demo_home.png
56
+ - lib/public/demo_hover.png
57
+ - lib/public/demo_oprations.png
58
+ - lib/public/js/bootstrap.min.js
59
+ - lib/public/js/jquery.min.js
60
+ - lib/views/_execute_sql.erb
61
+ - lib/views/_insert_panel.erb
62
+ - lib/views/_operations.erb
63
+ - lib/views/_pagination.erb
64
+ - lib/views/_recent_databases.erb
65
+ - lib/views/_schema.erb
66
+ - lib/views/_table.erb
67
+ - lib/views/home.erb
68
+ - lib/views/index.erb
69
+ - lib/views/layout.erb
70
+ - lib/views/layout_index.erb
71
+ - lib/views/select_sql.erb
72
+ - lib/views/table.erb
73
+ homepage: https://github.com/gazeldx/ruby-db-admin
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.0.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A Web for database admin!
96
+ test_files: []